Stop using system()
This commit is contained in:
parent
c341df6738
commit
4b90398cbf
@ -805,7 +805,6 @@ void bwave_upload_reply() {
|
||||
int stin;
|
||||
int sterr;
|
||||
sqlite3 *db;
|
||||
int ret;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
char *csql = "CREATE TABLE IF NOT EXISTS email ("
|
||||
|
25
src/doors.c
25
src/doors.c
@ -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) {
|
||||
|
||||
char buffer[1024];
|
||||
int pid;
|
||||
int ret;
|
||||
unsigned char c;
|
||||
int len;
|
||||
@ -253,6 +252,9 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c
|
||||
size_t ouc;
|
||||
size_t inc;
|
||||
size_t sz;
|
||||
char **args;
|
||||
int arg_count;
|
||||
pid_t pid;
|
||||
int iac;
|
||||
char iac_binary_will[] = {IAC, IAC_WILL, 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) {
|
||||
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) {
|
||||
chdir(conf.bbs_path);
|
||||
}
|
||||
|
27
src/files.c
27
src/files.c
@ -297,7 +297,11 @@ char *get_file_id_diz(char *filename) {
|
||||
int stout;
|
||||
int stin;
|
||||
int sterr;
|
||||
|
||||
int ret;
|
||||
pid_t pid;
|
||||
char **args;
|
||||
int arg_count;
|
||||
char *cmd;
|
||||
ext = 0;
|
||||
arch = -1;
|
||||
|
||||
@ -367,7 +371,26 @@ char *get_file_id_diz(char *filename) {
|
||||
dup2(bbs_stderr, STDERR_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) {
|
||||
|
||||
|
Reference in New Issue
Block a user