Skip to content

Commit

Permalink
Add 'stdouterr' directive in rarun2 ##tools
Browse files Browse the repository at this point in the history
  • Loading branch information
radare authored and trufae committed Oct 30, 2024
1 parent 2f84fcf commit 9f65b34
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion binr/rarun2/rarun2.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* radare2 - Copyleft 2011-2023 - pancake */
/* radare2 - Copyleft 2011-2024 - pancake */

#include <r_main.h>

Expand Down
3 changes: 3 additions & 0 deletions libr/include/r_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion libr/main/rarun2.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* radare2 - Copyleft 2011-2023 - pancake */
/* radare2 - Copyleft 2011-2024 - pancake */

#define R_LOG_ORIGIN "rarun2"

Expand Down
23 changes: 21 additions & 2 deletions libr/socket/run.c
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions man/rarun2.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9f65b34

Please sign in to comment.