Skip to content

Commit 4cfa83e

Browse files
committed
Use r_sys_cmd_str instead of popen to list sessions with r2agent
1 parent 4f0c21d commit 4cfa83e

File tree

1 file changed

+3
-19
lines changed

1 file changed

+3
-19
lines changed

src/tools.c

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -785,13 +785,9 @@ static char *tool_run_javascript(ServerState *ss, RJson *tool_args) {
785785
}
786786

787787
char *cmd = r_str_newf ("js base64:%s", encoded);
788-
789788
char *res = r2mcp_cmd (ss, cmd);
790-
791789
free (cmd);
792-
793790
free (encoded);
794-
795791
return tool_cmd_response (res);
796792
}
797793

@@ -804,22 +800,10 @@ static char *tool_list_sessions(ServerState *ss, RJson *tool_args) {
804800
// In HTTP mode, we can't run r2agent locally, return empty result
805801
res = strdup ("[]");
806802
} else {
807-
// Run r2agent command directly using system
808-
FILE *fp = popen ("r2agent -Lj 2>/dev/null", "r");
809-
if (!fp) {
803+
res = r_sys_cmd_str ("r2agent -Lj 2>/dev/null", NULL, NULL);
804+
if (R_STR_ISEMPTY (res)) {
805+
free (res);
810806
res = strdup ("[]");
811-
} else {
812-
char buffer[4096];
813-
RStrBuf *sb = r_strbuf_new ("");
814-
while (fgets (buffer, sizeof (buffer), fp)) {
815-
r_strbuf_append (sb, buffer);
816-
}
817-
pclose (fp);
818-
res = r_strbuf_drain (sb);
819-
if (R_STR_ISEMPTY (res)) {
820-
free (res);
821-
res = strdup ("[]");
822-
}
823807
}
824808
}
825809
return tool_cmd_response (res);

0 commit comments

Comments
 (0)