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

« back to all changes in this revision

Viewing changes to src/dbus-manager.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:
491
491
        return r;
492
492
}
493
493
 
 
494
static const char systemd_property_string[] = PACKAGE_STRING "\0" DISTRIBUTION "\0" SYSTEMD_FEATURES;
 
495
 
 
496
static const BusProperty bus_systemd_properties[] = {
 
497
        { "Version",       bus_property_append_string,    "s",  0                                             },
 
498
        { "Distribution",  bus_property_append_string,    "s",  sizeof(PACKAGE_STRING)                        },
 
499
        { "Features",      bus_property_append_string,    "s",  sizeof(PACKAGE_STRING) + sizeof(DISTRIBUTION) },
 
500
        { NULL, }
 
501
};
 
502
 
 
503
static const BusProperty bus_manager_properties[] = {
 
504
        { "RunningAs",     bus_manager_append_running_as,          "s", offsetof(Manager, running_as)                  },
 
505
        { "Tainted",       bus_manager_append_tainted,             "s", 0 },
 
506
        { "InitRDTimestamp", bus_property_append_uint64,           "t", offsetof(Manager, initrd_timestamp.realtime)   },
 
507
        { "InitRDTimestampMonotonic", bus_property_append_uint64,  "t", offsetof(Manager, initrd_timestamp.monotonic)  },
 
508
        { "StartupTimestamp", bus_property_append_uint64,          "t", offsetof(Manager, startup_timestamp.realtime)  },
 
509
        { "StartupTimestampMonotonic", bus_property_append_uint64, "t", offsetof(Manager, startup_timestamp.monotonic) },
 
510
        { "FinishTimestamp", bus_property_append_uint64,           "t", offsetof(Manager, finish_timestamp.realtime)   },
 
511
        { "FinishTimestampMonotonic", bus_property_append_uint64,  "t", offsetof(Manager, finish_timestamp.monotonic)  },
 
512
        { "LogLevel",      bus_manager_append_log_level,           "s", 0,                                             0, bus_manager_set_log_level },
 
513
        { "LogTarget",     bus_manager_append_log_target,          "s", 0,                                             0, bus_manager_set_log_target },
 
514
        { "NNames",        bus_manager_append_n_names,             "u", 0 },
 
515
        { "NJobs",         bus_manager_append_n_jobs,              "u", 0 },
 
516
        { "NInstalledJobs",bus_property_append_uint32,             "u", offsetof(Manager, n_installed_jobs)            },
 
517
        { "NFailedJobs",   bus_property_append_uint32,             "u", offsetof(Manager, n_failed_jobs)               },
 
518
        { "Progress",      bus_manager_append_progress,            "d", 0 },
 
519
        { "Environment",   bus_property_append_strv,              "as", offsetof(Manager, environment),                true },
 
520
        { "ConfirmSpawn",  bus_property_append_bool,               "b", offsetof(Manager, confirm_spawn)               },
 
521
        { "ShowStatus",    bus_property_append_bool,               "b", offsetof(Manager, show_status)                 },
 
522
        { "UnitPath",      bus_property_append_strv,              "as", offsetof(Manager, lookup_paths.unit_path),     true },
 
523
        { "NotifySocket",  bus_property_append_string,             "s", offsetof(Manager, notify_socket),              true },
 
524
        { "ControlGroupHierarchy", bus_property_append_string,     "s", offsetof(Manager, cgroup_hierarchy),           true },
 
525
        { "MountAuto",     bus_property_append_bool,               "b", offsetof(Manager, mount_auto)                  },
 
526
        { "SwapAuto",      bus_property_append_bool,               "b", offsetof(Manager, swap_auto)                   },
 
527
        { "DefaultControllers", bus_property_append_strv,         "as", offsetof(Manager, default_controllers),        true },
 
528
        { "DefaultStandardOutput", bus_manager_append_exec_output, "s", offsetof(Manager, default_std_output)          },
 
529
        { "DefaultStandardError",  bus_manager_append_exec_output, "s", offsetof(Manager, default_std_error)           },
 
530
#ifdef HAVE_SYSV_COMPAT
 
531
        { "SysVConsole",   bus_property_append_bool,               "b", offsetof(Manager, sysv_console)                },
 
532
        { "SysVInitPath",  bus_property_append_strv,              "as", offsetof(Manager, lookup_paths.sysvinit_path), true },
 
533
        { "SysVRcndPath",  bus_property_append_strv,              "as", offsetof(Manager, lookup_paths.sysvrcnd_path), true },
 
534
#endif
 
535
        { NULL, }
 
536
};
 
537
 
494
538
static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, DBusMessage *message, void *data) {
495
539
        Manager *m = data;
496
540
 
497
 
        const BusProperty properties[] = {
498
 
                { "org.freedesktop.systemd1.Manager", "Version",       bus_property_append_string,    "s",  PACKAGE_STRING     },
499
 
                { "org.freedesktop.systemd1.Manager", "Distribution",  bus_property_append_string,    "s",  DISTRIBUTION       },
500
 
                { "org.freedesktop.systemd1.Manager", "Features",      bus_property_append_string,    "s",  SYSTEMD_FEATURES   },
501
 
                { "org.freedesktop.systemd1.Manager", "RunningAs",     bus_manager_append_running_as, "s",  &m->running_as     },
502
 
                { "org.freedesktop.systemd1.Manager", "Tainted",       bus_manager_append_tainted,    "s",  m                  },
503
 
                { "org.freedesktop.systemd1.Manager", "InitRDTimestamp", bus_property_append_uint64,  "t",  &m->initrd_timestamp.realtime },
504
 
                { "org.freedesktop.systemd1.Manager", "InitRDTimestampMonotonic", bus_property_append_uint64, "t", &m->initrd_timestamp.monotonic },
505
 
                { "org.freedesktop.systemd1.Manager", "StartupTimestamp", bus_property_append_uint64, "t",  &m->startup_timestamp.realtime },
506
 
                { "org.freedesktop.systemd1.Manager", "StartupTimestampMonotonic", bus_property_append_uint64, "t", &m->startup_timestamp.monotonic },
507
 
                { "org.freedesktop.systemd1.Manager", "FinishTimestamp", bus_property_append_uint64,  "t",  &m->finish_timestamp.realtime },
508
 
                { "org.freedesktop.systemd1.Manager", "FinishTimestampMonotonic", bus_property_append_uint64, "t",&m->finish_timestamp.monotonic },
509
 
                { "org.freedesktop.systemd1.Manager", "LogLevel",      bus_manager_append_log_level,  "s",  m, bus_manager_set_log_level },
510
 
                { "org.freedesktop.systemd1.Manager", "LogTarget",     bus_manager_append_log_target, "s",  m, bus_manager_set_log_target },
511
 
                { "org.freedesktop.systemd1.Manager", "NNames",        bus_manager_append_n_names,    "u",  m                  },
512
 
                { "org.freedesktop.systemd1.Manager", "NJobs",         bus_manager_append_n_jobs,     "u",  m                  },
513
 
                { "org.freedesktop.systemd1.Manager", "NInstalledJobs",bus_property_append_uint32,    "u",  &m->n_installed_jobs },
514
 
                { "org.freedesktop.systemd1.Manager", "NFailedJobs",   bus_property_append_uint32,    "u",  &m->n_failed_jobs  },
515
 
                { "org.freedesktop.systemd1.Manager", "Progress",      bus_manager_append_progress,   "d",  m                  },
516
 
                { "org.freedesktop.systemd1.Manager", "Environment",   bus_property_append_strv,      "as", m->environment     },
517
 
                { "org.freedesktop.systemd1.Manager", "ConfirmSpawn",  bus_property_append_bool,      "b",  &m->confirm_spawn  },
518
 
                { "org.freedesktop.systemd1.Manager", "ShowStatus",    bus_property_append_bool,      "b",  &m->show_status    },
519
 
                { "org.freedesktop.systemd1.Manager", "UnitPath",      bus_property_append_strv,      "as", m->lookup_paths.unit_path },
520
 
                { "org.freedesktop.systemd1.Manager", "NotifySocket",  bus_property_append_string,    "s",  m->notify_socket   },
521
 
                { "org.freedesktop.systemd1.Manager", "ControlGroupHierarchy", bus_property_append_string, "s", m->cgroup_hierarchy },
522
 
                { "org.freedesktop.systemd1.Manager", "MountAuto",     bus_property_append_bool,      "b",  &m->mount_auto     },
523
 
                { "org.freedesktop.systemd1.Manager", "SwapAuto",      bus_property_append_bool,      "b",  &m->swap_auto      },
524
 
                { "org.freedesktop.systemd1.Manager", "DefaultControllers", bus_property_append_strv, "as", m->default_controllers },
525
 
                { "org.freedesktop.systemd1.Manager", "DefaultStandardOutput", bus_manager_append_exec_output, "s", &m->default_std_output },
526
 
                { "org.freedesktop.systemd1.Manager", "DefaultStandardError",  bus_manager_append_exec_output, "s", &m->default_std_error  },
527
 
#ifdef HAVE_SYSV_COMPAT
528
 
                { "org.freedesktop.systemd1.Manager", "SysVConsole",   bus_property_append_bool,      "b",  &m->sysv_console   },
529
 
                { "org.freedesktop.systemd1.Manager", "SysVInitPath",  bus_property_append_strv,      "as", m->lookup_paths.sysvinit_path },
530
 
                { "org.freedesktop.systemd1.Manager", "SysVRcndPath",  bus_property_append_strv,      "as", m->lookup_paths.sysvrcnd_path },
531
 
#endif
532
 
                { NULL, NULL, NULL, NULL, NULL }
533
 
        };
534
 
 
535
541
        int r;
536
542
        DBusError error;
537
543
        DBusMessage *reply = NULL;
777
783
                        uint32_t job_id;
778
784
                        Unit *f;
779
785
 
780
 
                        if (k != u->meta.id)
 
786
                        if (k != u->id)
781
787
                                continue;
782
788
 
783
789
                        if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2))
784
790
                                goto oom;
785
791
 
786
792
                        description = unit_description(u);
787
 
                        load_state = unit_load_state_to_string(u->meta.load_state);
 
793
                        load_state = unit_load_state_to_string(u->load_state);
788
794
                        active_state = unit_active_state_to_string(unit_active_state(u));
789
795
                        sub_state = unit_sub_state_to_string(u);
790
796
 
791
797
                        f = unit_following(u);
792
 
                        following = f ? f->meta.id : "";
 
798
                        following = f ? f->id : "";
793
799
 
794
800
                        if (!(u_path = unit_dbus_path(u)))
795
801
                                goto oom;
796
802
 
797
 
                        if (u->meta.job) {
798
 
                                job_id = (uint32_t) u->meta.job->id;
 
803
                        if (u->job) {
 
804
                                job_id = (uint32_t) u->job->id;
799
805
 
800
 
                                if (!(j_path = job_dbus_path(u->meta.job))) {
 
806
                                if (!(j_path = job_dbus_path(u->job))) {
801
807
                                        free(u_path);
802
808
                                        goto oom;
803
809
                                }
804
810
 
805
 
                                sjob_type = job_type_to_string(u->meta.job->type);
 
811
                                sjob_type = job_type_to_string(u->job->type);
806
812
                        } else {
807
813
                                job_id = 0;
808
814
                                j_path = u_path;
809
815
                                sjob_type = "";
810
816
                        }
811
817
 
812
 
                        if (!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &u->meta.id) ||
 
818
                        if (!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &u->id) ||
813
819
                            !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &description) ||
814
820
                            !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &load_state) ||
815
821
                            !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &active_state) ||
820
826
                            !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &sjob_type) ||
821
827
                            !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &j_path)) {
822
828
                                free(u_path);
823
 
                                if (u->meta.job)
 
829
                                if (u->job)
824
830
                                        free(j_path);
825
831
                                goto oom;
826
832
                        }
827
833
 
828
834
                        free(u_path);
829
 
                        if (u->meta.job)
 
835
                        if (u->job)
830
836
                                free(j_path);
831
837
 
832
838
                        if (!dbus_message_iter_close_container(&sub, &sub2))
871
877
                        }
872
878
 
873
879
                        if (!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT32, &id) ||
874
 
                            !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &j->unit->meta.id) ||
 
880
                            !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &j->unit->id) ||
875
881
                            !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &type) ||
876
882
                            !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &state) ||
877
883
                            !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &j_path) ||
1013
1019
                HASHMAP_FOREACH_KEY(u, k, m->units, i) {
1014
1020
                        char *p;
1015
1021
 
1016
 
                        if (k != u->meta.id)
 
1022
                        if (k != u->id)
1017
1023
                                continue;
1018
1024
 
1019
1025
                        if (!(p = bus_path_escape(k))) {
1416
1422
                if (!reply)
1417
1423
                        goto oom;
1418
1424
 
1419
 
        } else
1420
 
                return bus_default_message_handler(connection, message, NULL, INTERFACES_LIST, properties);
 
1425
        } else {
 
1426
                const BusBoundProperties bps[] = {
 
1427
                        { "org.freedesktop.systemd1.Manager", bus_systemd_properties, systemd_property_string },
 
1428
                        { "org.freedesktop.systemd1.Manager", bus_manager_properties, m },
 
1429
                        { NULL, }
 
1430
                };
 
1431
                return bus_default_message_handler(connection, message, NULL, INTERFACES_LIST, bps);
 
1432
        }
1421
1433
 
1422
1434
        if (job_type != _JOB_TYPE_INVALID) {
1423
1435
                const char *name, *smode, *old_name = NULL;
1447
1459
 
1448
1460
                if (old_name)
1449
1461
                        if (!(u = manager_get_unit(m, old_name)) ||
1450
 
                            !u->meta.job ||
1451
 
                            u->meta.job->type != JOB_START) {
 
1462
                            !u->job ||
 
1463
                            u->job->type != JOB_START) {
1452
1464
                                dbus_set_error(&error, BUS_ERROR_NO_SUCH_JOB, "No job queued for unit %s", old_name);
1453
1465
                                return bus_send_error_reply(connection, message, &error, -ENOENT);
1454
1466
                        }
1469
1481
                                job_type = JOB_RELOAD;
1470
1482
                }
1471
1483
 
1472
 
                if ((job_type == JOB_START && u->meta.refuse_manual_start) ||
1473
 
                    (job_type == JOB_STOP && u->meta.refuse_manual_stop) ||
 
1484
                if ((job_type == JOB_START && u->refuse_manual_start) ||
 
1485
                    (job_type == JOB_STOP && u->refuse_manual_stop) ||
1474
1486
                    ((job_type == JOB_RESTART || job_type == JOB_TRY_RESTART) &&
1475
 
                     (u->meta.refuse_manual_start || u->meta.refuse_manual_stop))) {
 
1487
                     (u->refuse_manual_start || u->refuse_manual_stop))) {
1476
1488
                        dbus_set_error(&error, BUS_ERROR_ONLY_BY_DEPENDENCY, "Operation refused, may be requested by dependency only.");
1477
1489
                        return bus_send_error_reply(connection, message, &error, -EPERM);
1478
1490
                }