diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2014-02-10 10:45:51 +0000 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2014-02-10 10:45:51 +0000 |
commit | 127cfd4f5abfa7913a8f5704f9ba8978f9b4baae (patch) | |
tree | edd29f22490d7289b46ac50b5e1bf121fa32c715 | |
parent | 2f850d402ed6419061855c40a925fe0cb8835459 (diff) | |
download | newlib-127cfd4f5abfa7913a8f5704f9ba8978f9b4baae.zip newlib-127cfd4f5abfa7913a8f5704f9ba8978f9b4baae.tar.gz newlib-127cfd4f5abfa7913a8f5704f9ba8978f9b4baae.tar.bz2 |
* 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.
-rw-r--r-- | winsup/cygwin/ChangeLog | 9 | ||||
-rw-r--r-- | winsup/cygwin/dcrt0.cc | 4 | ||||
-rw-r--r-- | winsup/cygwin/flock.cc | 28 |
3 files changed, 33 insertions, 8 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 76da1ec..b585aa7 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,12 @@ +2014-02-10 Corinna Vinschen <corinna@vinschen.de> + + * 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 <me.cygwin2014@cgf.cx> * environ.cc (strbrk): Properly deal with environment variable sans diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index d348d9b..07cbd4d 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 5306969..5ea3e06 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 (); } |