connectionMgr/inc/system.h File Reference

#include <sys/types.h>
#include <unistd.h>

Go to the source code of this file.

Functions

pid_t fork_exec_no_wait (const int argc, char *const argv[])
int fork_exec (const int argc, char *const argv[])
pid_t get_forkexec_child_pid (void)


Function Documentation

int fork_exec ( const int  argc,
char *const   argv[] 
)

Definition at line 85 of file system.c.

00086 {
00087     int   ret = -1;
00088     pid_t pid;
00089     int   status;
00090 
00091     CN_LOGPRINTF("entry: [%s]", argv[0]);
00092     g_assert(g_forkexec_child_pid == 0);
00093 
00094     // start child process
00095     pid = fork_exec_no_wait(argc, argv);
00096     if (pid > 0)
00097     {
00098         // child process started, wait for child and return its exit value
00099         g_forkexec_child_pid = pid;
00100         waitpid(pid, &status, 0);
00101         CN_WARNPRINTF("WIFEXITED [%d]", WIFEXITED(status));
00102         if (WIFEXITED(status))
00103         {
00104             CN_WARNPRINTF("WEXITSTATUS [%d]", WEXITSTATUS(status));
00105             ret = WEXITSTATUS(status);
00106         }
00107         g_forkexec_child_pid = 0;
00108     }
00109 
00110     return ret;
00111 }

Here is the call graph for this function:

pid_t fork_exec_no_wait ( const int  argc,
char *const   argv[] 
)

Definition at line 49 of file system.c.

00050 {
00051     pid_t pid = 0;
00052     int   rc;
00053 
00054     CN_LOGPRINTF("entry: [%s]", argv[0]);
00055     g_assert(argv[argc] == NULL);
00056     
00057     // spawn child process
00058     switch (pid = fork())
00059     {
00060         case 0:
00061             // child process: execute command
00062             rc = execvp(argv[0], argv);
00063             CN_ERRORPRINTF("execvp [%s] returns [%d] errno [%d] - %s", 
00064                            argv[0], rc, errno, strerror(errno));
00065             g_assert_not_reached();
00066             exit(1);
00067 
00068         case -1:
00069             // error: fork failed
00070             CN_ERRORPRINTF("fork returns [%d] errno [%d] - %s", 
00071                            pid, errno, strerror(errno));
00072             g_assert_not_reached();
00073             exit(1);
00074 
00075         default:
00076             // parent process: report child's pid
00077             CN_WARNPRINTF("my pid [%d] child pid [%d]", getpid(), pid);
00078             return pid;
00079     }
00080 }

pid_t get_forkexec_child_pid ( void   ) 

Definition at line 42 of file system.c.

00043 {
00044     return g_forkexec_child_pid;
00045 }


Generated on Sun Dec 14 17:15:50 2008 by  doxygen 1.5.6