All pastes #762812 Raw Edit

Mine

public text v1 · immutable
·published 2007-11-05 22:38 UTC
rendered paste body
static void
daemonize (void)
{
  int dev_null_fd, pidfile_fd;
  gchar *str;

  if (!getenv ("STB_NO_DAEMON"))
    {
      dev_null_fd = open ("/dev/null", O_RDWR);

      dup2 (dev_null_fd, 0);
      dup2 (dev_null_fd, 1);
      dup2 (dev_null_fd, 2);

      if (fork () != 0)
        exit (0);

      setsid ();

      if ((pidfile_fd = open (LOCALSTATEDIR "/run/system-tools-backends.pid", O_CREAT | O_WRONLY)) != -1)
        {
          str = g_strdup_printf ("%d", getpid ());
          write (pidfile_fd, str, strlen (str));
          g_free (str);

          close (pidfile_fd);
        }

      close (dev_null_fd);
    }
}