mirror of
https://gitlab.com/niansa/simpsh-httpd.git
synced 2025-03-06 20:53:36 +01:00
Updated C databuffer library
This commit is contained in:
parent
144f4ecd09
commit
ba19b2d8b6
1 changed files with 12 additions and 6 deletions
|
@ -135,20 +135,26 @@ void db_readline(struct databuffer *db, FILE *input) { // Appends one line from
|
||||||
db_append(db, &thisdb);
|
db_append(db, &thisdb);
|
||||||
}
|
}
|
||||||
|
|
||||||
void runcmd(const char **command) { // Dumbly runs command
|
int runcmd(const char **command, bool wait_exit) { // Dumbly runs command
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
if (fork() == 0) {
|
if (fork() == 0) {
|
||||||
execvp(command[0], command);
|
execvp(command[0], command);
|
||||||
perror(command[0]);
|
perror(command[0]);
|
||||||
}
|
}
|
||||||
wait(0);
|
if (wait_exit) {
|
||||||
|
int status;
|
||||||
|
wait(&status);
|
||||||
|
return status;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void db_cmdread(struct databuffer *db, const char **command) { // Appends output (stdout) of command to db
|
void db_cmdread(struct databuffer *db, const char **command) { // Appends output (stdout) of command to db
|
||||||
struct databuffer thisdb;
|
struct databuffer thisdb;
|
||||||
int stdout_backup = dup(1);
|
int stdout_backup = dup(1);
|
||||||
dup2(memfd_create("pipe", 0), 1);
|
dup2(memfd_create("pipe", 0), 1);
|
||||||
runcmd(command);
|
runcmd(command, true);
|
||||||
FILE *proc_out = fdopen(1, "r");
|
FILE *proc_out = fdopen(1, "r");
|
||||||
fseek(proc_out, 0, SEEK_SET);
|
fseek(proc_out, 0, SEEK_SET);
|
||||||
db_fread(db, proc_out);
|
db_fread(db, proc_out);
|
||||||
|
|
Loading…
Add table
Reference in a new issue