~ubuntu-branches/ubuntu/maverick/xdm/maverick

« back to all changes in this revision

Viewing changes to daemon.c

  • Committer: Bazaar Package Importer
  • Author(s): David Nusinow
  • Date: 2006-06-30 00:42:11 UTC
  • mto: (7.1.1 gutsy)
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: james.westby@ubuntu.com-20060630004211-puz2hz052bab3kq9
Tags: upstream-1.0.5
ImportĀ upstreamĀ versionĀ 1.0.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $XdotOrg: app/xdm/daemon.c,v 1.4 2006/03/30 21:14:31 alanc Exp $ */
1
2
/* $Xorg: daemon.c,v 1.4 2001/02/09 02:05:40 xorgcvs Exp $ */
2
3
/*
3
4
 
39
40
#include <stdlib.h>
40
41
#include <string.h>
41
42
 
42
 
 
43
 
#if defined(USG)
44
 
# include <termios.h>
45
 
#else
46
 
# include <sys/ioctl.h>
47
 
#endif
48
 
#ifdef hpux
49
 
# include <sys/ptyio.h>
50
 
#endif
51
 
 
52
 
#ifdef X_NOT_POSIX
53
 
# define Pid_t int
54
 
#else
55
 
# define Pid_t pid_t
56
 
#endif
57
 
 
58
43
#include "dm.h"
59
44
#include "dm_error.h"
60
45
 
61
 
#if defined(__GLIBC__) || defined(CSRG_BASED)
62
 
#define HAS_DAEMON
63
 
#endif
64
 
 
65
 
#ifndef X_NOT_POSIX
66
 
#define HAS_SETSID
67
 
#endif
68
 
 
69
 
#ifndef HAS_SETSID
70
 
#define setsid() MySetsid()
71
 
 
72
 
static Pid_t
73
 
MySetsid(void)
74
 
{
75
 
#if defined(TIOCNOTTY) || defined(TCCLRCTTY) || defined(TIOCTTY)
76
 
    int fd;
77
 
#endif
78
 
    int stat;
79
 
 
80
 
    fd = open("/dev/tty", O_RDWR);
81
 
    if (fd >= 0) {
82
 
#if defined(USG) && defined(TCCLRCTTY)
83
 
       int zero = 0;
84
 
       (void) ioctl (fd, TCCLRCTTY, &zero);
85
 
#elif (defined(SYSV) || defined(SVR4)) && defined(TIOCTTY)
86
 
       int zero = 0;
87
 
       (void) ioctl (i, TIOCTTY, &zero);
88
 
#elif defined(TIOCNOTTY)
89
 
       (void) ioctl (i, TIOCNOTTY, (char *) 0);    /* detach, BSD style */
90
 
#endif
91
 
        close(fd);
92
 
    }
93
 
 
94
 
#if defined(SYSV) || defined(__QNXNTO__)
95
 
    return setpgrp();
96
 
#else
97
 
    return setpgid(0, getpid());
98
 
#endif
99
 
}
100
 
#endif /* !HAS_SETSID */
101
 
 
102
46
/* detach */
103
47
void
104
48
BecomeDaemon (void)
105
49
{
106
50
 
107
51
    /* If our C library has the daemon() function, just use it. */
108
 
#ifdef HAS_DAEMON
109
 
    daemon (0, 0);
 
52
#ifdef HAVE_DAEMON
 
53
    if (daemon (0, 0) < 0) {
 
54
       /* error */
 
55
       LogError("daemon() failed, %s\n", strerror(errno));
 
56
       exit(1);
 
57
    }
110
58
#else
111
59
    switch (fork()) {
112
60
    case -1:
141
89
    (void) open ("/dev/null", O_RDWR);
142
90
    (void) dup2 (0, 1);
143
91
    (void) dup2 (0, 2);
144
 
#endif /* HAS_DAEMON */
 
92
#endif /* HAVE_DAEMON */
145
93
}