X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fcore%2Fmain.c;h=d052c8debc79ce281530ee7ce151b563fa870c11;hb=ccd06097c79218f7d5ea4c21721bbcbc7c467dca;hp=c89c12343ecafc6ef097630bb11af58c0fcf7a0b;hpb=c2e0d600ed76f6767d59715d93cf862808552ea2;p=elogind.git
diff --git a/src/core/main.c b/src/core/main.c
index c89c12343..d052c8deb 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -19,8 +19,6 @@
along with systemd; If not, see .
***/
-#include
-
#include
#include
#include
@@ -34,13 +32,19 @@
#include
#include
+#ifdef HAVE_VALGRIND_VALGRIND_H
+#include
+#endif
+
+#include "sd-daemon.h"
+#include "sd-messages.h"
+#include "sd-bus.h"
#include "manager.h"
#include "log.h"
#include "load-fragment.h"
#include "fdset.h"
#include "special.h"
#include "conf-parser.h"
-#include "dbus-common.h"
#include "missing.h"
#include "label.h"
#include "build.h"
@@ -54,20 +58,21 @@
#include "killall.h"
#include "env-util.h"
#include "hwclock.h"
-#include "sd-daemon.h"
-#include "sd-messages.h"
+#include "fileio.h"
+#include "dbus-manager.h"
+#include "bus-error.h"
+#include "bus-util.h"
#include "mount-setup.h"
#include "loopback-setup.h"
-#ifdef HAVE_KMOD
-#include "kmod-setup.h"
-#endif
#include "hostname-setup.h"
#include "machine-id-setup.h"
#include "selinux-setup.h"
#include "ima-setup.h"
-#include "fileio.h"
#include "smack-setup.h"
+#ifdef HAVE_KMOD
+#include "kmod-setup.h"
+#endif
static enum {
ACTION_RUN,
@@ -107,7 +112,7 @@ static FILE* serialization = NULL;
static void nop_handler(int sig) {
}
-_noreturn_ static void crash(int sig) {
+noreturn static void crash(int sig) {
if (getpid() != 1)
/* Pass this on immediately, if this is not PID 1 */
@@ -126,7 +131,7 @@ _noreturn_ static void crash(int sig) {
pid = fork();
if (pid < 0)
- log_error("Caught <%s>, cannot fork for core dump: %s", signal_to_string(sig), strerror(errno));
+ log_error("Caught <%s>, cannot fork for core dump: %m", signal_to_string(sig));
else if (pid == 0) {
struct rlimit rl = {};
@@ -161,7 +166,7 @@ _noreturn_ static void crash(int sig) {
else if (status.si_code != CLD_DUMPED)
log_error("Caught <%s>, core dump failed.", signal_to_string(sig));
else
- log_error("Caught <%s>, dumped core as pid %lu.", signal_to_string(sig), (unsigned long) pid);
+ log_error("Caught <%s>, dumped core as pid "PID_FMT".", signal_to_string(sig), pid);
}
}
@@ -192,7 +197,7 @@ _noreturn_ static void crash(int sig) {
_exit(1);
}
- log_info("Successfully spawned crash shell as pid %lu.", (unsigned long) pid);
+ log_info("Successfully spawned crash shell as pid "PID_FMT".", pid);
}
log_info("Freezing execution.");
@@ -412,7 +417,7 @@ static int parse_proc_cmdline_word(const char *word) {
* will block with every log message for for 60 seconds,
* before they give up. */
log_set_max_level(LOG_DEBUG);
- log_set_target(LOG_TARGET_KMSG);
+ log_set_target(detect_container(NULL) > 0 ? LOG_TARGET_CONSOLE : LOG_TARGET_KMSG);
} else if (!in_initrd()) {
unsigned i;
@@ -430,6 +435,7 @@ static int parse_proc_cmdline_word(const char *word) {
const char *filename, \
unsigned line, \
const char *section, \
+ unsigned section_line, \
const char *lvalue, \
int ltype, \
const char *rvalue, \
@@ -456,11 +462,11 @@ DEFINE_SETTER(config_parse_target, log_set_target_from_string, "target")
DEFINE_SETTER(config_parse_color, log_show_color_from_string, "color" )
DEFINE_SETTER(config_parse_location, log_show_location_from_string, "location")
-
static int config_parse_cpu_affinity2(const char *unit,
const char *filename,
unsigned line,
const char *section,
+ unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
@@ -533,6 +539,7 @@ static int config_parse_join_controllers(const char *unit,
const char *filename,
unsigned line,
const char *section,
+ unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
@@ -1039,7 +1046,7 @@ static int prepare_reexecute(Manager *m, FILE **_f, FDSet **_fds, bool switching
/* Make sure nothing is really destructed when we shut down */
m->n_reloading ++;
- bus_broadcast_reloading(m, true);
+ bus_manager_send_reloading(m, true);
fds = fdset_new();
if (!fds) {
@@ -1320,6 +1327,7 @@ int main(int argc, char *argv[]) {
/* Running inside a container, as PID 1 */
arg_running_as = SYSTEMD_SYSTEM;
log_set_target(LOG_TARGET_CONSOLE);
+ log_close_console(); /* force reopen of /dev/console */
log_open();
/* For the later on, see above... */
@@ -1442,9 +1450,6 @@ int main(int argc, char *argv[]) {
/* Move out of the way, so that we won't block unmounts */
assert_se(chdir("/") == 0);
- /* Make sure D-Bus doesn't fiddle with the SIGPIPE handlers */
- dbus_connection_set_change_sigpipe(FALSE);
-
/* Reset the console, but only if this is really init and we
* are freshly booted */
if (arg_running_as == SYSTEMD_SYSTEM && arg_action == ACTION_RUN)
@@ -1483,7 +1488,8 @@ int main(int argc, char *argv[]) {
status_welcome();
#ifdef HAVE_KMOD
- kmod_setup();
+ if (detect_container(NULL) <= 0)
+ kmod_setup();
#endif
hostname_setup();
machine_id_setup();
@@ -1526,7 +1532,7 @@ int main(int argc, char *argv[]) {
if (arg_running_as == SYSTEMD_SYSTEM)
bump_rlimit_nofile(&saved_rlimit_nofile);
- r = manager_new(arg_running_as, !!serialization, &m);
+ r = manager_new(arg_running_as, &m);
if (r < 0) {
log_error("Failed to allocate manager object: %s", strerror(-r));
goto finish;
@@ -1551,7 +1557,7 @@ int main(int argc, char *argv[]) {
manager_set_default_rlimits(m, arg_default_rlimit);
if (arg_default_environment)
- manager_environment_add(m, arg_default_environment);
+ manager_environment_add(m, NULL, arg_default_environment);
manager_set_show_status(m, arg_show_status);
@@ -1575,19 +1581,16 @@ int main(int argc, char *argv[]) {
}
if (queue_default_job) {
- DBusError error;
+ _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
Unit *target = NULL;
Job *default_unit_job;
- dbus_error_init(&error);
-
log_debug("Activating default unit: %s", arg_default_unit);
r = manager_load_unit(m, arg_default_unit, NULL, &error, &target);
- if (r < 0) {
- log_error("Failed to load default target: %s", bus_error(&error, r));
- dbus_error_free(&error);
- } else if (target->load_state == UNIT_ERROR || target->load_state == UNIT_NOT_FOUND)
+ if (r < 0)
+ log_error("Failed to load default target: %s", bus_error_message(&error, r));
+ else if (target->load_state == UNIT_ERROR || target->load_state == UNIT_NOT_FOUND)
log_error("Failed to load default target: %s", strerror(-target->load_error));
else if (target->load_state == UNIT_MASKED)
log_error("Default target masked.");
@@ -1597,8 +1600,7 @@ int main(int argc, char *argv[]) {
r = manager_load_unit(m, SPECIAL_RESCUE_TARGET, NULL, &error, &target);
if (r < 0) {
- log_error("Failed to load rescue target: %s", bus_error(&error, r));
- dbus_error_free(&error);
+ log_error("Failed to load rescue target: %s", bus_error_message(&error, r));
goto finish;
} else if (target->load_state == UNIT_ERROR || target->load_state == UNIT_NOT_FOUND) {
log_error("Failed to load rescue target: %s", strerror(-target->load_error));
@@ -1618,18 +1620,15 @@ int main(int argc, char *argv[]) {
r = manager_add_job(m, JOB_START, target, JOB_ISOLATE, false, &error, &default_unit_job);
if (r == -EPERM) {
- log_debug("Default target could not be isolated, starting instead: %s", bus_error(&error, r));
- dbus_error_free(&error);
+ log_debug("Default target could not be isolated, starting instead: %s", bus_error_message(&error, r));
r = manager_add_job(m, JOB_START, target, JOB_REPLACE, false, &error, &default_unit_job);
if (r < 0) {
- log_error("Failed to start default target: %s", bus_error(&error, r));
- dbus_error_free(&error);
+ log_error("Failed to start default target: %s", bus_error_message(&error, r));
goto finish;
}
} else if (r < 0) {
- log_error("Failed to isolate default target: %s", bus_error(&error, r));
- dbus_error_free(&error);
+ log_error("Failed to isolate default target: %s", bus_error_message(&error, r));
goto finish;
}
@@ -1725,7 +1724,6 @@ finish:
free(arg_default_unit);
free_join_controllers();
- dbus_shutdown();
label_finish();
if (reexecute) {
@@ -1748,7 +1746,7 @@ finish:
* initrd, but don't wait for them, so that we
* can handle the SIGCHLD for them after
* deserializing. */
- broadcast_signal(SIGTERM, false);
+ broadcast_signal(SIGTERM, false, true);
/* And switch root */
r = switch_root(switch_root_dir);
@@ -1840,6 +1838,15 @@ finish:
if (fds)
fdset_free(fds);
+#ifdef HAVE_VALGRIND_VALGRIND_H
+ /* If we are PID 1 and running under valgrind, then let's exit
+ * here explicitly. valgrind will only generate nice output on
+ * exit(), not on exec(), hence let's do the former not the
+ * latter here. */
+ if (getpid() == 1 && RUNNING_ON_VALGRIND)
+ return 0;
+#endif
+
if (shutdown_verb) {
const char * command_line[] = {
SYSTEMD_SHUTDOWN_BINARY_PATH,
@@ -1858,7 +1865,7 @@ finish:
watchdog_close(false);
/* Tell the binary how often to ping */
- snprintf(e, sizeof(e), "WATCHDOG_USEC=%llu", (unsigned long long) arg_shutdown_watchdog);
+ snprintf(e, sizeof(e), "WATCHDOG_USEC="USEC_FMT, arg_shutdown_watchdog);
char_array_0(e);
env_block = strv_append(environ, e);