diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2001-11-05 09:58:14 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2001-11-05 09:58:14 +0000 |
commit | c4c4dc76753a5e94426d15536edeba5c7714a6dc (patch) | |
tree | 28c76e68a542ec840388f7dc4b1907610bab8700 | |
parent | 1463f3cb36a3063339f2c99a85b4db002ff187ff (diff) |
some syslog_r uses in signal handlers
-rw-r--r-- | sbin/mount_portal/mount_portal.c | 15 | ||||
-rw-r--r-- | usr.bin/awk/lib.c | 37 | ||||
-rw-r--r-- | usr.sbin/pppd/main.c | 20 | ||||
-rw-r--r-- | usr.sbin/sliplogin/sliplogin.c | 15 |
4 files changed, 64 insertions, 23 deletions
diff --git a/sbin/mount_portal/mount_portal.c b/sbin/mount_portal/mount_portal.c index 9f460777094..d3ea7a53dfa 100644 --- a/sbin/mount_portal/mount_portal.c +++ b/sbin/mount_portal/mount_portal.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mount_portal.c,v 1.14 2001/01/19 17:57:39 deraadt Exp $ */ +/* $OpenBSD: mount_portal.c,v 1.15 2001/11/05 09:58:13 deraadt Exp $ */ /* $NetBSD: mount_portal.c,v 1.8 1996/04/13 01:31:54 jtc Exp $ */ /* @@ -47,7 +47,7 @@ char copyright[] = #if 0 static char sccsid[] = "@(#)mount_portal.c 8.6 (Berkeley) 4/26/95"; #else -static char rcsid[] = "$OpenBSD: mount_portal.c,v 1.14 2001/01/19 17:57:39 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: mount_portal.c,v 1.15 2001/11/05 09:58:13 deraadt Exp $"; #endif #endif /* not lint */ @@ -88,12 +88,13 @@ sigchld(sig) int sig; { int save_errno = errno; + struct syslog_data sdata = SYSLOG_DATA_INIT; pid_t pid; while ((pid = waitpid((pid_t) -1, NULL, WNOHANG)) > 0) ; if (pid < 0 && errno != ECHILD) - syslog(LOG_WARNING, "waitpid: %m"); /* XXX signal race */ + syslog_r(LOG_WARNING, &sdata, "waitpid: %m"); errno = save_errno; } @@ -109,10 +110,12 @@ static void sigterm(sig) int sig; { - /* XXX signal races */ + struct syslog_data sdata = SYSLOG_DATA_INIT; + if (unmount(mountpt, MNT_FORCE) < 0) - syslog(LOG_WARNING, "sigterm: unmounting %s failed: %m", - mountpt); + syslog_r(LOG_WARNING, &sdata, + "sigterm: unmounting %s failed: %m", mountpt); + _exit(1); } int diff --git a/usr.bin/awk/lib.c b/usr.bin/awk/lib.c index ef409d5d4ee..24bbf169489 100644 --- a/usr.bin/awk/lib.c +++ b/usr.bin/awk/lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib.c,v 1.8 2001/09/08 00:12:40 millert Exp $ */ +/* $OpenBSD: lib.c,v 1.9 2001/11/05 09:58:13 deraadt Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -29,6 +29,7 @@ THIS SOFTWARE. #include <ctype.h> #include <errno.h> #include <stdlib.h> +#include <unistd.h> #include <stdarg.h> #include "awk.h" #include "ytab.h" @@ -503,9 +504,39 @@ void SYNTAX(char *fmt, ...) eprint(); } -void fpecatch(int n) +void fpecatch(int sig) { - FATAL("floating point exception %d", n); + extern Node *curnode; + char buf[1024]; + + snprintf(buf, sizeof buf, "floating point exception\n"); + write(STDERR_FILENO, buf, strlen(buf)); + + if (compile_time != 2 && NR && *NR > 0) { + snprintf(buf, sizeof buf, " input record number %d", (int) (*FNR)); + write(STDERR_FILENO, buf, strlen(buf)); + + if (strcmp(*FILENAME, "-") != 0) { + snprintf(buf, sizeof buf, ", file %s", *FILENAME); + write(STDERR_FILENO, buf, strlen(buf)); + } + write(STDERR_FILENO, "\n", 1); + } + if (compile_time != 2 && curnode) { + snprintf(buf, sizeof buf, " source line number %d", curnode->lineno); + write(STDERR_FILENO, buf, strlen(buf)); + } else if (compile_time != 2 && lineno) { + snprintf(buf, sizeof buf, " source line number %d", lineno); + write(STDERR_FILENO, buf, strlen(buf)); + } + if (compile_time == 1 && cursource() != NULL) { + snprintf(buf, sizeof buf, " source file %s", cursource()); + write(STDERR_FILENO, buf, strlen(buf)); + } + write(STDERR_FILENO, "\n", 1); + if (dbg > 1) /* core dump if serious debugging on */ + abort(); + _exit(1); } extern int bracecnt, brackcnt, parencnt; diff --git a/usr.sbin/pppd/main.c b/usr.sbin/pppd/main.c index 68022067a23..ab67092be82 100644 --- a/usr.sbin/pppd/main.c +++ b/usr.sbin/pppd/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.31 2001/05/15 19:56:06 deraadt Exp $ */ +/* $OpenBSD: main.c,v 1.32 2001/11/05 09:58:13 deraadt Exp $ */ /* * main.c - Point-to-Point Protocol main module @@ -23,7 +23,7 @@ #if 0 static char rcsid[] = "Id: main.c,v 1.49 1998/05/05 05:24:17 paulus Exp $"; #else -static char rcsid[] = "$OpenBSD: main.c,v 1.31 2001/05/15 19:56:06 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: main.c,v 1.32 2001/11/05 09:58:13 deraadt Exp $"; #endif #endif @@ -751,9 +751,11 @@ void die(status) int status; { + struct syslog_data sdata = SYSLOG_DATA_INIT; + cleanup(); - syslog(LOG_INFO, "Exit."); - exit(status); + syslog_r(LOG_INFO, &sdata, "Exit."); + _exit(status); } /* @@ -962,10 +964,11 @@ hup(sig) int sig; { int save_errno = errno; + struct syslog_data sdata = SYSLOG_DATA_INIT; if (crashed) _exit(127); - syslog(LOG_INFO, "Hangup (SIGHUP)"); /* XXX unsafe */ + syslog_r(LOG_INFO, &sdata, "Hangup (SIGHUP)"); kill_link = 1; if (conn_running) /* Send the signal to the [dis]connector process(es) also */ @@ -985,10 +988,11 @@ term(sig) int sig; { int save_errno = errno; + struct syslog_data sdata = SYSLOG_DATA_INIT; if (crashed) _exit(127); - syslog(LOG_INFO, "Terminating on signal %d.", sig); /* XXX unsafe */ + syslog_r(LOG_INFO, &sdata, "Terminating on signal %d.", sig); persist = 0; /* don't try to restart */ kill_link = 1; if (conn_running) @@ -1053,10 +1057,12 @@ static void bad_signal(sig) int sig; { + struct syslog_data sdata = SYSLOG_DATA_INIT; + if (crashed) _exit(127); crashed = 1; - syslog(LOG_ERR, "Fatal signal %d", sig); /* XXX unsafe */ + syslog_r(LOG_ERR, &sdata, "Fatal signal %d", sig); if (conn_running) kill_my_pg(SIGTERM); die(1); /* XXX unsafe! */ diff --git a/usr.sbin/sliplogin/sliplogin.c b/usr.sbin/sliplogin/sliplogin.c index 2173f916c87..38017ea82c1 100644 --- a/usr.sbin/sliplogin/sliplogin.c +++ b/usr.sbin/sliplogin/sliplogin.c @@ -39,7 +39,7 @@ char copyright[] = #ifndef lint /*static char sccsid[] = "from: @(#)sliplogin.c 5.6 (Berkeley) 3/2/91";*/ -static char rcsid[] = "$Id: sliplogin.c,v 1.15 2001/09/04 23:35:59 millert Exp $"; +static char rcsid[] = "$Id: sliplogin.c,v 1.16 2001/11/05 09:58:13 deraadt Exp $"; #endif /* not lint */ /* @@ -148,7 +148,7 @@ findid(name) (void)snprintf(loginfile, sizeof loginfile, "%s.%s", _PATH_LOGIN, name); if (access(loginfile, R_OK|X_OK) != 0) { - (void)strcpy(loginfile, _PATH_LOGIN); + (void)strlcpy(loginfile, _PATH_LOGIN, sizeof(loginfile)); if (access(loginfile, R_OK|X_OK)) { fputs("access denied - no login file\n", stderr); @@ -185,23 +185,24 @@ hup_handler(s) int s; { char logoutfile[MAXPATHLEN]; + struct syslog_data sdata = SYSLOG_DATA_INIT; seteuid(0); (void)snprintf(logoutfile, sizeof logoutfile, "%s.%s", _PATH_LOGOUT, loginname); if (access(logoutfile, R_OK|X_OK) != 0) - (void)strcpy(logoutfile, _PATH_LOGOUT); + (void)strlcpy(logoutfile, _PATH_LOGOUT, sizeof(logoutfile)); if (access(logoutfile, R_OK|X_OK) == 0) { char logincmd[2*MAXPATHLEN+32]; (void) snprintf(logincmd, sizeof logincmd, "%s %d %d %s", logoutfile, unit, speed, loginargs); - (void) system(logincmd); + (void) system(logincmd); /* XXX major race!! */ } (void) close(0); - syslog(LOG_INFO, "closed %s slip unit %d (%s)", loginname, unit, - sigstr(s)); - exit(1); + syslog_r(LOG_INFO, &sdata, "closed %s slip unit %d (%s)", + loginname, unit, sigstr(s)); + _exit(1); /* NOTREACHED */ } |