From 9f65b34eeba922f289b961bf7c92167491189d11 Mon Sep 17 00:00:00 2001 From: pancake Date: Wed, 30 Oct 2024 11:02:25 +0100 Subject: [PATCH] Add 'stdouterr' directive in rarun2 ##tools --- binr/rarun2/rarun2.c | 2 +- libr/include/r_socket.h | 3 +++ libr/main/rarun2.c | 2 +- libr/socket/run.c | 23 +++++++++++++++++++++-- man/rarun2.1 | 2 ++ 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/binr/rarun2/rarun2.c b/binr/rarun2/rarun2.c index e1a5313c2a..4547a0eae4 100644 --- a/binr/rarun2/rarun2.c +++ b/binr/rarun2/rarun2.c @@ -1,4 +1,4 @@ -/* radare2 - Copyleft 2011-2023 - pancake */ +/* radare2 - Copyleft 2011-2024 - pancake */ #include diff --git a/libr/include/r_socket.h b/libr/include/r_socket.h index b81d547d58..ed99596490 100644 --- a/libr/include/r_socket.h +++ b/libr/include/r_socket.h @@ -258,6 +258,9 @@ typedef struct r_run_profile_t { int _timeout; int _timeout_sig; int _nice; +#if R2_USE_NEW_ABI + bool _stderrout; +#endif } RRunProfile; R_API RRunProfile *r_run_new(R_NULLABLE const char *str); diff --git a/libr/main/rarun2.c b/libr/main/rarun2.c index dbbc33b6d6..6fc225c4c9 100644 --- a/libr/main/rarun2.c +++ b/libr/main/rarun2.c @@ -1,4 +1,4 @@ -/* radare2 - Copyleft 2011-2023 - pancake */ +/* radare2 - Copyleft 2011-2024 - pancake */ #define R_LOG_ORIGIN "rarun2" diff --git a/libr/socket/run.c b/libr/socket/run.c index 518bbb1334..236c61f508 100644 --- a/libr/socket/run.c +++ b/libr/socket/run.c @@ -645,6 +645,13 @@ R_API bool r_run_parseline(RRunProfile *p, const char *b) { p->_seteuid = strdup (e); } else if (!strcmp (b, "setgid")) { p->_setgid = strdup (e); +#if R2_USE_NEW_ABI + } else if (!strcmp (b, "stderrout")) { + p->_stderrout = r_str_is_true (e); +#else + } else if (!strcmp (b, "stderrout")) { + R_LOG_ERROR ("stderrout directive is only supported in the new abi"); +#endif } else if (!strcmp (b, "setegid")) { p->_setegid = strdup (e); } else if (!strcmp (b, "nice")) { @@ -747,6 +754,7 @@ R_API const char *r_run_help(void) { "# #core=false\n" "# #stdio=blah.txt\n" "# #stderr=foo.txt\n" + "# #stderrout=false\n" "# stdout=foo.txt\n" "# stdin=input.txt # or !program to redirect input from another program\n" "# input=input.txt\n" @@ -1082,15 +1090,26 @@ R_API bool r_run_config_env(RRunProfile *p) { return false; } } +#if R2_USE_NEW_ABI + if (p->_stderrout) { +#if __wasi__ + R_LOG_WARN ("Directive 'stderrout' not supported in wasm"); +#else + if (dup2 (1, 2) == -1) { + return false; + } +#endif + } +#endif if (p->_setgid) { #if __wasi__ - ret = 0; + R_LOG_WARN ("Directive 'setgid' not supported in wasm"); #else ret = setgid (atoi (p->_setgid)); -#endif if (ret < 0) { return false; } +#endif } if (p->_input) { char *inp; diff --git a/man/rarun2.1 b/man/rarun2.1 index 31df3c5dbd..d82a6bc2d6 100644 --- a/man/rarun2.1 +++ b/man/rarun2.1 @@ -82,6 +82,8 @@ set effective process group id set effective process uid .It Ar setgid set process group id +.It Ar stderrout true|false +Redirect stderr filedescriptor to stdout .It Ar setuid set process uid .It Ar sleep