68
68
void daemon_is_ready()
70
71
kill(parent_pid, SIGUSR1);
73
if ((fd = open("/dev/null", O_RDWR, 0)) != -1)
75
if(dup2(fd, STDIN_FILENO) < 0)
81
if(dup2(fd, STDOUT_FILENO) < 0)
83
perror("dup2 stdout");
87
if(dup2(fd, STDERR_FILENO) < 0)
89
perror("dup2 stderr");
93
if (fd > STDERR_FILENO)
73
bool daemonize(bool nochdir, bool noclose, bool wait_sigusr1)
79
signal(SIGUSR1, sigusr1_handler);
108
parent_pid= getpid();
109
signal(SIGUSR1, sigusr1_handler);
95
while (waitpid(child, &status, 0) != child)
98
if (WIFEXITED(status))
100
exit_code= WEXITSTATUS(status);
102
if (WIFSIGNALED(status))
119
if(chdir("/") != 0) {
125
if (noclose == 0 && (fd = open("/dev/null", O_RDWR, 0)) != -1) {
126
if(dup2(fd, STDIN_FILENO) < 0) {
127
perror("dup2 stdin");
130
if(dup2(fd, STDOUT_FILENO) < 0) {
131
perror("dup2 stdout");
134
if(dup2(fd, STDERR_FILENO) < 0) {
135
perror("dup2 stderr");
139
if (fd > STDERR_FILENO) {
126
while (waitpid(child, &status, 0) != child)
129
if (WIFEXITED(status))
131
exit_code= WEXITSTATUS(status);
133
if (WIFSIGNALED(status))
149
150
} /* namespace drizzled */