Logo Search packages:      
Sourcecode: pcsc-lite version File versions  Download package

INTERNAL int SYS_Daemon ( int  nochdir,
int  noclose 
)

put the process to run in the background.

Parameters:
[in] nochdir if zero, change the current directory to "/".
[in] noclose if zero, redirect standard imput/output/error to /dev/nulll.
Returns:
error code.
Return values:
0 success.
-1 an error ocurred.

Definition at line 315 of file sys_unix.c.

References SYS_CloseFile().

{
#ifdef HAVE_DAEMON
      return daemon(nochdir, noclose);
#else

#if defined(__SVR4) && defined(__sun)
      pid_t pid;

      pid = SYS_Fork();
      if (-1 == pid)
      {
            Log2(PCSC_LOG_CRITICAL, "main: SYS_Fork() failed: %s", strerror(errno));
            return -1;
      }
      else
      {
            if (pid != 0)
                  /* the father exits */
                  exit(0);
      }

      setsid();

      pid = SYS_Fork();
      if (-1 == pid)
      {
            Log2(PCSC_LOG_CRITICAL, "main: SYS_Fork() failed: %s", strerror(errno));
            exit(1);
      }
      else
      {
            if (pid != 0)
                  /* the father exits */
                  exit(0);
      }
#else
      switch (SYS_Fork())
      {
      case -1:
            return (-1);
      case 0:
            break;
      default:
            return (0);
      }
#endif

      if (!noclose) {
            if (SYS_CloseFile(0))
                  Log2(PCSC_LOG_ERROR, "SYS_CloseFile(0) failed: %s",
                        strerror(errno));

            if (SYS_CloseFile(1))
                  Log2(PCSC_LOG_ERROR, "SYS_CloseFile(1) failed: %s",
                        strerror(errno));

            if (SYS_CloseFile(2))
                  Log2(PCSC_LOG_ERROR, "SYS_CloseFile(2) failed: %s",
                        strerror(errno));
      }
      if (!nochdir) {
            if (SYS_Chdir("/"))
                  Log2(PCSC_LOG_ERROR, "SYS_Chdir() failed: %s", strerror(errno));
      }
      return 0;
#endif
}


Generated by  Doxygen 1.6.0   Back to index