]> granicus.if.org Git - sudo/commitdiff
Quiet gcc warnings on glibc systems that use warn_unused_result for
authorTodd C. Miller <Todd.Miller@courtesan.com>
Tue, 3 Aug 2010 15:18:07 +0000 (11:18 -0400)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Tue, 3 Aug 2010 15:18:07 +0000 (11:18 -0400)
write(2) and others.

--HG--
branch : 1.7

check.c
exec_pty.c
get_pty.c
logging.c
sudoreplay.c
tgetpass.c
visudo.c

diff --git a/check.c b/check.c
index 8b7834a03b0f3a240f62396f29f9100cea2fa7a5..e35246f9d316264e579c630d6c44bb7af92bc601 100644 (file)
--- a/check.c
+++ b/check.c
@@ -219,7 +219,8 @@ update_timestamp(timestampdir, timestampfile)
            log_error(NO_EXIT|USE_ERRNO, "Can't open %s", timestampfile);
        else {
            lock_file(fd, SUDO_LOCK);
-           write(fd, &tty_info, sizeof(tty_info));
+           if (write(fd, &tty_info, sizeof(tty_info)) != sizeof(tty_info))
+               log_error(NO_EXIT|USE_ERRNO, "Can't write %s", timestampfile);
            close(fd);
        }
     } else {
index 191e0e3ff40197342dbb956a3430186273f742c4..57e950c5deea98acbaa31467154dbc528248425c 100644 (file)
@@ -525,10 +525,14 @@ pty_close(cstat)
            const char *reason = strsignal(signo);
            n = io_fds[SFD_USERTTY] != -1 ?
                io_fds[SFD_USERTTY] : STDOUT_FILENO;
-           write(n, reason, strlen(reason));
-           if (WCOREDUMP(cstat->val))
-               write(n, " (core dumped)", 14);
-           write(n, "\n", 1);
+           if (write(n, reason, strlen(reason)) != -1) {
+               if (WCOREDUMP(cstat->val)) {
+                   if (write(n, " (core dumped)", 14) == -1)
+                       /* shut up glibc */;
+               }
+               if (write(n, "\n", 1) == -1)
+                   /* shut up glibc */;
+           }
        }
     }
 }
@@ -763,7 +767,8 @@ exec_monitor(path, argv, envp, backchannel, rbac)
        exec_pty(path, argv, envp, rbac);
        cstat.type = CMD_ERRNO;
        cstat.val = errno;
-       write(errpipe[1], &cstat, sizeof(cstat));
+       if (write(errpipe[1], &cstat, sizeof(cstat)) == -1)
+           /* shut up glibc */;
        _exit(1);
     }
     close(errpipe[1]);
index 7bc035518f4786efc613cf41df5390fa2618727f..5eb653faed2fe6889f5359ba6a0520ebbf1a4afc 100644 (file)
--- a/get_pty.c
+++ b/get_pty.c
@@ -72,7 +72,8 @@ get_pty(master, slave, name, namesz, ttyuid)
 
     if (openpty(master, slave, name, NULL, NULL) != 0)
        return(0);
-    (void) chown(name, ttyuid, ttygid);
+    if (chown(name, ttyuid, ttygid) != 0)
+       return(0);
     return(1);
 }
 
index 2b329683f187c73c59073c17efa4be9673d51ad1..1339391754b944d4306ff0c3b5adf591eeca445b 100644 (file)
--- a/logging.c
+++ b/logging.c
@@ -479,7 +479,8 @@ send_mail(fmt, va_alist)
     /* Daemonize - disassociate from session/tty. */
     if (setsid() == -1)
       warning("setsid");
-    (void) chdir("/");
+    if (chdir("/") == -1)
+      warning("chdir(/)");
     if ((fd = open(_PATH_DEVNULL, O_RDWR, 0644)) != -1) {
        (void) dup2(fd, STDIN_FILENO);
        (void) dup2(fd, STDOUT_FILENO);
index 58b8639d7a1b641e02fd285670621805832cf880..98cde87aabc45a1e83e660fa22ad62fa29d6a85e 100644 (file)
@@ -316,9 +316,12 @@ main(argc, argv)
        error(1, "unable to open %s", path);
     cp = NULL;
     len = 0;
-    getline(&cp, &len, lfile); /* log */
-    getline(&cp, &len, lfile); /* cwd */
-    getline(&cp, &len, lfile); /* command */
+    /* Pull out command (third line). */
+    if (getline(&cp, &len, lfile) == -1 ||
+       getline(&cp, &len, lfile) == -1 ||
+       getline(&cp, &len, lfile) == -1) {
+       error(1, "invalid log file %s", path);
+    }
     printf("Replaying sudo session: %s", cp);
     free(cp);
     fclose(lfile);
index 8127eab1e0540bf8a89f81d8bbee97e9a3ad593a..44bb062f5724f29a1f44edc6f3cccb14d184c4ab 100644 (file)
@@ -127,8 +127,10 @@ restart:
     sa.sa_handler = SIG_IGN;
     (void) sigaction(SIGPIPE, &sa, &savepipe);
 
-    if (prompt)
-       (void) write(output, prompt, strlen(prompt));
+    if (prompt) {
+       if (write(output, prompt, strlen(prompt)) == -1)
+           goto restore;
+    }
 
     if (timeout > 0)
        alarm(timeout);
@@ -136,9 +138,12 @@ restart:
     alarm(0);
     save_errno = errno;
 
-    if (neednl || pass == NULL)
-       (void) write(output, "\n", 1);
+    if (neednl || pass == NULL) {
+       if (write(output, "\n", 1) == -1)
+           goto restore;
+    }
 
+restore:
     /* Restore old tty settings and signals. */
     if (!ISSET(flags, TGP_ECHO))
        term_restore(input, 1);
@@ -252,20 +257,23 @@ getln(fd, buf, bufsiz, feedback)
        if (feedback) {
            if (c == term_kill) {
                while (cp > buf) {
-                   (void) write(fd, "\b \b", 3);
+                   if (write(fd, "\b \b", 3) == -1)
+                       break;
                    --cp;
                }
                left = bufsiz;
                continue;
            } else if (c == term_erase) {
                if (cp > buf) {
-                   (void) write(fd, "\b \b", 3);
+                   if (write(fd, "\b \b", 3) == -1)
+                       break;
                    --cp;
                    left++;
                }
                continue;
            }
-           (void) write(fd, "*", 1);
+           if (write(fd, "*", 1) == -1)
+               /* shut up glibc */;
        }
        *cp++ = c;
     }
@@ -273,7 +281,8 @@ getln(fd, buf, bufsiz, feedback)
     if (feedback) {
        /* erase stars */
        while (cp > buf) {
-           (void) write(fd, "\b \b", 3);
+           if (write(fd, "\b \b", 3) == -1)
+               break;
            --cp;
        }
     }
index ab8d58744e258899cf59ee97631d6f2ada935e6d..e2ca61a11b419954c01cf29579db3f4a58b87080 100644 (file)
--- a/visudo.c
+++ b/visudo.c
@@ -293,7 +293,8 @@ edit_sudoers(sp, editor, args, lineno)
            /* Add missing newline at EOF if needed. */
            if (nread > 0 && buf[nread - 1] != '\n') {
                buf[0] = '\n';
-               write(tfd, buf, 1);
+               if (write(tfd, buf, 1) != 1)
+                   error(1, "write error");
            }
        }
        (void) close(tfd);
@@ -490,8 +491,14 @@ install_sudoers(sp, oldperms)
        if (stat(sp->path, &sb) == -1)
 #endif
            error(1, "can't stat %s", sp->path);
-       (void) chown(sp->tpath, sb.st_uid, sb.st_gid);
-       (void) chmod(sp->tpath, sb.st_mode & 0777);
+       if (chown(sp->tpath, sb.st_uid, sb.st_gid) != 0) {
+           warning("unable to set (uid, gid) of %s to (%d, %d)",
+               sp->tpath, sb.st_uid, sb.st_gid);
+       }
+       if (chmod(sp->tpath, sb.st_mode & 0777) != 0) {
+           warning("unable to change mode of %s to 0%o", sp->tpath,
+               (sb.st_mode & 0777));
+       }
     } else {
        if (chown(sp->tpath, SUDOERS_UID, SUDOERS_GID) != 0) {
            warning("unable to set (uid, gid) of %s to (%d, %d)",
@@ -1168,8 +1175,9 @@ quit(signo)
 {
     cleanup(signo);
 #define        emsg     " exiting due to signal.\n"
-    write(STDERR_FILENO, getprogname(), strlen(getprogname()));
-    write(STDERR_FILENO, emsg, sizeof(emsg) - 1);
+    if (write(STDERR_FILENO, getprogname(), strlen(getprogname())) == -1 ||
+       write(STDERR_FILENO, emsg, sizeof(emsg) - 1) == -1)
+       /* shut up glibc */;
     _exit(signo);
 }