From: Karel Zak Date: Fri, 10 Dec 2010 13:05:27 +0000 (+0100) Subject: login: fix "ignoring return value" errors X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=11784a84423ee79c6411163e187f30faea270512;p=util-linux login: fix "ignoring return value" errors login.c:542:8: warning: ignoring return value of ‘fchown’, declared with attribute warn_unused_result login.c:1013:11: warning: ignoring return value of ‘fchown’, declared with attribute warn_unused_result login.c: In function ‘dolastlog’: login.c:1452:7: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result login.c: In function ‘motd’: login.c:1391:7: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result Signed-off-by: Karel Zak --- diff --git a/login-utils/login.c b/login-utils/login.c index 5ece59b2..ad2932d0 100644 --- a/login-utils/login.c +++ b/login-utils/login.c @@ -539,7 +539,10 @@ main(int argc, char **argv) ttt.c_cflag &= ~HUPCL; /* These can fail, e.g. with ttyn on a read-only filesystem */ - fchown(0, 0, 0); + if (fchown(0, 0, 0)) { + ; /* glibc warn_unused_result */ + } + fchmod(0, TTY_MODE); /* Kill processes left on this tty */ @@ -1010,16 +1013,22 @@ Michael Riepe logaudit(tty_name, username, hostname, pwd, 1); dolastlog(quietlog); - fchown(0, pwd->pw_uid, - (gr = getgrnam(TTYGRPNAME)) ? gr->gr_gid : pwd->pw_gid); + if (fchown(0, pwd->pw_uid, + (gr = getgrnam(TTYGRPNAME)) ? gr->gr_gid : pwd->pw_gid)) + warn(_("change terminal owner failed")); + fchmod(0, TTY_MODE); #ifdef LOGIN_CHOWN_VCS /* if tty is one of the VC's then change owner and mode of the special /dev/vcs devices as well */ if (consoletty(0)) { - chown(vcsn, pwd->pw_uid, (gr ? gr->gr_gid : pwd->pw_gid)); - chown(vcsan, pwd->pw_uid, (gr ? gr->gr_gid : pwd->pw_gid)); + + if (chown(vcsn, pwd->pw_uid, (gr ? gr->gr_gid : pwd->pw_gid))) + warn(_("change terminal owner failed")); + if (chown(vcsan, pwd->pw_uid, (gr ? gr->gr_gid : pwd->pw_gid))) + warn(_("change terminal owner failed")); + chmod(vcsn, TTY_MODE); chmod(vcsan, TTY_MODE); } @@ -1387,8 +1396,11 @@ motd(void) { return; oldint = signal(SIGINT, sigint); if (setjmp(motdinterrupt) == 0) - while ((nchars = read(fd, tbuf, sizeof(tbuf))) > 0) - write(fileno(stdout), tbuf, nchars); + while ((nchars = read(fd, tbuf, sizeof(tbuf))) > 0) { + if (write(fileno(stdout), tbuf, nchars)) { + ; /* glibc warn_unused_result */ + } + } signal(SIGINT, oldint); close(fd); } @@ -1405,8 +1417,11 @@ checknologin(void) { char tbuf[8192]; if ((fd = open(_PATH_NOLOGIN, O_RDONLY, 0)) >= 0) { - while ((nchars = read(fd, tbuf, sizeof(tbuf))) > 0) - write(fileno(stdout), tbuf, nchars); + while ((nchars = read(fd, tbuf, sizeof(tbuf))) > 0) { + if (write(fileno(stdout), tbuf, nchars)) { + ; /* glibc warn_unused_result */ + } + } close(fd); sleepexit(EXIT_SUCCESS); } @@ -1449,7 +1464,8 @@ dolastlog(int quiet) { if (hostname) xstrncpy(ll.ll_host, hostname, sizeof(ll.ll_host)); - write(fd, (char *)&ll, sizeof(ll)); + if (write(fd, (char *)&ll, sizeof(ll)) < 0) + warn(_("write lastlog failed")); close(fd); } }