> Hi!

Hi, Cyril.
>> -    if (!pid)
>> +    if (!pid) {
>> +            /* redirecting stdout and stderr if needed */
>> +            if (stdout_path != NULL) {
>> +                    child_stdout = open(stdout_path,
>> +                                    OPEN_FLAGS, OPEN_MODE);
>> +
>> +                    if (child_stdout == -1) {
>> +                            tst_resm(TWARN | TERRNO,
>> +                                    "open() on %s failed at %s:%d: %s",
>> +                                    stdout_path, __FILE__, __LINE__,
>> +                                    strerror(errno));
> You should not call the tst_resm() here for two reasons.
>
> 1. It is not designed to be called from a child of the main test process
>
> 2. It still may corrupt the parent memory although in this case it's
>     not that likely (as it operates on FILE* used for the test output,
>     note that ANY operation on FILE* may get it into inconsistent state
>     in the parent later)

Ok. I understand.

>
> What about passing file descriptors to function (-1 means no
> redirection) and create a second function on the top of it that
> opens the files, does the checks and the calls the tst_run_cmd?

So you propose creating two functions: one will accept (const char *) 
arguments, the other - file descriptors. Yes?
But do we really need this functionality in LTP (ie redirect cmd output 
either to filename or to file descriptor)?

What about modifying tst_run_cmd interface as I propose:
tst_run_cmd_redirected(void (cleanup_fn)(void),
                                         char *const argv[],
                                         const char *stdout_path,
                                         const char *stderr_path)
but putting all the related to file descriptors' opening/closing in 
parent's body.

Something like this:
  /* define file descriptors*/
int child_stdout = -1;
int child_stderr = -1;

if (stdout_path != NULL) {
   child_stdout = child_stdout(stdout_path, ...)
   if (child_stdout == -1) {
     tst_resm(TWARN | TERRNO, ...)
   }
}

/* the same for stderr_path*/

if (!pid) {
   /* redirect child's stdout if needed */
   if (child_stout != -1) {
     close(STDOUT_FILENO);
     dup2(child_stdout, STDOUT_FILENO);
   }

   /* the same for child's stderr */

   /* execve and etc */
}


if (close(child_stdout) < 0) {
   tst_resm(TWARN | TERRNO, ...)
}

Would it be sufficient?

Thank you.



------------------------------------------------------------------------------
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