Quiet gcc warnings on glibc systems that use warn_unused_result for
write(2) and others.
This commit is contained in:
@@ -216,7 +216,8 @@ update_timestamp(char *timestampdir, char *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 {
|
||||
|
@@ -452,7 +452,8 @@ send_mail(const char *fmt, ...)
|
||||
/* 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);
|
||||
|
@@ -312,9 +312,12 @@ main(int argc, char *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);
|
||||
|
@@ -290,7 +290,8 @@ edit_sudoers(struct sudoersfile *sp, char *editor, char *args, int 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);
|
||||
@@ -483,8 +484,14 @@ install_sudoers(struct sudoersfile *sp, int 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)",
|
||||
@@ -1143,8 +1150,9 @@ quit(int 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);
|
||||
}
|
||||
|
||||
|
@@ -639,10 +639,14 @@ pty_close(struct command_status *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 */;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -875,7 +879,8 @@ exec_monitor(struct command_details *details, char *argv[], char *envp[],
|
||||
exec_pty(details, argv, envp);
|
||||
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]);
|
||||
|
@@ -67,7 +67,8 @@ get_pty(int *master, int *slave, char *name, size_t namesz, uid_t 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);
|
||||
}
|
||||
|
||||
|
@@ -150,8 +150,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);
|
||||
@@ -159,9 +161,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);
|
||||
@@ -277,20 +282,23 @@ getln(int fd, char *buf, size_t bufsiz, int 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;
|
||||
}
|
||||
@@ -298,7 +306,8 @@ getln(int fd, char *buf, size_t bufsiz, int feedback)
|
||||
if (feedback) {
|
||||
/* erase stars */
|
||||
while (cp > buf) {
|
||||
(void) write(fd, "\b \b", 3);
|
||||
if (write(fd, "\b \b", 3) == -1)
|
||||
break;
|
||||
--cp;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user