[Spice-devel] [linux-agent v1 3/5] After fork, use one expression per line
Victor Toso
victortoso at redhat.com
Tue Dec 18 16:18:04 UTC 2018
From: Victor Toso <me at victortoso.com>
And use well defined macros for standard file descriptors.
Signed-off-by: Victor Toso <victortoso at redhat.com>
---
src/vdagent/vdagent.c | 8 ++++++--
src/vdagentd/vdagentd.c | 8 ++++++--
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/src/vdagent/vdagent.c b/src/vdagent/vdagent.c
index f7c8b72..87dfa7c 100644
--- a/src/vdagent/vdagent.c
+++ b/src/vdagent/vdagent.c
@@ -294,9 +294,13 @@ static int daemonize(void)
/* detach from terminal */
switch (fork()) {
case 0:
- close(0); close(1); close(2);
+ close(STDIN_FILENO);
+ close(STDOUT_FILENO);
+ close(STDERR_FILENO);
setsid();
- x = open("/dev/null", O_RDWR); x = dup(x); x = dup(x);
+ x = open("/dev/null", O_RDWR);
+ x = dup(x);
+ x = dup(x);
close(fd[0]);
return fd[1];
case -1:
diff --git a/src/vdagentd/vdagentd.c b/src/vdagentd/vdagentd.c
index 99683da..a2f0946 100644
--- a/src/vdagentd/vdagentd.c
+++ b/src/vdagentd/vdagentd.c
@@ -949,9 +949,13 @@ static void daemonize(void)
/* detach from terminal */
switch (fork()) {
case 0:
- close(0); close(1); close(2);
+ close(STDIN_FILENO);
+ close(STDOUT_FILENO);
+ close(STDERR_FILENO);
setsid();
- x = open("/dev/null", O_RDWR); x = dup(x); x = dup(x);
+ x = open("/dev/null", O_RDWR);
+ x = dup(x);
+ x = dup(x);
pidfile = fopen(pidfilename, "w");
if (pidfile) {
fprintf(pidfile, "%d\n", (int)getpid());
--
2.19.2
More information about the Spice-devel
mailing list