mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-11 01:27:58 +01:00
cli: handle missing manpages gracefully
Instead of exiting when we can't find a manpage, set the command and continue so that we can try the json rpc for help. Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
parent
cc4357f0a6
commit
d23a0e8adc
1 changed files with 23 additions and 6 deletions
|
@ -14,6 +14,7 @@
|
|||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define NO_ERROR 0
|
||||
|
@ -171,9 +172,23 @@ static void add_input(char **cmd, const char *input,
|
|||
}
|
||||
|
||||
static void
|
||||
exec_man (const char *page) {
|
||||
execlp("man", "man", page, (char *)NULL);
|
||||
err(1, "Running man command");
|
||||
try_exec_man (const char *page) {
|
||||
int status;
|
||||
|
||||
switch (fork()) {
|
||||
case -1:
|
||||
err(1, "Forking man command");
|
||||
case 0:
|
||||
/* child, run man command. */
|
||||
execlp("man", "man", page, (char *)NULL);
|
||||
err(1, "Running man command");
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
wait(&status);
|
||||
if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
@ -192,6 +207,7 @@ int main(int argc, char *argv[])
|
|||
int parserr;
|
||||
enum format format = DEFAULT_FORMAT;
|
||||
enum input input = DEFAULT_INPUT;
|
||||
char *command = NULL;
|
||||
|
||||
err_set_progname(argv[0]);
|
||||
jsmn_init(&parser);
|
||||
|
@ -234,9 +250,10 @@ int main(int argc, char *argv[])
|
|||
/* Launch a manpage if we have a help command with an argument. We do
|
||||
* not need to have lightningd running in this case. */
|
||||
if (streq(method, "help") && format == HUMAN && argc >= 3) {
|
||||
char command[strlen(argv[2]) + sizeof("lightning-")];
|
||||
snprintf(command, sizeof(command), "lightning-%s", argv[2]);
|
||||
exec_man(command);
|
||||
command = argv[2];
|
||||
char page[strlen(command) + sizeof("lightning-")];
|
||||
snprintf(page, sizeof(page), "lightning-%s", command);
|
||||
try_exec_man(page);
|
||||
}
|
||||
|
||||
if (chdir(lightning_dir) != 0)
|
||||
|
|
Loading…
Add table
Reference in a new issue