~ubuntu-branches/debian/jessie/systemd/jessie

« back to all changes in this revision

Viewing changes to src/main.c

  • Committer: Package Import Robot
  • Author(s): Tollef Fog Heen, Tollef Fog Heen, Michael Biebl
  • Date: 2012-04-03 19:59:17 UTC
  • mfrom: (1.1.10) (6.1.3 experimental)
  • Revision ID: package-import@ubuntu.com-20120403195917-l532urrbg4pkreas
Tags: 44-1
[ Tollef Fog Heen ]
* New upstream version.
  - Backport 3492207: journal: PAGE_SIZE is not known on ppc and other
    archs
  - Backport 5a2a2a1: journal: react with immediate rotation to a couple
    of more errors
  - Backport 693ce21: util: never follow symlinks in rm_rf_children()
    Fixes CVE-2012-1174, closes: #664364
* Drop output message from init-functions hook, it's pointless.
* Only rmdir /lib/init/rw if it exists.
* Explicitly order debian-fixup before sysinit.target to prevent a
  possible race condition with the creation of sockets.  Thanks to
  Michael Biebl for debugging this.
* Always restart the initctl socket on upgrades, to mask sysvinit
  removing it.

[ Michael Biebl ]
* Remove workaround for non-interactive sessions from pam config again.
* Create compat /dev/initctl symlink in case we are upgrading from a system
  running a newer version of sysvinit (using /run/initctl) and sysvinit is
  replaced with systemd-sysv during the upgrade. Closes: #663219
* Install new man pages.
* Build-Depend on valac (>= 0.12) instead of valac-0.12. Closes: #663323

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
static bool arg_swap_auto = true;
78
78
static char **arg_default_controllers = NULL;
79
79
static char ***arg_join_controllers = NULL;
80
 
static ExecOutput arg_default_std_output = EXEC_OUTPUT_SYSLOG;
 
80
static ExecOutput arg_default_std_output = EXEC_OUTPUT_JOURNAL;
81
81
static ExecOutput arg_default_std_error = EXEC_OUTPUT_INHERIT;
82
82
 
83
83
static FILE* serialization = NULL;
200
200
        if (!do_reset)
201
201
                return 0;
202
202
 
203
 
        if ((tty_fd = open_terminal("/dev/console", O_WRONLY|O_NOCTTY|O_CLOEXEC)) < 0) {
 
203
        tty_fd = open_terminal("/dev/console", O_WRONLY|O_NOCTTY|O_CLOEXEC);
 
204
        if (tty_fd < 0) {
204
205
                log_error("Failed to open /dev/console: %s", strerror(-tty_fd));
205
206
                return -tty_fd;
206
207
        }
207
208
 
208
 
        if ((r = reset_terminal_fd(tty_fd)) < 0)
 
209
        /* We don't want to force text mode.
 
210
         * plymouth may be showing pictures already from initrd. */
 
211
        r = reset_terminal_fd(tty_fd, false);
 
212
        if (r < 0)
209
213
                log_error("Failed to reset /dev/console: %s", strerror(-r));
210
214
 
211
215
        close_nointr_nofail(tty_fd);
270
274
                int r;
271
275
 
272
276
                if ((r = parse_boolean(word + 18)) < 0)
273
 
                        log_warning("Failed to parse dump core switch %s, Ignoring.", word + 18);
 
277
                        log_warning("Failed to parse dump core switch %s. Ignoring.", word + 18);
274
278
                else
275
279
                        arg_dump_core = r;
276
280
 
278
282
                int r;
279
283
 
280
284
                if ((r = parse_boolean(word + 20)) < 0)
281
 
                        log_warning("Failed to parse crash shell switch %s, Ignoring.", word + 20);
 
285
                        log_warning("Failed to parse crash shell switch %s. Ignoring.", word + 20);
282
286
                else
283
287
                        arg_crash_shell = r;
284
288
 
286
290
                int r;
287
291
 
288
292
                if ((r = parse_boolean(word + 22)) < 0)
289
 
                        log_warning("Failed to parse confirm spawn switch %s, Ignoring.", word + 22);
 
293
                        log_warning("Failed to parse confirm spawn switch %s. Ignoring.", word + 22);
290
294
                else
291
295
                        arg_confirm_spawn = r;
292
296
 
294
298
                int k;
295
299
 
296
300
                if (safe_atoi(word + 19, &k) < 0)
297
 
                        log_warning("Failed to parse crash chvt switch %s, Ignoring.", word + 19);
 
301
                        log_warning("Failed to parse crash chvt switch %s. Ignoring.", word + 19);
298
302
                else
299
303
                        arg_crash_chvt = k;
300
304
 
302
306
                int r;
303
307
 
304
308
                if ((r = parse_boolean(word + 20)) < 0)
305
 
                        log_warning("Failed to parse show status switch %s, Ignoring.", word + 20);
 
309
                        log_warning("Failed to parse show status switch %s. Ignoring.", word + 20);
306
310
                else
307
311
                        arg_show_status = r;
308
312
        } else if (startswith(word, "systemd.default_standard_output=")) {
309
313
                int r;
310
314
 
311
315
                if ((r = exec_output_from_string(word + 32)) < 0)
312
 
                        log_warning("Failed to parse default standard output switch %s, Ignoring.", word + 32);
 
316
                        log_warning("Failed to parse default standard output switch %s. Ignoring.", word + 32);
313
317
                else
314
318
                        arg_default_std_output = r;
315
319
        } else if (startswith(word, "systemd.default_standard_error=")) {
316
320
                int r;
317
321
 
318
322
                if ((r = exec_output_from_string(word + 31)) < 0)
319
 
                        log_warning("Failed to parse default standard error switch %s, Ignoring.", word + 31);
 
323
                        log_warning("Failed to parse default standard error switch %s. Ignoring.", word + 31);
320
324
                else
321
325
                        arg_default_std_error = r;
 
326
        } else if (startswith(word, "systemd.setenv=")) {
 
327
                char *cenv, *eq;
 
328
                int r;
 
329
 
 
330
                cenv = strdup(word + 15);
 
331
                if (!cenv)
 
332
                        return -ENOMEM;
 
333
 
 
334
                eq = strchr(cenv, '=');
 
335
                if (!eq) {
 
336
                        r = unsetenv(cenv);
 
337
                        if (r < 0)
 
338
                                log_warning("unsetenv failed %s. Ignoring.", strerror(errno));
 
339
                } else {
 
340
                        *eq = 0;
 
341
                        r = setenv(cenv, eq + 1, 1);
 
342
                        if (r < 0)
 
343
                                log_warning("setenv failed %s. Ignoring.", strerror(errno));
 
344
                }
 
345
                free(cenv);
322
346
#ifdef HAVE_SYSV_COMPAT
323
347
        } else if (startswith(word, "systemd.sysv_console=")) {
324
348
                int r;
325
349
 
326
350
                if ((r = parse_boolean(word + 21)) < 0)
327
 
                        log_warning("Failed to parse SysV console switch %s, Ignoring.", word + 20);
 
351
                        log_warning("Failed to parse SysV console switch %s. Ignoring.", word + 20);
328
352
                else
329
353
                        arg_sysv_console = r;
330
354
#endif
343
367
#ifdef HAVE_SYSV_COMPAT
344
368
                         "systemd.sysv_console=0|1                 Connect output of SysV scripts to console\n"
345
369
#endif
346
 
                         "systemd.log_target=console|kmsg|syslog|syslog-or-kmsg|null\n"
 
370
                         "systemd.log_target=console|kmsg|journal|journal-or-kmsg|syslog|syslog-or-kmsg|null\n"
347
371
                         "                                         Log target\n"
348
372
                         "systemd.log_level=LEVEL                  Log level\n"
349
373
                         "systemd.log_color=0|1                    Highlight important log messages\n"
350
374
                         "systemd.log_location=0|1                 Include code location in log messages\n"
351
 
                         "systemd.default_standard_output=null|tty|syslog|syslog+console|kmsg|kmsg+console\n"
 
375
                         "systemd.default_standard_output=null|tty|syslog|syslog+console|kmsg|kmsg+console|journal|journal+console\n"
352
376
                         "                                         Set default log output for services\n"
353
 
                         "systemd.default_standard_error=null|tty|syslog|syslog+console|kmsg|kmsg+console\n"
 
377
                         "systemd.default_standard_error=null|tty|syslog|syslog+console|kmsg|kmsg+console|journal|journal+console\n"
354
378
                         "                                         Set default log error output for services\n");
355
379
 
356
380
        } else if (streq(word, "quiet")) {
993
1017
#ifdef HAVE_SYSV_COMPAT
994
1018
               "     --sysv-console[=0|1]        Connect output of SysV scripts to console\n"
995
1019
#endif
996
 
               "     --log-target=TARGET         Set log target (console, syslog, kmsg, syslog-or-kmsg, null)\n"
 
1020
               "     --log-target=TARGET         Set log target (console, journal, syslog, kmsg, journal-or-kmsg, syslog-or-kmsg, null)\n"
997
1021
               "     --log-level=LEVEL           Set log level (debug, info, notice, warning, err, crit, alert, emerg)\n"
998
1022
               "     --log-color[=0|1]           Highlight important log messages\n"
999
1023
               "     --log-location[=0|1]        Include code location in log messages\n"
1134
1158
        bool reexecute = false;
1135
1159
        const char *shutdown_verb = NULL;
1136
1160
        dual_timestamp initrd_timestamp = { 0ULL, 0ULL };
1137
 
        char systemd[] = "systemd";
 
1161
        static char systemd[] = "systemd";
1138
1162
        bool is_reexec = false;
1139
1163
        int j;
1140
1164
        bool loaded_policy = false;
1165
1189
           called 'init'. After a subsequent reexecution we are then
1166
1190
           called 'systemd'. That is confusing, hence let's call us
1167
1191
           systemd right-away. */
1168
 
 
1169
1192
        program_invocation_short_name = systemd;
1170
1193
        prctl(PR_SET_NAME, systemd);
 
1194
 
1171
1195
        saved_argv = argv;
1172
1196
        saved_argc = argc;
1173
1197
 
1177
1201
 
1178
1202
        if (getpid() == 1) {
1179
1203
                arg_running_as = MANAGER_SYSTEM;
1180
 
                log_set_target(detect_container(NULL) > 0 ? LOG_TARGET_CONSOLE : LOG_TARGET_SYSLOG_OR_KMSG);
 
1204
                log_set_target(detect_container(NULL) > 0 ? LOG_TARGET_CONSOLE : LOG_TARGET_JOURNAL_OR_KMSG);
1181
1205
 
1182
1206
                if (!is_reexec)
1183
1207
                        if (selinux_setup(&loaded_policy) < 0)
1288
1312
 
1289
1313
        /* Set up PATH unless it is already set */
1290
1314
        setenv("PATH",
 
1315
#ifdef HAVE_SPLIT_USR
1291
1316
               "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
 
1317
#else
 
1318
               "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin",
 
1319
#endif
1292
1320
               arg_running_as == MANAGER_SYSTEM);
1293
1321
 
1294
1322
        if (arg_running_as == MANAGER_SYSTEM) {
1400
1428
        } else {
1401
1429
                DBusError error;
1402
1430
                Unit *target = NULL;
 
1431
                Job *default_unit_job;
1403
1432
 
1404
1433
                dbus_error_init(&error);
1405
1434
 
1408
1437
                if ((r = manager_load_unit(m, arg_default_unit, NULL, &error, &target)) < 0) {
1409
1438
                        log_error("Failed to load default target: %s", bus_error(&error, r));
1410
1439
                        dbus_error_free(&error);
1411
 
                } else if (target->meta.load_state == UNIT_ERROR)
1412
 
                        log_error("Failed to load default target: %s", strerror(-target->meta.load_error));
1413
 
                else if (target->meta.load_state == UNIT_MASKED)
 
1440
                } else if (target->load_state == UNIT_ERROR)
 
1441
                        log_error("Failed to load default target: %s", strerror(-target->load_error));
 
1442
                else if (target->load_state == UNIT_MASKED)
1414
1443
                        log_error("Default target masked.");
1415
1444
 
1416
 
                if (!target || target->meta.load_state != UNIT_LOADED) {
 
1445
                if (!target || target->load_state != UNIT_LOADED) {
1417
1446
                        log_info("Trying to load rescue target...");
1418
1447
 
1419
1448
                        if ((r = manager_load_unit(m, SPECIAL_RESCUE_TARGET, NULL, &error, &target)) < 0) {
1420
1449
                                log_error("Failed to load rescue target: %s", bus_error(&error, r));
1421
1450
                                dbus_error_free(&error);
1422
1451
                                goto finish;
1423
 
                        } else if (target->meta.load_state == UNIT_ERROR) {
1424
 
                                log_error("Failed to load rescue target: %s", strerror(-target->meta.load_error));
 
1452
                        } else if (target->load_state == UNIT_ERROR) {
 
1453
                                log_error("Failed to load rescue target: %s", strerror(-target->load_error));
1425
1454
                                goto finish;
1426
 
                        } else if (target->meta.load_state == UNIT_MASKED) {
 
1455
                        } else if (target->load_state == UNIT_MASKED) {
1427
1456
                                log_error("Rescue target masked.");
1428
1457
                                goto finish;
1429
1458
                        }
1430
1459
                }
1431
1460
 
1432
 
                assert(target->meta.load_state == UNIT_LOADED);
 
1461
                assert(target->load_state == UNIT_LOADED);
1433
1462
 
1434
1463
                if (arg_action == ACTION_TEST) {
1435
1464
                        printf("-> By units:\n");
1436
1465
                        manager_dump_units(m, stdout, "\t");
1437
1466
                }
1438
1467
 
1439
 
                if ((r = manager_add_job(m, JOB_START, target, JOB_REPLACE, false, &error, NULL)) < 0) {
 
1468
                r = manager_add_job(m, JOB_START, target, JOB_REPLACE, false, &error, &default_unit_job);
 
1469
                if (r < 0) {
1440
1470
                        log_error("Failed to start default target: %s", bus_error(&error, r));
1441
1471
                        dbus_error_free(&error);
1442
1472
                        goto finish;
1443
1473
                }
 
1474
                m->default_unit_job_id = default_unit_job->id;
1444
1475
 
1445
1476
                after_startup = now(CLOCK_MONOTONIC);
1446
1477
                log_full(arg_action == ACTION_TEST ? LOG_INFO : LOG_DEBUG,