mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 08:25:20 +09:00
ptyfwd: always write additional line break on stop
Currently we do that in the user of PTY forwarder, e.g. nspawn. But, let's do that unconditionally in the PTY forwarder.
This commit is contained in:
@@ -1212,7 +1212,6 @@ static int on_machine_removed(sd_bus_message *m, void *userdata, sd_bus_error *r
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@@ -1239,17 +1238,12 @@ static int process_forward(sd_event *event, PTYForward **forward, int master, PT
|
||||
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);
|
||||
|
||||
@@ -5740,16 +5740,9 @@ static int run_container(
|
||||
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);
|
||||
|
||||
@@ -2094,14 +2094,6 @@ static int start_transient_service(sd_bus *bus) {
|
||||
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
|
||||
|
||||
@@ -136,6 +136,19 @@ static void pty_forward_disconnect(PTYForward *f) {
|
||||
(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);
|
||||
}
|
||||
@@ -994,17 +1007,6 @@ PTYForward* pty_forward_free(PTYForward *f) {
|
||||
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;
|
||||
|
||||
|
||||
@@ -28,8 +28,6 @@ typedef int (*PTYForwardHandler)(PTYForward *f, int rcode, void *userdata);
|
||||
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user