]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/main.c
Fixing main.c with regards to default GCC/CLANG compiler warnings
[ppp.git] / pppd / main.c
index 203202fe6ed6ffcbc21cbcf7cd102c58e5b3a9a9..b1ac8b4fd68087d54c1e6b9a6eeda87ca5130bc5 100644 (file)
@@ -753,6 +753,7 @@ void
 detach(void)
 {
     int pid;
+    int ret;
     char numbuf[16];
     int pipefd[2];
 
@@ -774,7 +775,10 @@ detach(void)
        exit(0);                /* parent dies */
     }
     setsid();
-    chdir("/");
+    ret = chdir("/");
+    if (ret != 0) {
+        fatal("Could not change directory to '/', %m");
+    }
     dup2(fd_devnull, 0);
     dup2(fd_devnull, 1);
     dup2(fd_devnull, 2);
@@ -1413,8 +1417,12 @@ hup(int sig)
        /* Send the signal to the [dis]connector process(es) also */
        kill_my_pg(sig);
     notify(sigreceived, sig);
-    if (waiting)
+    if (waiting) {
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-result"
        write(sigpipe[1], &sig, sizeof(sig));
+#pragma GCC diagnostic pop
+    }
 }
 
 
@@ -1433,8 +1441,12 @@ term(int sig)
        /* Send the signal to the [dis]connector process(es) also */
        kill_my_pg(sig);
     notify(sigreceived, sig);
-    if (waiting)
+    if (waiting) {
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-result"
        write(sigpipe[1], &sig, sizeof(sig));
+#pragma GCC diagnostic pop
+    }
 }
 
 
@@ -1446,8 +1458,12 @@ static void
 chld(int sig)
 {
     got_sigchld = 1;
-    if (waiting)
+    if (waiting) {
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-result"
        write(sigpipe[1], &sig, sizeof(sig));
+#pragma GCC diagnostic pop
+    }
 }
 
 
@@ -1479,8 +1495,12 @@ static void
 open_ccp(int sig)
 {
     got_sigusr2 = 1;
-    if (waiting)
+    if (waiting) {
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-result"
        write(sigpipe[1], &sig, sizeof(sig));
+#pragma GCC diagnostic pop
+    }
 }
 
 
@@ -1642,6 +1662,7 @@ device_script(char *program, int in, int out, int dont_wait)
     int pid;
     int status = -1;
     int errfd;
+    int ret;
 
     if (log_to_fd >= 0)
        errfd = log_to_fd;
@@ -1676,12 +1697,15 @@ device_script(char *program, int in, int out, int dont_wait)
     }
 
     /* here we are executing in the child */
-
-    setgid(getgid());
-    setuid(uid);
-    if (getuid() != uid) {
-       fprintf(stderr, "pppd: setuid failed\n");
-       exit(1);
+    ret = setgid(getgid());
+    if (ret != 0) {
+        perror("pppd: setgid failed\n");
+        exit(1);
+    }
+    ret = setuid(uid);
+    if (ret != 0 || getuid() != uid) {
+        perror("pppd: setuid failed\n");
+        exit(1);
     }
     update_system_environment();
     execl("/bin/sh", "sh", "-c", program, (char *)0);
@@ -1742,7 +1766,7 @@ update_script_environment(void)
 pid_t
 run_program(char *prog, char **args, int must_exist, void (*done)(void *), void *arg, int wait)
 {
-    int pid, status;
+    int pid, status, ret;
     struct stat sbuf;
 
     /*
@@ -1782,9 +1806,18 @@ run_program(char *prog, char **args, int must_exist, void (*done)(void *), void
     /* Leave the current location */
     (void) setsid();   /* No controlling tty. */
     (void) umask (S_IRWXG|S_IRWXO);
-    (void) chdir ("/");        /* no current directory. */
-    setuid(0);         /* set real UID = root */
-    setgid(getegid());
+    ret = chdir ("/"); /* no current directory. */
+    if (ret != 0) {
+        fatal("Failed to change directory to '/', %m");
+    }
+    ret = setuid(0);           /* set real UID = root */
+    if (ret != 0) {
+        fatal("Failed to set uid, %m");
+    }
+    ret = setgid(getegid());
+    if (ret != 0) {
+        fatal("failed to set gid, %m");
+    }
 
 #ifdef BSD
     /* Force the priority back to zero if pppd is running higher. */