]> granicus.if.org Git - sudo/commitdiff
Fix stair-stepped output when the output of a sudo command is piped
authorTodd C. Miller <Todd.Miller@courtesan.com>
Tue, 26 Sep 2017 20:21:11 +0000 (14:21 -0600)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Tue, 26 Sep 2017 20:21:11 +0000 (14:21 -0600)
to another command and use_pty is set.

include/sudo_compat.h
src/exec_pty.c

index bbf8736a9df86f380d126a8e5265190f8e2e96de..4c99c1234eb8dfe4faa1e45ba0040de338f0aa8d 100644 (file)
 #ifndef _S_IFLNK
 # define _S_IFLNK              S_IFLNK
 #endif /* _S_IFLNK */
+#ifndef _S_IFIFO
+# define _S_IFIFO              S_IFIFO
+#endif /* _S_IFIFO */
 #ifndef S_ISREG
 # define S_ISREG(m)            (((m) & _S_IFMT) == _S_IFREG)
 #endif /* S_ISREG */
 #ifndef S_ISLNK
 # define S_ISLNK(m)            (((m) & _S_IFMT) == _S_IFLNK)
 #endif /* S_ISLNK */
+#ifndef S_ISFIFO
+# define S_ISFIFO(m)           (((m) & _S_IFMT) == _S_IFIFO)
+#endif /* S_ISLNK */
 #ifndef S_ISTXT
 # define S_ISTXT               0001000
 #endif /* S_ISTXT */
index 61a9fdc03ca9dece3733d7ab3027ab3e66705f7e..f55506655db0f1ff54a0751c715d868126903ba7 100644 (file)
@@ -17,6 +17,7 @@
 #include <config.h>
 
 #include <sys/types.h>
+#include <sys/stat.h>
 #include <sys/socket.h>
 #include <sys/wait.h>
 #include <sys/ioctl.h>
@@ -1159,6 +1160,7 @@ exec_pty(struct command_details *details, struct command_status *cstat)
     struct plugin_container *plugin;
     sigset_t set, oset;
     struct sigaction sa;
+    struct stat sb;
     pid_t ppgrp;
     int sv[2];
     debug_decl(exec_pty, SUDO_DEBUG_EXEC)
@@ -1259,6 +1261,8 @@ exec_pty(struct command_details *details, struct command_status *cstat)
            /* Not logging stdin, do not interpose. */
            sudo_debug_printf(SUDO_DEBUG_INFO,
                "stdin not a tty, not logging");
+           if (fstat(STDIN_FILENO, &sb) == 0 && S_ISFIFO(sb.st_mode))
+               pipeline = true;
            io_fds[SFD_STDIN] = dup(STDIN_FILENO);
            if (io_fds[SFD_STDIN] == -1)
                sudo_fatal("dup");
@@ -1278,6 +1282,8 @@ exec_pty(struct command_details *details, struct command_status *cstat)
            /* Not logging stdout, do not interpose. */
            sudo_debug_printf(SUDO_DEBUG_INFO,
                "stdout not a tty, not logging");
+           if (fstat(STDOUT_FILENO, &sb) == 0 && S_ISFIFO(sb.st_mode))
+               pipeline = true;
            io_fds[SFD_STDOUT] = dup(STDOUT_FILENO);
            if (io_fds[SFD_STDOUT] == -1)
                sudo_fatal("dup");
@@ -1297,6 +1303,8 @@ exec_pty(struct command_details *details, struct command_status *cstat)
            /* Not logging stderr, do not interpose. */
            sudo_debug_printf(SUDO_DEBUG_INFO,
                "stderr not a tty, not logging");
+           if (fstat(STDERR_FILENO, &sb) == 0 && S_ISFIFO(sb.st_mode))
+               pipeline = true;
            io_fds[SFD_STDERR] = dup(STDERR_FILENO);
            if (io_fds[SFD_STDERR] == -1)
                sudo_fatal("dup");