summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2001-11-18 21:25:56 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2001-11-18 21:25:56 +0000
commit2dd4805b4284c6c16b8c00a78737405cec52617b (patch)
treea6b0edcdf77031d7fe9407d6eb7163584bdcacf7
parentfa8d3d70e01d6cd33b9a9b3b63b33df1b83faf91 (diff)
Ensure SA_RESTART is not set on SIGALRM. With it set, the SIGALRM is not
seen after a successful recv(). This affects some other programs too.. but turning off SA_RESTART requires SIGNIFICANT analysis -- not for the faint of heart.
-rw-r--r--libexec/comsat/comsat.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/libexec/comsat/comsat.c b/libexec/comsat/comsat.c
index ad73b46a239..8dc016a271f 100644
--- a/libexec/comsat/comsat.c
+++ b/libexec/comsat/comsat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: comsat.c,v 1.18 2001/11/17 19:54:56 deraadt Exp $ */
+/* $OpenBSD: comsat.c,v 1.19 2001/11/18 21:25:55 deraadt Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -41,7 +41,7 @@ static char copyright[] =
#ifndef lint
/*static char sccsid[] = "from: @(#)comsat.c 8.1 (Berkeley) 6/4/93";*/
-static char rcsid[] = "$OpenBSD: comsat.c,v 1.18 2001/11/17 19:54:56 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: comsat.c,v 1.19 2001/11/18 21:25:55 deraadt Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -92,6 +92,7 @@ main(argc, argv)
char *argv[];
{
struct sockaddr_storage from;
+ struct sigaction sa;
register int cc;
int fromlen;
char msgbuf[100];
@@ -118,9 +119,19 @@ main(argc, argv)
(void)time(&lastmsgtime);
(void)gethostname(hostname, sizeof(hostname));
doreadutmp();
- (void)signal(SIGALRM, readutmp);
+
(void)signal(SIGTTOU, SIG_IGN);
- (void)signal(SIGCHLD, reapchildren);
+
+ bzero(&sa, sizeof sa);
+ sigemptyset(&sa.sa_mask);
+ sa.sa_handler = readutmp;
+ sa.sa_flags = 0; /* no SA_RESTART */
+ (void)sigaction(SIGALRM, &sa, NULL);
+
+ sa.sa_handler = reapchildren;
+ sa.sa_flags = SA_RESTART;
+ (void)sigaction(SIGCHLD, &sa, NULL);
+
for (;;) {
if (wantreadutmp) {
doreadutmp();
@@ -170,11 +181,9 @@ doreadutmp(void)
static u_int utmpsize; /* last malloced size for utmp */
static u_int utmpmtime; /* last modification time for utmp */
struct stat statbf;
- int save_errno = errno;
if (time(NULL) - lastmsgtime >= MAXIDLE)
exit(0);
- (void)alarm((u_int)15);
(void)fstat(uf, &statbf);
if (statbf.st_mtime > utmpmtime) {
utmpmtime = statbf.st_mtime;
@@ -188,7 +197,7 @@ doreadutmp(void)
(void)lseek(uf, (off_t)0, SEEK_SET);
nutmp = read(uf, utmp, (int)statbf.st_size)/sizeof(struct utmp);
}
- errno = save_errno;
+ (void)alarm((u_int)15);
}
void
@@ -218,7 +227,7 @@ notify(utp, offset)
FILE *tp;
struct stat stb;
struct termios ttybuf;
- char tty[20], name[sizeof(utmp[0].ut_name) + 1];
+ char tty[MAXPATHLEN], name[sizeof(utmp[0].ut_name) + 1];
(void)snprintf(tty, sizeof(tty), "%s%.*s",
_PATH_DEV, (int)sizeof(utp->ut_line), utp->ut_line);