mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-04 04:06:06 -05:00
spawn: add optional reaper callback, return pid_t
This will allow spawn() callers to do things when the spawned process has terminated.
This commit is contained in:
parent
57af75f988
commit
a42f990818
6 changed files with 26 additions and 19 deletions
14
spawn.c
14
spawn.c
|
|
@ -15,9 +15,9 @@
|
|||
#include "debug.h"
|
||||
#include "xmalloc.h"
|
||||
|
||||
bool
|
||||
pid_t
|
||||
spawn(struct reaper *reaper, const char *cwd, char *const argv[],
|
||||
int stdin_fd, int stdout_fd, int stderr_fd,
|
||||
int stdin_fd, int stdout_fd, int stderr_fd, reaper_cb cb, void *cb_data,
|
||||
const char *xdg_activation_token)
|
||||
{
|
||||
int pipe_fds[2] = {-1, -1};
|
||||
|
|
@ -104,16 +104,16 @@ spawn(struct reaper *reaper, const char *cwd, char *const argv[],
|
|||
close(pipe_fds[0]);
|
||||
|
||||
if (ret == 0) {
|
||||
reaper_add(reaper, pid, NULL, NULL);
|
||||
return true;
|
||||
reaper_add(reaper, pid, cb, cb_data);
|
||||
return pid;
|
||||
} else if (ret < 0) {
|
||||
LOG_ERRNO("failed to read from pipe");
|
||||
return false;
|
||||
return -1;
|
||||
} else {
|
||||
LOG_ERRNO_P(errno_copy, "%s: failed to spawn", argv[0]);
|
||||
errno = errno_copy;
|
||||
waitpid(pid, NULL, 0);
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
err:
|
||||
|
|
@ -121,7 +121,7 @@ err:
|
|||
close(pipe_fds[0]);
|
||||
if (pipe_fds[1] != -1)
|
||||
close(pipe_fds[1]);
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue