core: add 'i' in confirm spawn to give a short summary of the unit to spawn

This commit is contained in:
Franck Bui 2016-11-12 14:55:12 +01:00
parent d172b175f6
commit eedf223a30
2 changed files with 11 additions and 3 deletions

1
NEWS
View file

@ -7,6 +7,7 @@ CHANGES WITH 233 in spe
(f)ail, don't execute the command and pretend it failed (f)ail, don't execute the command and pretend it failed
(h)elp (h)elp
(i)nfo, show a short summary of the unit
(s)kip, don't execute the command and pretend it succeeded (s)kip, don't execute the command and pretend it succeeded
(y)es, execute the command (y)es, execute the command

View file

@ -720,7 +720,7 @@ enum {
CONFIRM_EXECUTE = 1, CONFIRM_EXECUTE = 1,
}; };
static int ask_for_confirmation(const char *vc, const char *cmdline) { static int ask_for_confirmation(const char *vc, Unit *u, const char *cmdline) {
int saved_stdout = -1, saved_stdin = -1, r; int saved_stdout = -1, saved_stdin = -1, r;
_cleanup_free_ char *e = NULL; _cleanup_free_ char *e = NULL;
char c; char c;
@ -740,7 +740,7 @@ static int ask_for_confirmation(const char *vc, const char *cmdline) {
} }
for (;;) { for (;;) {
r = ask_char(&c, "yfsh", "Execute %s? [y, f, s h for help] ", e); r = ask_char(&c, "yfshi", "Execute %s? [y, f, s h for help] ", e);
if (r < 0) { if (r < 0) {
write_confirm_error_fd(r, STDOUT_FILENO); write_confirm_error_fd(r, STDOUT_FILENO);
r = CONFIRM_EXECUTE; r = CONFIRM_EXECUTE;
@ -755,9 +755,16 @@ static int ask_for_confirmation(const char *vc, const char *cmdline) {
case 'h': case 'h':
printf(" f - fail, don't execute the command and pretend it failed\n" printf(" f - fail, don't execute the command and pretend it failed\n"
" h - help\n" " h - help\n"
" i - info, show a short summary of the unit\n"
" s - skip, don't execute the command and pretend it succeeded\n" " s - skip, don't execute the command and pretend it succeeded\n"
" y - yes, execute the command\n"); " y - yes, execute the command\n");
continue; continue;
case 'i':
printf(" Description: %s\n"
" Unit: %s\n"
" Command: %s\n",
u->id, u->description, cmdline);
continue; /* ask again */
case 's': case 's':
printf("Skipping execution.\n"); printf("Skipping execution.\n");
r = CONFIRM_PRETEND_SUCCESS; r = CONFIRM_PRETEND_SUCCESS;
@ -2368,7 +2375,7 @@ static int exec_child(
return -ENOMEM; return -ENOMEM;
} }
r = ask_for_confirmation(vc, cmdline); r = ask_for_confirmation(vc, unit, cmdline);
if (r != CONFIRM_EXECUTE) { if (r != CONFIRM_EXECUTE) {
if (r == CONFIRM_PRETEND_SUCCESS) { if (r == CONFIRM_PRETEND_SUCCESS) {
*exit_status = EXIT_SUCCESS; *exit_status = EXIT_SUCCESS;