#include <sys/socket.h>
#include <sys/un.h>
#include <stddef.h>
+#include <printf.h>
#include "log.h"
#include "util.h"
return 0;
if (getpid() == 1) {
-
console_fd = open_terminal("/dev/console", O_WRONLY|O_NOCTTY|O_CLOEXEC);
- if (console_fd < 0) {
- log_error("Failed to open /dev/console for logging: %s", strerror(-console_fd));
+ if (console_fd < 0)
return console_fd;
- }
-
- log_debug("Successfully opened /dev/console for logging.");
} else
console_fd = STDERR_FILENO;
return 0;
kmsg_fd = open("/dev/kmsg", O_WRONLY|O_NOCTTY|O_CLOEXEC);
- if (kmsg_fd < 0) {
- log_error("Failed to open /dev/kmsg for logging: %s", strerror(errno));
+ if (kmsg_fd < 0)
return -errno;
- }
-
- log_debug("Successfully opened /dev/kmsg for logging.");
return 0;
}
} else
syslog_is_stream = false;
- log_debug("Successfully opened syslog for logging.");
-
return 0;
fail:
log_close_syslog();
- log_debug("Failed to open syslog for logging: %s", strerror(-r));
return r;
}
goto fail;
}
- log_debug("Successfully opened journal for logging.");
-
return 0;
fail:
log_close_journal();
- log_debug("Failed to open journal for logging: %s", strerror(-r));
return r;
}
va_start(ap, format);
while (format && n + 1 < ELEMENTSOF(iovec)) {
char *buf;
+ va_list aq;
+
+ /* We need to copy the va_list structure,
+ * since vasprintf() leaves it afterwards at
+ * an undefined location */
- if (vasprintf(&buf, format, ap) < 0) {
+ va_copy(aq, ap);
+ if (vasprintf(&buf, format, aq) < 0) {
+ va_end(aq);
r = -ENOMEM;
goto finish;
}
+ va_end(aq);
+
+ /* Now, jump enough ahead, so that we point to
+ * the next format string */
+ VA_FORMAT_ADVANCE(format, ap);
IOVEC_SET_STRING(iovec[n++], buf);
format = va_arg(ap, char *);
}
- va_end(ap);
zero(mh);
mh.msg_iov = iovec;
r = 1;
finish:
+ va_end(ap);
for (i = 1; i < n; i += 2)
free(iovec[i].iov_base);
va_start(ap, format);
while (format) {
+ va_list aq;
- vsnprintf(buf, sizeof(buf), format, ap);
+ va_copy(aq, ap);
+ vsnprintf(buf, sizeof(buf), format, aq);
+ va_end(aq);
char_array_0(buf);
if (startswith(buf, "MESSAGE=")) {
break;
}
+ VA_FORMAT_ADVANCE(format, ap);
+
format = va_arg(ap, char *);
}
va_end(ap);