Hi!
> -void tst_run_cmd(void (cleanup_fn)(void), char *const argv[])
> +void tst_run_cmd(void (cleanup_fn)(void),
> +             char *const argv[],
> +             const char *stdout_path,
> +             const char *stderr_path)
>  {
>       if (argv == NULL || argv[0] == NULL) {
>               tst_brkm(TBROK, cleanup_fn,
> @@ -36,8 +40,20 @@ void tst_run_cmd(void (cleanup_fn)(void), char *const 
> argv[])
>               tst_brkm(TBROK | TERRNO, cleanup_fn, "vfork failed at %s:%d",
>                       __FILE__, __LINE__);
>       }
> -     if (!pid)
> +     if (!pid) {
> +             /* redirecting stdout and stderr if needed */
> +             if ((stdout_path != NULL) &&
> +                             (freopen(stdout_path, "a", stdout) == NULL))
> +                     tst_resm(TWARN | TERRNO, "freopen failed at %s:%d",
> +                                     __FILE__, __LINE__);
> +
> +             if ((stderr_path != NULL) &&
> +                             (freopen(stderr_path, "a", stderr) == NULL))
> +                     tst_resm(TWARN | TERRNO, "freopen failed at %s:%d",
> +                                     __FILE__, __LINE__);

There is a slight problem bin this part of the code. As you did vfork()
the virtual memory is not duplicated in the child and only safe
operations you can do is, exec(), _exit() and operations that affects
file description table (which is one of the things that is duplicated,
or guaranteed to be copy on write after vfork()).

So we can't just freopen the streams as freopen() is not guaranteed not
to modify memory (The FILE* object for stdout may end up in inconsistent
state in parent because it was closed by freopen() in child), but we can
close the stdout and stderr in child and redirect them via dup2().

-- 
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
Get your SQL database under version control now!
Version control is standard for application code, but databases havent 
caught up. So what steps can you take to put your SQL databases under 
version control? Why should you start doing it? Read more to find out.
http://pubads.g.doubleclick.net/gampad/clk?id=49501711&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to