summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorPierre-Yves Ritschard <pyr@cvs.openbsd.org>2007-10-19 14:40:52 +0000
committerPierre-Yves Ritschard <pyr@cvs.openbsd.org>2007-10-19 14:40:52 +0000
commita12b708cc18af38c602719d1b27fdb605488f0e3 (patch)
tree940b13e2068d0419e5fde51808f4520e0d4e24d8 /usr.sbin
parent7b2fec24dc6c06ae7630d946853cd97e83be9b4f (diff)
Do log initialisation correctly, like bgpd does.
This removes the double warn/log_warn madness i introduced yesterday. This also keeps messages on stderr at startup and when running with -n.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/hoststated/hoststated.c9
-rw-r--r--usr.sbin/hoststated/parse.y8
-rw-r--r--usr.sbin/relayd/parse.y8
-rw-r--r--usr.sbin/relayd/relayd.c9
4 files changed, 14 insertions, 20 deletions
diff --git a/usr.sbin/hoststated/hoststated.c b/usr.sbin/hoststated/hoststated.c
index ad9e9a3f7f8..89e21ae589f 100644
--- a/usr.sbin/hoststated/hoststated.c
+++ b/usr.sbin/hoststated/hoststated.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hoststated.c,v 1.45 2007/10/19 14:15:14 pyr Exp $ */
+/* $OpenBSD: hoststated.c,v 1.46 2007/10/19 14:40:51 pyr Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -128,6 +128,8 @@ main(int argc, char *argv[])
debug = 0;
conffile = CONF_FILE;
+ log_init(1); /* log to stderr until daemonized */
+
while ((c = getopt(argc, argv, "dD:nf:v")) != -1) {
switch (c) {
case 'd':
@@ -139,6 +141,7 @@ main(int argc, char *argv[])
optarg);
break;
case 'n':
+ debug = 1;
opts |= HOSTSTATED_OPT_NOACTION;
break;
case 'f':
@@ -152,8 +155,6 @@ main(int argc, char *argv[])
}
}
- log_init(debug);
-
if ((env = parse_config(conffile, opts)) == NULL)
exit(1);
hoststated_env = env;
@@ -171,6 +172,8 @@ main(int argc, char *argv[])
if (getpwnam(HOSTSTATED_USER) == NULL)
errx(1, "unknown user %s", HOSTSTATED_USER);
+ log_init(debug);
+
if (!debug) {
if (daemon(1, 0) == -1)
err(1, "failed to daemonize");
diff --git a/usr.sbin/hoststated/parse.y b/usr.sbin/hoststated/parse.y
index 3406b589e64..e9c5e618ecb 100644
--- a/usr.sbin/hoststated/parse.y
+++ b/usr.sbin/hoststated/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.70 2007/10/19 14:15:14 pyr Exp $ */
+/* $OpenBSD: parse.y,v 1.71 2007/10/19 14:40:51 pyr Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -1509,17 +1509,14 @@ check_file_secrecy(int fd, const char *fname)
if (fstat(fd, &st)) {
log_warn("cannot stat %s", fname);
- warn("cannot stat %s", fname);
return (-1);
}
if (st.st_uid != 0 && st.st_uid != getuid()) {
log_warnx("%s: owner not root or current user", fname);
- warnx("%s: owner not root or current user", fname);
return (-1);
}
if (st.st_mode & (S_IRWXG | S_IRWXO)) {
log_warnx("%s: group/world readable/writeable", fname);
- warnx("%s: group/world readable/writeable", fname);
return (-1);
}
return (0);
@@ -1533,12 +1530,10 @@ pushfile(const char *name, int secret)
if ((nfile = calloc(1, sizeof(struct file))) == NULL ||
(nfile->name = strdup(name)) == NULL) {
log_warn("malloc");
- warn("malloc");
return (NULL);
}
if ((nfile->stream = fopen(nfile->name, "r")) == NULL) {
log_warnx("%s", nfile->name);
- warnx("%s", nfile->name);
free(nfile->name);
free(nfile);
return (NULL);
@@ -1583,7 +1578,6 @@ parse_config(const char *filename, int opts)
(conf->relays = calloc(1, sizeof(*conf->relays))) == NULL ||
(conf->services = calloc(1, sizeof(*conf->services))) == NULL) {
log_warn("cannot allocate memory");
- warn("cannot allocate memory");
return (NULL);
}
diff --git a/usr.sbin/relayd/parse.y b/usr.sbin/relayd/parse.y
index 3406b589e64..e9c5e618ecb 100644
--- a/usr.sbin/relayd/parse.y
+++ b/usr.sbin/relayd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.70 2007/10/19 14:15:14 pyr Exp $ */
+/* $OpenBSD: parse.y,v 1.71 2007/10/19 14:40:51 pyr Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -1509,17 +1509,14 @@ check_file_secrecy(int fd, const char *fname)
if (fstat(fd, &st)) {
log_warn("cannot stat %s", fname);
- warn("cannot stat %s", fname);
return (-1);
}
if (st.st_uid != 0 && st.st_uid != getuid()) {
log_warnx("%s: owner not root or current user", fname);
- warnx("%s: owner not root or current user", fname);
return (-1);
}
if (st.st_mode & (S_IRWXG | S_IRWXO)) {
log_warnx("%s: group/world readable/writeable", fname);
- warnx("%s: group/world readable/writeable", fname);
return (-1);
}
return (0);
@@ -1533,12 +1530,10 @@ pushfile(const char *name, int secret)
if ((nfile = calloc(1, sizeof(struct file))) == NULL ||
(nfile->name = strdup(name)) == NULL) {
log_warn("malloc");
- warn("malloc");
return (NULL);
}
if ((nfile->stream = fopen(nfile->name, "r")) == NULL) {
log_warnx("%s", nfile->name);
- warnx("%s", nfile->name);
free(nfile->name);
free(nfile);
return (NULL);
@@ -1583,7 +1578,6 @@ parse_config(const char *filename, int opts)
(conf->relays = calloc(1, sizeof(*conf->relays))) == NULL ||
(conf->services = calloc(1, sizeof(*conf->services))) == NULL) {
log_warn("cannot allocate memory");
- warn("cannot allocate memory");
return (NULL);
}
diff --git a/usr.sbin/relayd/relayd.c b/usr.sbin/relayd/relayd.c
index 8b56d93f6c0..8994572fbbb 100644
--- a/usr.sbin/relayd/relayd.c
+++ b/usr.sbin/relayd/relayd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: relayd.c,v 1.45 2007/10/19 14:15:14 pyr Exp $ */
+/* $OpenBSD: relayd.c,v 1.46 2007/10/19 14:40:51 pyr Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -128,6 +128,8 @@ main(int argc, char *argv[])
debug = 0;
conffile = CONF_FILE;
+ log_init(1); /* log to stderr until daemonized */
+
while ((c = getopt(argc, argv, "dD:nf:v")) != -1) {
switch (c) {
case 'd':
@@ -139,6 +141,7 @@ main(int argc, char *argv[])
optarg);
break;
case 'n':
+ debug = 1;
opts |= HOSTSTATED_OPT_NOACTION;
break;
case 'f':
@@ -152,8 +155,6 @@ main(int argc, char *argv[])
}
}
- log_init(debug);
-
if ((env = parse_config(conffile, opts)) == NULL)
exit(1);
hoststated_env = env;
@@ -171,6 +172,8 @@ main(int argc, char *argv[])
if (getpwnam(HOSTSTATED_USER) == NULL)
errx(1, "unknown user %s", HOSTSTATED_USER);
+ log_init(debug);
+
if (!debug) {
if (daemon(1, 0) == -1)
err(1, "failed to daemonize");