Browse Source

Check return value of freopen() because it could fail

Georgi Chorbadzhiyski 8 years ago
parent
commit
48f7087fe7
1 changed files with 3 additions and 3 deletions
  1. 3
    3
      server.c

+ 3
- 3
server.c View File

@@ -32,9 +32,9 @@ void daemonize(char *pidfile) {
32 32
 	}
33 33
 	// Child process continues...
34 34
 	setsid();	// request a new session (job control)
35
-	freopen("/dev/null", "r", stdin);
36
-	freopen("/dev/null", "w", stdout);
37
-	freopen("/dev/null", "w", stderr);
35
+	if (!freopen("/dev/null", "r", stdin)) return;
36
+	if (!freopen("/dev/null", "w", stdout)) return;
37
+	if (!freopen("/dev/null", "w", stderr)) return;
38 38
 }
39 39
 
40 40
 void init_server_socket(char *bind_addr, int bind_port, struct sockaddr_in *server, int *server_socket) {

Loading…
Cancel
Save