Skip to content

Output isn’t rendered until child processes complete

The following genmon script:

#!/bin/bash
/usr/bin/sleep 10 &>/dev/null &
echo "<txt>$(date)</txt>"

displays time 10 seconds behind the current time. In other words, genmon doesn’t render the script’s output until the sleep process it spawned terminates.

AFAICT, this happens because genmon dup2s the pipes into stdout and stderr after forking, but doesn’t close the original file descriptors, which still refer to the pipes and get leaked to the sleep process. Genmon is waiting for EOF on the pipes but it won’t happen as long as sleep is holding on to it.

The following patch fixes the problem for me:

--- xfce4-genmon-plugin-4.1.1.orig/panel-plugin/cmdspawn.c
+++ xfce4-genmon-plugin-4.1.1/panel-plugin/cmdspawn.c
@@ -93,6 +93,8 @@ char *genmon_Spawn (char **argv, int wai
                     perror ("dup2()");
                     exit (-1);
                 }
+                /* Don't leak the open descriptor to potential long-lived grandchildren. */
+                close (aaiPipe[i][WR]);
             }
         /* Execute the given command */
         execvp (argv[0], argv);

Let me know if you want me to submit this as a merge request.

Edited by Vasia