Small adjustments
This commit is contained in:
parent
731455f164
commit
29457a1d28
@ -20,6 +20,9 @@
|
|||||||
int file_to_vector(const char *filename, Vector<CharArray> &arr);
|
int file_to_vector(const char *filename, Vector<CharArray> &arr);
|
||||||
char *strdup2(const char *s, size_t *size = nullptr);
|
char *strdup2(const char *s, size_t *size = nullptr);
|
||||||
|
|
||||||
|
int exec_array(bool err, int *fd, void (*pre_exec)(void), const char **argv);
|
||||||
|
int exec_command(bool err, int *fd, void (*cb)(void), const char *argv0, ...);
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -91,8 +94,6 @@ unsigned get_system_uid();
|
|||||||
unsigned get_radio_uid();
|
unsigned get_radio_uid();
|
||||||
ssize_t fdgets(char *buf, size_t size, int fd);
|
ssize_t fdgets(char *buf, size_t size, int fd);
|
||||||
int is_num(const char *s);
|
int is_num(const char *s);
|
||||||
int exec_array(bool err, int *fd, void (*cb)(void), const char **argv);
|
|
||||||
int exec_command(bool err, int *fd, void (*cb)(void), const char *argv0, ...);
|
|
||||||
int exec_command_sync(const char *argv0, ...);
|
int exec_command_sync(const char *argv0, ...);
|
||||||
int fork_dont_care();
|
int fork_dont_care();
|
||||||
void gen_rand_str(char *buf, int len);
|
void gen_rand_str(char *buf, int len);
|
||||||
|
@ -184,9 +184,9 @@ int __fsetxattr(int fd, const char *name, const void *value, size_t size, int fl
|
|||||||
fd == nullptr -> Ignore output
|
fd == nullptr -> Ignore output
|
||||||
*fd < 0 -> Open pipe and set *fd to the read end
|
*fd < 0 -> Open pipe and set *fd to the read end
|
||||||
*fd >= 0 -> STDOUT (or STDERR) will be redirected to *fd
|
*fd >= 0 -> STDOUT (or STDERR) will be redirected to *fd
|
||||||
*cb -> A callback function which calls after forking
|
*pre_exec -> A callback function called after forking, before execvp
|
||||||
*/
|
*/
|
||||||
int exec_array(bool err, int *fd, void (*cb)(void), const char **argv) {
|
int exec_array(bool err, int *fd, void (*pre_exec)(void), const char **argv) {
|
||||||
int pipefd[2], outfd = -1;
|
int pipefd[2], outfd = -1;
|
||||||
|
|
||||||
if (fd) {
|
if (fd) {
|
||||||
@ -209,15 +209,16 @@ int exec_array(bool err, int *fd, void (*cb)(void), const char **argv) {
|
|||||||
return pid;
|
return pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fd) {
|
if (outfd >= 0) {
|
||||||
xdup2(outfd, STDOUT_FILENO);
|
xdup2(outfd, STDOUT_FILENO);
|
||||||
if (err)
|
if (err)
|
||||||
xdup2(outfd, STDERR_FILENO);
|
xdup2(outfd, STDERR_FILENO);
|
||||||
|
close(outfd);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup environment
|
// Call the pre-exec callback
|
||||||
if (cb)
|
if (pre_exec)
|
||||||
cb();
|
pre_exec();
|
||||||
|
|
||||||
execvp(argv[0], (char **) argv);
|
execvp(argv[0], (char **) argv);
|
||||||
PLOGE("execvp %s", argv[0]);
|
PLOGE("execvp %s", argv[0]);
|
||||||
|
Loading…
Reference in New Issue
Block a user