mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 08:25:20 +09:00
ptyfwd: replace pty_forward_set_ignore_vhangup() with pty_forward_honor_vhangup()
Currently, pty_forward_set_ignore_vhangup() is only used for disabling the flag. To make the function also disable PTY_FORWARD_IGNORE_INITIAL_VHANGUP flag, this renames it to pty_forward_honor_vhangup(). Also, for consistency, pty_forward_get_ignore_vhangup() and ignore_vhangup() are replaced with pty_forward_vhangup_honored().
This commit is contained in:
@@ -1236,10 +1236,10 @@ static int on_machine_removed(sd_bus_message *m, void *userdata, sd_bus_error *r
|
||||
/* Tell the forwarder to exit on the next vhangup(), so that we still flush out what might be queued
|
||||
* and exit then. */
|
||||
|
||||
r = pty_forward_set_ignore_vhangup(forward, false);
|
||||
r = pty_forward_honor_vhangup(forward);
|
||||
if (r < 0) {
|
||||
/* On error, quit immediately. */
|
||||
log_error_errno(r, "Failed to set ignore_vhangup flag: %m");
|
||||
log_error_errno(r, "Failed to make PTY forwarder honor vhangup(): %m");
|
||||
(void) sd_event_exit(sd_bus_get_event(sd_bus_message_get_bus(m)), EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@@ -1285,8 +1285,8 @@ static int process_forward(sd_event *event, sd_bus_slot *machine_removed_slot, i
|
||||
return log_error_errno(r, "Failed to run event loop: %m");
|
||||
|
||||
bool machine_died =
|
||||
(flags & PTY_FORWARD_IGNORE_VHANGUP) &&
|
||||
pty_forward_get_ignore_vhangup(forward) == 0;
|
||||
FLAGS_SET(flags, PTY_FORWARD_IGNORE_VHANGUP) &&
|
||||
!pty_forward_vhangup_honored(forward);
|
||||
|
||||
if (!arg_quiet) {
|
||||
if (machine_died)
|
||||
|
||||
@@ -249,18 +249,6 @@ static RequestOperation look_for_escape(PTYForward *f, const char *buffer, size_
|
||||
return REQUEST_NOP;
|
||||
}
|
||||
|
||||
static bool ignore_vhangup(PTYForward *f) {
|
||||
assert(f);
|
||||
|
||||
if (f->flags & PTY_FORWARD_IGNORE_VHANGUP)
|
||||
return true;
|
||||
|
||||
if ((f->flags & PTY_FORWARD_IGNORE_INITIAL_VHANGUP) && !f->read_from_master)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool drained(PTYForward *f) {
|
||||
int q = 0;
|
||||
|
||||
@@ -720,9 +708,9 @@ static int do_shovel(PTYForward *f) {
|
||||
|
||||
/* Note that EIO on the master device might be caused by vhangup() or
|
||||
* temporary closing of everything on the other side, we treat it like EAGAIN
|
||||
* here and try again, unless ignore_vhangup is off. */
|
||||
* here and try again, unless vhangup() is honored. */
|
||||
|
||||
if (errno == EAGAIN || (errno == EIO && ignore_vhangup(f)))
|
||||
if (errno == EAGAIN || (errno == EIO && !pty_forward_vhangup_honored(f)))
|
||||
f->master_readable = false;
|
||||
else if (IN_SET(errno, EPIPE, ECONNRESET, EIO)) {
|
||||
f->master_readable = f->master_writable = false;
|
||||
@@ -1087,33 +1075,29 @@ PTYForward* pty_forward_free(PTYForward *f) {
|
||||
return mfree(f);
|
||||
}
|
||||
|
||||
int pty_forward_set_ignore_vhangup(PTYForward *f, bool b) {
|
||||
int r;
|
||||
|
||||
int pty_forward_honor_vhangup(PTYForward *f) {
|
||||
assert(f);
|
||||
|
||||
if (FLAGS_SET(f->flags, PTY_FORWARD_IGNORE_VHANGUP) == b)
|
||||
return 0;
|
||||
if ((f->flags & (PTY_FORWARD_IGNORE_VHANGUP | PTY_FORWARD_IGNORE_INITIAL_VHANGUP)) == 0)
|
||||
return 0; /* nothing changed. */
|
||||
|
||||
SET_FLAG(f->flags, PTY_FORWARD_IGNORE_VHANGUP, b);
|
||||
f->flags &= ~(PTY_FORWARD_IGNORE_VHANGUP | PTY_FORWARD_IGNORE_INITIAL_VHANGUP);
|
||||
|
||||
if (!ignore_vhangup(f)) {
|
||||
|
||||
/* We shall now react to vhangup()s? Let's check immediately if we might be in one. */
|
||||
|
||||
f->master_readable = true;
|
||||
r = shovel(f);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
return 0;
|
||||
/* We shall now react to vhangup()s? Let's check immediately if we might be in one. */
|
||||
f->master_readable = true;
|
||||
return shovel(f);
|
||||
}
|
||||
|
||||
bool pty_forward_get_ignore_vhangup(PTYForward *f) {
|
||||
bool pty_forward_vhangup_honored(const PTYForward *f) {
|
||||
assert(f);
|
||||
|
||||
return FLAGS_SET(f->flags, PTY_FORWARD_IGNORE_VHANGUP);
|
||||
if (FLAGS_SET(f->flags, PTY_FORWARD_IGNORE_VHANGUP))
|
||||
return false;
|
||||
|
||||
if (FLAGS_SET(f->flags, PTY_FORWARD_IGNORE_INITIAL_VHANGUP) && !f->read_from_master)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void pty_forward_set_hangup_handler(PTYForward *f, PTYForwardHangupHandler cb, void *userdata) {
|
||||
|
||||
@@ -28,8 +28,8 @@ extern const int pty_forward_signals[N_PTY_FORWARD_SIGNALS];
|
||||
int pty_forward_new(sd_event *event, int master, PTYForwardFlags flags, PTYForward **ret);
|
||||
PTYForward* pty_forward_free(PTYForward *f);
|
||||
|
||||
int pty_forward_set_ignore_vhangup(PTYForward *f, bool ignore_vhangup);
|
||||
bool pty_forward_get_ignore_vhangup(PTYForward *f);
|
||||
int pty_forward_honor_vhangup(PTYForward *f);
|
||||
bool pty_forward_vhangup_honored(const PTYForward *f);
|
||||
|
||||
void pty_forward_set_hangup_handler(PTYForward *f, PTYForwardHangupHandler handler, void *userdata);
|
||||
void pty_forward_set_hotkey_handler(PTYForward *f, PTYForwardHotkeyHandler handler, void *userdata);
|
||||
|
||||
Reference in New Issue
Block a user