/***
This file is part of systemd.
Copyright 2013 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include "alloc-util.h"
#include "bus-internal.h"
#include "bus-util.h"
#include "cgroup-util.h"
#include "conf-parser.h"
#include "dirent-util.h"
#include "fd-util.h"
#include "fileio.h"
#include "mkdir.h"
#include "special.h"
#include "unit-name.h"
#include "util.h"
static int create_dbus_files(
const char *path,
const char *name,
const char *service,
const char *exec,
const char *user,
const char *type) {
int r;
if (!service) {
_cleanup_free_ char *a = NULL;
if (!s)
return log_oom();
if (!a)
return log_oom();
f = fopen(a, "wxe");
if (!f)
fprintf(f,
"# Automatically generated by systemd-dbus1-generator\n\n"
"[Unit]\n"
"SourcePath=%s\n"
"Description=DBUS1: %s\n"
"Documentation=man:systemd-dbus1-generator(8)\n\n"
"[Service]\n"
"ExecStart=%s\n"
"Type=dbus\n"
"BusName=%s\n",
path,
name,
exec,
name);
if (user)
if (type) {
char *run;
if (!run) {
log_error("XDG_RUNTIME_DIR not set.");
return -EINVAL;
}
fprintf(f, "Environment=DBUS_STARTER_ADDRESS="KERNEL_USER_BUS_ADDRESS_FMT ";" UNIX_USER_BUS_ADDRESS_FMT "\n",
}
}
r = fflush_and_check(f);
if (r < 0)
return log_error_errno(r, "Failed to write %s: %m", a);
f = safe_fclose(f);
service = s;
}
if (!b)
return log_oom();
f = fopen(b, "wxe");
if (!f)
fprintf(f,
"# Automatically generated by systemd-dbus1-generator\n\n"
"[Unit]\n"
"SourcePath=%s\n"
"Description=DBUS1: %s\n"
"Documentation=man:systemd-dbus1-generator(8)\n\n"
"[BusName]\n"
"Name=%s\n"
"Service=%s\n"
"AllowWorld=talk\n",
path,
name,
name,
service);
r = fflush_and_check(f);
if (r < 0)
return log_error_errno(r, "Failed to write %s: %m", b);
if (!lnk)
return log_oom();
return 0;
}
{ },
};
char *p;
int r;
"D-BUS Service\0",
true, false, true, NULL);
if (r < 0)
return r;
if (!name) {
log_warning("Activation file %s lacks name setting, ignoring.", p);
return 0;
}
if (!service_name_is_valid(name)) {
return 0;
}
log_debug("Skipping %s, identified as systemd.", p);
return 0;
}
if (service) {
return 0;
}
log_warning("Bus names can only activate services, ignoring %s.", p);
return 0;
}
} else {
log_warning("Neither service name nor binary path specified, ignoring %s.", p);
return 0;
}
if (exec[0] != '/') {
log_warning("Exec= in %s does not start with an absolute path, ignoring.", p);
return 0;
}
}
}
int r;
if (!d) {
return 0;
}
r = 0;
int q;
continue;
if (q < 0)
r = q;
}
return r;
fail:
}
const char *f, *t;
mkdir_parents_label(t, 0755);
if (symlink(f, t) < 0)
return 0;
}
const char *f, *t;
mkdir_parents_label(t, 0755);
if (symlink(f, t) < 0)
mkdir_parents_label(t, 0755);
if (symlink(f, t) < 0)
return 0;
}
int r, q;
log_error("This program takes three or no arguments.");
return EXIT_FAILURE;
}
if (argc > 1) {
}
log_open();
umask(0022);
if (!is_kdbus_available())
return 0;
r = cg_pid_get_owner_uid(0, NULL);
if (r >= 0) {
type = "session";
} else if (r == -ENXIO) {
path = "/usr/share/dbus-1/system-services";
type = "system";
} else
return log_error_errno(r, "Failed to determine whether we are running as user or system instance: %m");
/* FIXME: One day this should just be pulled in statically from basic.target */
q = link_busnames_target(units);
if (q < 0)
r = q;
q = link_compatibility(units);
if (q < 0)
r = q;
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}