]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: limit the length of the confirmation question
authorFranck Bui <fbui@suse.com>
Mon, 7 Nov 2016 16:14:59 +0000 (17:14 +0100)
committerFranck Bui <fbui@suse.com>
Thu, 17 Nov 2016 17:16:50 +0000 (18:16 +0100)
When "confirmation_spawn=1", the confirmation question can look like:

  Execute /usr/bin/kmod static-nodes --format=tmpfiles --output=/run/tmpfiles.d/kmod.conf? [Yes, No, Skip]

which is pretty verbose and might not fit in the console width size (which is
usually 80 chars) and thus question will be splitted into 2 consecutive lines.

However since the question is now refreshed every 2 secs, the reprinted
question will overwrite the second line of the previous one...

To prevent this, this patch makes sure that the command line won't be longer
than 60 chars by ellipsizing it if the command is longer:

  Execute /usr/bin/kmod static-nodes --format=tmpfiles --output=/ru…nf? [Yes, No, View, Skip]

A following patch will introduce a new choice that will allow the user to get
details on the command to be executed so it will still be possible to see the
full command line.

src/core/execute.c

index 10e9dd7cc8fd6471e72f70ba096def64febf4d16..0273b1966fa002532917e1d05d961d0575b3652c 100644 (file)
@@ -722,6 +722,7 @@ enum {
 
 static int ask_for_confirmation(const char *vc, const char *cmdline) {
         int saved_stdout = -1, saved_stdin = -1, r;
+        _cleanup_free_ char *e = NULL;
         char c;
 
         /* For any internal errors, assume a positive response. */
@@ -731,7 +732,14 @@ static int ask_for_confirmation(const char *vc, const char *cmdline) {
                 return CONFIRM_EXECUTE;
         }
 
-        r = ask_char(&c, "yfs", "Execute %s? [Yes, Fail, Skip] ", cmdline);
+        e = ellipsize(cmdline, 60, 100);
+        if (!e) {
+                log_oom();
+                r = CONFIRM_EXECUTE;
+                goto restore_stdio;
+        }
+
+        r = ask_char(&c, "yfs", "Execute %s? [Yes, Fail, Skip] ", e);
         if (r < 0) {
                 write_confirm_error_fd(r, STDOUT_FILENO);
                 r = CONFIRM_EXECUTE;