Similar to systemctl man, implement the info and doc commands. The former will open the appropriate info page, the latter will open any http (or https) documentation via xdg-open.
Signed-off-by: Gergely Nagy <[email protected]> --- man/systemctl.xml | 23 +++++++++++++++++ src/systemctl/systemctl.c | 59 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 0 deletions(-) diff --git a/man/systemctl.xml b/man/systemctl.xml index 34a3ea8..5878d7a 100644 --- a/man/systemctl.xml +++ b/man/systemctl.xml @@ -642,6 +642,29 @@ is shown.</para></listitem> </varlistentry> <varlistentry> + <term><command>info [NAME...|PID...]</command></term> + + <listitem><para>Show info pages for + one or more units, if available. If a + PID is passed the info pages for the + unit the process of the PID belongs to + is shown.</para></listitem> + </varlistentry> + <varlistentry> + <term><command>doc [NAME...|PID...]</command></term> + + <listitem><para>Show online documentation for + one or more units, if available. If a + PID is passed the documentation for the + unit the process of the PID belongs to + is shown.</para> + + <para>Only documentation available + on-line via http will be considered, + and will be opened with + <literal>xdg-open</literal></para></listitem> + </varlistentry> + <varlistentry> <term><command>reset-failed [NAME...]</command></term> <listitem><para>Reset the diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index f65bd2f..a0a6d07 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -2525,6 +2525,57 @@ static void man_status_info(UnitStatusInfo *i) { } } +static void simple_status_info(const char *cmd, const char *prefix, bool strip_prefix, UnitStatusInfo *i) { + char **p; + + assert(i); + + if (!i->documentation) { + log_info("Documentation for %s not known.", i->id); + return; + } + + STRV_FOREACH(p, i->documentation) { + + if (startswith(*p, prefix)) { + pid_t pid; + char *page; + const char *args[3] = { cmd, NULL, NULL }; + + if (strip_prefix) { + page = *p + strlen(prefix); + } else + page = *p; + + args[1] = page; + + pid = fork(); + if (pid < 0) { + log_error("Failed to fork: %m"); + continue; + } + + if (pid == 0) { + /* Child */ + execvp(args[0], (char **) args); + log_error("Failed to execute %s: %m", cmd); + _exit(EXIT_FAILURE); + } + + wait_for_terminate(pid, NULL); + } else + log_info("Can't show %s.", *p); + } +} + +static void info_status_info(UnitStatusInfo *i) { + simple_status_info("info", "info:", true, i); +} + +static void doc_status_info(UnitStatusInfo *i) { + simple_status_info("xdg-open", "http", false, i); +} + static int status_property(const char *name, DBusMessageIter *iter, UnitStatusInfo *i) { assert(name); @@ -3022,6 +3073,10 @@ static int show_one(const char *verb, DBusConnection *bus, const char *path, boo if (!show_properties) { if (streq(verb, "man")) man_status_info(&info); + else if (streq(verb, "info")) + info_status_info(&info); + else if (streq(verb, "doc")) + doc_status_info(&info); else print_status_info(&info); } @@ -4285,6 +4340,8 @@ static int systemctl_help(void) { " show [NAME...|JOB...] Show properties of one or more\n" " units/jobs or the manager\n" " man [NAME...|PID...] Show manual for one or more units\n" + " info [NAME...|PID...] Show info pages for one or more units\n" + " doc [NAME...|PID...] Show on-line documentation for one or more units\n" " reset-failed [NAME...] Reset failed state for all, one, or more\n" " units\n" " load [NAME...] Load one or more units\n\n" @@ -5249,6 +5306,8 @@ static int systemctl_main(DBusConnection *bus, int argc, char *argv[], DBusError { "show", MORE, 1, show }, { "status", MORE, 2, show }, { "man", MORE, 2, show }, + { "info", MORE, 2, show }, + { "doc", MORE, 2, show }, { "dump", EQUAL, 1, dump }, { "dot", EQUAL, 1, dot }, { "snapshot", LESS, 2, snapshot }, -- 1.7.9 _______________________________________________ systemd-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/systemd-devel
