lib/pty: save sigmask, add API to free all resources

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2019-08-08 15:34:00 +02:00
parent 46737a7332
commit ab61a03881
2 changed files with 7 additions and 6 deletions

View File

@ -41,8 +41,8 @@ struct ul_pty {
void ul_pty_init_debug(int mask);
struct ul_pty *ul_new_pty(int is_stdin_tty);
void ul_free_pty(struct ul_pty *pty);
sigset_t *ul_pty_get_orig_sigset(struct ul_pty *pty);
int ul_pty_get_delivered_signal(struct ul_pty *pty);
void ul_pty_set_callback_data(struct ul_pty *pty, void *data);

View File

@ -66,12 +66,12 @@ struct ul_pty *ul_new_pty(int is_stdin_tty)
return pty;
}
sigset_t *ul_pty_get_orig_sigset(struct ul_pty *pty)
void ul_free_pty(struct ul_pty *pty)
{
assert(pty);
return &pty->orgsig;
free(pty);
}
int ul_pty_get_delivered_signal(struct ul_pty *pty)
{
assert(pty);
@ -128,6 +128,9 @@ int ul_pty_setup(struct ul_pty *pty)
struct termios slave_attrs;
int rc;
/* save the current signals setting */
sigprocmask(0, NULL, &pty->orgsig);
if (pty->isterm) {
DBG(SETUP, ul_debugobj(pty, "create for terminal"));
@ -590,8 +593,6 @@ int main(int argc, char *argv[])
cb->child_wait = wait_for_child;
cb->child_sigstop = child_sigstop;
sigprocmask(SIG_BLOCK, NULL, ul_pty_get_orig_sigset(ss.pty));
if (ul_pty_setup(ss.pty))
err(EXIT_FAILURE, "failed to create pseudo-terminal");