bin/79232: WARNS6 clean libexec/comsat
Divacky Roman
xdivac02 at stud.fit.vutbr.cz
Fri Mar 25 09:20:02 PST 2005
>Number: 79232
>Category: bin
>Synopsis: WARNS6 clean libexec/comsat
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: update
>Submitter-Id: current-users
>Arrival-Date: Fri Mar 25 17:20:01 GMT 2005
>Closed-Date:
>Last-Modified:
>Originator: Divacky Roman
>Release: FreeBSD 6.0-CURRENT i386
>Organization:
home
>Environment:
System: FreeBSD eva.fit.vutbr.cz 4.11-STABLE FreeBSD 4.11-STABLE #9: Sat Jan 15 07:22:51 CET 2005 root at tereza.fit.vutbr.cz:/home/src/sys/sys-49/compile/EVA i386
>Description:
this patch makes libexec/comsat WARN6 clean + checks some return codes of some
functions + some more fixes..
>How-To-Repeat:
apply this patch
>Fix:
Index: Makefile
===================================================================
RCS file: /home/ncvs/src/libexec/comsat/Makefile,v
retrieving revision 1.8
diff -u -r1.8 Makefile
--- Makefile 26 Mar 2001 14:22:03 -0000 1.8
+++ Makefile 25 Mar 2005 17:10:25 -0000
@@ -3,5 +3,6 @@
PROG= comsat
MAN= comsat.8
+WARNS?= 6
.include <bsd.prog.mk>
Index: comsat.c
===================================================================
RCS file: /home/ncvs/src/libexec/comsat/comsat.c,v
retrieving revision 1.17
diff -u -r1.17 comsat.c
--- comsat.c 14 Feb 2005 17:42:56 -0000 1.17
+++ comsat.c 25 Mar 2005 17:10:25 -0000
@@ -85,7 +85,7 @@
void reapchildren(int);
int
-main(int argc, char *argv[])
+main(int __unused argc, char __unused *argv[])
{
struct sockaddr_in from;
socklen_t fromlen;
@@ -99,20 +99,21 @@
openlog("comsat", LOG_PID, LOG_DAEMON);
if (chdir(_PATH_MAILDIR)) {
syslog(LOG_ERR, "chdir: %s: %m", _PATH_MAILDIR);
- (void) recv(0, msgbuf, sizeof(msgbuf) - 1, 0);
+ recv(0, msgbuf, sizeof(msgbuf) - 1, 0);
exit(1);
}
if ((uf = open(_PATH_UTMP, O_RDONLY, 0)) < 0) {
syslog(LOG_ERR, "open: %s: %m", _PATH_UTMP);
- (void) recv(0, msgbuf, sizeof(msgbuf) - 1, 0);
+ recv(0, msgbuf, sizeof(msgbuf) - 1, 0);
exit(1);
}
- (void)time(&lastmsgtime);
- (void)gethostname(hostname, sizeof(hostname));
+ time(&lastmsgtime);
+ if (gethostname(hostname, sizeof(hostname)) == -1)
+ err(1, "gehostname");
onalrm(0);
- (void)signal(SIGALRM, onalrm);
- (void)signal(SIGTTOU, SIG_IGN);
- (void)signal(SIGCHLD, reapchildren);
+ signal(SIGALRM, onalrm);
+ signal(SIGTTOU, SIG_IGN);
+ signal(SIGCHLD, reapchildren);
for (;;) {
cc = recv(0, msgbuf, sizeof(msgbuf) - 1, 0);
if (cc <= 0) {
@@ -125,29 +126,30 @@
continue;
sigblock(sigmask(SIGALRM));
msgbuf[cc] = '\0';
- (void)time(&lastmsgtime);
+ time(&lastmsgtime);
mailfor(msgbuf);
sigsetmask(0L);
}
}
void
-reapchildren(int signo)
+reapchildren(int __unused signo)
{
while (wait3(NULL, WNOHANG, NULL) > 0);
}
void
-onalrm(int signo)
+onalrm(int __unused signo)
{
- static u_int utmpsize; /* last malloced size for utmp */
- static u_int utmpmtime; /* last modification time for utmp */
+ static size_t utmpsize; /* last malloced size for utmp */
+ static time_t utmpmtime; /* last modification time for utmp */
struct stat statbf;
if (time(NULL) - lastmsgtime >= MAXIDLE)
exit(0);
- (void)alarm((u_int)15);
- (void)fstat(uf, &statbf);
+ alarm(15);
+ if (fstat(uf, &statbf) == -1)
+ err(1, "fstat");
if (statbf.st_mtime > utmpmtime) {
utmpmtime = statbf.st_mtime;
if (statbf.st_size > utmpsize) {
@@ -157,7 +159,8 @@
exit(1);
}
}
- (void)lseek(uf, (off_t)0, SEEK_SET);
+ if (lseek(uf, 0, SEEK_SET) == -1)
+ err(1, "lseek");
nutmp = read(uf, utmp, (size_t)statbf.st_size)/sizeof(struct utmp);
}
}
@@ -181,11 +184,10 @@
file = name;
else
file = cp + 1;
- sprintf(buf, "%s/%.*s", _PATH_MAILDIR, (int)sizeof(utmp[0].ut_name),
- name);
+ sprintf(buf, "%s/%.*s", _PATH_MAILDIR, sizeof(utmp[0].ut_name), name);
if (*file != '/') {
sprintf(buf2, "%s/%.*s", _PATH_MAILDIR,
- (int)sizeof(utmp[0].ut_name), file);
+ sizeof(utmp[0].ut_name), file);
file = buf2;
}
folder = strcmp(buf, file);
@@ -194,7 +196,7 @@
notify(utp, file, offset, folder);
}
-static char *cr;
+const char *cr = "\n";
void
notify(struct utmp *utp, char file[], off_t offset, int folder)
@@ -202,10 +204,10 @@
FILE *tp;
struct stat stb;
struct termios tio;
- char tty[20], name[sizeof(utmp[0].ut_name) + 1];
+ char tty[20];
- (void)snprintf(tty, sizeof(tty), "%s%.*s",
- _PATH_DEV, (int)sizeof(utp->ut_line), utp->ut_line);
+ snprintf(tty, sizeof(tty), "%s%.*s",
+ _PATH_DEV, sizeof(utp->ut_line), utp->ut_line);
if (strchr(tty + sizeof(_PATH_DEV) - 1, '/')) {
/* A slash is an attempt to break security... */
syslog(LOG_AUTH | LOG_NOTICE, "'/' in \"%s\"", tty);
@@ -218,36 +220,34 @@
dsyslog(LOG_DEBUG, "notify %s on %s\n", utp->ut_name, tty);
if (fork())
return;
- (void)signal(SIGALRM, SIG_DFL);
- (void)alarm((u_int)30);
+ signal(SIGALRM, SIG_DFL);
+ alarm(30);
if ((tp = fopen(tty, "w")) == NULL) {
dsyslog(LOG_ERR, "%s: %s", tty, strerror(errno));
_exit(1);
}
- (void)tcgetattr(fileno(tp), &tio);
- cr = ((tio.c_oflag & (OPOST|ONLCR)) == (OPOST|ONLCR)) ? "\n" : "\n\r";
- (void)strncpy(name, utp->ut_name, sizeof(utp->ut_name));
- name[sizeof(name) - 1] = '\0';
+ if (tcgetattr(fileno(tp), &tio) == -1)
+ err(1, "tcgetattr");
switch (stb.st_mode & (S_IXUSR | S_IXGRP)) {
case S_IXUSR:
case (S_IXUSR | S_IXGRP):
- (void)fprintf(tp,
+ fprintf(tp,
"%s\007New mail for %s@%.*s\007 has arrived%s%s%s:%s----%s",
- cr, name, (int)sizeof(hostname), hostname,
+ cr, utp->ut_name, sizeof(hostname), hostname,
folder ? cr : "", folder ? "to " : "", folder ? file : "",
cr, cr);
- jkfprintf(tp, name, file, offset);
+ jkfprintf(tp, utp->ut_name, file, offset);
break;
case S_IXGRP:
- (void)fprintf(tp, "\007");
- (void)fflush(tp);
- (void)sleep(1);
- (void)fprintf(tp, "\007");
+ fprintf(tp, "\007");
+ fflush(tp);
+ sleep(1);
+ fprintf(tp, "\007");
break;
default:
break;
}
- (void)fclose(tp);
+ fclose(tp);
_exit(0);
}
@@ -258,16 +258,18 @@
FILE *fi;
int linecnt, charcnt, inheader;
struct passwd *p;
- unsigned char line[BUFSIZ];
+ char line[BUFSIZ];
/* Set effective uid to user in case mail drop is on nfs */
if ((p = getpwnam(user)) != NULL)
- (void) setuid(p->pw_uid);
+ if (setuid(p->pw_uid) == -1)
+ err(1, "setuid");
if ((fi = fopen(file, "r")) == NULL)
return;
- (void)fseeko(fi, offset, SEEK_CUR);
+ if (fseeko(fi, offset, SEEK_CUR) == -1)
+ err(1, "fseeko");
/*
* Print the first 7 lines or 560 characters of the new mail
* (whichever comes first). Skip header crap other than
@@ -288,12 +290,13 @@
continue;
}
if (linecnt <= 0 || charcnt <= 0) {
- (void)fprintf(tp, "...more...%s", cr);
- (void)fclose(fi);
+ fprintf(tp, "...more...%s", cr);
+ fclose(fi);
return;
}
/* strip weird stuff so can't trojan horse stupid terminals */
- for (cp = line; (ch = *cp) && ch != '\n'; ++cp, --charcnt) {
+ for (cp = (unsigned char *)line; (ch = *cp) && ch != '\n';
+ ++cp, --charcnt) {
/* disable upper controls and enable all other
8bit codes due to lack of locale knowledge
*/
@@ -303,18 +306,18 @@
) {
if (ch & 0x80) {
ch &= ~0x80;
- (void)fputs("M-", tp);
+ fputs("M-", tp);
}
if (iscntrl(ch)) {
ch ^= 0x40;
- (void)fputc('^', tp);
+ fputc('^', tp);
}
}
- (void)fputc(ch, tp);
+ fputc(ch, tp);
}
- (void)fputs(cr, tp);
+ fputs(cr, tp);
--linecnt;
}
- (void)fprintf(tp, "----%s\n", cr);
- (void)fclose(fi);
+ fprintf(tp, "----%s\n", cr);
+ fclose(fi);
}
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list