Skip to content

Commit

Permalink
mx_util: Add mx_call_external
Browse files Browse the repository at this point in the history
  • Loading branch information
donald committed May 5, 2022
1 parent da60fe7 commit 0713866
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions mx_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,24 @@ time_t mx_clock_boottime(void) {
return (ts.tv_sec);
}

int mx_call_external(char *helper, char **argv) {
pid_t pid = fork();
if (pid == 0) {
execv(helper, argv);
mx_log_err("%s: %m", helper);
_exit(1);
}
if (pid == -1)
return -1;
int wstatus;
waitpid(pid, &wstatus, 0);
if (wstatus != 0) {
errno = EPROTO;
return -1;
}
return 0;
}

static ssize_t readall(int fd, char *buf, size_t buflen) {
ssize_t len = 0;
while (buflen) {
Expand Down
1 change: 1 addition & 0 deletions mx_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ void _mx_sort_linked_list(void **list, int (*cmp)(void *o1,void *o2), void ** (*

unsigned long mx_df(const char *path);
time_t mx_clock_boottime(void);
int mx_call_external(char *helper, char **argv);
char *mx_pipe_external(char *args, char **argv);

#endif

0 comments on commit 0713866

Please sign in to comment.