ptyfwd.c revision da054c3782f25b3b18243f6c76dcfcf90ba70274
9aac953a11452e825bad68750f811fe8722324b4Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering This file is part of systemd.
9aac953a11452e825bad68750f811fe8722324b4Lennart Poettering Copyright 2010-2013 Lennart Poettering
9aac953a11452e825bad68750f811fe8722324b4Lennart Poettering systemd is free software; you can redistribute it and/or modify it
9aac953a11452e825bad68750f811fe8722324b4Lennart Poettering under the terms of the GNU Lesser General Public License as published by
49dbfa7b2b0bf3906704dac1eaeb4eba91056a19Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
9aac953a11452e825bad68750f811fe8722324b4Lennart Poettering (at your option) any later version.
9aac953a11452e825bad68750f811fe8722324b4Lennart Poettering systemd is distributed in the hope that it will be useful, but
along with systemd; If not, see <http://www.gnu.org/licenses/>.
#include <limits.h>
#include <termios.h>
#include "util.h"
#include "ptyfwd.h"
struct PTYForward {
int master;
char last_char;
unsigned escape_counter;
assert(f);
assert(n > 0);
(f->escape_counter)++;
f->escape_timestamp = 0;
f->escape_counter = 0;
ssize_t k;
assert(f);
f->stdin_readable = false;
f->stdin_readable = false;
f->stdin_hangup = true;
f->stdin_readable = false;
f->stdin_hangup = true;
f->master_writable = false;
f->master_hangup = true;
f->in_buffer_full -= k;
f->master_readable = false;
f->master_hangup = true;
f->stdout_writable = false;
f->stdout_writable = false;
f->stdout_hangup = true;
f->last_char_set = true;
f->out_buffer_full -= k;
assert(f);
assert(e);
f->master_readable = true;
f->master_writable = true;
return shovel(f);
assert(f);
assert(e);
f->stdin_readable = true;
return shovel(f);
assert(f);
assert(e);
f->stdout_writable = true;
return shovel(f);
static int on_sigwinch_event(sd_event_source *e, const struct signalfd_siginfo *si, void *userdata) {
assert(f);
assert(e);
return -ENOMEM;
if (event)
f->saved_stdin = true;
f->saved_stdout = true;
r = sd_event_add_io(f->event, &f->master_event_source, master, EPOLLIN|EPOLLOUT|EPOLLET, on_master_event, f);
r = sd_event_add_io(f->event, &f->stdin_event_source, STDIN_FILENO, EPOLLIN|EPOLLET, on_stdin_event, f);
if (r < 0 && r != -EPERM)
r = sd_event_add_io(f->event, &f->stdout_event_source, STDOUT_FILENO, EPOLLOUT|EPOLLET, on_stdout_event, f);
if (r == -EPERM)
f->stdout_writable = true;
*ret = f;
f = NULL;
if (f->saved_stdout)
if (f->saved_stdin)
free(f);
return NULL;
assert(f);
if (!f->last_char_set)
return -ENXIO;
assert(f);
if (!f->ignore_vhangup) {
f->master_readable = true;
r = shovel(f);
assert(f);
return f->ignore_vhangup;