95f1d6bfec
This reworks systemd-run so that in --pty mode we watch the unit state the way we do it in --wait mode. Whenever we notice that the service is in failed or inactive state finish right-away, but first write all unwritten characters we can read from the master TTY device. This makes sure that when the TTY service fails before it opens the slave PTY device we properly notice that and exit early, so that borked start parameters result in immediate systemd-run failure. Previously, we'd not notice this at all, as a PTY slave that never was opened won't result in POLLHUP events, and we'd hence simply keep reading from it forever. In essence, --pty now enables the same unit watching logic that --wait enables. However, unless --wait is specified we won#t show the final summary, hence the effective difference should be pretty minimal. Fixes: #3915
57 lines
1.7 KiB
C
57 lines
1.7 KiB
C
#pragma once
|
|
|
|
/***
|
|
This file is part of systemd.
|
|
|
|
Copyright 2010-2013 Lennart Poettering
|
|
|
|
systemd is free software; you can redistribute it and/or modify it
|
|
under the terms of the GNU Lesser General Public License as published by
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
|
(at your option) any later version.
|
|
|
|
systemd is distributed in the hope that it will be useful, but
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
|
***/
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include "sd-event.h"
|
|
|
|
#include "macro.h"
|
|
|
|
typedef struct PTYForward PTYForward;
|
|
|
|
typedef enum PTYForwardFlags {
|
|
PTY_FORWARD_READ_ONLY = 1,
|
|
|
|
/* Continue reading after hangup? */
|
|
PTY_FORWARD_IGNORE_VHANGUP = 2,
|
|
|
|
/* Continue reading after hangup but only if we never read anything else? */
|
|
PTY_FORWARD_IGNORE_INITIAL_VHANGUP = 4,
|
|
} PTYForwardFlags;
|
|
|
|
typedef int (*PTYForwardHandler)(PTYForward *f, int rcode, void*userdata);
|
|
|
|
int pty_forward_new(sd_event *event, int master, PTYForwardFlags flags, PTYForward **f);
|
|
PTYForward *pty_forward_free(PTYForward *f);
|
|
|
|
int pty_forward_get_last_char(PTYForward *f, char *ch);
|
|
|
|
int pty_forward_set_ignore_vhangup(PTYForward *f, bool ignore_vhangup);
|
|
bool pty_forward_get_ignore_vhangup(PTYForward *f);
|
|
|
|
bool pty_forward_is_done(PTYForward *f);
|
|
|
|
void pty_forward_set_handler(PTYForward *f, PTYForwardHandler handler, void *userdata);
|
|
|
|
bool pty_forward_drain(PTYForward *f);
|
|
|
|
DEFINE_TRIVIAL_CLEANUP_FUNC(PTYForward*, pty_forward_free);
|