Currently we do that in the user of PTY forwarder, e.g. nspawn.
But, let's do that unconditionally in the PTY forwarder.
}
static int process_forward(sd_event *event, PTYForward **forward, int master, PTYForwardFlags flags, const char *name) {
- char last_char = 0;
bool machine_died;
int r;
if (r < 0)
return log_error_errno(r, "Failed to run event loop: %m");
- pty_forward_get_last_char(*forward, &last_char);
-
machine_died =
(flags & PTY_FORWARD_IGNORE_VHANGUP) &&
pty_forward_get_ignore_vhangup(*forward) == 0;
*forward = pty_forward_free(*forward);
- if (last_char != '\n')
- fputc('\n', stdout);
-
if (!arg_quiet) {
if (machine_died)
log_info("Machine %s terminated.", name);
if (r < 0)
return log_error_errno(r, "Failed to run event loop: %m");
- if (forward) {
- char last_char = 0;
-
- (void) pty_forward_get_last_char(forward, &last_char);
+ if (forward)
forward = pty_forward_free(forward);
- if (!arg_quiet && last_char != '\n')
- putc('\n', stdout);
- }
-
/* Kill if it is not dead yet anyway */
if (!arg_register && !arg_keep_unit && bus)
terminate_scope(bus, arg_machine);
if (r < 0)
return log_error_errno(r, "Failed to run event loop: %m");
- if (c.forward) {
- char last_char = 0;
-
- r = pty_forward_get_last_char(c.forward, &last_char);
- if (r >= 0 && !arg_quiet && last_char != '\n')
- fputc('\n', stdout);
- }
-
if (arg_wait && !arg_quiet) {
/* Explicitly destroy the PTY forwarder, so that the PTY device is usable again, with its
(void) loop_write(f->output_fd, ANSI_WINDOW_TITLE_POP, SIZE_MAX);
}
+ if (f->last_char_set && f->last_char != '\n') {
+ const char *s;
+
+ if (isatty_safe(f->output_fd) && f->last_char != '\r')
+ s = "\r\n";
+ else
+ s = "\n";
+ (void) loop_write(f->output_fd, s, SIZE_MAX);
+
+ f->last_char_set = true;
+ f->last_char = '\n';
+ }
+
if (f->close_output_fd)
f->output_fd = safe_close(f->output_fd);
}
return mfree(f);
}
-int pty_forward_get_last_char(PTYForward *f, char *ret) {
- assert(f);
- assert(ret);
-
- if (!f->last_char_set)
- return -ENXIO;
-
- *ret = f->last_char;
- return 0;
-}
-
int pty_forward_set_ignore_vhangup(PTYForward *f, bool b) {
int r;
int pty_forward_new(sd_event *event, int master, PTYForwardFlags flags, PTYForward **ret);
PTYForward* pty_forward_free(PTYForward *f);
-int pty_forward_get_last_char(PTYForward *f, char *ret);
-
int pty_forward_set_ignore_vhangup(PTYForward *f, bool ignore_vhangup);
bool pty_forward_get_ignore_vhangup(PTYForward *f);