work on making log.c similar in all daemons:
reduce the (mostly whitespace) differences so that log.c's can be
diffed easily. disclaimer change ok henning@.
diff --git usr.sbin/ypldap/ldapclient.c usr.sbin/ypldap/ldapclient.c
index 02cd4616acf..3a8fb90d33e 100644
--- usr.sbin/ypldap/ldapclient.c
+++ usr.sbin/ypldap/ldapclient.c
@@ -39,6 +39,7 @@
#include <limits.h>
#include "aldap.h"
+#include "log.h"
#include "ypldap.h"
void client_sig_handler(int, short, void *);
@@ -383,6 +384,7 @@ ldapclient(int pipe_main2client[2])
#endif
setproctitle("ldap client");
ypldap_process = PROC_CLIENT;
+ log_procname = log_procnames[ypldap_process];
#ifndef DEBUG
if (setgroups(1, &pw->pw_gid) ||
diff --git usr.sbin/ypldap/log.c usr.sbin/ypldap/log.c
index ce60ae1f8ec..d3a5ba20727 100644
--- usr.sbin/ypldap/log.c
+++ usr.sbin/ypldap/log.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.c,v 1.2 2015/11/17 02:16:52 deraadt Exp $ */
+/* $OpenBSD: log.c,v 1.9 2016/09/02 14:02:48 benno Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <[email protected]>
@@ -11,13 +11,11 @@
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
- * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <sys/types.h>
-
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
@@ -25,19 +23,13 @@
#include <string.h>
#include <syslog.h>
#include <time.h>
+#include <unistd.h>
-void log_init(int);
-void log_warn(const char *, ...);
-void log_warnx(const char *, ...);
-void log_info(const char *, ...);
-void log_debug(const char *, ...);
-__dead void fatal(const char *);
-__dead void fatalx(const char *);
-
-int debug;
+#include "log.h"
-void vlog(int, const char *, va_list);
-void logit(int, const char *, ...);
+int debug;
+int verbose;
+const char *log_procname;
void
log_init(int n_debug)
@@ -53,6 +45,12 @@ log_init(int n_debug)
}
void
+log_verbose(int v)
+{
+ verbose = v;
+}
+
+void
logit(int pri, const char *fmt, ...)
{
va_list ap;
@@ -81,7 +79,6 @@ vlog(int pri, const char *fmt, va_list ap)
vsyslog(pri, fmt, ap);
}
-
void
log_warn(const char *emsg, ...)
{
@@ -131,7 +128,7 @@ log_debug(const char *emsg, ...)
{
va_list ap;
- if (debug > 1) {
+ if (verbose) {
va_start(ap, emsg);
vlog(LOG_DEBUG, emsg, ap);
va_end(ap);
@@ -142,13 +139,15 @@ void
fatal(const char *emsg)
{
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, emsg, strerror(errno));
else
- logit(LOG_CRIT, "fatal: %s", emsg);
+ logit(LOG_CRIT, "fatal in %s: %s",
+ log_procname, emsg);
exit(1);
}
diff --git usr.sbin/ypldap/log.h usr.sbin/ypldap/log.h
new file mode 100644
index 00000000000..56f7b9246ac
--- /dev/null
+++ usr.sbin/ypldap/log.h
@@ -0,0 +1,45 @@
+/* $OpenBSD: log.h,v 1.8 2016/09/02 14:02:48 benno Exp $ */
+
+/*
+ * Copyright (c) 2003, 2004 Henning Brauer <[email protected]>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef LOG_H
+#define LOG_H
+
+#include <stdarg.h>
+
+extern const char *log_procname;
+
+void log_init(int);
+void log_verbose(int);
+void logit(int, const char *, ...)
+ __attribute__((__format__ (printf, 2, 3)));
+void vlog(int, const char *, va_list)
+ __attribute__((__format__ (printf, 2, 0)));
+void log_warn(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+void log_warnx(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+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 fatalx(const char *) __dead
+ __attribute__((__format__ (printf, 1, 0)));
+
+#endif /* LOG_H */
diff --git usr.sbin/ypldap/ypldap.c usr.sbin/ypldap/ypldap.c
index c478532bf80..56bdcf15d46 100644
--- usr.sbin/ypldap/ypldap.c
+++ usr.sbin/ypldap/ypldap.c
@@ -37,6 +37,7 @@
#include <limits.h>
#include "ypldap.h"
+#include "log.h"
__dead void usage(void);
int check_child(pid_t, const char *);
@@ -507,6 +508,7 @@ main(int argc, char *argv[])
debug = 0;
ypldap_process = PROC_MAIN;
+ log_procname = log_procnames[ypldap_process];
log_init(1);
@@ -514,6 +516,7 @@ main(int argc, char *argv[])
switch (c) {
case 'd':
debug = 2;
+ log_verbose(debug);
break;
case 'D':
if (cmdline_symset(optarg) < 0)
diff --git usr.sbin/ypldap/ypldap.h usr.sbin/ypldap/ypldap.h
index d12eaa90024..099725947ef 100644
--- usr.sbin/ypldap/ypldap.h
+++ usr.sbin/ypldap/ypldap.h
@@ -51,6 +51,11 @@ enum {
PROC_CLIENT
} ypldap_process;
+static const char * const log_procnames[] = {
+ "parent",
+ "ldapclient"
+};
+
struct userent {
RB_ENTRY(userent) ue_name_node;
RB_ENTRY(userent) ue_uid_node;