X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flibsystemd%2Fsd-bus%2Fsd-bus.c;h=636715f7590961c09c9fab9a95763719aa64279b;hb=df1e02046144f41176c32ed011369fd8dba36b76;hp=e494cd2ba907636b6b267696b91dced494145e9c;hpb=23abf5d5820ed9f24e8fe92fad32a207fe75398c;p=elogind.git diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c index e494cd2ba..636715f75 100644 --- a/src/libsystemd/sd-bus/sd-bus.c +++ b/src/libsystemd/sd-bus/sd-bus.c @@ -36,6 +36,7 @@ #include "missing.h" #include "def.h" #include "cgroup-util.h" +#include "bus-label.h" #include "sd-bus.h" #include "bus-internal.h" @@ -399,11 +400,11 @@ static int bus_send_hello(sd_bus *bus) { r = sd_bus_message_new_method_call( bus, + &m, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", - "Hello", - &m); + "Hello"); if (r < 0) return r; @@ -794,7 +795,7 @@ static int parse_container_unix_address(sd_bus *b, const char **p, char **guid) b->sockaddr.un.sun_family = AF_UNIX; strncpy(b->sockaddr.un.sun_path, "/var/run/dbus/system_bus_socket", sizeof(b->sockaddr.un.sun_path)); - b->sockaddr_size = offsetof(struct sockaddr_un, sun_path) + sizeof("/var/run/dbus/system_bus_socket") - 1; + b->sockaddr_size = offsetof(struct sockaddr_un, sun_path) + strlen("/var/run/dbus/system_bus_socket"); return 0; } @@ -1214,7 +1215,7 @@ fail: return r; } -_public_ int sd_bus_open_system_remote(const char *host, sd_bus **ret) { +_public_ int sd_bus_open_system_remote(sd_bus **ret, const char *host) { _cleanup_free_ char *e = NULL; char *p = NULL; sd_bus *bus; @@ -1250,7 +1251,7 @@ _public_ int sd_bus_open_system_remote(const char *host, sd_bus **ret) { return 0; } -_public_ int sd_bus_open_system_container(const char *machine, sd_bus **ret) { +_public_ int sd_bus_open_system_container(sd_bus **ret, const char *machine) { _cleanup_free_ char *e = NULL; sd_bus *bus; char *p; @@ -2384,10 +2385,10 @@ static int process_closing(sd_bus *bus, sd_bus_message **ret) { /* Then, synthesize a Disconnected message */ r = sd_bus_message_new_signal( bus, + &m, "/org/freedesktop/DBus/Local", "org.freedesktop.DBus.Local", - "Disconnected", - &m); + "Disconnected"); if (r < 0) return r; @@ -2821,7 +2822,7 @@ static int attach_io_events(sd_bus *bus) { return 0; if (!bus->input_io_event_source) { - r = sd_event_add_io(bus->event, bus->input_fd, 0, io_callback, bus, &bus->input_io_event_source); + r = sd_event_add_io(bus->event, &bus->input_io_event_source, bus->input_fd, 0, io_callback, bus); if (r < 0) return r; @@ -2840,7 +2841,7 @@ static int attach_io_events(sd_bus *bus) { assert(bus->output_fd >= 0); if (!bus->output_io_event_source) { - r = sd_event_add_io(bus->event, bus->output_fd, 0, io_callback, bus, &bus->output_io_event_source); + r = sd_event_add_io(bus->event, &bus->output_io_event_source, bus->output_fd, 0, io_callback, bus); if (r < 0) return r; @@ -2889,7 +2890,7 @@ _public_ int sd_bus_attach_event(sd_bus *bus, sd_event *event, int priority) { bus->event_priority = priority; - r = sd_event_add_monotonic(bus->event, 0, 0, time_callback, bus, &bus->time_event_source); + r = sd_event_add_monotonic(bus->event, &bus->time_event_source, 0, 0, time_callback, bus); if (r < 0) goto fail; @@ -2897,7 +2898,7 @@ _public_ int sd_bus_attach_event(sd_bus *bus, sd_event *event, int priority) { if (r < 0) goto fail; - r = sd_event_add_exit(bus->event, quit_callback, bus, &bus->quit_event_source); + r = sd_event_add_exit(bus->event, &bus->quit_event_source, quit_callback, bus); if (r < 0) goto fail; @@ -3041,75 +3042,11 @@ _public_ int sd_bus_get_tid(sd_bus *b, pid_t *tid) { } _public_ char *sd_bus_label_escape(const char *s) { - char *r, *t; - const char *f; - - assert_return(s, NULL); - - /* Escapes all chars that D-Bus' object path cannot deal - * with. Can be reversed with bus_path_unescape(). We special - * case the empty string. */ - - if (*s == 0) - return strdup("_"); - - r = new(char, strlen(s)*3 + 1); - if (!r) - return NULL; - - for (f = s, t = r; *f; f++) { - - /* Escape everything that is not a-zA-Z0-9. We also - * escape 0-9 if it's the first character */ - - if (!(*f >= 'A' && *f <= 'Z') && - !(*f >= 'a' && *f <= 'z') && - !(f > s && *f >= '0' && *f <= '9')) { - *(t++) = '_'; - *(t++) = hexchar(*f >> 4); - *(t++) = hexchar(*f); - } else - *(t++) = *f; - } - - *t = 0; - - return r; + return bus_label_escape(s); } _public_ char *sd_bus_label_unescape(const char *f) { - char *r, *t; - - assert_return(f, NULL); - - /* Special case for the empty string */ - if (streq(f, "_")) - return strdup(""); - - r = new(char, strlen(f) + 1); - if (!r) - return NULL; - - for (t = r; *f; f++) { - - if (*f == '_') { - int a, b; - - if ((a = unhexchar(f[1])) < 0 || - (b = unhexchar(f[2])) < 0) { - /* Invalid escape code, let's take it literal then */ - *(t++) = '_'; - } else { - *(t++) = (char) ((a << 4) | b); - f += 2; - } - } else - *(t++) = *f; - } - - *t = 0; - - return r; + return bus_label_unescape(f); } _public_ int sd_bus_get_peer_creds(sd_bus *bus, uint64_t mask, sd_bus_creds **ret) {