diff --git a/usr.bin/wall/ttymsg.c b/usr.bin/wall/ttymsg.c --- a/usr.bin/wall/ttymsg.c +++ b/usr.bin/wall/ttymsg.c @@ -30,7 +30,7 @@ */ - +#include #include #include #include @@ -54,7 +54,6 @@ * error; string is not newline-terminated. Various "normal" errors are * ignored (exclusive-use, lack of permission, etc.). */ -int fdp; const char * ttymsg(struct iovec *iov, int iovcnt, const char *line, int tmout) { @@ -64,10 +63,8 @@ char device[MAXNAMLEN] = _PATH_DEV; static char errbuf[1024]; char *p; - int forked; cap_rights_t rights; - forked = 0; if (iovcnt > (int)(sizeof(localiov) / sizeof(localiov[0]))) return ("too many iov's (change code in wall/ttymsg.c)"); @@ -123,14 +120,12 @@ } continue; } + if (caph_enter() < 0) + err(1, "unable to enter capability mode"); if (errno == EWOULDBLOCK) { int cpid; - if (forked) { - (void) close(fd); - _exit(1); - } - cpid = pdfork(&pfd,0);; + cpid = pdfork(&fd,0); if (cpid < 0) { (void) snprintf(errbuf, sizeof(errbuf), "fork: %s", strerror(errno)); @@ -141,7 +136,6 @@ (void) close(fd); return (NULL); } - forked++; /* wait at most tmout seconds */ (void) signal(SIGALRM, SIG_DFL); (void) signal(SIGTERM, SIG_DFL); /* XXX */ @@ -157,15 +151,11 @@ if (errno == ENODEV || errno == EIO) break; (void) close(fd); - if (forked) - _exit(1); (void) snprintf(errbuf, sizeof(errbuf), "%s: %s", device, strerror(errno)); return (errbuf); } (void) close(fd); - if (forked) - _exit(0); return (NULL); } diff --git a/usr.bin/wall/wall.c b/usr.bin/wall/wall.c --- a/usr.bin/wall/wall.c +++ b/usr.bin/wall/wall.c @@ -61,8 +61,8 @@ static struct wallgroup { struct wallgroup *next; - char *name; - gid_t gid; + char *name; + gid_t gid; } *grouplist; static int nobanner; static int mbufsize; @@ -96,12 +96,11 @@ (void)setlocale(LC_CTYPE, ""); - /* - * Cache NLS data, for strerror, for err(3), before entering capability - * mode. - */ - caph_cache_catpages(); - + /* + * Cache NLS data, for strerror, for err(3), before entering capability + * mode. + */ + caph_cache_catpages(); while ((ch = getopt(argc, argv, "g:n")) != -1) switch (ch) { @@ -156,7 +155,8 @@ ingroup = 1; else if ((grp = getgrgid(g->gid)) != NULL) { for (np = grp->gr_mem; *np; np++) { - if (strcmp(*np, utmp->ut_user) == 0) { + if (strcmp(*np, + utmp->ut_user) == 0) { ingroup = 1; break; } @@ -166,13 +166,9 @@ if (ingroup == 0) continue; } - if ((p = ttymsg(&iov, 1, utmp->ut_line, 60*5)) != NULL) + if ((p = ttymsg(&iov, 1, utmp->ut_line, 60 * 5)) != NULL) warnx("%s", p); } - - if (caph_enter() < 0) - err(1, "unable to enter capability mode"); - exit(0); } @@ -224,13 +220,12 @@ * in column 80, but that can't be helped. */ (void)fwprintf(fp, L"\r%79s\r\n", " "); - (void)swprintf(lbuf, sizeof(lbuf)/sizeof(wchar_t), - L"Broadcast Message from %s@%s", - whom, hostname); + (void)swprintf(lbuf, sizeof(lbuf) / sizeof(wchar_t), + L"Broadcast Message from %s@%s", whom, hostname); (void)fwprintf(fp, L"%-79.79S\007\007\r\n", lbuf); - (void)swprintf(lbuf, sizeof(lbuf)/sizeof(wchar_t), - L" (%s) at %d:%02d %s...", tty, - lt->tm_hour, lt->tm_min, lt->tm_zone); + (void)swprintf(lbuf, sizeof(lbuf) / sizeof(wchar_t), + L" (%s) at %d:%02d %s...", tty, lt->tm_hour, + lt->tm_min, lt->tm_zone); (void)fwprintf(fp, L"%-79.79S\r\n", lbuf); } (void)fwprintf(fp, L"%79s\r\n", " "); @@ -244,7 +239,7 @@ err(1, "setegid failed"); } cnt = 0; - while (fgetws(lbuf, sizeof(lbuf)/sizeof(wchar_t), stdin)) { + while (fgetws(lbuf, sizeof(lbuf) / sizeof(wchar_t), stdin)) { for (p = lbuf; (ch = *p) != L'\0'; ++p, ++cnt) { if (ch == L'\r') { putwc(L'\r', fp); @@ -262,10 +257,13 @@ putwc(L'\n', fp); cnt = 0; } - if (iswprint(ch) || iswspace(ch) || ch == L'\a' || ch == L'\b') { + if (iswprint(ch) || iswspace(ch) || ch == L'\a' || + ch == L'\b') { putwc(ch, fp); } else { - (void)swprintf(codebuf, sizeof(codebuf)/sizeof(wchar_t), L"<0x%X>", ch); + (void)swprintf(codebuf, + sizeof(codebuf) / sizeof(wchar_t), + L"<0x%X>", ch); for (tmp = codebuf; *tmp != L'\0'; ++tmp) { putwc(*tmp, fp); if (++cnt == 79) {