If we might have two links, we'd better print our program name when we

emit an error -- and it would be nice if it were the *right* program name.
Since it's convenient, change most perror calls to warn, and a lot of
fprintf ...  exit to errx.  Fix at least one fprintf that could run off
the end of its arguments (%s but no argument, how did we never catch this?).
This commit is contained in:
tls 2006-04-02 06:11:45 +00:00
parent 9a2b9dd63b
commit b8dc57b8d9
7 changed files with 45 additions and 50 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: cmds.c,v 1.17 2006/03/29 12:37:59 yamt Exp $ */
/* $NetBSD: cmds.c,v 1.18 2006/04/02 06:11:45 tls Exp $ */
/*
* Copyright (c) 1983, 1993
@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)cmds.c 8.1 (Berkeley) 6/6/93";
#endif
__RCSID("$NetBSD: cmds.c,v 1.17 2006/03/29 12:37:59 yamt Exp $");
__RCSID("$NetBSD: cmds.c,v 1.18 2006/04/02 06:11:45 tls Exp $");
#endif /* not lint */
#include "tip.h"
@ -895,7 +895,7 @@ expand(name)
if (!anyof(name, "~{[*?$`'\"\\"))
return(name);
if (pipe(pivec) < 0) {
perror("pipe");
warn("pipe");
return(name);
}
(void)snprintf(cmdbuf, sizeof cmdbuf, "echo %s", name);
@ -913,7 +913,7 @@ expand(name)
_exit(1);
}
if (mypid == -1) {
perror("fork");
warn("fork");
close(pivec[0]);
close(pivec[1]);
return(NULL);
@ -929,7 +929,7 @@ expand(name)
return(NULL);
}
if (l < 0) {
perror("read");
warn("read");
return(NULL);
}
if (l == 0) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: cu.c,v 1.8 2006/03/16 23:25:17 christos Exp $ */
/* $NetBSD: cu.c,v 1.9 2006/04/02 06:11:45 tls Exp $ */
/*
* Copyright (c) 1983, 1993
@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)cu.c 8.1 (Berkeley) 6/6/93";
#endif
__RCSID("$NetBSD: cu.c,v 1.8 2006/03/16 23:25:17 christos Exp $");
__RCSID("$NetBSD: cu.c,v 1.9 2006/04/02 06:11:45 tls Exp $");
#endif /* not lint */
#include "tip.h"
@ -73,9 +73,7 @@ cumain(argc, argv)
case 's':
if (argc < 3 || speed(atoi(argv[2])) == 0) {
fprintf(stderr, "cu: unsupported speed %s\n",
argv[2]);
exit(3);
errx(3, "unsupported speed %s", argv[2]);
}
BR = atoi(argv[2]); ++argv; --argc;
break;

View File

@ -1,4 +1,4 @@
/* $NetBSD: hunt.c,v 1.10 2003/08/07 11:16:17 agc Exp $ */
/* $NetBSD: hunt.c,v 1.11 2006/04/02 06:11:45 tls Exp $ */
/*
* Copyright (c) 1983, 1993
@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)hunt.c 8.1 (Berkeley) 6/6/93";
#endif
__RCSID("$NetBSD: hunt.c,v 1.10 2003/08/07 11:16:17 agc Exp $");
__RCSID("$NetBSD: hunt.c,v 1.11 2006/04/02 06:11:45 tls Exp $");
#endif /* not lint */
#include "tip.h"
@ -81,7 +81,7 @@ hunt(name)
}
alarm(0);
if (FD < 0) {
perror(cp);
warn(cp);
deadfl = 1;
}
if (!deadfl) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: log.c,v 1.10 2004/04/23 22:11:44 christos Exp $ */
/* $NetBSD: log.c,v 1.11 2006/04/02 06:11:45 tls Exp $ */
/*
* Copyright (c) 1983, 1993
@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)log.c 8.1 (Berkeley) 6/6/93";
#endif
__RCSID("$NetBSD: log.c,v 1.10 2004/04/23 22:11:44 christos Exp $");
__RCSID("$NetBSD: log.c,v 1.11 2006/04/02 06:11:45 tls Exp $");
#endif /* not lint */
#include "tip.h"
@ -58,7 +58,7 @@ logent(group, num, acu, message)
if (flog == NULL)
return;
if (flock(fileno(flog), LOCK_EX) < 0) {
perror("tip: flock");
warn("flock");
return;
}
if ((user = getlogin()) == NULL) {
@ -92,6 +92,6 @@ loginit()
return;
flog = fopen(logfile, "a");
if (flog == NULL)
fprintf(stderr, "can't open log file %s.\r\n", logfile);
warnx("can't open log file %s.\r", logfile);
}
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: remote.c,v 1.12 2006/03/29 12:37:59 yamt Exp $ */
/* $NetBSD: remote.c,v 1.13 2006/04/02 06:11:45 tls Exp $ */
/*
* Copyright (c) 1992, 1993
@ -40,7 +40,7 @@ __COPYRIGHT("@(#) Copyright (c) 1992, 1993\n\
#if 0
static char sccsid[] = "@(#)remote.c 8.1 (Berkeley) 6/6/93";
#endif
__RCSID("$NetBSD: remote.c,v 1.12 2006/03/29 12:37:59 yamt Exp $");
__RCSID("$NetBSD: remote.c,v 1.13 2006/04/02 06:11:45 tls Exp $");
#endif /* not lint */
#include "pathnames.h"
@ -103,15 +103,15 @@ getremcap(host)
}
switch(status) {
case -1:
fprintf(stderr, "tip: unknown host %s\n", host);
warnx("unknown host %s", host);
break;
case -2:
fprintf(stderr,
"tip: can't open host description file\n");
warnx("can't open host description file");
break;
case -3:
fprintf(stderr,
"tip: possible reference loop in host description file\n");
warnx("possible reference loop in host "
"description file");
break;
}
exit(3);
@ -129,14 +129,12 @@ getremcap(host)
else
DU = cgetflag("du");
if (DV == NULL) {
fprintf(stderr, "%s: missing device spec\n", host);
exit(3);
errx(3, "%s: missing device spec\n", host);
}
if (DU && CU == NULL)
CU = DV;
if (DU && PN == NULL) {
fprintf(stderr, "%s: missing phone number\n", host);
exit(3);
errx(3, "%s: missing phone number\n", host);
}
HD = cgetflag("hd");
@ -209,8 +207,7 @@ getremote(host)
if (!lookedup) {
if (host == NULL && (host = getenv("HOST")) == NULL) {
fprintf(stderr, "tip: no host specified\n");
exit(3);
errx(3, "no host specified\n");
}
getremcap(host);
next = DV;

View File

@ -1,4 +1,4 @@
/* $NetBSD: tip.c,v 1.31 2006/04/02 04:28:38 tls Exp $ */
/* $NetBSD: tip.c,v 1.32 2006/04/02 06:11:45 tls Exp $ */
/*
* Copyright (c) 1983, 1993
@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\
#if 0
static char sccsid[] = "@(#)tip.c 8.1 (Berkeley) 6/6/93";
#endif
__RCSID("$NetBSD: tip.c,v 1.31 2006/04/02 04:28:38 tls Exp $");
__RCSID("$NetBSD: tip.c,v 1.32 2006/04/02 06:11:45 tls Exp $");
#endif /* not lint */
/*
@ -92,11 +92,12 @@ main(argc, argv)
}
if (argc > 4) {
fprintf(stderr, "usage: tip [-v] [-speed] [system-name]\n");
fprintf(stderr, "usage: %s [-v] [-speed] [system-name]\n",
getprogname());
exit(1);
}
if (!isatty(0)) {
fprintf(stderr, "tip: must be interactive\n");
fprintf(stderr, "%s: must be interactive\n", getprogname());
exit(1);
}
@ -115,7 +116,7 @@ main(argc, argv)
break;
default:
fprintf(stderr, "tip: %s, unknown option\n", argv[1]);
warnx("%s, unknown option", argv[1]);
break;
}
}
@ -130,9 +131,8 @@ main(argc, argv)
* is private, we don't want 'ps' or 'w' to find it).
*/
if (strlen(System) > sizeof PNbuf - 1) {
fprintf(stderr, "tip: phone number too long (max = %d bytes)\n",
errx(1, "phone number too long (max = %d bytes)",
(int)sizeof(PNbuf) - 1);
exit(1);
}
(void)strlcpy(PNbuf, System, sizeof(PNbuf));
for (p = System; *p; p++)
@ -177,7 +177,7 @@ notnumber:
vinit(); /* init variables */
setparity("none"); /* set the parity table */
if ((i = speed(number(value(BAUDRATE)))) == 0) {
printf("tip: bad baud rate %d\n", (int)number(value(BAUDRATE)));
warnx("bad baud rate %d", (int)number(value(BAUDRATE)));
daemon_uid();
(void)uu_unlock(uucplock);
exit(3);
@ -207,7 +207,7 @@ notnumber:
if (DC &&
((fcarg = fcntl(FD, F_GETFL, 0)) < 0 ||
fcntl(FD, F_SETFL, fcarg & ~O_NONBLOCK) < 0)) {
printf("tip: can't clear O_NONBLOCK: %s", strerror (errno));
warn("can't clear O_NONBLOCK");
daemon_uid();
(void)uu_unlock(uucplock);
exit(1);
@ -592,7 +592,7 @@ xpwrite(fd, buf, n)
if (errno == EIO)
tipabort("Lost carrier.");
/* this is questionable */
perror("write");
warn("write");
}
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: uucplock.c,v 1.12 2004/04/23 22:11:44 christos Exp $ */
/* $NetBSD: uucplock.c,v 1.13 2006/04/02 06:11:45 tls Exp $ */
/*
* Copyright (c) 1988, 1993
@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)uucplock.c 8.1 (Berkeley) 6/6/93";
#endif
__RCSID("$NetBSD: uucplock.c,v 1.12 2004/04/23 22:11:44 christos Exp $");
__RCSID("$NetBSD: uucplock.c,v 1.13 2006/04/02 06:11:45 tls Exp $");
#endif /* not lint */
#include "pathnames.h"
@ -64,15 +64,15 @@ uu_lock(ttname)
*/
fd = open(tbuf, O_RDWR, 0);
if (fd < 0) {
perror(tbuf);
fprintf(stderr, "Can't open lock file.\n");
warn(tbuf);
warnx("Can't open lock file.");
return(-1);
}
len = read(fd, text_pid, sizeof(text_pid)-1);
if(len <= 0) {
perror(tbuf);
warn(tbuf);
(void)close(fd);
fprintf(stderr, "Can't read lock file.\n");
warnx("Can't read lock file.");
return(-1);
}
text_pid[len] = 0;
@ -86,12 +86,12 @@ uu_lock(ttname)
* The process that locked the file isn't running, so
* we'll lock it ourselves
*/
fprintf(stderr, "Stale lock on %s PID=%d... overriding.\n",
warnx("Stale lock on %s PID=%d... overriding.",
ttname, mypid);
if (lseek(fd, (off_t)0, SEEK_SET) < 0) {
perror(tbuf);
warn(tbuf);
(void)close(fd);
fprintf(stderr, "Can't seek lock file.\n");
warnx("Can't seek lock file.");
return(-1);
}
/* fall out and finish the locking process */
@ -102,7 +102,7 @@ uu_lock(ttname)
if (write(fd, text_pid, len) != len) {
(void)close(fd);
(void)unlink(tbuf);
perror("lock write");
warn("lock write");
return(-1);
}
(void)close(fd);