chiark / gitweb /
machinectl,nspawn: don't print extra final newline if pty terminal output was newline...
authorLennart Poettering <lennart@poettering.net>
Mon, 22 Dec 2014 19:33:45 +0000 (20:33 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 23 Dec 2014 02:26:24 +0000 (03:26 +0100)
src/machine/machinectl.c
src/nspawn/nspawn.c

index 4eebcb7..f5b87a2 100644 (file)
@@ -1110,6 +1110,7 @@ static int login_machine(int argc, char *argv[], void *userdata) {
         pid_t leader;
         sigset_t mask;
         int r, ret = 0;
+        char last_char = 0;
 
         assert(bus);
 
@@ -1186,9 +1187,12 @@ static int login_machine(int argc, char *argv[], void *userdata) {
         if (r < 0)
                 return log_error_errno(r, "Failed to run event loop: %m");
 
+        pty_forward_last_char(forward, &last_char);
+
         forward = pty_forward_free(forward);
 
-        fputc('\n', stdout);
+        if (last_char != '\n')
+                fputc('\n', stdout);
 
         log_info("Connection to container %s terminated.", argv[1]);
 
index f1f9b78..01b8c32 100644 (file)
@@ -3462,6 +3462,7 @@ int main(int argc, char *argv[]) {
                 if (barrier_place_and_sync(&barrier)) {
                         _cleanup_event_unref_ sd_event *event = NULL;
                         _cleanup_(pty_forward_freep) PTYForward *forward = NULL;
+                        char last_char = 0;
                         int ifi = 0;
 
                         r = move_network_interfaces(pid);
@@ -3531,9 +3532,11 @@ int main(int argc, char *argv[]) {
                                 goto finish;
                         }
 
+                        pty_forward_last_char(forward, &last_char);
+
                         forward = pty_forward_free(forward);
 
-                        if (!arg_quiet)
+                        if (!arg_quiet && last_char != '\n')
                                 putc('\n', stdout);
 
                         /* Kill if it is not dead yet anyway */