diff --git a/native/jni/core/db.cpp b/native/jni/core/db.cpp index 9c3a0df37..701f62c41 100644 --- a/native/jni/core/db.cpp +++ b/native/jni/core/db.cpp @@ -274,23 +274,24 @@ int validate_manager(string &alt_pkg, int userid, struct stat *st) { void exec_sql(int client) { char *sql = read_string(client); - FILE *out = fdopen(recv_fd(client), "a"); char *err = db_exec(sql, [&](db_row &row) -> bool { - bool first = false; + string out; + bool first = true; for (auto it : row) { - if (first) fprintf(out, "|"); - else first = true; - fprintf(out, "%s=%s", it.first.data(), it.second.data()); + if (first) first = false; + else out += '|'; + out += it.first; + out += '='; + out += it.second; } - fprintf(out, "\n"); + write_int(client, out.length()); + xwrite(client, out.data(), out.length()); return true; }); free(sql); - fclose(out); db_err_cmd(err, - write_int(client, 1); + write_int(client, 0); return; ); - write_int(client, 0); close(client); } diff --git a/native/jni/core/magisk.cpp b/native/jni/core/magisk.cpp index b14300f9f..7d95b2018 100644 --- a/native/jni/core/magisk.cpp +++ b/native/jni/core/magisk.cpp @@ -105,8 +105,14 @@ int magisk_main(int argc, char *argv[]) { int fd = connect_daemon(); write_int(fd, SQLITE_CMD); write_string(fd, argv[2]); - send_fd(fd, STDOUT_FILENO); - return read_int(fd); + for (;;) { + char *res = read_string(fd); + if (res[0] == '\0') { + return 0; + } + printf("%s\n", res); + free(res); + } } else if (argv[1] == "--use-broadcast"sv) { int fd = connect_daemon(); write_int(fd, BROADCAST_ACK);