diff options
author | Sebastian Benoit <benno@cvs.openbsd.org> | 2017-01-23 08:41:03 +0000 |
---|---|---|
committer | Sebastian Benoit <benno@cvs.openbsd.org> | 2017-01-23 08:41:03 +0000 |
commit | aaf4acc81559f4d4f236103fc2dc549d893b06f3 (patch) | |
tree | 7d605b0fa60a6ca53e2749d0c038c1f46934080a | |
parent | 1725dd6539ca8b8bac4d5c74ca744cc200f880d9 (diff) |
copy log.c/h from bgpd.
ok claudio
-rw-r--r-- | usr.sbin/iscsid/iscsid.c | 4 | ||||
-rw-r--r-- | usr.sbin/iscsid/log.c | 22 | ||||
-rw-r--r-- | usr.sbin/iscsid/log.h | 8 | ||||
-rw-r--r-- | usr.sbin/ospf6d/log.c | 22 | ||||
-rw-r--r-- | usr.sbin/ospf6d/log.h | 6 | ||||
-rw-r--r-- | usr.sbin/ospfd/log.c | 21 | ||||
-rw-r--r-- | usr.sbin/ospfd/log.h | 6 |
7 files changed, 54 insertions, 35 deletions
diff --git a/usr.sbin/iscsid/iscsid.c b/usr.sbin/iscsid/iscsid.c index ae8bb8b8525..c100ef3dc5a 100644 --- a/usr.sbin/iscsid/iscsid.c +++ b/usr.sbin/iscsid/iscsid.c @@ -1,4 +1,4 @@ -/* $OpenBSD: iscsid.c,v 1.19 2016/08/16 18:41:57 tedu Exp $ */ +/* $OpenBSD: iscsid.c,v 1.20 2017/01/23 08:40:07 benno Exp $ */ /* * Copyright (c) 2009 Claudio Jeker <claudio@openbsd.org> @@ -71,6 +71,8 @@ main(int argc, char *argv[]) int name[] = { CTL_KERN, KERN_PROC_NOBROADCASTKILL, 0 }; int ch, debug = 0, verbose = 0, nobkill = 1; + log_procname = getprogname(); + log_init(1); /* log to stderr until daemonized */ log_verbose(1); diff --git a/usr.sbin/iscsid/log.c b/usr.sbin/iscsid/log.c index e1a6c753d05..79f827951c7 100644 --- a/usr.sbin/iscsid/log.c +++ b/usr.sbin/iscsid/log.c @@ -1,7 +1,6 @@ -/* $OpenBSD: log.c,v 1.7 2016/09/02 16:22:31 benno Exp $ */ +/* $OpenBSD: log.c,v 1.8 2017/01/23 08:40:07 benno Exp $ */ /* - * Copyright (c) 2009 Claudio Jeker <claudio@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> * * Permission to use, copy, modify, and distribute this software for any @@ -29,6 +28,7 @@ int debug; int verbose; +const char *log_procname; void log_init(int n_debug) @@ -135,15 +135,25 @@ log_debug(const char *emsg, ...) } void -fatal(const char *emsg) +fatal(const char *emsg, ...) { + char s[1024]; + va_list ap; + + va_start(ap, emsg); + vsnprintf(s, sizeof(s), emsg, ap); + va_end(ap); + if (emsg == NULL) - logit(LOG_CRIT, "fatal: %s", strerror(errno)); + logit(LOG_CRIT, "fatal in %s: %s", log_procname, + strerror(errno)); else if (errno) - logit(LOG_CRIT, "fatal: %s: %s", emsg, strerror(errno)); + logit(LOG_CRIT, "fatal in %s: %s: %s", + log_procname, s, strerror(errno)); else - logit(LOG_CRIT, "fatal: %s", emsg); + logit(LOG_CRIT, "fatal in %s: %s", + log_procname, s); exit(1); } diff --git a/usr.sbin/iscsid/log.h b/usr.sbin/iscsid/log.h index 745933b2f4a..abd99848a7c 100644 --- a/usr.sbin/iscsid/log.h +++ b/usr.sbin/iscsid/log.h @@ -1,4 +1,4 @@ -/* $OpenBSD: log.h,v 1.4 2016/09/02 16:22:31 benno Exp $ */ +/* $OpenBSD: log.h,v 1.5 2017/01/23 08:40:07 benno Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -22,6 +22,8 @@ #include <stdarg.h> #include <sys/cdefs.h> +extern const char *log_procname; + void log_init(int); void log_verbose(int); void logit(int, const char *, ...) @@ -36,8 +38,8 @@ void log_info(const char *, ...) __attribute__((__format__ (printf, 1, 2))); void log_debug(const char *, ...) __attribute__((__format__ (printf, 1, 2))); -void fatal(const char *) __dead - __attribute__((__format__ (printf, 1, 0))); +void fatal(const char *, ...) __dead + __attribute__((__format__ (printf, 1, 2))); void fatalx(const char *) __dead __attribute__((__format__ (printf, 1, 0))); diff --git a/usr.sbin/ospf6d/log.c b/usr.sbin/ospf6d/log.c index 17fb38e74a5..1b2d737b38f 100644 --- a/usr.sbin/ospf6d/log.c +++ b/usr.sbin/ospf6d/log.c @@ -1,7 +1,6 @@ -/* $OpenBSD: log.c,v 1.12 2016/09/02 14:06:35 benno Exp $ */ +/* $OpenBSD: log.c,v 1.13 2017/01/23 08:41:02 benno Exp $ */ /* - * Copyright (c) 2006 Claudio Jeker <claudio@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> * * Permission to use, copy, modify, and distribute this software for any @@ -24,7 +23,6 @@ #include <string.h> #include <syslog.h> #include <time.h> -#include <unistd.h> #include "log.h" #include "ospf6d.h" @@ -138,23 +136,27 @@ log_debug(const char *emsg, ...) } void -fatal(const char *emsg) +fatal(const char *emsg, ...) { + char s[1024]; + va_list ap; + + va_start(ap, emsg); + vsnprintf(s, sizeof(s), emsg, ap); + va_end(ap); + if (emsg == NULL) logit(LOG_CRIT, "fatal in %s: %s", log_procname, strerror(errno)); else if (errno) logit(LOG_CRIT, "fatal in %s: %s: %s", - log_procname, emsg, strerror(errno)); + log_procname, s, strerror(errno)); else logit(LOG_CRIT, "fatal in %s: %s", - log_procname, emsg); + log_procname, s); - if (ospfd_process == PROC_MAIN) - exit(1); - else /* parent copes via SIGCHLD */ - _exit(1); + exit(1); } void diff --git a/usr.sbin/ospf6d/log.h b/usr.sbin/ospf6d/log.h index 580fb608df4..1745e8282d0 100644 --- a/usr.sbin/ospf6d/log.h +++ b/usr.sbin/ospf6d/log.h @@ -1,4 +1,4 @@ -/* $OpenBSD: log.h,v 1.10 2016/09/02 14:06:35 benno Exp $ */ +/* $OpenBSD: log.h,v 1.11 2017/01/23 08:41:02 benno Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -38,8 +38,8 @@ void log_info(const char *, ...) __attribute__((__format__ (printf, 1, 2))); void log_debug(const char *, ...) __attribute__((__format__ (printf, 1, 2))); -void fatal(const char *) __dead - __attribute__((__format__ (printf, 1, 0))); +void fatal(const char *, ...) __dead + __attribute__((__format__ (printf, 1, 2))); void fatalx(const char *) __dead __attribute__((__format__ (printf, 1, 0))); diff --git a/usr.sbin/ospfd/log.c b/usr.sbin/ospfd/log.c index 48d344ffb43..711a62f0b91 100644 --- a/usr.sbin/ospfd/log.c +++ b/usr.sbin/ospfd/log.c @@ -1,4 +1,4 @@ -/* $OpenBSD: log.c,v 1.9 2016/09/02 14:02:48 benno Exp $ */ +/* $OpenBSD: log.c,v 1.10 2017/01/23 08:40:45 benno Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -23,7 +23,6 @@ #include <string.h> #include <syslog.h> #include <time.h> -#include <unistd.h> #include "log.h" #include "ospfd.h" @@ -137,23 +136,27 @@ log_debug(const char *emsg, ...) } void -fatal(const char *emsg) +fatal(const char *emsg, ...) { + char s[1024]; + va_list ap; + + va_start(ap, emsg); + vsnprintf(s, sizeof(s), emsg, ap); + va_end(ap); + if (emsg == NULL) logit(LOG_CRIT, "fatal in %s: %s", log_procname, strerror(errno)); else if (errno) logit(LOG_CRIT, "fatal in %s: %s: %s", - log_procname, emsg, strerror(errno)); + log_procname, s, strerror(errno)); else logit(LOG_CRIT, "fatal in %s: %s", - log_procname, emsg); + log_procname, s); - if (ospfd_process == PROC_MAIN) - exit(1); - else /* parent copes via SIGCHLD */ - _exit(1); + exit(1); } void diff --git a/usr.sbin/ospfd/log.h b/usr.sbin/ospfd/log.h index 166a5c7ea9e..803a02707f4 100644 --- a/usr.sbin/ospfd/log.h +++ b/usr.sbin/ospfd/log.h @@ -1,4 +1,4 @@ -/* $OpenBSD: log.h,v 1.8 2016/09/02 14:02:48 benno Exp $ */ +/* $OpenBSD: log.h,v 1.9 2017/01/23 08:40:45 benno Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -38,8 +38,8 @@ void log_info(const char *, ...) __attribute__((__format__ (printf, 1, 2))); void log_debug(const char *, ...) __attribute__((__format__ (printf, 1, 2))); -void fatal(const char *) __dead - __attribute__((__format__ (printf, 1, 0))); +void fatal(const char *, ...) __dead + __attribute__((__format__ (printf, 1, 2))); void fatalx(const char *) __dead __attribute__((__format__ (printf, 1, 0))); |