]> git.ipfire.org Git - thirdparty/util-linux.git/blame - include/pty-session.h
login: reduce file-descriptors cleanup overhead
[thirdparty/util-linux.git] / include / pty-session.h
CommitLineData
6954895c
KZ
1/*
2 * This code is in the public domain; do with it what you wish.
3 *
4 * Written by Karel Zak <kzak@redhat.com> in Jul 2019
5 */
6#ifndef UTIL_LINUX_PTY_SESSION_H
7#define UTIL_LINUX_PTY_SESSION_H
8
9#include <pty.h>
10#include <termios.h>
11#include <signal.h>
4d5b2fed 12#include <sys/time.h>
6954895c 13
04f0c95f
KZ
14#include <sys/signalfd.h>
15
16/*
17 * Callbacks -- the first argument is always callback data, see
18 * ul_pty_set_callback_data().
19 */
6954895c 20struct ul_pty_callbacks {
04f0c95f 21 /*
bdd43357
KZ
22 * Optional. Executed on SIGCHLD when ssi_code is EXITED, KILLED or
23 * DUMPED; The callback has to call ul_pty_set_child(pty, (pid_t) -1)
24 * if child is no more alive.
04f0c95f 25 */
bdd43357
KZ
26 void (*child_wait)(void *, pid_t);
27
28 /*
29 * Used when child_wait() undefined to informa about child status
30 */
31 void (*child_die)(void *, pid_t, int);
04f0c95f
KZ
32
33 /*
34 * Executed on SIGCHLD when ssi_status is SIGSTOP
35 */
bdd43357 36 void (*child_sigstop)(void *, pid_t);
4d5b2fed 37
04f0c95f
KZ
38 /*
39 * Executed in master loop before ul_pty enter poll() and in time set by
40 * ul_pty_set_mainloop_time(). The callback is no used when time is not set.
41 */
4d5b2fed 42 int (*mainloop)(void *);
04f0c95f
KZ
43
44 /*
45 * Executed on master or stdin activity, arguments:
46 * 2nd - file descriptor
47 * 3rd - buffer with data
48 * 4th - size of the data
49 */
50 int (*log_stream_activity)(void *, int, char *, size_t);
51
52 /*
53 * Executed on signal, arguments:
54 * 2nd - signal info
55 * 3rd - NULL or signal specific data (e.g. struct winsize on SIGWINCH
56 */
4f7f723b 57 int (*log_signal)(void *, struct signalfd_siginfo *, void *);
6954895c
KZ
58};
59
60struct ul_pty {
61 struct termios stdin_attrs; /* stdin and slave terminal runtime attributes */
62 int master; /* parent side */
63 int slave; /* child side */
64 int sigfd; /* signalfd() */
65 int poll_timeout;
66 struct winsize win; /* terminal window size */
67 sigset_t orgsig; /* original signal mask */
68
69 int delivered_signal;
70
71 struct ul_pty_callbacks callbacks;
72 void *callback_data;
73
74 pid_t child;
75
4d5b2fed
KZ
76 struct timeval next_callback_time;
77
6954895c
KZ
78 unsigned int isterm:1; /* is stdin terminal? */
79};
80
81void ul_pty_init_debug(int mask);
82struct ul_pty *ul_new_pty(int is_stdin_tty);
ab61a038 83void ul_free_pty(struct ul_pty *pty);
6954895c 84
6954895c
KZ
85int ul_pty_get_delivered_signal(struct ul_pty *pty);
86
87void ul_pty_set_callback_data(struct ul_pty *pty, void *data);
88void ul_pty_set_child(struct ul_pty *pty, pid_t child);
89
90struct ul_pty_callbacks *ul_pty_get_callbacks(struct ul_pty *pty);
91int ul_pty_is_running(struct ul_pty *pty);
92int ul_pty_setup(struct ul_pty *pty);
93void ul_pty_cleanup(struct ul_pty *pty);
94void ul_pty_init_slave(struct ul_pty *pty);
95int ul_pty_proxy_master(struct ul_pty *pty);
96
4d5b2fed
KZ
97void ul_pty_set_mainloop_time(struct ul_pty *pty, struct timeval *tv);
98int ul_pty_get_childfd(struct ul_pty *pty);
bdd43357
KZ
99void ul_pty_wait_for_child(struct ul_pty *pty);
100pid_t ul_pty_get_child(struct ul_pty *pty);
4d5b2fed 101
6954895c 102#endif /* UTIL_LINUX_PTY_H */