]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/pty-session: add loggin callback to code, follow return codes
authorKarel Zak <kzak@redhat.com>
Thu, 3 Oct 2019 11:23:41 +0000 (13:23 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 8 Oct 2019 11:11:54 +0000 (13:11 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
include/pty-session.h
lib/pty-session.c

index 66b62a1dea581c3f56c2622e895e90b67417f4e4..272dbac04718ee412ada17235ec522eed83c11b4 100644 (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 {
index 81af3b11b37d4e6e78a7583ca53ca10194932bab..d91f2e821cdafb9b001ad01606e1b916e231906a 100644 (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 */