diff options
author | Richard Jones <rjones@redhat.com> | 2010-04-24 09:10:28 +0100 |
---|---|---|
committer | Richard Jones <rjones@redhat.com> | 2010-04-24 09:11:37 +0100 |
commit | 78d2523ec8997679f7fca810de60620df4001e16 (patch) | |
tree | 68016189961d61b5d10788c898a5d59ccad10967 /fish/man.c | |
parent | ce95be8b185ce697816c3446406d7129e01cc0e1 (diff) | |
download | libguestfs-78d2523ec8997679f7fca810de60620df4001e16.tar.gz libguestfs-78d2523ec8997679f7fca810de60620df4001e16.tar.xz libguestfs-78d2523ec8997679f7fca810de60620df4001e16.zip |
fish: Add 'man' command which opens the manual.
Diffstat (limited to 'fish/man.c')
-rw-r--r-- | fish/man.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/fish/man.c b/fish/man.c new file mode 100644 index 00000000..e28e892a --- /dev/null +++ b/fish/man.c @@ -0,0 +1,58 @@ +/* guestfish - the filesystem interactive shell + * Copyright (C) 2010 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include <config.h> + +#include <stdio.h> +#include <stdlib.h> +#include <signal.h> +#include <sys/wait.h> + +#include "fish.h" + +/* guestfish man command */ + +int +do_man (const char *cmd, int argc, char *argv[]) +{ + if (argc != 0) { + fprintf (stderr, _("use 'man' without parameters to open the manual\n")); + return -1; + } + + /* We have to restore SIGPIPE to the default action around the + * external 'man' command to avoid the warning 'gzip: stdout: Broken pipe'. + */ + struct sigaction sa, old_sa; + memset (&sa, 0, sizeof sa); + sa.sa_handler = SIG_DFL; + sigaction (SIGPIPE, &sa, &old_sa); + + int r = system ("man 1 guestfish"); + + sigaction (SIGPIPE, &old_sa, NULL); + + if (r != 0) + return -1; + if (!WIFEXITED (r) || WEXITSTATUS (r) != 0) { + fprintf (stderr, _("the external 'man' program failed\n")); + return -1; + } + + return 0; +} |