[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnet/support spawn.c,1.6,1.7
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnet/support spawn.c,1.6,1.7 |
Date: |
Sat, 08 Feb 2003 19:11:18 -0500 |
Update of /cvsroot/dotgnu-pnet/pnet/support
In directory subversions:/tmp/cvs-serv2744/support
Modified Files:
spawn.c
Log Message:
Add "ILSpawnProcessWithPipe" to allow the standard output of a command to be
captured.
Index: spawn.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/support/spawn.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** spawn.c 16 Dec 2002 06:26:13 -0000 1.6
--- spawn.c 9 Feb 2003 00:11:16 -0000 1.7
***************
*** 2,6 ****
* spawn.c - Spawn child processes.
*
! * Copyright (C) 2001 Southern Storm Software, Pty Ltd.
*
* This program is free software; you can redistribute it and/or modify
--- 2,6 ----
* spawn.c - Spawn child processes.
*
! * Copyright (C) 2001-2003 Southern Storm Software, Pty Ltd.
*
* This program is free software; you can redistribute it and/or modify
***************
*** 207,210 ****
--- 207,222 ----
}
+ int ILSpawnProcessWithPipe(char *argv[], void **stream)
+ {
+ /* Not supported */
+ return 0;
+ }
+
+ int ILSpawnProcessWaitForExit(int pid, char *argv[])
+ {
+ /* Not supported */
+ return 1;
+ }
+
#else
#if defined(HAVE_FORK) && defined(HAVE_EXECV) && (defined(HAVE_WAITPID) ||
defined(HAVE_WAIT))
***************
*** 261,293 ****
{
/* We are in the parent process */
! int status = 1;
! #ifdef HAVE_WAITPID
! waitpid(pid, &status, 0);
! #else
! int result;
! while((result = wait(&status)) != pid && result != -1)
! {
! /* Some other child fell: not the one we are interested
in */
! }
! #endif
! if(WIFEXITED(status))
! {
! /* Return the child's exit status as the final status */
! return WEXITSTATUS(status);
! }
! else if(WIFSIGNALLED(status) &&
! (ImportantSignal(WTERMSIG(status)) ||
WCOREDUMP(status)))
! {
! /* Some kind of signal occurred */
! fprintf(stderr, "%s: exited with signal %d%s\n",
! argv[0], (int)(WTERMSIG(status)),
! (WCOREDUMP(status) ? " (core dumped)" :
""));
! return -1;
! }
! else
{
! /* Some other kind of signal or error */
return -1;
}
}
}
--- 273,359 ----
{
/* We are in the parent process */
! return ILSpawnProcessWaitForExit(pid, argv);
! }
! }
!
! int ILSpawnProcessWithPipe(char *argv[], void **stream)
! {
! int pipefds[2];
! int pid;
!
! /* Initialize the return stream */
! *stream = 0;
!
! /* Create a pipe to capture the child's stdout */
! if(pipe(pipefds) < 0)
! {
! perror("pipe");
! return -1;
! }
!
! /* Launch the child process */
! pid = fork();
! if(pid < 0)
! {
! /* Could not fork the child process */
! perror("fork");
! return -1;
! }
! else if(pid == 0)
! {
! /* We are in the child process */
! dup2(pipefds[1], 1);
! close(pipefds[0]);
! close(pipefds[1]);
! execvp(argv[0], argv);
! perror(argv[0]);
! exit(1);
! return -1; /* Keep the compiler happy */
! }
! else
! {
! /* We are in the parent process */
! close(pipefds[1]);
! *stream = fdopen(pipefds[0], "r");
! if(!(*stream))
{
! perror("fdopen");
! close(pipefds[0]);
return -1;
}
+ return pid;
+ }
+ }
+
+ int ILSpawnProcessWaitForExit(int pid, char *argv[])
+ {
+ int status = 1;
+ #ifdef HAVE_WAITPID
+ waitpid(pid, &status, 0);
+ #else
+ int result;
+ while((result = wait(&status)) != pid && result != -1)
+ {
+ /* Some other child fell: not the one we are interested in */
+ }
+ #endif
+ if(WIFEXITED(status))
+ {
+ /* Return the child's exit status as the final status */
+ return WEXITSTATUS(status);
+ }
+ else if(WIFSIGNALLED(status) &&
+ (ImportantSignal(WTERMSIG(status)) || WCOREDUMP(status)))
+ {
+ /* Some kind of signal occurred */
+ fprintf(stderr, "%s: exited with signal %d%s\n",
+ argv[0], (int)(WTERMSIG(status)),
+ (WCOREDUMP(status) ? " (core dumped)" : ""));
+ return -1;
+ }
+ else
+ {
+ /* Some other kind of signal or error */
+ return -1;
}
}
***************
*** 302,305 ****
--- 368,383 ----
{
fputs("Don't know how to spawn child processes on this system\n",
stderr);
+ return -1;
+ }
+
+ int ILSpawnProcessWithPipe(char *argv[], void **stream)
+ {
+ /* Not supported */
+ return 0;
+ }
+
+ int ILSpawnProcessWaitForExit(int pid, char *argv[])
+ {
+ /* Not supported */
return -1;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnet/support spawn.c,1.6,1.7,
Rhys Weatherley <address@hidden> <=