+
+fail:
+ log_close_syslog();
+ log_info("Failed to open syslog for logging: %s", strerror(-r));
+ return r;
+}
+
+int log_open(void) {
+ int r;
+
+ /* If we don't use the console we close it here, to not get
+ * killed by SAK. If we don't use syslog we close it here so
+ * that we are not confused by somebody deleting the socket in
+ * the fs. If we don't use /dev/kmsg we still keep it open,
+ * because there is no reason to close it. */
+
+ if (log_target == LOG_TARGET_SYSLOG_OR_KMSG ||
+ log_target == LOG_TARGET_SYSLOG)
+ if ((r = log_open_syslog()) >= 0) {
+ log_close_console();
+ return r;
+ }
+
+ if (log_target == LOG_TARGET_SYSLOG_OR_KMSG ||
+ log_target == LOG_TARGET_KMSG)
+ if ((r = log_open_kmsg()) >= 0) {
+ log_close_syslog();
+ log_close_console();
+ return r;
+ }
+
+ log_close_syslog();
+ return log_open_console();