[Bro-Dev] #583: system function with feedback
Gilbert Clark
gc355804 at ohio.edu
Thu Sep 1 11:24:14 PDT 2011
I think I'd be worried about spawning too many long-running background
processes and hitting the process fd limit (default is 1024 on Linux, I
think?).
Counter-proposal: fork(), configure pipes (dup2, I think?), exec(), and
then wait for SIGCHLD. Alternatively, since the timer would allow for a
poll every so often, could possibly mask SIGCHLD away and just do a
waitpid with WNOHANG in the fired timing event to loop over all the bg
processes and report on the ones that are done. I can't remember enough
about fork and SIGCHLD to know exactly how kosher the second option is,
though, so YMMV.
--Gilbert
On 9/1/2011 1:28 PM, Bro Tracker wrote:
> #583: system function with feedback
> -----------------------------+--------------------
> Reporter: seth | Owner:
> Type: Feature Request | Status: new
> Priority: Normal | Milestone: Bro1.7
> Component: Bro | Version:
> Keywords: language |
> -----------------------------+--------------------
> Jon and I just came up with a proposal for talking to external processes
> and getting results. Our idea is to center it around running the external
> process in the background as it's done now then redirecting stdin and
> stdout to temporary files and to have a file handle where the exit code
> will be available. Bro could poll using timers for the exit code to
> indicate the external process has completed then an event would be
> generated. Here is an example of using this function/event combination:
>
> {{{
> global called_procs: table[string] of string = {};
>
> # These are the prototypes for the function and event that need to be
> added
> # to the core. The names are both terrible.
> global piped_exec_with_result: function(uid: string, program: string,
> to_write: string);
> global system_result: event(uid: string, exit_code: int, stdout: string,
> stderr: string);
>
> event bro_init()
> {
> local uid = unique_id("");
> called_procs[uid] = "date";
> piped_exec_with_result(uid, "date", "");
> }
>
> event system_result(uid: string, exit_code: int, stdout: string, stderr:
> string)
> {
> print fmt("The command line %s was run and exited with %d.",
> called_procs[uid], exit_code);
> print fmt(" On stdout: %s", stdout);
> print fmt(" On stderr: %s", stderr);
> }
> }}}
>
More information about the bro-dev
mailing list