@@ -407,22 +407,34 @@ exec_cmnd_pty(struct command_details *details, sigset_t *mask,
407407}
408408
409409/*
410- * Fill in the monitor closure and setup initial events.
411- * Allocates read events for the signal pipe, error pipe and backchannel.
410+ * Fill in the non-event part of the monitor closure.
412411 */
413412static void
414- fill_exec_closure_monitor (struct monitor_closure * mc ,
413+ init_exec_closure_monitor (struct monitor_closure * mc ,
415414 const struct command_details * details , struct command_status * cstat ,
416- int errfd , int backchannel )
415+ int backchannel )
417416{
418- debug_decl (fill_exec_closure_monitor , SUDO_DEBUG_EXEC );
417+ debug_decl (init_exec_closure_monitor , SUDO_DEBUG_EXEC );
419418
420419 /* Fill in the non-event part of the closure. */
420+ memset (mc , 0 , sizeof (* mc ));
421421 mc -> details = details ;
422422 mc -> cstat = cstat ;
423423 mc -> backchannel = backchannel ;
424424 mc -> mon_pgrp = getpgrp ();
425425
426+ debug_return ;
427+ }
428+
429+ /*
430+ * Fill in the monitor closure and setup initial events.
431+ * Allocates read events for the signal pipe, error pipe and backchannel.
432+ */
433+ static void
434+ init_exec_events_monitor (struct monitor_closure * mc , int errfd )
435+ {
436+ debug_decl (init_exec_events_monitor , SUDO_DEBUG_EXEC );
437+
426438 /* Setup event base and events. */
427439 mc -> evbase = sudo_ev_base_alloc ();
428440 if (mc -> evbase == NULL )
@@ -437,7 +449,7 @@ fill_exec_closure_monitor(struct monitor_closure *mc,
437449 sudo_fatal ("%s" , U_ ("unable to add event to queue" ));
438450
439451 /* Event for forwarded signals via backchannel. */
440- mc -> backchannel_event = sudo_ev_alloc (backchannel ,
452+ mc -> backchannel_event = sudo_ev_alloc (mc -> backchannel ,
441453 SUDO_EV_READ |SUDO_EV_PERSIST , mon_backchannel_cb , mc );
442454 if (mc -> backchannel_event == NULL )
443455 sudo_fatalx (U_ ("%s: %s" ), __func__ , U_ ("unable to allocate memory" ));
542554exec_monitor (struct command_details * details , sigset_t * oset ,
543555 bool foreground , int backchannel , int intercept_fd )
544556{
545- struct monitor_closure mc = { 0 } ;
557+ struct monitor_closure mc ;
546558 struct command_status cstat ;
547559 struct sigaction sa ;
548560 int errsock [2 ];
@@ -578,6 +590,9 @@ exec_monitor(struct command_details *details, sigset_t *oset,
578590 goto bad ;
579591 }
580592
593+ /* Fill in exec closure after creating a new session. */
594+ init_exec_closure_monitor (& mc , details , & cstat , backchannel );
595+
581596 /*
582597 * The child waits on the other end of a socketpair for the
583598 * parent to set the controlling terminal. It also writes
@@ -648,7 +663,7 @@ exec_monitor(struct command_details *details, sigset_t *oset,
648663 * Create new event base and register read events for the
649664 * signal pipe, error pipe, and backchannel.
650665 */
651- fill_exec_closure_monitor (& mc , details , & cstat , errsock [0 ], backchannel );
666+ init_exec_events_monitor (& mc , errsock [0 ]);
652667
653668 /* Restore signal mask now that signal handlers are setup. */
654669 sigprocmask (SIG_SETMASK , oset , NULL );
0 commit comments