0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering This file is part of systemd.
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering Copyright 2013 Lennart Poettering
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering systemd is free software; you can redistribute it and/or modify it
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering under the terms of the GNU Lesser General Public License as published by
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering (at your option) any later version.
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering systemd is distributed in the hope that it will be useful, but
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering Lesser General Public License for more details.
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering You should have received a copy of the GNU Lesser General Public License
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poetteringstatic const char *arg_dest_late = "/tmp", *arg_dest = "/tmp";
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering const char *type) {
86e9cbcaeda647eb4f1db77333f7069d5bf549f1Lennart Poettering _cleanup_free_ char *b = NULL, *s = NULL, *lnk = NULL;
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering s = strjoin("dbus-", name, ".service", NULL);
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering a = strjoin(arg_dest_late, "/", s, NULL);
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering return log_error_errno(errno, "Failed to create %s: %m", a);
86e9cbcaeda647eb4f1db77333f7069d5bf549f1Lennart Poettering "# Automatically generated by systemd-dbus1-generator\n\n"
86e9cbcaeda647eb4f1db77333f7069d5bf549f1Lennart Poettering "SourcePath=%s\n"
d76f90f1711e55d23ee6c8c0957fa3db17927327Lennart Poettering "Description=DBUS1: %s\n"
d76f90f1711e55d23ee6c8c0957fa3db17927327Lennart Poettering "Documentation=man:systemd-dbus1-generator(8)\n\n"
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering "ExecStart=%s\n"
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering "BusName=%s\n",
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering fprintf(f, "Environment=DBUS_STARTER_BUS_TYPE=%s\n", type);
105e151299dc1208855380be2b22d0db2d66ebc6Lennart Poettering fprintf(f, "Environment=DBUS_STARTER_ADDRESS=" DEFAULT_SYSTEM_BUS_ADDRESS "\n");
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering fprintf(f, "Environment=DBUS_STARTER_ADDRESS="KERNEL_USER_BUS_ADDRESS_FMT ";" UNIX_USER_BUS_ADDRESS_FMT "\n",
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering return log_error_errno(r, "Failed to write %s: %m", a);
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering b = strjoin(arg_dest_late, "/", name, ".busname", NULL);
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering return log_error_errno(errno, "Failed to create %s: %m", b);
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering "# Automatically generated by systemd-dbus1-generator\n\n"
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering "SourcePath=%s\n"
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering "Description=DBUS1: %s\n"
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering "Documentation=man:systemd-dbus1-generator(8)\n\n"
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering "Service=%s\n"
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering "AllowWorld=talk\n",
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering return log_error_errno(r, "Failed to write %s: %m", b);
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering lnk = strjoin(arg_dest_late, "/" SPECIAL_BUSNAMES_TARGET ".wants/", name, ".busname", NULL);
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering return log_error_errno(errno, "Failed to create symlink %s: %m", lnk);
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poetteringstatic int add_dbus(const char *path, const char *fname, const char *type) {
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering _cleanup_free_ char *name = NULL, *exec = NULL, *user = NULL, *service = NULL;
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering { "D-BUS Service", "Name", config_parse_string, 0, &name },
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering { "D-BUS Service", "Exec", config_parse_string, 0, &exec },
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering { "D-BUS Service", "User", config_parse_string, 0, &user },
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering { "D-BUS Service", "SystemdService", config_parse_string, 0, &service },
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering "D-BUS Service\0",
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering true, false, true, NULL);
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering log_warning("Activation file %s lacks name setting, ignoring.", p);
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering log_warning("Bus service name %s is not valid, ignoring.", name);
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering if (streq(name, "org.freedesktop.systemd1")) {
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering log_debug("Skipping %s, identified as systemd.", p);
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering if (!unit_name_is_valid(service, UNIT_NAME_PLAIN|UNIT_NAME_INSTANCE)) {
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering log_warning("Unit name %s is not valid, ignoring.", service);
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering log_warning("Bus names can only activate services, ignoring %s.", p);
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering if (streq(exec, "/bin/false") || !exec) {
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering log_warning("Neither service name nor binary path specified, ignoring %s.", p);
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering log_warning("Exec= in %s does not start with an absolute path, ignoring.", p);
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering return create_dbus_files(p, name, service, exec, user, type);
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poetteringstatic int parse_dbus_fragments(const char *path, const char *type) {
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering return log_error_errno(errno, "Failed to enumerate D-Bus activated services: %m");
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering return log_error_errno(errno, "Failed to read D-Bus services directory: %m");
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poetteringstatic int link_busnames_target(const char *units) {
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering const char *f, *t;
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering f = strjoina(units, "/" SPECIAL_BUSNAMES_TARGET);
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering t = strjoina(arg_dest, "/" SPECIAL_BASIC_TARGET ".wants/" SPECIAL_BUSNAMES_TARGET);
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering return log_error_errno(errno, "Failed to create symlink %s: %m", t);
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poetteringstatic int link_compatibility(const char *units) {
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering const char *f, *t;
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering f = strjoina(units, "/systemd-bus-proxyd.socket");
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering t = strjoina(arg_dest, "/" SPECIAL_DBUS_SOCKET);
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering return log_error_errno(errno, "Failed to create symlink %s: %m", t);
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering f = strjoina(units, "/systemd-bus-proxyd.socket");
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering t = strjoina(arg_dest, "/" SPECIAL_SOCKETS_TARGET ".wants/systemd-bus-proxyd.socket");
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering return log_error_errno(errno, "Failed to create symlink %s: %m", t);
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering t = strjoina(arg_dest, "/" SPECIAL_DBUS_SERVICE);
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering return log_error_errno(errno, "Failed to mask %s: %m", t);
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering log_error("This program takes three or no arguments.");
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering } else if (r == -ENXIO) {
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering path = "/usr/share/dbus-1/system-services";
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering return log_error_errno(r, "Failed to determine whether we are running as user or system instance: %m");
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering /* FIXME: One day this should just be pulled in statically from basic.target */