lib/pty-session: add loggin callback to code, follow return codes

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2019-10-03 13:23:41 +02:00
parent 04f0c95f93
commit 4f7f723b31
2 changed files with 17 additions and 3 deletions

View File

@ -48,7 +48,7 @@ struct ul_pty_callbacks {
* 2nd - signal info
* 3rd - NULL or signal specific data (e.g. struct winsize on SIGWINCH
*/
int (*log_signal)(void *, struct signalfd_siginfo, void *);
int (*log_signal)(void *, struct signalfd_siginfo *, void *);
};
struct ul_pty {

View File

@ -270,6 +270,7 @@ static int handle_io(struct ul_pty *pty, int fd, int *eof)
{
char buf[BUFSIZ];
ssize_t bytes;
int rc = 0;
DBG(IO, ul_debugobj(pty, " handle I/O on fd=%d", fd));
*eof = 0;
@ -304,13 +305,18 @@ static int handle_io(struct ul_pty *pty, int fd, int *eof)
write_output(buf, bytes);
}
return 0;
if (pty->callbacks.log_stream_activity)
rc = pty->callbacks.log_stream_activity(
pty->callback_data, fd, buf, bytes);
return rc;
}
static int handle_signal(struct ul_pty *pty, int fd)
{
struct signalfd_siginfo info;
ssize_t bytes;
int rc = 0;
DBG(SIG, ul_debugobj(pty, " handle signal on fd=%d", fd));
@ -343,6 +349,10 @@ static int handle_signal(struct ul_pty *pty, int fd)
if (pty->isterm) {
ioctl(STDIN_FILENO, TIOCGWINSZ, (char *)&pty->win);
ioctl(pty->slave, TIOCSWINSZ, (char *)&pty->win);
if (pty->callbacks.log_signal)
rc = pty->callbacks.log_signal(pty->callback_data,
&info, (void *) &pty->win);
}
break;
case SIGTERM:
@ -355,12 +365,16 @@ static int handle_signal(struct ul_pty *pty, int fd)
/* Child termination is going to generate SIGCHILD (see above) */
if (pty->child > 0)
kill(pty->child, SIGTERM);
if (pty->callbacks.log_signal)
rc = pty->callbacks.log_signal(pty->callback_data,
&info, (void *) &pty->win);
break;
default:
abort();
}
return 0;
return rc;
}
/* loop in parent */