diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 76da1ec23..b585aa736 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,12 @@ +2014-02-10 Corinna Vinschen + + * dcrt0.cc (child_info_spawn::handle_spawn): Call fixup_lockf_after_exec + with additional argument to specify if the process has been execed + or spawned. + * flock.cc (fixup_lockf_after_exec): Take bool parameter to handle + exec and spawn differently. In case of spawn, just give up POSIX + locks in favor of the still running parent. Add comments to explain. + 2014-02-09 Christopher Faylor * environ.cc (strbrk): Properly deal with environment variable sans diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index d348d9bd5..07cbd4d26 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -655,7 +655,7 @@ child_info_spawn::get_parent_handle () void child_info_spawn::handle_spawn () { - extern void fixup_lockf_after_exec (); + extern void fixup_lockf_after_exec (bool); HANDLE h; if (!dynamically_loaded || get_parent_handle ()) { @@ -706,7 +706,7 @@ child_info_spawn::handle_spawn () } signal_fixup_after_exec (); - fixup_lockf_after_exec (); + fixup_lockf_after_exec (type == _CH_EXEC); } /* Retrieve and store system directory for later use. Note that the diff --git a/winsup/cygwin/flock.cc b/winsup/cygwin/flock.cc index 53069694d..5ea3e067d 100644 --- a/winsup/cygwin/flock.cc +++ b/winsup/cygwin/flock.cc @@ -439,7 +439,7 @@ fhandler_base::del_my_locks (del_lock_called_from from) wait on. If the node has been abandoned due to close_on_exec on the referencing fhandlers, remove the inode entirely. */ void -fixup_lockf_after_exec () +fixup_lockf_after_exec (bool exec) { inode_t *node, *next_node; @@ -464,13 +464,29 @@ fixup_lockf_after_exec () else { node->LOCK (); - for (lockf_t *lock = node->i_lockf; lock; lock = lock->lf_next) + lockf_t *lock, *n_lock; + lockf_t **prev = &node->i_lockf; + for (lock = *prev; lock && (n_lock = lock->lf_next, 1); lock = n_lock) if (lock->lf_flags & F_POSIX) { - lock->del_lock_obj (NULL); - lock->lf_wid = myself->dwProcessId; - lock->lf_ver = 0; - lock->create_lock_obj (); + if (exec) + { + /* The parent called exec. The lock is passed to the child. + Recreate lock object with changed ownership. */ + lock->del_lock_obj (NULL); + lock->lf_wid = myself->dwProcessId; + lock->lf_ver = 0; + lock->create_lock_obj (); + } + else + { + /* The parent called spawn. The parent continues to hold + the POSIX lock, ownership is not passed to the child. + Give up the lock in the child. */ + *prev = n_lock; + lock->close_lock_obj (); + delete lock; + } } node->UNLOCK (); }