File: daemon.c

package info (click to toggle)
httptunnel 3.0-2
  • links: PTS
  • area: main
  • in suites: potato
  • size: 1,092 kB
  • ctags: 299
  • sloc: ansic: 4,505; sh: 338; makefile: 88
file content (41 lines) | stat: -rw-r--r-- 610 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
port/daemon.c

Copyright (C) 1999 Lars Brinkhoff.  See COPYING for terms and conditions.
*/

#include "config.h"

#ifndef HAVE_DAEMON

#include <unistd_.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int
daemon (int nochdir, int noclose)
{
  if (fork () != 0)
    exit (0);

  if (!nochdir)
    chdir ("/");

  close (0);
  close (1);
  close (2);

  if (noclose == 0)
    {
      open ("/dev/null", O_RDONLY);
      open ("/dev/null", O_WRONLY);
      open ("/dev/null", O_WRONLY);
    }

  /* FIXME: disassociate from controlling terminal. */

  return 0;
}

#endif /* HAVE_DAEMON */