summaryrefslogtreecommitdiff
path: root/src/sysexec.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sysexec.c')
-rw-r--r--src/sysexec.c51
1 files changed, 26 insertions, 25 deletions
diff --git a/src/sysexec.c b/src/sysexec.c
index 79f4e74..abfd6f8 100644
--- a/src/sysexec.c
+++ b/src/sysexec.c
@@ -1,26 +1,27 @@
/*
- * rhdropbox
+ * dropnroll
*
- * Copyright (C) 2009 Christian Pointner <equinox@helsinki.at>
+ * Copyright (C) 2009-2015 Christian Pointner <equinox@spreadspace.org>
*
- * This file is part of rhdropbox.
+ * This file is part of dropnroll.
*
- * rhdropbox is free software: you can redistribute it and/or modify
+ * dropnroll is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
- * rhdropbox is distributed in the hope that it will be useful,
+ * dropnroll is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with rhdropbox. If not, see <http://www.gnu.org/licenses/>.
+ * along with dropnroll. If not, see <http://www.gnu.org/licenses/>.
*/
#include "datatypes.h"
+#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@@ -49,12 +50,12 @@ char** dup_ptrptr(char* const ptrptr[])
int i;
for(i = 0; i < n; ++i) {
- my_ptrptr[i] = strdup(ptrptr[i]);
+ my_ptrptr[i] = strdup(ptrptr[i]);
if(!my_ptrptr[i]) {
i--;
for(; i >= 0; --i)
free(my_ptrptr[i]);
-
+
free(my_ptrptr);
return NULL;
}
@@ -73,7 +74,7 @@ void free_ptrptr(char** ptrptr)
int i;
for(i = 0; ptrptr[i]; ++i)
free(ptrptr[i]);
-
+
free(ptrptr);
}
@@ -81,7 +82,7 @@ void child_list_init(child_list_t* list)
{
if(!list)
return;
-
+
list->first_ = NULL;
}
@@ -107,7 +108,7 @@ child_list_element_t* child_list_new(const char* script, char* const argv[], cha
new_child = malloc(sizeof(child_list_element_t));
if(!new_child)
return NULL;
-
+
new_child->next_ = 0;
new_child->pid_ = -1;
new_child->err_fd_ = -1;
@@ -117,15 +118,15 @@ child_list_element_t* child_list_new(const char* script, char* const argv[], cha
free(new_child);
return NULL;
}
-
+
new_child->argv_ = dup_ptrptr(argv);
if(!new_child->argv_) {
free(new_child->script_);
free(new_child);
return NULL;
-
+
}
-
+
new_child->evp_ = dup_ptrptr(evp);
if(!new_child->evp_) {
free_ptrptr(new_child->argv_);
@@ -190,12 +191,12 @@ void child_list_rm_pid(child_list_t* list, pid_t pid)
{
if(!list)
return;
-
+
child_list_element_t* tmp = NULL;
if(list->first_->pid_ == pid) {
tmp = list->first_;
list->first_ = list->first_->next_;
-
+
free_ptrptr(tmp->argv_);
free_ptrptr(tmp->evp_);
if(tmp->script_)
@@ -215,7 +216,7 @@ void child_list_rm_pid(child_list_t* list, pid_t pid)
if(tmp->script_)
free(tmp->script_);
free(tmp);
- return;
+ return;
}
prev = tmp;
tmp = tmp->next_;
@@ -226,14 +227,14 @@ child_list_element_t* child_list_find(child_list_t* list, pid_t pid)
{
if(!list)
return NULL;
-
+
child_list_element_t* tmp = list->first_;
while(tmp) {
if(tmp->pid_ == pid)
return tmp;
tmp = tmp->next_;
}
-
+
return NULL;
}
@@ -243,11 +244,11 @@ int child_list_num_running(child_list_t* list)
if(!list)
return 0;
-
+
child_list_element_t* tmp = list->first_;
for(;tmp;tmp=tmp->next_)
if(tmp->running_) num++;
-
+
return num;
}
@@ -305,10 +306,11 @@ int rh_exec_child(child_list_element_t* child)
log_printf(WARNING, "can't open stderr");
}
execve(child->script_, child->argv_, child->evp_);
- // if execve returns, an error occurred, but logging doesn't work
+ // if execve returns, an error occurred, but logging doesn't work
// because we closed all file descriptors, so just write errno to
// pipe and call exit
- write(pipefd[1], (void*)(&errno), sizeof(errno));
+ int ret = write(pipefd[1], (void*)(&errno), sizeof(errno));
+ if(ret == -1) exit(-1);
exit(-1);
}
close(pipefd[1]);
@@ -365,7 +367,6 @@ int rh_waitpid(child_list_t* child_lst, options_t* opt)
if(child_list_num_running(child_lst) < opt->max_children_)
rh_exec_child(child_list_find(child_lst, -1));
-
+
return status;
}
-