X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Fbus-util.c;h=cd05a82d345cc5be54b63fa976484bdf0e2b075d;hb=414b8da030c67923c3bcad749512cb46d81995b3;hp=64c389b356738e4729bb534f40d9d540dbbb2035;hpb=f40e6926d3a7d4f52443462bfbd22287721e1cc2;p=elogind.git diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c index 64c389b35..cd05a82d3 100644 --- a/src/shared/bus-util.c +++ b/src/shared/bus-util.c @@ -19,27 +19,29 @@ along with systemd; If not, see . ***/ -#include +// #include -#include "sd-daemon.h" -#include "sd-event.h" -#include "util.h" +// #include "sd-daemon.h" +// #include "sd-event.h" +// #include "util.h" #include "strv.h" -#include "macro.h" -#include "def.h" -#include "path-util.h" -#include "missing.h" -#include "set.h" -#include "signal-util.h" +// #include "macro.h" +// #include "def.h" +// #include "path-util.h" +// #include "missing.h" +// #include "set.h" +// #include "signal-util.h" #include "unit-name.h" -#include "sd-bus.h" -#include "bus-error.h" -#include "bus-label.h" +// #include "sd-bus.h" +// #include "bus-error.h" +// #include "bus-label.h" #include "bus-message.h" #include "bus-util.h" #include "bus-internal.h" +/// UNNEEDED by elogind +#if 0 static int name_owner_change_callback(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) { sd_event *e = userdata; @@ -93,8 +95,6 @@ int bus_async_unregister_and_exit(sd_event *e, sd_bus *bus, const char *name) { return 0; } -/// UNNEEDED by elogind -#if 0 int bus_event_loop_with_idle( sd_event *e, sd_bus *bus, @@ -551,6 +551,8 @@ void bus_verify_polkit_async_registry_free(Hashmap *registry) { #endif } +/// UNNEEDED by elogind +#if 0 int bus_check_peercred(sd_bus *c) { struct ucred ucred; socklen_t l; @@ -575,14 +577,14 @@ int bus_check_peercred(sd_bus *c) { return 1; } -int bus_open_system_systemd(sd_bus **_bus) { +int bus_connect_system_systemd(sd_bus **_bus) { _cleanup_bus_unref_ sd_bus *bus = NULL; int r; assert(_bus); if (geteuid() != 0) - return sd_bus_open_system(_bus); + return sd_bus_default_system(_bus); /* If we are root and kdbus is not available, then let's talk * directly to the system instance, instead of going via the @@ -617,7 +619,7 @@ int bus_open_system_systemd(sd_bus **_bus) { r = sd_bus_start(bus); if (r < 0) - return sd_bus_open_system(_bus); + return sd_bus_default_system(_bus); r = bus_check_peercred(bus); if (r < 0) @@ -629,7 +631,7 @@ int bus_open_system_systemd(sd_bus **_bus) { return 0; } -int bus_open_user_systemd(sd_bus **_bus) { +int bus_connect_user_systemd(sd_bus **_bus) { _cleanup_bus_unref_ sd_bus *bus = NULL; _cleanup_free_ char *ee = NULL; const char *e; @@ -659,7 +661,7 @@ int bus_open_user_systemd(sd_bus **_bus) { e = secure_getenv("XDG_RUNTIME_DIR"); if (!e) - return sd_bus_open_user(_bus); + return sd_bus_default_user(_bus); ee = bus_address_escape(e); if (!ee) @@ -675,7 +677,7 @@ int bus_open_user_systemd(sd_bus **_bus) { r = sd_bus_start(bus); if (r < 0) - return sd_bus_open_user(_bus); + return sd_bus_default_user(_bus); r = bus_check_peercred(bus); if (r < 0) @@ -686,6 +688,7 @@ int bus_open_user_systemd(sd_bus **_bus) { return 0; } +#endif // 0 int bus_print_property(const char *name, sd_bus_message *property, bool all) { char type; @@ -1213,7 +1216,7 @@ int bus_map_all_properties( return bus_message_map_all_properties(m, map, userdata); } -int bus_open_transport(BusTransport transport, const char *host, bool user, sd_bus **bus) { +int bus_connect_transport(BusTransport transport, const char *host, bool user, sd_bus **bus) { int r; assert(transport >= 0); @@ -1226,9 +1229,12 @@ int bus_open_transport(BusTransport transport, const char *host, bool user, sd_b switch (transport) { case BUS_TRANSPORT_LOCAL: +/// elogind does not support a user bus +#if 0 if (user) r = sd_bus_default_user(bus); else +#endif // 0 r = sd_bus_default_system(bus); break; @@ -1250,7 +1256,7 @@ int bus_open_transport(BusTransport transport, const char *host, bool user, sd_b /// UNNEEDED by elogind #if 0 -int bus_open_transport_systemd(BusTransport transport, const char *host, bool user, sd_bus **bus) { +int bus_connect_transport_systemd(BusTransport transport, const char *host, bool user, sd_bus **bus) { int r; assert(transport >= 0); @@ -1264,9 +1270,9 @@ int bus_open_transport_systemd(BusTransport transport, const char *host, bool us case BUS_TRANSPORT_LOCAL: if (user) - r = bus_open_user_systemd(bus); + r = bus_connect_user_systemd(bus); else - r = bus_open_system_systemd(bus); + r = bus_connect_system_systemd(bus); break; @@ -1350,12 +1356,12 @@ int bus_log_parse_error(int r) { return log_error_errno(r, "Failed to parse bus message: %m"); } +/// UNNEEDED by elogind +#if 0 int bus_log_create_error(int r) { return log_error_errno(r, "Failed to create bus message: %m"); } -/// UNNEEDED by elogind -#if 0 int bus_parse_unit_info(sd_bus_message *message, UnitInfo *u) { assert(message); assert(u); @@ -1432,9 +1438,10 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen return bus_log_create_error(r); if (STR_IN_SET(field, - "CPUAccounting", "MemoryAccounting", "BlockIOAccounting", + "CPUAccounting", "MemoryAccounting", "BlockIOAccounting", "TasksAccounting", "SendSIGHUP", "SendSIGKILL", "WakeSystem", "DefaultDependencies", - "IgnoreSIGPIPE", "TTYVHangup", "TTYReset", "RemainAfterExit")) { + "IgnoreSIGPIPE", "TTYVHangup", "TTYReset", "RemainAfterExit", + "PrivateTmp", "PrivateDevices", "PrivateNetwork", "NoNewPrivileges")) { r = parse_boolean(eq); if (r < 0) { @@ -1445,20 +1452,50 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen r = sd_bus_message_append(m, "v", "b", r); } else if (streq(field, "MemoryLimit")) { - off_t bytes; + uint64_t bytes; + if (isempty(eq) || streq(eq, "infinity")) + bytes = (uint64_t) -1; + else { r = parse_size(eq, 1024, &bytes); if (r < 0) { log_error("Failed to parse bytes specification %s", assignment); return -EINVAL; } + } + + r = sd_bus_message_append(m, "v", "t", bytes); + + } else if (streq(field, "TasksMax")) { + uint64_t n; + + if (isempty(eq) || streq(eq, "infinity")) + n = (uint64_t) -1; + else { + r = safe_atou64(eq, &n); + if (r < 0) { + log_error("Failed to parse maximum tasks specification %s", assignment); + return -EINVAL; + } + } - r = sd_bus_message_append(m, "v", "t", (uint64_t) bytes); + r = sd_bus_message_append(m, "v", "t", n); - } else if (STR_IN_SET(field, "CPUShares", "BlockIOWeight")) { + } else if (STR_IN_SET(field, "CPUShares", "StartupCPUShares")) { uint64_t u; - r = safe_atou64(eq, &u); + r = cg_cpu_shares_parse(eq, &u); + if (r < 0) { + log_error("Failed to parse %s value %s.", field, eq); + return -EINVAL; + } + + r = sd_bus_message_append(m, "v", "t", u); + + } else if (STR_IN_SET(field, "BlockIOWeight", "StartupBlockIOWeight")) { + uint64_t u; + + r = cg_cpu_shares_parse(eq, &u); if (r < 0) { log_error("Failed to parse %s value %s.", field, eq); return -EINVAL; @@ -1470,7 +1507,8 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen "User", "Group", "DevicePolicy", "KillMode", "UtmpIdentifier", "UtmpMode", "PAMName", "TTYPath", "StandardInput", "StandardOutput", "StandardError", - "Description", "Slice", "Type")) + "Description", "Slice", "Type", "WorkingDirectory", + "RootDirectory")) r = sd_bus_message_append(m, "v", "s", eq); else if (streq(field, "DeviceAllow")) { @@ -1503,7 +1541,7 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen r = sd_bus_message_append(m, "v", "a(st)", 0); else { const char *path, *bandwidth, *e; - off_t bytes; + uint64_t bytes; e = strchr(eq, ' '); if (e) { @@ -1525,7 +1563,7 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen return -EINVAL; } - r = sd_bus_message_append(m, "v", "a(st)", 1, path, (uint64_t) bytes); + r = sd_bus_message_append(m, "v", "a(st)", 1, path, bytes); } } else if (streq(field, "BlockIODeviceWeight")) { @@ -1674,7 +1712,6 @@ static int match_job_removed(sd_bus_message *m, void *userdata, sd_bus_error *er return 0; } -#endif // 0 void bus_wait_for_jobs_free(BusWaitForJobs *d) { if (!d) @@ -1693,8 +1730,6 @@ void bus_wait_for_jobs_free(BusWaitForJobs *d) { free(d); } -/// UNNEEDED by elogind -#if 0 int bus_wait_for_jobs_new(sd_bus *bus, BusWaitForJobs **ret) { _cleanup_(bus_wait_for_jobs_freep) BusWaitForJobs *d = NULL; int r; @@ -1744,7 +1779,6 @@ int bus_wait_for_jobs_new(sd_bus *bus, BusWaitForJobs **ret) { return 0; } -#endif // 0 static int bus_process_wait(sd_bus *bus) { int r; @@ -1902,11 +1936,8 @@ int bus_wait_for_jobs(BusWaitForJobs *d, bool quiet) { log_debug_errno(q, "Got result %s/%m for job %s", strna(d->result), strna(d->name)); } - free(d->name); - d->name = NULL; - - free(d->result); - d->result = NULL; + d->name = mfree(d->name); + d->result = mfree(d->result); } return r; @@ -1924,8 +1955,16 @@ int bus_wait_for_jobs_add(BusWaitForJobs *d, const char *path) { return set_put_strdup(d->jobs, path); } -/// UNNEEDED by elogind -#if 0 +int bus_wait_for_jobs_one(BusWaitForJobs *d, const char *path, bool quiet) { + int r; + + r = bus_wait_for_jobs_add(d, path); + if (r < 0) + return log_oom(); + + return bus_wait_for_jobs(d, quiet); +} + int bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool quiet, UnitFileChange **changes, unsigned *n_changes) { const char *type, *path, *source; int r; @@ -1955,7 +1994,6 @@ int bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool quiet, Un return 0; } -#endif // 0 /** * bus_path_encode_unique() - encode unique object path @@ -2083,6 +2121,7 @@ int bus_path_decode_unique(const char *path, const char *prefix, char **ret_send *ret_external = external; return 1; } +#endif // 0 bool is_kdbus_wanted(void) { _cleanup_free_ char *value = NULL;