Stop using system()

This commit is contained in:
Andrew Pamment 2018-06-20 19:39:57 +10:00
parent c341df6738
commit 4b90398cbf
3 changed files with 48 additions and 5 deletions

View File

@ -805,7 +805,6 @@ void bwave_upload_reply() {
int stin; int stin;
int sterr; int sterr;
sqlite3 *db; sqlite3 *db;
int ret;
sqlite3_stmt *res; sqlite3_stmt *res;
int rc; int rc;
char *csql = "CREATE TABLE IF NOT EXISTS email (" char *csql = "CREATE TABLE IF NOT EXISTS email ("

View File

@ -221,7 +221,6 @@ void rundoor(struct user_record *user, char *cmd, int stdio, char *codepage) {
void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], char *cwd, int raw, char *codepage) { void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], char *cwd, int raw, char *codepage) {
char buffer[1024]; char buffer[1024];
int pid;
int ret; int ret;
unsigned char c; unsigned char c;
int len; int len;
@ -253,6 +252,9 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c
size_t ouc; size_t ouc;
size_t inc; size_t inc;
size_t sz; size_t sz;
char **args;
int arg_count;
pid_t pid;
int iac; int iac;
char iac_binary_will[] = {IAC, IAC_WILL, IAC_TRANSMIT_BINARY, '\0'}; char iac_binary_will[] = {IAC, IAC_WILL, IAC_TRANSMIT_BINARY, '\0'};
char iac_binary_do[] = {IAC, IAC_DO, IAC_TRANSMIT_BINARY, '\0'}; char iac_binary_do[] = {IAC, IAC_DO, IAC_TRANSMIT_BINARY, '\0'};
@ -527,7 +529,26 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c
if (cwd != NULL) { if (cwd != NULL) {
chdir(cwd); chdir(cwd);
} }
system(buffer); args = (char **)malloc(sizeof (char *));
arg_count = 0;
args[arg_count] = strtok(buffer, " ");
while (args[arg_count] != NULL) {
arg_count++;
args = (char **)realloc(args, sizeof(char *) * (arg_count + 1));
args[arg_count] = strtok(NULL, " ");
}
cmd = strdup(args[0]);
pid = fork();
if (pid == 0) {
execvp(cmd, args);
exit(0);
} else if (pid > 0) {
waitpid(pid, &ret, 0);
} else {
ret = -1;
}
free(cmd);
free(args);
if (cwd != NULL) { if (cwd != NULL) {
chdir(conf.bbs_path); chdir(conf.bbs_path);
} }

View File

@ -297,7 +297,11 @@ char *get_file_id_diz(char *filename) {
int stout; int stout;
int stin; int stin;
int sterr; int sterr;
int ret;
pid_t pid;
char **args;
int arg_count;
char *cmd;
ext = 0; ext = 0;
arch = -1; arch = -1;
@ -367,7 +371,26 @@ char *get_file_id_diz(char *filename) {
dup2(bbs_stderr, STDERR_FILENO); dup2(bbs_stderr, STDERR_FILENO);
dup2(bbs_stdin, STDIN_FILENO); dup2(bbs_stdin, STDIN_FILENO);
} }
system(buffer); args = (char **)malloc(sizeof (char *));
arg_count = 0;
args[arg_count] = strtok(buffer, " ");
while (args[arg_count] != NULL) {
arg_count++;
args = (char **)realloc(args, sizeof(char *) * (arg_count + 1));
args[arg_count] = strtok(NULL, " ");
}
cmd = strdup(args[0]);
pid = fork();
if (pid == 0) {
execvp(cmd, args);
exit(0);
} else if (pid > 0) {
waitpid(pid, &ret, 0);
} else {
ret = -1;
}
free(cmd);
free(args);
if (sshBBS) { if (sshBBS) {