From: Stanislav kholmanskikh <[email protected]>

Signed-off-by: Stanislav kholmanskikh <[email protected]>
---
 include/test.h    |    9 ++++++++-
 lib/tst_run_cmd.c |   20 ++++++++++++++++++--
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/include/test.h b/include/test.h
index a76fafc..f294b16 100644
--- a/include/test.h
+++ b/include/test.h
@@ -219,8 +219,15 @@ long tst_ncpus_max(void);
  * @argv: a list of two (at least program name + NULL) or more pointers that
  * represent the argument list to the new program. The array of pointers
  * must be terminated by a NULL pointer.
+ * @stdout_path: path where to redirect stdout. Set NULL if redirection is
+ * not needed.
+ * @stderr_path: path where to redirect stderr. Set NULL if redirection is
+ * not needed.
  */
-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);
 
 #ifdef TST_USE_COMPAT16_SYSCALL
 #define TCID_BIT_SUFFIX "_16"
diff --git a/lib/tst_run_cmd.c b/lib/tst_run_cmd.c
index 93fe2d6..c54c650 100644
--- a/lib/tst_run_cmd.c
+++ b/lib/tst_run_cmd.c
@@ -19,12 +19,16 @@
  *
  */
 
+#include <stdio.h>
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <unistd.h>
 #include "test.h"
 
-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__);
+
                _exit(execvp(argv[0], argv));
+       }
 
        int ret = -1;
        if (waitpid(pid, &ret, 0) != pid) {
-- 
1.7.1


>From 5cc0b5ffd90736a780bd487947f804ed2ab4d03d Mon Sep 17 00:00:00 2001
From: Stanislav kholmanskikh <[email protected]>
Date: Fri, 19 Jul 2013 13:02:55 +0400
Subject: [PATCH 2/2] lib/tst_module.c: modification for updated tst_run_cmd 
specification

Modified lib/tst_module.c:
* for updated tst_run_cmd specification
* to hide gcc warning "initialization discards qualifiers from pointer target 
type"

Signed-off-by: Stanislav kholmanskikh <[email protected]>
---
 lib/tst_module.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/tst_module.c b/lib/tst_module.c
index 832da27..4871005 100644
--- a/lib/tst_module.c
+++ b/lib/tst_module.c
@@ -94,12 +94,12 @@ void tst_module_load(void (cleanup_fn)(void),
        for (i = offset; i < size; ++i)
                mod_argv[i] = argv[i - offset];
 
-       tst_run_cmd(cleanup_fn, mod_argv);
+       tst_run_cmd(cleanup_fn, mod_argv, NULL, NULL);
        free(mod_path);
 }
 
 void tst_module_unload(void (cleanup_fn)(void), const char *mod_name)
 {
-       char *const argv[] = { "rmmod", mod_name, NULL };
-       tst_run_cmd(cleanup_fn, argv);
+       char *const argv[] = { "rmmod", (char *) mod_name, NULL };
+       tst_run_cmd(cleanup_fn, argv, NULL, NULL);
 }
-- 
1.7.1


------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to