Minor adjustments to exec_sql

This commit is contained in:
topjohnwu 2019-09-01 13:58:50 +08:00
parent 1283590eeb
commit dd35224f92
2 changed files with 18 additions and 11 deletions

View File

@ -274,23 +274,24 @@ int validate_manager(string &alt_pkg, int userid, struct stat *st) {
void exec_sql(int client) { void exec_sql(int client) {
char *sql = read_string(client); char *sql = read_string(client);
FILE *out = fdopen(recv_fd(client), "a");
char *err = db_exec(sql, [&](db_row &row) -> bool { char *err = db_exec(sql, [&](db_row &row) -> bool {
bool first = false; string out;
bool first = true;
for (auto it : row) { for (auto it : row) {
if (first) fprintf(out, "|"); if (first) first = false;
else first = true; else out += '|';
fprintf(out, "%s=%s", it.first.data(), it.second.data()); out += it.first;
out += '=';
out += it.second;
} }
fprintf(out, "\n"); write_int(client, out.length());
xwrite(client, out.data(), out.length());
return true; return true;
}); });
free(sql); free(sql);
fclose(out);
db_err_cmd(err, db_err_cmd(err,
write_int(client, 1); write_int(client, 0);
return; return;
); );
write_int(client, 0);
close(client); close(client);
} }

View File

@ -105,8 +105,14 @@ int magisk_main(int argc, char *argv[]) {
int fd = connect_daemon(); int fd = connect_daemon();
write_int(fd, SQLITE_CMD); write_int(fd, SQLITE_CMD);
write_string(fd, argv[2]); write_string(fd, argv[2]);
send_fd(fd, STDOUT_FILENO); for (;;) {
return read_int(fd); char *res = read_string(fd);
if (res[0] == '\0') {
return 0;
}
printf("%s\n", res);
free(res);
}
} else if (argv[1] == "--use-broadcast"sv) { } else if (argv[1] == "--use-broadcast"sv) {
int fd = connect_daemon(); int fd = connect_daemon();
write_int(fd, BROADCAST_ACK); write_int(fd, BROADCAST_ACK);