summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/pager.c53
-rw-r--r--src/shared/pager.h2
2 files changed, 55 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;
+}
diff --git a/src/shared/pager.h b/src/shared/pager.h
index 03dca8bc03..67446170d0 100644
--- a/src/shared/pager.h
+++ b/src/shared/pager.h
@@ -28,3 +28,5 @@
int pager_open(bool jump_to_end);
void pager_close(void);
bool pager_have(void) _pure_;
+
+int show_man_page(const char *page, bool null_stdio);