@@ -62,6 +62,7 @@ static struct pam_conv conv = { NULL, NULL};
6262#include "queue.h"
6363#include "rc.h"
6464#include "misc.h"
65+ #include "../start-stop-daemon/pipes.h"
6566#include "plugin.h"
6667#include "schedules.h"
6768#include "_usage.h"
7980 LONGOPT_OOM_SCORE_ADJ ,
8081 LONGOPT_NO_NEW_PRIVS ,
8182 LONGOPT_SECBITS ,
83+ LONGOPT_STDERR_LOGGER ,
84+ LONGOPT_STDOUT_LOGGER ,
8285};
8386
8487const char * applet = NULL ;
@@ -110,6 +113,8 @@ const struct option longopts[] = {
110113 { "user" , 1 , NULL , 'u' },
111114 { "stdout" , 1 , NULL , '1' },
112115 { "stderr" , 1 , NULL , '2' },
116+ { "stdout-logger" ,1 , NULL , LONGOPT_STDOUT_LOGGER },
117+ { "stderr-logger" ,1 , NULL , LONGOPT_STDERR_LOGGER },
113118 { "reexec" , 0 , NULL , '3' },
114119 longopts_COMMON
115120};
@@ -138,6 +143,8 @@ const char * const longopts_help[] = {
138143 "Change the process user" ,
139144 "Redirect stdout to file" ,
140145 "Redirect stderr to file" ,
146+ "Redirect stdout to process" ,
147+ "Redirect stderr to process" ,
141148 "reexec (used internally)" ,
142149 longopts_help_COMMON
143150};
@@ -160,6 +167,8 @@ static int stdout_fd;
160167static int stderr_fd ;
161168static char * redirect_stderr = NULL ;
162169static char * redirect_stdout = NULL ;
170+ static char * stderr_process = NULL ;
171+ static char * stdout_process = NULL ;
163172#ifdef TIOCNOTTY
164173static int tty_fd = -1 ;
165174#endif
@@ -549,6 +558,12 @@ RC_NORETURN static void child_process(char *exec, char **argv)
549558 eerrorx ("%s: unable to open the logfile"
550559 " for stdout `%s': %s" ,
551560 applet , redirect_stdout , strerror (errno ));
561+ } else if (stdout_process ) {
562+ stdout_fd = rc_pipe_command (stdout_process );
563+ if (stdout_fd == -1 )
564+ eerrorx ("%s: unable to open the logging process"
565+ " for stdout `%s': %s" ,
566+ applet , stdout_process , strerror (errno ));
552567 }
553568 if (redirect_stderr ) {
554569 if ((stderr_fd = open (redirect_stderr ,
@@ -557,12 +572,18 @@ RC_NORETURN static void child_process(char *exec, char **argv)
557572 eerrorx ("%s: unable to open the logfile"
558573 " for stderr `%s': %s" ,
559574 applet , redirect_stderr , strerror (errno ));
575+ } else if (stderr_process ) {
576+ stderr_fd = rc_pipe_command (stderr_process );
577+ if (stderr_fd == -1 )
578+ eerrorx ("%s: unable to open the logging process"
579+ " for stderr `%s': %s" ,
580+ applet , stderr_process , strerror (errno ));
560581 }
561582
562583 dup2 (stdin_fd , STDIN_FILENO );
563- if (redirect_stdout || rc_yesno (getenv ("EINFO_QUIET" )))
584+ if (redirect_stdout || stdout_process || rc_yesno (getenv ("EINFO_QUIET" )))
564585 dup2 (stdout_fd , STDOUT_FILENO );
565- if (redirect_stderr || rc_yesno (getenv ("EINFO_QUIET" )))
586+ if (redirect_stderr || stderr_process || rc_yesno (getenv ("EINFO_QUIET" )))
566587 dup2 (stderr_fd , STDERR_FILENO );
567588
568589 cloexec_fds_from (3 );
@@ -1039,6 +1060,14 @@ int main(int argc, char **argv)
10391060 reexec = true;
10401061 break ;
10411062
1063+ case LONGOPT_STDOUT_LOGGER : /* --stdout-logger "command to run for stdout logging" */
1064+ stdout_process = optarg ;
1065+ break ;
1066+
1067+ case LONGOPT_STDERR_LOGGER : /* --stderr-logger "command to run for stderr logging" */
1068+ stderr_process = optarg ;
1069+ break ;
1070+
10421071 case_RC_COMMON_GETOPT
10431072 }
10441073
0 commit comments