Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 25 Nov 2000 21:59:13 -0800
From:      Kris Kennaway <kris@FreeBSD.org>
To:        current@FreeBSD.org
Subject:   wall/rwall cleanups
Message-ID:  <20001125215912.A15309@citusc17.usc.edu>

next in thread | raw e-mail | index | archive | help

--Nq2Wo0NMKNjxTN9z
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

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
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
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 @@
=20
 void	makemsg __P((char *));
 static void usage __P((void));
+char   *ttymsg __P((struct iovec *, int, char *, int));
=20
 #define	IGNOREUSER	"sleeper"
=20
@@ -85,7 +86,7 @@
 	struct iovec iov;
 	struct utmp utmp;
 	FILE *fp;
-	char *p, *ttymsg();
+	char *p;
 	char line[sizeof(utmp.ut_line) + 1];
=20
 	(void)setlocale(LC_CTYPE, "");
@@ -109,7 +110,7 @@
 	makemsg(*argv);
=20
 	if (!(fp =3D fopen(_PATH_UTMP, "r")))
-		errx(1, "cannot read %s", _PATH_UTMP);
+		err(1, "cannot read %s", _PATH_UTMP);
 	iov.iov_base =3D mbuf;
 	iov.iov_len =3D 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;
=20
-	snprintf(tmpname, sizeof(tmpname), "%s/wall.XXXXXX", _PATH_TMP);
-
-	if (!(fd =3D mkstemp(tmpname)) || !(fp =3D fdopen(fd, "r+")))
-		errx(1, "can't open temporary file");
+	(void)snprintf(tmpname, sizeof(tmpname), "%s/wall.XXXXXX", _PATH_TMP);
+	if ((fd =3D mkstemp(tmpname)) =3D=3D -1 || !(fp =3D fdopen(fd, "r+")))
+		err(1, "can't open temporary file");
 	(void)unlink(tmpname);
=20
 	if (!nobanner) {
-		char *tty =3D ttyname(2);
-		if (!tty)
+		tty =3D ttyname(STDERR_FILENO);
+		if (tty =3D=3D NULL)
 			tty =3D "no tty";
=20
 		if (!(whom =3D 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),=20
+		(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", " ");
=20
 	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 =3D 0, p =3D lbuf; (ch =3D *p) !=3D '\0'; ++p, ++cnt) {
 			if (ch =3D=3D '\r') {
@@ -232,11 +233,11 @@
 	rewind(fp);
=20
 	if (fstat(fd, &sbuf))
-		errx(1, "can't stat temporary file");
+		err(1, "can't stat temporary file");
 	mbufsize =3D sbuf.st_size;
 	if (!(mbuf =3D malloc((u_int)mbufsize)))
-		errx(1, "out of memory");
+		err(1, "out of memory");
 	if (fread(mbuf, sizeof(*mbuf), mbufsize, fp) !=3D mbufsize)
-		errx(1, "can't read temporary file");
+		err(1, "can't read temporary file");
 	(void)close(fd);
 }
Index: rwall/rwall.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
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 <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <time.h>
 #include <unistd.h>
 #include <utmp.h>
=20
@@ -70,8 +71,9 @@
 int mbufsize;
 char *mbuf;
=20
-void makemsg __P((char *));
+void	makemsg __P((char *));
 static void usage __P((void));
+char   *ttymsg __P((struct iovec *, int, char *, int));
=20
 /* 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);
 }
=20
@@ -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;
=20
-	snprintf(tmpname, sizeof(tmpname), "%s/wall.XXXXXX", _PATH_TMP);
-	if (!(fd =3D mkstemp(tmpname)) || !(fp =3D fdopen(fd, "r+")))
-		errx(1, "can't open temporary file");
+	(void)snprintf(tmpname, sizeof(tmpname), "%s/wall.XXXXXX", _PATH_TMP);
+	if ((fd =3D mkstemp(tmpname)) =3D=3D -1 || !(fp =3D fdopen(fd, "r+")))
+		err(1, "can't open temporary file");
 	(void)unlink(tmpname);
=20
 	if (!(whom =3D getlogin()))
@@ -156,23 +159,26 @@
 	 */
 	(void)fprintf(fp, "Remote Broadcast Message from %s@%s\n",
 	    whom, hostname);
-	(void)fprintf(fp, "        (%s) at %d:%02d ...\n", ttyname(2),
+	tty =3D ttyname(STDERR_FILENO);
+	if (tty =3D=3D NULL)
+		tty =3D "no tty";
+	(void)fprintf(fp, "        (%s) at %d:%02d ...\n", tty,
 	    lt->tm_hour, lt->tm_min);
=20
 	putc('\n', fp);
=20
 	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))
 		fputs(lbuf, fp);
 	rewind(fp);
=20
 	if (fstat(fd, &sbuf))
-		errx(1, "can't stat temporary file");
+		err(1, "can't stat temporary file");
 	mbufsize =3D sbuf.st_size;
 	if (!(mbuf =3D malloc((u_int)mbufsize)))
-		errx(1, "out of memory");
+		err(1, "out of memory");
 	if (fread(mbuf, sizeof(*mbuf), mbufsize, fp) !=3D mbufsize)
-		errx(1, "can't read temporary file");
+		err(1, "can't read temporary file");
 	(void)close(fd);
 }

--Nq2Wo0NMKNjxTN9z
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.4 (FreeBSD)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAjogprAACgkQWry0BWjoQKX3EACeK1sHctkqaOK5PTMYx4t1fYZz
ukgAoJ1XJU80PSq12PpM35YSvLCENAQx
=RSwv
-----END PGP SIGNATURE-----

--Nq2Wo0NMKNjxTN9z--


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20001125215912.A15309>