mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 13:05:47 +00:00
fix(session): recheck a taken exit's child and commit a launch only on a whole go line
This commit is contained in:
1 parent
2ba290c2f1
commit
6f42e1cf1a
5 files changed
+35
-11
No files matched your search
@@ -992,6 +992,16 @@ static int ddh_selects(const struct ddh_entry *e, pid_t pid) {
|
||||
return e->pad[1] == (pid == 0 ? getpgrp() : -pid);
|
||||
}
|
||||
|
||||
// Takes e's exit for a wait for pid, checked again once taken: between finding e and taking it,
|
||||
// another waiter may have released the slot and a later child of ours (or one of another group)
|
||||
// have exited in it.
|
||||
static int ddh_take_for(struct ddh_entry *e, pid_t pid) {
|
||||
if (!ddh_take(e)) return 0;
|
||||
if (e->parent == getpid() && ddh_selects(e, pid)) return 1;
|
||||
ddh_untake(e);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ddh_any_live(pid_t pid) {
|
||||
if (!g_ddh) return 0;
|
||||
pid_t me = getpid();
|
||||
@@ -1112,7 +1122,7 @@ static pid_t ddh_wait(pid_t pid, int *status, int options, struct rusage *ru) {
|
||||
struct ddh_entry *e = pid > 0 ? ddh_find(pid) : NULL;
|
||||
if (pid > 0 && e) {
|
||||
if (!e->reaped && real(pid, NULL, WNOHANG, NULL) == pid) e->reaped = 1;
|
||||
if (ddh_take(e)) {
|
||||
if (ddh_take_for(e, pid)) {
|
||||
// the forked child is between its last write and its exit: reap it first, or a later
|
||||
// wait() would report its pid a second time (not blocking for WNOHANG: then later)
|
||||
if (!e->reaped && !ddh_reap_shim(real, pid, options)) {
|
||||
@@ -1132,7 +1142,7 @@ static pid_t ddh_wait(pid_t pid, int *status, int options, struct rusage *ru) {
|
||||
continue;
|
||||
}
|
||||
if (pid <= 0 && (e = ddh_exited(pid))) {
|
||||
if (!ddh_take(e)) continue; // another waiter has it
|
||||
if (!ddh_take_for(e, pid)) continue; // another waiter has it, or the slot went to another child
|
||||
pid_t child = e->child;
|
||||
if (!e->reaped && !ddh_reap_shim(real, child, options)) {
|
||||
ddh_untake(e);
|
||||
|
||||
@@ -458,9 +458,16 @@ int close_range(unsigned int first, unsigned int last, int flags) {
|
||||
const int *kept = (flags & CLOSE_RANGE_CLOEXEC) ? g_cloexec_kept_fds : g_kept_fds;
|
||||
int kept_count = (flags & CLOSE_RANGE_CLOEXEC) ? g_cloexec_kept_count : g_kept_fd_count;
|
||||
if (kept_count == 0) return close_range_all(first, last, flags);
|
||||
// The table is unshared once, even when every fd in the range is kept (no fd has the top number)
|
||||
// The table is unshared once, even when every fd in the range is kept: the system call itself on
|
||||
// the one number no fd has (close_range_all() would emulate a missing call by closing fds)
|
||||
if (flags & CLOSE_RANGE_UNSHARE) {
|
||||
if (close_range_all(~0U, ~0U, CLOSE_RANGE_UNSHARE) != 0) return -1;
|
||||
static long (*raw_syscall)(long, ...) = NULL;
|
||||
if (!raw_syscall) raw_syscall = (long (*)(long, ...))dlsym(RTLD_NEXT, "syscall");
|
||||
if (!raw_syscall) {
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
if (raw_syscall(__NR_close_range, ~0U, ~0U, CLOSE_RANGE_UNSHARE) != 0) return -1;
|
||||
flags &= ~CLOSE_RANGE_UNSHARE;
|
||||
}
|
||||
return for_each_range_without(first, last, kept, kept_count, close_range_part, &flags);
|
||||
|
||||
@@ -239,6 +239,7 @@ class NativeHookHandoffTest(unittest.TestCase):
|
||||
def test_a_posix_spawn_of_a_missing_program_fails_as_it_would(self):
|
||||
# posix_spawn() returns the exec's error, even with closefrom(3) among the file actions
|
||||
result, requests, out = self.run_parent("spawn", "6", "/bin/missing", handoff="missing")
|
||||
self.assertEqual(0, out.returncode, out.stderr)
|
||||
self.assertEqual([], requests)
|
||||
self.assertEqual(str(errno.ENOENT), result.get("spawned"), out.stdout)
|
||||
self.assertNotIn("exit", result, out.stdout)
|
||||
@@ -249,6 +250,10 @@ class NativeHookHandoffTest(unittest.TestCase):
|
||||
# as a separate process, gets 0 and an exit status of 127.
|
||||
result, requests, out = self.run_parent("spawn", "6", "/bin/missing", handoff="other")
|
||||
plain, _, plain_out = self.run_parent("spawn", "6", "/bin/missing", handoff="other", hook=False)
|
||||
self.assertEqual(0, out.returncode, out.stderr)
|
||||
self.assertEqual(0, plain_out.returncode, plain_out.stderr)
|
||||
self.assertIn("spawned", result, out.stdout)
|
||||
self.assertIn("spawned", plain, plain_out.stdout)
|
||||
self.assertEqual([], requests)
|
||||
self.assertEqual(plain.get("spawned"), result.get("spawned"), out.stdout + plain_out.stdout)
|
||||
self.assertEqual(plain.get("exit"), result.get("exit"), out.stdout + plain_out.stdout)
|
||||
|
||||
Reference in new issue
Block a user