Fix: Detach from controlling TTY if daemonized
This commit is contained in:
parent
26ca852a45
commit
6859b0b9b3
@ -1,5 +1,6 @@
|
|||||||
0.6.1
|
0.6.1
|
||||||
=====
|
=====
|
||||||
|
28-Nov-2007: - Fix: Detach from controlling TTY if daemonized
|
||||||
22-Nov-2007: - Working on code that that will allow siproxd to use
|
22-Nov-2007: - Working on code that that will allow siproxd to use
|
||||||
separate interfaces in its "in front of NAT routes" setup.
|
separate interfaces in its "in front of NAT routes" setup.
|
||||||
( UA1[LAN0]--siproxd--LAN1--NAT--Internet--UA2 )
|
( UA1[LAN0]--siproxd--LAN1--NAT--Internet--UA2 )
|
||||||
|
|||||||
@ -25,6 +25,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
@ -215,6 +216,23 @@ int main (int argc, char *argv[])
|
|||||||
if (fork()!=0) exit(0);
|
if (fork()!=0) exit(0);
|
||||||
|
|
||||||
log_set_stderr(0);
|
log_set_stderr(0);
|
||||||
|
|
||||||
|
/* detach STDIN/OUT/ERR file */
|
||||||
|
i=open("/dev/null", O_RDWR);
|
||||||
|
close(STDIN_FILENO);
|
||||||
|
close(STDOUT_FILENO);
|
||||||
|
close(STDERR_FILENO);
|
||||||
|
if (dup2(i, STDIN_FILENO) <0) {
|
||||||
|
WARN("detaching STDIN failed: %s",strerror(errno));
|
||||||
|
}
|
||||||
|
if (dup2(i, STDOUT_FILENO) <0) {
|
||||||
|
WARN("detaching STDOUT failed: %s",strerror(errno));
|
||||||
|
}
|
||||||
|
if (dup2(i, STDERR_FILENO) <0) {
|
||||||
|
WARN("detaching STDERR failed: %s",strerror(errno));
|
||||||
|
}
|
||||||
|
close(i);
|
||||||
|
|
||||||
INFO("daemonized, pid=%i", getpid());
|
INFO("daemonized, pid=%i", getpid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user