]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/shared/ask-password-api.c
io-util: introduce loop_write_full that takes a timeout
[thirdparty/systemd.git] / src / shared / ask-password-api.c
index 92a191ee60b3d508577aadcb928f70709f60beff..416130b9cc68846ee3c3a55b9e348f213be161dc 100644 (file)
@@ -181,7 +181,7 @@ static int backspace_chars(int ttyfd, size_t p) {
         for (size_t i = 0; i < p; i++)
                 memcpy(buf + 3 * i, "\b \b", 3);
 
-        return loop_write(ttyfd, buf, 3*p, false);
+        return loop_write(ttyfd, buf, 3 * p);
 }
 
 static int backspace_string(int ttyfd, const char *str) {
@@ -252,7 +252,7 @@ int ask_password_plymouth(
         if (!packet)
                 return -ENOMEM;
 
-        r = loop_write(fd, packet, n + 1, true);
+        r = loop_write_full(fd, packet, n + 1, USEC_INFINITY);
         if (r < 0)
                 return r;
 
@@ -311,7 +311,7 @@ int ask_password_plymouth(
                                 if (asprintf(&packet, "*\002%c%s%n", (int) (strlen(message) + 1), message, &n) < 0)
                                         return -ENOMEM;
 
-                                r = loop_write(fd, packet, n+1, true);
+                                r = loop_write_full(fd, packet, n + 1, USEC_INFINITY);
                                 if (r < 0)
                                         return r;
 
@@ -429,20 +429,21 @@ int ask_password_tty(
                         use_color = colors_enabled();
 
                 if (use_color)
-                        (void) loop_write(ttyfd, ANSI_HIGHLIGHT, SIZE_MAX, false);
+                        (void) loop_write(ttyfd, ANSI_HIGHLIGHT, SIZE_MAX);
 
-                (void) loop_write(ttyfd, message, SIZE_MAX, false);
-                (void) loop_write(ttyfd, " ", 1, false);
+                (void) loop_write(ttyfd, message, SIZE_MAX);
+                (void) loop_write(ttyfd, " ", 1);
 
                 if (!FLAGS_SET(flags, ASK_PASSWORD_SILENT) && !FLAGS_SET(flags, ASK_PASSWORD_ECHO)) {
                         if (use_color)
-                                (void) loop_write(ttyfd, ansi_grey(), SIZE_MAX, false);
-                        (void) loop_write(ttyfd, PRESS_TAB, SIZE_MAX, false);
+                                (void) loop_write(ttyfd, ansi_grey(), SIZE_MAX);
+
+                        (void) loop_write(ttyfd, PRESS_TAB, SIZE_MAX);
                         press_tab_visible = true;
                 }
 
                 if (use_color)
-                        (void) loop_write(ttyfd, ANSI_NORMAL, SIZE_MAX, false);
+                        (void) loop_write(ttyfd, ANSI_NORMAL, SIZE_MAX);
 
                 new_termios = old_termios;
                 new_termios.c_lflag &= ~(ICANON|ECHO);
@@ -527,7 +528,7 @@ int ask_password_tty(
 
                 if (c == 4) { /* C-d also known as EOT */
                         if (ttyfd >= 0)
-                                (void) loop_write(ttyfd, SKIPPED, SIZE_MAX, false);
+                                (void) loop_write(ttyfd, SKIPPED, SIZE_MAX);
 
                         goto skipped;
                 }
@@ -577,10 +578,10 @@ int ask_password_tty(
                                  * first key (and only as first key), or ... */
 
                                 if (ttyfd >= 0)
-                                        (void) loop_write(ttyfd, NO_ECHO, SIZE_MAX, false);
+                                        (void) loop_write(ttyfd, NO_ECHO, SIZE_MAX);
 
                         } else if (ttyfd >= 0)
-                                (void) loop_write(ttyfd, "\a", 1, false);
+                                (void) loop_write(ttyfd, "\a", 1);
 
                 } else if (c == '\t' && !FLAGS_SET(flags, ASK_PASSWORD_SILENT)) {
 
@@ -590,13 +591,13 @@ int ask_password_tty(
                         /* ... or by pressing TAB at any time. */
 
                         if (ttyfd >= 0)
-                                (void) loop_write(ttyfd, NO_ECHO, SIZE_MAX, false);
+                                (void) loop_write(ttyfd, NO_ECHO, SIZE_MAX);
 
                 } else if (p >= sizeof(passphrase)-1) {
 
                         /* Reached the size limit */
                         if (ttyfd >= 0)
-                                (void) loop_write(ttyfd, "\a", 1, false);
+                                (void) loop_write(ttyfd, "\a", 1);
 
                 } else {
                         passphrase[p++] = c;
@@ -606,13 +607,11 @@ int ask_password_tty(
                                 n = utf8_encoded_valid_unichar(passphrase + codepoint, SIZE_MAX);
                                 if (n >= 0) {
                                         if (FLAGS_SET(flags, ASK_PASSWORD_ECHO))
-                                                (void) loop_write(ttyfd, passphrase + codepoint, n, false);
+                                                (void) loop_write(ttyfd, passphrase + codepoint, n);
                                         else
-                                                (void) loop_write(
-                                                                ttyfd,
-                                                                special_glyph(SPECIAL_GLYPH_BULLET),
-                                                                SIZE_MAX,
-                                                                false);
+                                                (void) loop_write(ttyfd,
+                                                                  special_glyph(SPECIAL_GLYPH_BULLET),
+                                                                  SIZE_MAX);
                                         codepoint = p;
                                 }
                         }
@@ -644,7 +643,7 @@ skipped:
 
 finish:
         if (ttyfd >= 0 && reset_tty) {
-                (void) loop_write(ttyfd, "\n", 1, false);
+                (void) loop_write(ttyfd, "\n", 1);
                 (void) tcsetattr(ttyfd, TCSADRAIN, &old_termios);
         }