diff options
author | Lennart Poettering <lennart@poettering.net> | 2004-09-28 22:47:48 +0000 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2004-09-28 22:47:48 +0000 |
commit | 6f59ae1763ee48f27448a7de9d635f61886052e1 (patch) | |
tree | e83ab47226b6c716c200e9fa40f44668997eb642 /polyp/util.c | |
parent | 450ad85b35bd600ed020f7ec119d51e7e7bc01a4 (diff) |
Add module-tunnel
add proper locking when autospawning a daemon
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@245 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'polyp/util.c')
-rw-r--r-- | polyp/util.c | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/polyp/util.c b/polyp/util.c index fa33ffff..70ec120d 100644 --- a/polyp/util.c +++ b/polyp/util.c @@ -502,7 +502,7 @@ finish: return r; } -int pa_lock_file(int fd, int b) { +int pa_lock_fd(int fd, int b) { struct flock flock; @@ -525,3 +525,44 @@ char* pa_strip_nl(char *s) { s[strcspn(s, "\r\n")] = 0; return s; } + +int pa_lock_lockfile(const char *fn) { + int fd; + assert(fn); + + if ((fd = open(fn, O_CREAT|O_RDWR, S_IRUSR|S_IWUSR)) < 0) { + pa_log(__FILE__": failed to create lock file '%s'\n", fn); + goto fail; + } + + if (pa_lock_fd(fd, 1) < 0) + goto fail; + + return fd; + +fail: + + if (fd >= 0) + close(fd); + + return -1; +} + + +int pa_unlock_lockfile(int fd) { + int r = 0; + assert(fd >= 0); + + if (pa_lock_fd(fd, 0) < 0) { + pa_log(__FILE__": WARNING: failed to unlock file.\n"); + r = -1; + } + + if (close(fd) < 0) { + pa_log(__FILE__": WARNING: failed to close lock file.\n"); + r = -1; + } + + return r; +} + |