Skip to content

Commit

Permalink
Ignore signals when waiting for vfork completion
Browse files Browse the repository at this point in the history
  • Loading branch information
Theodore Dubois committed Nov 12, 2018
1 parent 1df316a commit 12e4058
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
3 changes: 1 addition & 2 deletions kernel/fork.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ dword_t sys_clone(dword_t flags, addr_t stack, addr_t ptid, addr_t tls, addr_t c
if (flags & CLONE_VFORK_) {
lock(&task->vfork_lock);
while (!task->vfork_done)
// ignore EINTR
wait_for(&task->vfork_cond, &task->vfork_lock);
wait_for_ignore_signals(&task->vfork_cond, &task->vfork_lock);
unlock(&task->vfork_lock);
}
return pid;
Expand Down
9 changes: 6 additions & 3 deletions util/sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ void cond_destroy(cond_t *cond) {
int wait_for(cond_t *cond, lock_t *lock) {
if (current && current->pending)
return 1;
wait_for_ignore_signals(cond, lock);
if (current && current->pending)
return 1;
return 0;
}
void wait_for_ignore_signals(cond_t *cond, lock_t *lock) {
if (current) {
lock(&current->waiting_cond_lock);
current->waiting_cond = cond;
Expand All @@ -27,9 +33,6 @@ int wait_for(cond_t *cond, lock_t *lock) {
current->waiting_lock = NULL;
unlock(&current->waiting_cond_lock);
}
if (current && current->pending)
return 1;
return 0;
}

void notify(cond_t *cond) {
Expand Down
2 changes: 2 additions & 0 deletions util/sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ void cond_destroy(cond_t *cond);
// Releases the lock, waits for the condition, and reacquires the lock. Return
// 1 if waiting stopped because the thread received a signal, 0 otherwise.
int wait_for(cond_t *cond, lock_t *lock);
// Use this if you want to wait even if there are signals pending
void wait_for_ignore_signals(cond_t *cond, lock_t *lock);
// Wake up all waiters.
void notify(cond_t *cond);
// Wake up one waiter.
Expand Down

0 comments on commit 12e4058

Please sign in to comment.