summaryrefslogtreecommitdiffstats
path: root/fuse/helper.c
diff options
context:
space:
mode:
authorDees_Troy <dees_troy@teamw.in>2013-02-06 20:13:00 +0100
committerbigbiff bigbiff <bigbiff@teamw.in>2013-02-07 14:21:17 +0100
commite34c133ec6053025124416a3861f9f4c4f7fd772 (patch)
tree027d856cea0aa7abd29234727ef0924683d4d409 /fuse/helper.c
parentMerge "Fix misspelling and white space on fix perms" into twrp2.4 (diff)
downloadandroid_bootable_recovery-e34c133ec6053025124416a3861f9f4c4f7fd772.tar
android_bootable_recovery-e34c133ec6053025124416a3861f9f4c4f7fd772.tar.gz
android_bootable_recovery-e34c133ec6053025124416a3861f9f4c4f7fd772.tar.bz2
android_bootable_recovery-e34c133ec6053025124416a3861f9f4c4f7fd772.tar.lz
android_bootable_recovery-e34c133ec6053025124416a3861f9f4c4f7fd772.tar.xz
android_bootable_recovery-e34c133ec6053025124416a3861f9f4c4f7fd772.tar.zst
android_bootable_recovery-e34c133ec6053025124416a3861f9f4c4f7fd772.zip
Diffstat (limited to 'fuse/helper.c')
-rw-r--r--fuse/helper.c43
1 files changed, 33 insertions, 10 deletions
diff --git a/fuse/helper.c b/fuse/helper.c
index 7b994fd3b..ace19dd70 100644
--- a/fuse/helper.c
+++ b/fuse/helper.c
@@ -179,14 +179,38 @@ err:
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;
}
@@ -227,7 +251,8 @@ static void fuse_unmount_common(const char *mountpoint, struct fuse_chan *ch)
{
int fd = ch ? fuse_chan_fd(ch) : -1;
fuse_kern_unmount(mountpoint, fd);
- fuse_chan_destroy(ch);
+ if (ch)
+ fuse_chan_destroy(ch);
}
void fuse_unmount(const char *mountpoint, struct fuse_chan *ch)
@@ -324,11 +349,9 @@ static int fuse_main_common(int argc, char *argv[],
if (fuse == NULL)
return 1;
-#ifdef __MULTI_THREAD
if (multithreaded)
res = fuse_loop_mt(fuse);
else
-#endif
res = fuse_loop(fuse);
fuse_teardown_common(fuse, mountpoint);
@@ -359,7 +382,7 @@ int fuse_version(void)
#include "fuse_compat.h"
-#ifndef __FreeBSD__
+#if !defined(__FreeBSD__) && !defined(__NetBSD__)
struct fuse *fuse_setup_compat22(int argc, char *argv[],
const struct fuse_operations_compat22 *op,
@@ -417,7 +440,7 @@ FUSE_SYMVER(".symver fuse_teardown,__fuse_teardown@");
FUSE_SYMVER(".symver fuse_main_compat2,fuse_main@");
FUSE_SYMVER(".symver fuse_main_real_compat22,fuse_main_real@FUSE_2.2");
-#endif /* __FreeBSD__ */
+#endif /* __FreeBSD__ || __NetBSD__ */
struct fuse *fuse_setup_compat25(int argc, char *argv[],