summaryrefslogtreecommitdiffstats
path: root/contrib/apple
diff options
context:
space:
mode:
authorCsaba Henk <csaba@gluster.com>2011-05-15 04:52:33 +0000
committerAnand Avati <avati@gluster.com>2011-05-19 15:41:47 -0700
commitc5d781e05599e9e7ad736d42c9c1033992c76ded (patch)
treeaff88649bc98a6c8babc3d75760fae2ef36b4cc3 /contrib/apple
parent357df32e16dd21e7aedb699c7bd99cac9b95a040 (diff)
upon daemonizing, wait on mtab update to terminate in parent
This fixes the race in between the mtab update attempts of mount and umount when we do a lazy umount right after mounting, in order to hide the given fs instance; yet this way we still avoid the deadlock of the fs and mount which we can hit if we wait unconditionally for the mtab update to terminate (cf. bz #511). Signed-off-by: Csaba Henk <csaba@gluster.com> Signed-off-by: Anand Avati <avati@gluster.com> BUG: 2690 (race between mtab updates of mount and umount) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2690
Diffstat (limited to 'contrib/apple')
-rw-r--r--contrib/apple/daemon.c26
-rw-r--r--contrib/apple/daemon.h1
2 files changed, 18 insertions, 9 deletions
diff --git a/contrib/apple/daemon.c b/contrib/apple/daemon.c
index 9389201a1..07dbbc400 100644
--- a/contrib/apple/daemon.c
+++ b/contrib/apple/daemon.c
@@ -44,7 +44,7 @@
#include <unistd.h>
int
-os_daemon(nochdir, noclose)
+os_daemon_return(nochdir, noclose)
int nochdir, noclose;
{
struct sigaction osa, sa;
@@ -52,6 +52,7 @@ os_daemon(nochdir, noclose)
pid_t newgrp;
int oerrno;
int osa_ok;
+ int ret;
/* A SIGHUP may be thrown when the parent exits below. */
sigemptyset(&sa.sa_mask);
@@ -59,14 +60,9 @@ os_daemon(nochdir, noclose)
sa.sa_flags = 0;
osa_ok = sigaction(SIGHUP, &sa, &osa);
- switch (fork()) {
- case -1:
- return (-1);
- case 0:
- break;
- default:
- _exit(0);
- }
+ ret = fork();
+ if (ret)
+ return ret;
newgrp = setsid();
oerrno = errno;
@@ -90,3 +86,15 @@ os_daemon(nochdir, noclose)
}
return (0);
}
+
+int
+os_daemon(int nochdir, int noclose)
+{
+ int ret;
+
+ ret = os_daemon_return(nochdir, noclose);
+ if (ret <= 0)
+ return ret;
+
+ _exit(0);
+}
diff --git a/contrib/apple/daemon.h b/contrib/apple/daemon.h
index 7a2824b6a..aa88d9baa 100644
--- a/contrib/apple/daemon.h
+++ b/contrib/apple/daemon.h
@@ -17,4 +17,5 @@
<http://www.gnu.org/licenses/>.
*/
+int os_daemon_return(int nochdir, int noclose);
int os_daemon(int nochdir, int noclose);