src/bg.c File Reference

#include <eggdrop/eggdrop.h>
#include <unistd.h>
#include <sys/wait.h>
#include <signal.h>
#include "main.h"
#include "bg.h"

Go to the source code of this file.

Functions

void bg_begin_split ()
void bg_finish_split ()

Variables

static const char rcsid [] = "$Id: bg.c,v 1.22 2004-10-17 05:14:07 stdarg Exp $"
static int pipefd [2]


Function Documentation

void bg_begin_split (  ) 

Definition at line 56 of file bg.c.

References fatal(), and pipefd.

Referenced by core_init().

00057 {
00058   int parent_pid = -1, child_pid = -1;
00059   int result;
00060   char temp = 0;
00061 
00062   parent_pid = getpid();
00063 
00064   pipe(pipefd);
00065 
00066   child_pid = fork();
00067   if (child_pid == -1) fatal("CANNOT FORK PROCESS.");
00068 
00069   /* Are we the child? */
00070   if (child_pid == 0) {
00071     /* Yes. Continue as normal. */
00072     return;
00073   }
00074   /* We are the parent. Just hang around until the child is done. When
00075    * the child wants us to exit, it will send us the signal and trigger
00076    * wait_for_child. */
00077   close(pipefd[1]);
00078   result = read(pipefd[0], &temp, 1);
00079 
00080   if (result <= 0) {
00081     printf("Eggdrop exited abnormally!\n");
00082     exit(1);
00083   }
00084   else {
00085     printf("Eggdrop launched successfully into the background, pid = %d.\n", child_pid);
00086     exit(0);
00087   }
00088 }

void bg_finish_split (  ) 

Definition at line 90 of file bg.c.

References pipefd.

Referenced by core_init().

00091 {
00092   char temp = 0;
00093   write(pipefd[1], &temp, 1);
00094   close(pipefd[1]);
00095   close(pipefd[0]);
00096 
00097 #if HAVE_SETPGID && !defined(CYGWIN_HACKS)
00098   setpgid(0, 0);
00099 #endif
00100   freopen("/dev/null", "r", stdin);
00101   freopen("/dev/null", "w", stdout);
00102   freopen("/dev/null", "w", stderr);
00103 
00104 #ifdef CYGWIN_HACKS
00105   FreeConsole();
00106 #endif
00107 }


Variable Documentation

int pipefd[2] [static]

Definition at line 54 of file bg.c.

Referenced by bg_begin_split(), and bg_finish_split().

const char rcsid[] = "$Id: bg.c,v 1.22 2004-10-17 05:14:07 stdarg Exp $" [static]

Definition at line 23 of file bg.c.


Generated on Sun Nov 30 18:43:36 2008 for eggdrop1.9 by  doxygen 1.5.6