Skip to content
Browse files

Change behaviour of uv_flock_destroy and uv_flock_release.

Move the unlink call out of uv_flock_destroy and into uv_flock_release (which
was apparently unused originally), so that uv_flock_destroy only closes any
open file descriptors and frees memory.

Then, in uv_pipe_bind, on error, call uv_flock_destroy, but release the lock
only if the lock isn't held by another process. In uv_pipe_cleanup, do both.
  • Loading branch information...
1 parent 89524a5 commit f3ac65a791e5b61ed1d45f1da81d03f6557986eb @bacchusrx committed Dec 21, 2011
Showing with 14 additions and 29 deletions.
  1. +14 −29 src/unix/pipe.c
View
43 src/unix/pipe.c
@@ -61,7 +61,7 @@ int uv_flock_release(uv_flock_t* lock);
/* Destroy the file lock. Releases the file lock and associated resources.
*/
-int uv_flock_destroy(uv_flock_t* lock);
+void uv_flock_destroy(uv_flock_t* lock);
int uv_pipe_init(uv_loop_t* loop, uv_pipe_t* handle, int ipc) {
uv__stream_init(loop, (uv_stream_t*)handle, UV_NAMED_PIPE);
@@ -163,15 +163,13 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
}
uv__close(sockfd);
- /* If you clear the lock here, then only the first attempt to bind a locked
- * pipe fails. Presumably, some kind of cleanup still belongs here. */
-
- /*
- * if (pipe_flock) {
- * uv_flock_destroy(pipe_flock);
- * }
- *
- */
+ if (pipe_flock) {
+ if (!locked) {
+ uv_flock_release(pipe_flock);
+ }
+ uv_flock_destroy(pipe_flock);
+ free(pipe_flock);
+ }
free((void*)pipe_fname);
}
@@ -230,6 +228,7 @@ int uv_pipe_cleanup(uv_pipe_t* handle) {
}
if (handle->pipe_flock) {
+ uv_flock_release((uv_flock_t*)handle->pipe_flock);
uv_flock_destroy((uv_flock_t*)handle->pipe_flock);
free(handle->pipe_flock);
}
@@ -423,41 +422,27 @@ int uv_flock_acquire(uv_flock_t* lock, int* locked_p) {
return status;
}
-int uv_flock_release(uv_flock_t* lock) {
+void uv_flock_destroy(uv_flock_t* lock) {
int saved_errno;
- int status;
saved_errno = errno;
- status = -1;
-
- if (unlink(lock->lockfile) == -1) {
- /* Now what? */
- goto out;
- }
uv__close(lock->lockfd);
lock->lockfd = -1;
- status = 0;
-out:
+ free((void*)lock->lockfile);
+ lock->lockfile = NULL;
+
errno = saved_errno;
- return status;
}
-
-int uv_flock_destroy(uv_flock_t* lock) {
+int uv_flock_release(uv_flock_t* lock) {
int saved_errno;
int status;
saved_errno = errno;
status = unlink(lock->lockfile);
- uv__close(lock->lockfd);
- lock->lockfd = -1;
-
- free((void*)lock->lockfile);
- lock->lockfile = NULL;
-
errno = saved_errno;
return status;
}

0 comments on commit f3ac65a

Please sign in to comment.
Something went wrong with that request. Please try again.