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: also color filenames of drop-ins in cat
[elogind.git]
/
src
/
systemctl
/
systemctl.c
diff --git
a/src/systemctl/systemctl.c
b/src/systemctl/systemctl.c
index aab92c466f2641e0d662ca7eab32acc1cc573914..c20a82b8b45ad0c2938f1613341993418f711719 100644
(file)
--- a/
src/systemctl/systemctl.c
+++ b/
src/systemctl/systemctl.c
@@
-3678,6
+3678,7
@@
static int get_unit_dbus_path_by_pid(
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
+ char *u;
int r;
r = sd_bus_call_method(
int r;
r = sd_bus_call_method(
@@
-3694,10
+3695,15
@@
static int get_unit_dbus_path_by_pid(
return r;
}
return r;
}
- r = sd_bus_message_read(reply, "o",
unit
);
+ r = sd_bus_message_read(reply, "o",
&u
);
if (r < 0)
return bus_log_parse_error(r);
if (r < 0)
return bus_log_parse_error(r);
+ u = strdup(u);
+ if (!u)
+ return log_oom();
+
+ *unit = u;
return 0;
}
return 0;
}
@@
-3746,6
+3752,7
@@
static int cat(sd_bus *bus, char **args) {
_cleanup_free_ char *unit = NULL, *n = NULL;
int r = 0;
char **name;
_cleanup_free_ char *unit = NULL, *n = NULL;
int r = 0;
char **name;
+ bool first = true;
assert(bus);
assert(args);
assert(bus);
assert(args);
@@
-3796,11
+3803,16
@@
static int cat(sd_bus *bus, char **args) {
continue;
}
continue;
}
+ if (first)
+ first = false;
+ else
+ puts("");
+
if (!isempty(fragment_path)) {
if (!isempty(fragment_path)) {
-
fprintf(stdout,
"%s# %s%s\n",
-
ansi_highlight_blue(),
-
fragment_path,
-
ansi_highlight_off());
+
printf(
"%s# %s%s\n",
+ ansi_highlight_blue(),
+ fragment_path,
+ ansi_highlight_off());
fflush(stdout);
r = sendfile_full(STDOUT_FILENO, fragment_path);
fflush(stdout);
r = sendfile_full(STDOUT_FILENO, fragment_path);
@@
-3811,9
+3823,11
@@
static int cat(sd_bus *bus, char **args) {
}
STRV_FOREACH(path, dropin_paths) {
}
STRV_FOREACH(path, dropin_paths) {
- fprintf(stdout, "%s# %s\n",
- isempty(fragment_path) && path == dropin_paths ? "" : "\n",
- *path);
+ printf("%s%s# %s%s\n",
+ isempty(fragment_path) && path == dropin_paths ? "" : "\n",
+ ansi_highlight_blue(),
+ *path,
+ ansi_highlight_off());
fflush(stdout);
r = sendfile_full(STDOUT_FILENO, *path);
fflush(stdout);
r = sendfile_full(STDOUT_FILENO, *path);
@@
-3874,8
+3888,10
@@
static int show(sd_bus *bus, char **args) {
} else {
/* Interpret as PID */
r = get_unit_dbus_path_by_pid(bus, id, &unit);
} else {
/* Interpret as PID */
r = get_unit_dbus_path_by_pid(bus, id, &unit);
- if (r < 0)
+ if (r < 0)
{
ret = r;
ret = r;
+ continue;
+ }
}
show_one(args[0], bus, unit, show_properties, &new_line, &ellipsized);
}
show_one(args[0], bus, unit, show_properties, &new_line, &ellipsized);