Add 'stdouterr' directive in rarun2 ##tools

This commit is contained in:
pancake 2024-10-30 11:02:25 +01:00 committed by pancake
parent 2f84fcfa2f
commit 9f65b34eeb
5 changed files with 28 additions and 4 deletions

View File

@ -1,4 +1,4 @@
/* radare2 - Copyleft 2011-2023 - pancake */ /* radare2 - Copyleft 2011-2024 - pancake */
#include <r_main.h> #include <r_main.h>

View File

@ -258,6 +258,9 @@ typedef struct r_run_profile_t {
int _timeout; int _timeout;
int _timeout_sig; int _timeout_sig;
int _nice; int _nice;
#if R2_USE_NEW_ABI
bool _stderrout;
#endif
} RRunProfile; } RRunProfile;
R_API RRunProfile *r_run_new(R_NULLABLE const char *str); R_API RRunProfile *r_run_new(R_NULLABLE const char *str);

View File

@ -1,4 +1,4 @@
/* radare2 - Copyleft 2011-2023 - pancake */ /* radare2 - Copyleft 2011-2024 - pancake */
#define R_LOG_ORIGIN "rarun2" #define R_LOG_ORIGIN "rarun2"

View File

@ -645,6 +645,13 @@ R_API bool r_run_parseline(RRunProfile *p, const char *b) {
p->_seteuid = strdup (e); p->_seteuid = strdup (e);
} else if (!strcmp (b, "setgid")) { } else if (!strcmp (b, "setgid")) {
p->_setgid = strdup (e); 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")) { } else if (!strcmp (b, "setegid")) {
p->_setegid = strdup (e); p->_setegid = strdup (e);
} else if (!strcmp (b, "nice")) { } else if (!strcmp (b, "nice")) {
@ -747,6 +754,7 @@ R_API const char *r_run_help(void) {
"# #core=false\n" "# #core=false\n"
"# #stdio=blah.txt\n" "# #stdio=blah.txt\n"
"# #stderr=foo.txt\n" "# #stderr=foo.txt\n"
"# #stderrout=false\n"
"# stdout=foo.txt\n" "# stdout=foo.txt\n"
"# stdin=input.txt # or !program to redirect input from another program\n" "# stdin=input.txt # or !program to redirect input from another program\n"
"# input=input.txt\n" "# input=input.txt\n"
@ -1082,15 +1090,26 @@ R_API bool r_run_config_env(RRunProfile *p) {
return false; 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 (p->_setgid) {
#if __wasi__ #if __wasi__
ret = 0; R_LOG_WARN ("Directive 'setgid' not supported in wasm");
#else #else
ret = setgid (atoi (p->_setgid)); ret = setgid (atoi (p->_setgid));
#endif
if (ret < 0) { if (ret < 0) {
return false; return false;
} }
#endif
} }
if (p->_input) { if (p->_input) {
char *inp; char *inp;

View File

@ -82,6 +82,8 @@ set effective process group id
set effective process uid set effective process uid
.It Ar setgid .It Ar setgid
set process group id set process group id
.It Ar stderrout true|false
Redirect stderr filedescriptor to stdout
.It Ar setuid .It Ar setuid
set process uid set process uid
.It Ar sleep .It Ar sleep