static char **arg_load_states = NULL;
static char **arg_properties = NULL;
static bool arg_all = false;
+static enum dependency {
+ DEPENDENCY_FORWARD,
+ DEPENDENCY_REVERSE,
+ DEPENDENCY_AFTER,
+ DEPENDENCY_BEFORE,
+} arg_dependency = DEPENDENCY_FORWARD;
static const char *arg_job_mode = "replace";
static UnitFileScope arg_scope = UNIT_FILE_SYSTEM;
static bool arg_no_block = false;
static const char *arg_host = NULL;
static unsigned arg_lines = 10;
static OutputMode arg_output = OUTPUT_SHORT;
+static bool arg_plain = false;
static bool private_bus = false;
id_len = max_id_len;
for (u = unit_infos; u < unit_infos + c; u++) {
- char _cleanup_free_ *e = NULL;
+ _cleanup_free_ char *e = NULL;
const char *on_loaded, *off_loaded, *on = "";
const char *on_active, *off_active, *off = "";
{
const char *interface = "org.freedesktop.systemd1.Unit",
*triggers_property = "Triggers";
- DBusMessage _cleanup_dbus_message_unref_ *reply = NULL;
+ _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
DBusMessageIter iter, sub;
int r;
{
const char *interface = "org.freedesktop.systemd1.Socket",
*listen_property = "Listen";
- DBusMessage _cleanup_dbus_message_unref_ *reply = NULL;
+ _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
DBusMessageIter iter, sub;
int r;
for (u = unit_infos; u < unit_infos + cu; u++) {
const char *dot;
- char _cleanup_strv_free_ **listen = NULL, **triggered = NULL;
+ _cleanup_strv_free_ char **listen = NULL, **triggered = NULL;
unsigned c = 0, i;
if (!output_show_unit(u))
printf("%-*s %-*s\n", id_cols, "UNIT FILE", state_cols, "STATE");
for (u = units; u < units + c; u++) {
- char _cleanup_free_ *e = NULL;
+ _cleanup_free_ char *e = NULL;
const char *on, *off;
const char *id;
size_t len = 0;
size_t max_len = MAX(columns(),20u);
- for (i = level - 1; i >= 0; i--) {
+ if (!arg_plain) {
+ for (i = level - 1; i >= 0; i--) {
+ len += 2;
+ if(len > max_len - 3 && !arg_full) {
+ printf("%s...\n",max_len % 2 ? "" : " ");
+ return 0;
+ }
+ printf("%s", draw_special_char(branches & (1 << i) ? DRAW_TREE_VERT : DRAW_TREE_SPACE));
+ }
len += 2;
if(len > max_len - 3 && !arg_full) {
printf("%s...\n",max_len % 2 ? "" : " ");
return 0;
}
- printf("%s", draw_special_char(branches & (1 << i) ? DRAW_TREE_VERT : DRAW_TREE_SPACE));
+ printf("%s", draw_special_char(last ? DRAW_TREE_RIGHT : DRAW_TREE_BRANCH));
}
- len += 2;
- if(len > max_len - 3 && !arg_full) {
- printf("%s...\n",max_len % 2 ? "" : " ");
- return 0;
- }
- printf("%s", draw_special_char(last ? DRAW_TREE_RIGHT : DRAW_TREE_BRANCH));
if(arg_full){
printf("%s\n", name);
}
static int list_dependencies_get_dependencies(DBusConnection *bus, const char *name, char ***deps) {
- static const char dependencies[] =
- "Requires\0"
- "RequiresOverridable\0"
- "Requisite\0"
- "RequisiteOverridable\0"
- "Wants\0";
+ static const char *dependencies[] = {
+ [DEPENDENCY_FORWARD] = "Requires\0"
+ "RequiresOverridable\0"
+ "Requisite\0"
+ "RequisiteOverridable\0"
+ "Wants\0",
+ [DEPENDENCY_REVERSE] = "RequiredBy\0"
+ "RequiredByOverridable\0"
+ "WantedBy\0"
+ "PartOf\0",
+ [DEPENDENCY_AFTER] = "After\0",
+ [DEPENDENCY_BEFORE] = "Before\0",
+ };
_cleanup_free_ char *path;
const char *interface = "org.freedesktop.systemd1.Unit";
dbus_message_iter_recurse(&sub2, &sub3);
dbus_message_iter_next(&sub);
- if (!nulstr_contains(dependencies, prop))
+ assert(arg_dependency < ELEMENTSOF(dependencies));
+ if (!nulstr_contains(dependencies[arg_dependency], prop))
continue;
if (dbus_message_iter_get_arg_type(&sub3) == DBUS_TYPE_ARRAY) {
return strcasecmp(*a, *b);
}
-static int list_dependencies_one(DBusConnection *bus, const char *name, int level, char **units, unsigned int branches) {
- char _cleanup_strv_free_ **deps = NULL, **u;
+static int list_dependencies_one(DBusConnection *bus, const char *name, int level, char ***units, unsigned int branches) {
+ _cleanup_strv_free_ char **deps = NULL, **u;
char **c;
int r = 0;
- u = strv_append(units, name);
+ u = strv_append(*units, name);
if (!u)
return log_oom();
STRV_FOREACH(c, deps) {
if (strv_contains(u, *c)) {
- r = list_dependencies_print("...", level + 1, (branches << 1) | (c[1] == NULL ? 0 : 1), 1);
- if (r < 0)
- return r;
+ if (!arg_plain) {
+ r = list_dependencies_print("...", level + 1, (branches << 1) | (c[1] == NULL ? 0 : 1), 1);
+ if (r < 0)
+ return r;
+ }
continue;
}
return r;
if (arg_all || unit_name_to_type(*c) == UNIT_TARGET) {
- r = list_dependencies_one(bus, *c, level + 1, u, (branches << 1) | (c[1] == NULL ? 0 : 1));
+ r = list_dependencies_one(bus, *c, level + 1, &u, (branches << 1) | (c[1] == NULL ? 0 : 1));
if(r < 0)
return r;
}
}
-
+ if (arg_plain) {
+ strv_free(*units);
+ *units = u;
+ u = NULL;
+ }
return 0;
}
static int list_dependencies(DBusConnection *bus, char **args) {
_cleanup_free_ char *unit = NULL;
+ _cleanup_strv_free_ char **units = NULL;
const char *u;
assert(bus);
puts(u);
- return list_dependencies_one(bus, u, 0, NULL, 0);
+ return list_dependencies_one(bus, u, 0, &units, 0);
}
struct job_info {
for (i = 0, j = jobs; i < n; i++, j++) {
assert(j->name && j->type && j->state);
- l0 = MAX(l0, decimal_str_max(j->id));
+ l0 = MAX(l0, DECIMAL_STR_WIDTH(j->id));
l1 = MAX(l1, strlen(j->name));
l2 = MAX(l2, strlen(j->type));
l3 = MAX(l3, strlen(j->state));
l3, "STATE");
for (i = 0, j = jobs; i < n; i++, j++) {
- char _cleanup_free_ *e = NULL;
+ _cleanup_free_ char *e = NULL;
if (streq(j->state, "running")) {
on = ansi_highlight(true);
goto finish;
}
- if (!greedy_realloc((void**) &jobs, &size,
- sizeof(struct job_info) * (used + 1))) {
+ if (!GREEDY_REALLOC(jobs, size, used + 1)) {
r = log_oom();
goto finish;
}
} WaitData;
static DBusHandlerResult wait_filter(DBusConnection *connection, DBusMessage *message, void *data) {
- DBusError _cleanup_dbus_error_free_ error;
+ _cleanup_dbus_error_free_ DBusError error;
WaitData *d = data;
dbus_error_init(&error);
*load_state_property = "LoadState",
*triggered_by_property = "TriggeredBy",
*state;
- char _cleanup_free_ *unit_path = NULL, *n = NULL;
+ _cleanup_free_ char *unit_path = NULL, *n = NULL;
bool print_warning_label = true;
int r;
if (!p)
return log_oom();
- r = set_put(s, p);
+ r = set_consume(s, p);
if (r < 0) {
- free(p);
log_error("Failed to add path to set.");
return r;
}
int r, ret = 0;
const char *method, *mode, *one_name;
- Set _cleanup_set_free_free_ *s = NULL;
- DBusError _cleanup_dbus_error_free_ error;
+ _cleanup_set_free_free_ Set *s = NULL;
+ _cleanup_dbus_error_free_ DBusError error;
char **name;
dbus_error_init(&error);
if (startswith(*p, "man:")) {
size_t k;
char *e = NULL;
- char _cleanup_free_ *page = NULL, *section = NULL;
+ _cleanup_free_ char *page = NULL, *section = NULL;
const char *args[4] = { "man", NULL, NULL, NULL };
pid_t pid;
if (exec_status_info_deserialize(&sub, &info) >= 0) {
char timestamp1[FORMAT_TIMESTAMP_MAX], timestamp2[FORMAT_TIMESTAMP_MAX];
- char _cleanup_free_ *t;
+ _cleanup_free_ char *t;
t = strv_join(info.argv, " ");
}
static int show_one(const char *verb, DBusConnection *bus, const char *path, bool show_properties, bool *new_line) {
- DBusMessage _cleanup_free_ *reply = NULL;
+ _cleanup_free_ DBusMessage *reply = NULL;
const char *interface = "";
int r;
DBusMessageIter iter, sub, sub2, sub3;
static int show_one_by_pid(const char *verb, DBusConnection *bus, uint32_t pid, bool *new_line) {
_cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
const char *path = NULL;
- DBusError _cleanup_dbus_error_free_ error;
+ _cleanup_dbus_error_free_ DBusError error;
int r;
dbus_error_init(&error);
qsort(unit_infos, c, sizeof(struct unit_info), compare_unit_info);
for (u = unit_infos; u < unit_infos + c; u++) {
- char _cleanup_free_ *p = NULL;
+ _cleanup_free_ char *p = NULL;
if (!output_show_unit(u))
continue;
r = 0;
for (f = 1; args[f]; f++) {
const char *name;
- char *p;
+ _cleanup_free_ char *p = NULL, *q = NULL;
bool found_native = false, found_sysv;
unsigned c = 1;
const char *argv[6] = { "/sbin/chkconfig", NULL, NULL, NULL, NULL };
- char **k, *l, *q = NULL;
+ char **k, *l;
int j;
pid_t pid;
siginfo_t status;
continue;
STRV_FOREACH(k, paths.unit_path) {
- p = NULL;
-
if (!isempty(arg_root))
asprintf(&p, "%s/%s/%s", arg_root, *k, name);
else
found_native = access(p, F_OK) >= 0;
free(p);
+ p = NULL;
if (found_native)
break;
if (found_native)
continue;
- p = NULL;
if (!isempty(arg_root))
asprintf(&p, "%s/" SYSTEM_SYSVINIT_PATH "/%s", arg_root, name);
else
p[strlen(p) - sizeof(".service") + 1] = 0;
found_sysv = access(p, F_OK) >= 0;
- if (!found_sysv) {
- free(p);
+ if (!found_sysv)
continue;
- }
/* Mark this entry, so that we don't try enabling it as native unit */
args[f] = (char*) "";
l = strv_join((char**)argv, " ");
if (!l) {
- free(q);
- free(p);
r = log_oom();
goto finish;
}
pid = fork();
if (pid < 0) {
log_error("Failed to fork: %m");
- free(p);
- free(q);
r = -errno;
goto finish;
} else if (pid == 0) {
_exit(EXIT_FAILURE);
}
- free(p);
- free(q);
-
j = wait_for_terminate(pid, &status);
if (j < 0) {
log_error("Failed to wait for child: %s", strerror(-r));
UnitFileChange *changes = NULL;
unsigned n_changes = 0, i;
int carries_install_info = -1;
- DBusMessage _cleanup_dbus_message_unref_ *m = NULL, *reply = NULL;
+ _cleanup_dbus_message_unref_ DBusMessage *m = NULL, *reply = NULL;
int r;
- DBusError _cleanup_dbus_error_free_ error;
- char _cleanup_strv_free_ **mangled_names = NULL;
+ _cleanup_dbus_error_free_ DBusError error;
+ _cleanup_strv_free_ char **mangled_names = NULL;
dbus_error_init(&error);
}
static int unit_is_enabled(DBusConnection *bus, char **args) {
- DBusError _cleanup_dbus_error_free_ error;
+ _cleanup_dbus_error_free_ DBusError error;
int r;
- DBusMessage _cleanup_dbus_message_unref_ *reply = NULL;
+ _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
bool enabled;
char **name;
char *n;
" --version Show package version\n"
" -t --type=TYPE List only units of a particular type\n"
" -p --property=NAME Show only properties by this name\n"
- " -a --all Show all units/properties, including dead/empty ones\n"
+ " -a --all Show all loaded units/properties, including dead/empty\n"
+ " ones. To list all units installed on the system, use\n"
+ " the 'list-unit-files' command instead.\n"
+ " --reverse Show reverse dependencies with 'list-dependencies'\n"
" --failed Show only failed units\n"
" --full Don't ellipsize unit names on output\n"
" --fail When queueing a new job, fail if conflicting jobs are\n"
" unset-cgroup [NAME] [CGROUP...] Remove unit from a control group\n"
" load [NAME...] Load one or more units\n"
" list-dependencies [NAME] Recursively show units which are required\n"
- " or wanted by this unit\n\n"
+ " or wanted by this unit or by which this\n"
+ " unit is required or wanted\n\n"
"Unit File Commands:\n"
" list-unit-files List installed unit files\n"
" enable [NAME...] Enable one or more unit files\n"
enum {
ARG_FAIL = 0x100,
+ ARG_REVERSE,
+ ARG_AFTER,
+ ARG_BEFORE,
ARG_SHOW_TYPES,
ARG_IRREVERSIBLE,
ARG_IGNORE_DEPENDENCIES,
ARG_NO_ASK_PASSWORD,
ARG_FAILED,
ARG_RUNTIME,
- ARG_FORCE
+ ARG_FORCE,
+ ARG_PLAIN
};
static const struct option options[] = {
{ "type", required_argument, NULL, 't' },
{ "property", required_argument, NULL, 'p' },
{ "all", no_argument, NULL, 'a' },
+ { "reverse", no_argument, NULL, ARG_REVERSE },
+ { "after", no_argument, NULL, ARG_AFTER },
+ { "before", no_argument, NULL, ARG_BEFORE },
{ "show-types", no_argument, NULL, ARG_SHOW_TYPES },
{ "failed", no_argument, NULL, ARG_FAILED },
{ "full", no_argument, NULL, ARG_FULL },
{ "runtime", no_argument, NULL, ARG_RUNTIME },
{ "lines", required_argument, NULL, 'n' },
{ "output", required_argument, NULL, 'o' },
+ { "plain", no_argument, NULL, ARG_PLAIN },
{ NULL, 0, NULL, 0 }
};
size_t size;
FOREACH_WORD_SEPARATOR(word, size, optarg, ",", state) {
- char _cleanup_free_ *type;
+ _cleanup_free_ char *type;
type = strndup(word, size);
if (!type)
arg_all = true;
break;
+ case ARG_REVERSE:
+ arg_dependency = DEPENDENCY_REVERSE;
+ break;
+
+ case ARG_AFTER:
+ arg_dependency = DEPENDENCY_AFTER;
+ break;
+
+ case ARG_BEFORE:
+ arg_dependency = DEPENDENCY_BEFORE;
+ break;
+
case ARG_SHOW_TYPES:
arg_show_types = true;
break;
arg_ignore_inhibitors = true;
break;
+ case ARG_PLAIN:
+ arg_plain = true;
+ break;
+
case '?':
return -EINVAL;
return systemctl_parse_argv(argc, argv);
}
-static int action_to_runlevel(void) {
+_pure_ static int action_to_runlevel(void) {
static const char table[_ACTION_MAX] = {
[ACTION_HALT] = '0',
}
static int talk_upstart(void) {
- DBusMessage _cleanup_dbus_message_unref_ *m = NULL, *reply = NULL;
- DBusError _cleanup_dbus_error_free_ error;
+ _cleanup_dbus_message_unref_ DBusMessage *m = NULL, *reply = NULL;
+ _cleanup_dbus_error_free_ DBusError error;
int previous, rl, r;
char
env1_buf[] = "RUNLEVEL=X",
static int talk_initctl(void) {
struct init_request request = {};
int r;
- int _cleanup_close_ fd = -1;
+ _cleanup_close_ int fd = -1;
char rl;
rl = action_to_runlevel();
}
static int send_shutdownd(usec_t t, char mode, bool dry_run, bool warn, const char *message) {
- int _cleanup_close_ fd;
+ _cleanup_close_ int fd;
struct sd_shutdown_command c = {
.usec = t,
.mode = mode,
}
if (arg_when > 0) {
- char _cleanup_free_ *m;
+ _cleanup_free_ char *m;
m = strv_join(arg_wall, " ");
r = send_shutdownd(arg_when,
int main(int argc, char*argv[]) {
int r, retval = EXIT_FAILURE;
DBusConnection *bus = NULL;
- DBusError _cleanup_dbus_error_free_ error;
+ _cleanup_dbus_error_free_ DBusError error;
dbus_error_init(&error);