summaryrefslogtreecommitdiff
path: root/src/shared/pager.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-07-20 18:23:53 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-07-20 19:48:16 -0400
commit78002a678106a9a4e0e9d747f54458ba84322f1a (patch)
treec25747b7ae2cd0c8ebed0a01ab5a880df61e7064 /src/shared/pager.c
parent8b835fccdad78d89f9cc64f9b02059fb75ffbab1 (diff)
systemd-verify: check man pages
Diffstat (limited to 'src/shared/pager.c')
-rw-r--r--src/shared/pager.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/shared/pager.c b/src/shared/pager.c
index 002e3aa373..54790947ba 100644
--- a/src/shared/pager.c
+++ b/src/shared/pager.c
@@ -150,3 +150,56 @@ void pager_close(void) {
bool pager_have(void) {
return pager_pid > 0;
}
+
+int show_man_page(const char *desc, bool null_stdio) {
+ const char *args[4] = { "man", NULL, NULL, NULL };
+ char *e = NULL;
+ pid_t pid;
+ size_t k;
+ int r;
+ siginfo_t status;
+
+ k = strlen(desc);
+
+ if (desc[k-1] == ')')
+ e = strrchr(desc, '(');
+
+ if (e) {
+ char *page = NULL, *section = NULL;
+
+ page = strndupa(desc, e - desc);
+ section = strndupa(e + 1, desc + k - e - 2);
+
+ args[1] = section;
+ args[2] = page;
+ } else
+ args[1] = desc;
+
+ pid = fork();
+ if (pid < 0) {
+ log_error("Failed to fork: %m");
+ return -errno;
+ }
+
+ if (pid == 0) {
+ /* Child */
+ if (null_stdio) {
+ r = make_null_stdio();
+ if (r < 0) {
+ log_error("Failed to kill stdio: %s", strerror(-r));
+ _exit(EXIT_FAILURE);
+ }
+ }
+
+ execvp(args[0], (char**) args);
+ log_error("Failed to execute man: %m");
+ _exit(EXIT_FAILURE);
+ }
+
+ r = wait_for_terminate(pid, &status);
+ if (r < 0)
+ return r;
+
+ log_debug("Exit code %i status %i", status.si_code, status.si_status);
+ return status.si_status;
+}