chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
systemctl: we can make this faster and shorten it a bit with strv_extend()
[elogind.git]
/
src
/
systemctl
/
systemctl.c
diff --git
a/src/systemctl/systemctl.c
b/src/systemctl/systemctl.c
index 442179d34049c89e6c7610376c0b6e3a431f7ef5..852c4d1a860d55f8c5d7da01b4525f17c5041719 100644
(file)
--- a/
src/systemctl/systemctl.c
+++ b/
src/systemctl/systemctl.c
@@
-745,13
+745,12
@@
static int list_dependencies_print(const char *name, int level, unsigned int bra
}
static int list_dependencies_get_dependencies(DBusConnection *bus, const char *name, char ***deps) {
}
static int list_dependencies_get_dependencies(DBusConnection *bus, const char *name, char ***deps) {
- static const char * const dependencies[] = {
- "Requires",
- "RequiresOverridable",
- "Requisite",
- "RequisiteOverridable",
- "Wants"
- };
+ static const char dependencies[] =
+ "Requires\0"
+ "RequiresOverridable\0"
+ "Requisite\0"
+ "RequisiteOverridable\0"
+ "Wants\0";
_cleanup_free_ char *path;
const char *interface = "org.freedesktop.systemd1.Unit";
_cleanup_free_ char *path;
const char *interface = "org.freedesktop.systemd1.Unit";
@@
-760,10
+759,7
@@
static int list_dependencies_get_dependencies(DBusConnection *bus, const char *n
DBusMessageIter iter, sub, sub2, sub3;
int r = 0;
DBusMessageIter iter, sub, sub2, sub3;
int r = 0;
- unsigned int i;
-
char **ret = NULL;
char **ret = NULL;
- char **c;
assert(bus);
assert(name);
assert(bus);
assert(name);
@@
-822,15
+818,9
@@
static int list_dependencies_get_dependencies(DBusConnection *bus, const char *n
}
dbus_message_iter_recurse(&sub2, &sub3);
}
dbus_message_iter_recurse(&sub2, &sub3);
-
dbus_message_iter_next(&sub);
dbus_message_iter_next(&sub);
- for (i = 0; i < ELEMENTSOF(dependencies); i++)
- if (streq(dependencies[i], prop)) {
- break;
- }
-
- if (i == ELEMENTSOF(dependencies))
+ if (!nulstr_contains(dependencies, prop))
continue;
if (dbus_message_iter_get_arg_type(&sub3) == DBUS_TYPE_ARRAY) {
continue;
if (dbus_message_iter_get_arg_type(&sub3) == DBUS_TYPE_ARRAY) {
@@
-843,13
+833,13
@@
static int list_dependencies_get_dependencies(DBusConnection *bus, const char *n
assert(dbus_message_iter_get_arg_type(&sub4) == DBUS_TYPE_STRING);
dbus_message_iter_get_basic(&sub4, &s);
assert(dbus_message_iter_get_arg_type(&sub4) == DBUS_TYPE_STRING);
dbus_message_iter_get_basic(&sub4, &s);
- c = strv_append(ret, s);
- if (c == NULL) {
- r = log_oom();
+
+ r = strv_extend(&ret, s);
+ if (r < 0) {
+ log_oom();
goto finish;
}
goto finish;
}
- strv_free(ret);
- ret = c;
+
dbus_message_iter_next(&sub4);
}
}
dbus_message_iter_next(&sub4);
}
}
@@
-914,20
+904,24
@@
finish:
}
static int list_dependencies(DBusConnection *bus, char **args) {
}
static int list_dependencies(DBusConnection *bus, char **args) {
- int r = 0;
_cleanup_free_ char *unit = NULL;
_cleanup_free_ char *unit = NULL;
+ const char *u;
assert(bus);
assert(bus);
- assert(args[1]);
- unit = unit_name_mangle(args[1]);
- if (!unit)
- return log_oom();
+ if (args[1]) {
+ unit = unit_name_mangle(args[1]);
+ if (!unit)
+ return log_oom();
+ u = unit;
+ } else
+ u = SPECIAL_DEFAULT_TARGET;
pager_open_if_enabled();
pager_open_if_enabled();
- printf("%s\n", unit);
- r = list_dependencies_one(bus, unit, 0, NULL, 0);
- return r;
+
+ puts(u);
+
+ return list_dependencies_one(bus, u, 0, NULL, 0);
}
static int dot_one_property(const char *name, const char *prop, DBusMessageIter *iter) {
}
static int dot_one_property(const char *name, const char *prop, DBusMessageIter *iter) {
@@
-5310,7
+5304,7
@@
static int systemctl_main(DBusConnection *bus, int argc, char *argv[], DBusError
{ "unmask", MORE, 2, enable_unit },
{ "link", MORE, 2, enable_unit },
{ "switch-root", MORE, 2, switch_root },
{ "unmask", MORE, 2, enable_unit },
{ "link", MORE, 2, enable_unit },
{ "switch-root", MORE, 2, switch_root },
- { "list-dependencies",
EQUAL,
2, list_dependencies },
+ { "list-dependencies",
LESS,
2, list_dependencies },
};
int left;
};
int left;