public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/2] tst_run_cmd: added support for stdout and stderr redirection
@ 2013-07-19  9:26 Stanislav Kholmanskikh
  2013-07-19  9:26 ` [LTP] [PATCH 2/2] lib/tst_module.c: modification for updated tst_run_cmd specification Stanislav Kholmanskikh
  2013-07-31 14:19 ` [LTP] [PATCH 1/2] tst_run_cmd: added support for stdout and stderr redirection chrubis
  0 siblings, 2 replies; 6+ messages in thread
From: Stanislav Kholmanskikh @ 2013-07-19  9:26 UTC (permalink / raw)
  To: ltp-list; +Cc: vasily.isaenko, alexey.kodanev

From: Stanislav kholmanskikh <stanislav.kholmanskikh@oracle.com>

Signed-off-by: Stanislav kholmanskikh <stanislav.kholmanskikh@oracle.com>
---
 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


------------------------------------------------------------------------------
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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-08-05 11:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-19  9:26 [LTP] [PATCH 1/2] tst_run_cmd: added support for stdout and stderr redirection Stanislav Kholmanskikh
2013-07-19  9:26 ` [LTP] [PATCH 2/2] lib/tst_module.c: modification for updated tst_run_cmd specification Stanislav Kholmanskikh
2013-07-31 14:19 ` [LTP] [PATCH 1/2] tst_run_cmd: added support for stdout and stderr redirection chrubis
2013-08-01 13:08   ` [LTP] [PATCH 1/2 V2] " Stanislav Kholmanskikh
2013-08-01 16:04     ` chrubis
     [not found]       ` <51FB6D7F.3080507@oracle.com>
2013-08-05 11:33         ` chrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox