+2011-09-23 Miklos Szeredi <miklos@szeredi.hu>
+
+ * Replace daemon() function with fork(). Patch by Anatol Pomozov
+
2011-08-26 Miklos Szeredi <miklos@szeredi.hu>
* If configured with --disable-mtab then don't call mount(8) from
int fuse_daemonize(int foreground)
{
- int res;
-
if (!foreground) {
- res = daemon(0, 0);
- if (res == -1) {
- perror("fuse: failed to daemonize program\n");
+ int nullfd;
+
+ /*
+ * demonize current process by forking it and killing the
+ * parent. This makes current process as a child of 'init'.
+ */
+ switch(fork()) {
+ case -1:
+ perror("fuse_daemonize: fork");
+ return -1;
+ case 0:
+ break;
+ default:
+ _exit(0);
+ }
+
+ if (setsid() == -1) {
+ perror("fuse_daemonize: setsid");
return -1;
}
+
+ (void) chdir("/");
+
+ nullfd = open("/dev/null", O_RDWR, 0);
+ if (nullfd != -1) {
+ (void) dup2(nullfd, 0);
+ (void) dup2(nullfd, 1);
+ (void) dup2(nullfd, 2);
+ if (nullfd > 2)
+ close(nullfd);
+ }
}
return 0;
}
if (*end)
goto out_inval;
- if (daemon(0, 1) == -1) {
- perror("ulockmgr_server: daemon");
+ /* demonize current process */
+ switch(fork()) {
+ case -1:
+ perror("ulockmgr_server: fork");
exit(1);
+ case 0:
+ break;
+ default:
+ _exit(0);
}
+ if (setsid() == -1) {
+ perror("ulockmgr_server: setsid");
+ exit(1);
+ }
+
+ (void) chdir("/");
+
sigemptyset(&empty);
sigprocmask(SIG_SETMASK, &empty, NULL);