Re: wall/rwall cleanups

2000-12-05 Thread kris

On Tue, Nov 28, 2000 at 02:57:45PM -0700, Warner Losh wrote:
> In message <[EMAIL PROTECTED]> Kris Kennaway writes:
> : Please review. This syncs up our code with some NetBSD changes, as well
> : as attempting to sync rwall up with wall.
> 
> You might also want to bruing in the openBSD changes for wall -g.

I thought that was your project ;-)

> Plus a few nits:
> + char *tty, hostname[MAXHOSTNAMELEN], lbuf[256], tmpname[64];
> 
> tmpname should be tmpname[MAXPATHLEN] since it is a path.  Note well,
> not MAXPATHLEN + 1 since MAXPATHLEN is defined to include the trailing
> NUL (I have patches in my tree that fix this for the rest of the tree,
> at least the +1 issue, other issues will have to wait until I can
> audit all strings passed to open, mktemp, et al).

Yeah..I pondered doing that, but it's used to store a
#define'd string so I didn't worry about it too much. Since I'm out of
touch, feel free to do this yourself before I get back.

Kris


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message



Re: wall/rwall cleanups

2000-11-28 Thread Warner Losh

In message <[EMAIL PROTECTED]> Kris Kennaway writes:
: Please review. This syncs up our code with some NetBSD changes, as well
: as attempting to sync rwall up with wall.

You might also want to bruing in the openBSD changes for wall -g.

Plus a few nits:
+   char *tty, hostname[MAXHOSTNAMELEN], lbuf[256], tmpname[64];

tmpname should be tmpname[MAXPATHLEN] since it is a path.  Note well,
not MAXPATHLEN + 1 since MAXPATHLEN is defined to include the trailing
NUL (I have patches in my tree that fix this for the rest of the tree,
at least the +1 issue, other issues will have to wait until I can
audit all strings passed to open, mktemp, et al).

Warner


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message



wall/rwall cleanups

2000-11-25 Thread Kris Kennaway

Please review. This syncs up our code with some NetBSD changes, as well
as attempting to sync rwall up with wall.

Kris

Index: wall/wall.c
===
RCS file: /mnt/ncvs/src/usr.bin/wall/wall.c,v
retrieving revision 1.15
diff -u -r1.15 wall.c
--- wall/wall.c 2000/10/02 17:31:57 1.15
+++ wall/wall.c 2000/11/26 05:55:24
@@ -68,6 +68,7 @@
 
 void   makemsg __P((char *));
 static void usage __P((void));
+char   *ttymsg __P((struct iovec *, int, char *, int));
 
 #defineIGNOREUSER  "sleeper"
 
@@ -85,7 +86,7 @@
struct iovec iov;
struct utmp utmp;
FILE *fp;
-   char *p, *ttymsg();
+   char *p;
char line[sizeof(utmp.ut_line) + 1];
 
(void)setlocale(LC_CTYPE, "");
@@ -109,7 +110,7 @@
makemsg(*argv);
 
if (!(fp = fopen(_PATH_UTMP, "r")))
-   errx(1, "cannot read %s", _PATH_UTMP);
+   err(1, "cannot read %s", _PATH_UTMP);
iov.iov_base = mbuf;
iov.iov_len = mbufsize;
/* NOSTRICT */
@@ -144,17 +145,17 @@
time_t now;
FILE *fp;
int fd;
-   char *p, *whom, hostname[MAXHOSTNAMELEN], lbuf[256], tmpname[64];
+   char *p, *tty, hostname[MAXHOSTNAMELEN], lbuf[256], tmpname[64];
+   const char *whom;
 
-   snprintf(tmpname, sizeof(tmpname), "%s/wall.XX", _PATH_TMP);
-
-   if (!(fd = mkstemp(tmpname)) || !(fp = fdopen(fd, "r+")))
-   errx(1, "can't open temporary file");
+   (void)snprintf(tmpname, sizeof(tmpname), "%s/wall.XX", _PATH_TMP);
+   if ((fd = mkstemp(tmpname)) == -1 || !(fp = fdopen(fd, "r+")))
+   err(1, "can't open temporary file");
(void)unlink(tmpname);
 
if (!nobanner) {
-   char *tty = ttyname(2);
-   if (!tty)
+   tty = ttyname(STDERR_FILENO);
+   if (tty == NULL)
tty = "no tty";
 
if (!(whom = getlogin()))
@@ -175,7 +176,7 @@
"Broadcast Message from %s@%s",
whom, hostname);
(void)fprintf(fp, "%-79.79s\007\007\r\n", lbuf);
-   (void)snprintf(lbuf, sizeof(lbuf), 
+   (void)snprintf(lbuf, sizeof(lbuf),
"(%s) at %d:%02d %s...", tty,
lt->tm_hour, lt->tm_min, lt->tm_zone);
(void)fprintf(fp, "%-79.79s\r\n", lbuf);
@@ -183,7 +184,7 @@
(void)fprintf(fp, "%79s\r\n", " ");
 
if (fname && !(freopen(fname, "r", stdin)))
-   errx(1, "can't read %s", fname);
+   err(1, "can't read %s", fname);
while (fgets(lbuf, sizeof(lbuf), stdin))
for (cnt = 0, p = lbuf; (ch = *p) != '\0'; ++p, ++cnt) {
if (ch == '\r') {
@@ -232,11 +233,11 @@
rewind(fp);
 
if (fstat(fd, &sbuf))
-   errx(1, "can't stat temporary file");
+   err(1, "can't stat temporary file");
mbufsize = sbuf.st_size;
if (!(mbuf = malloc((u_int)mbufsize)))
-   errx(1, "out of memory");
+   err(1, "out of memory");
if (fread(mbuf, sizeof(*mbuf), mbufsize, fp) != mbufsize)
-   errx(1, "can't read temporary file");
+   err(1, "can't read temporary file");
(void)close(fd);
 }
Index: rwall/rwall.c
===
RCS file: /mnt/ncvs/src/usr.bin/rwall/rwall.c,v
retrieving revision 1.8
diff -u -r1.8 rwall.c
--- rwall/rwall.c   1999/08/28 01:05:32 1.8
+++ rwall/rwall.c   2000/11/26 05:55:59
@@ -61,6 +61,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -70,8 +71,9 @@
 int mbufsize;
 char *mbuf;
 
-void makemsg __P((char *));
+void   makemsg __P((char *));
 static void usage __P((void));
+char   *ttymsg __P((struct iovec *, int, char *, int));
 
 /* ARGSUSED */
 int
@@ -120,7 +122,7 @@
 static void
 usage()
 {
-   fprintf(stderr, "usage: rwall hostname [file]\n");
+   (void)fprintf(stderr, "usage: rwall hostname [file]\n");
exit(1);
 }
 
@@ -131,14 +133,15 @@
struct tm *lt;
struct passwd *pw;
struct stat sbuf;
-   time_t now, time();
+   time_t now;
FILE *fp;
int fd;
-   char *whom, hostname[MAXHOSTNAMELEN], lbuf[256], tmpname[64];
+   char *tty, hostname[MAXHOSTNAMELEN], lbuf[256], tmpname[64];
+   const char *whom;
 
-   snprintf(tmpname, sizeof(tmpname), "%s/wall.XX", _PATH_TMP);
-   if (!(fd = mkstemp(tmpname)) || !(fp = fdopen(fd, "r+")))
-   errx(1, "can't open temporary file");
+   (void)snprintf(tmpname, sizeof(tmpname), "%s/wall.XX", _PATH_TMP);
+   if ((fd = mkstemp(tmpname)) == -1 || !(fp = fdopen(fd, "r+")))
+   err(1, "can't open temporary file");
(void)unlink(tmpname);
 
if (!(whom = getlogin()))
@@ -156,23 +159,26 @@