summaryrefslogtreecommitdiff
path: root/lib/daemon.cc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/daemon.cc')
-rw-r--r--lib/daemon.cc19
1 files changed, 13 insertions, 6 deletions
diff --git a/lib/daemon.cc b/lib/daemon.cc
index 6e46bd5..fc052ff 100644
--- a/lib/daemon.cc
+++ b/lib/daemon.cc
@@ -31,7 +31,7 @@
#include <signal.h>
#include <stdio.h>
-// For getgrent and getgrent
+// For getpwent and getgrent
#include <sys/types.h>
#include <grp.h>
#include <pwd.h>
@@ -47,9 +47,6 @@ Daemon::~Daemon()
int Daemon::run(const char *user, const char* group)
{
- int f;
- int fd;
-
// Fetch user id
int uid = -1;
struct passwd *p = getpwent();
@@ -72,6 +69,8 @@ int Daemon::run(const char *user, const char* group)
fprintf(stderr, "Could not find group \"%s\" in /etc/group file.\n", group);
}
+
+ /*
chdir("/");
umask(0);
@@ -86,19 +85,22 @@ int Daemon::run(const char *user, const char* group)
if(setgid(gid) != 0) {
fprintf(stderr, "Failed to change to group \"%s\" (gid: %d), quitting.\n", group, gid);
perror("");
- fprintf(stderr, "Runnning daemon as current group\n");
+ fprintf(stderr, "Running daemon as current group\n");
}
// Switch to given user
if(setuid(uid) != 0) {
fprintf(stderr, "Failed to change to user \"%s\" (uid: %d), quitting.\n", user, uid);
perror("");
- fprintf(stderr, "Runnning daemon as current user\n");
+ fprintf(stderr, "Running daemon as current user\n");
}
// Redirect stdin, stdout and stderr to /dev/null
fd = open("/dev/null", O_NOCTTY | O_RDWR, 0666);
+ int f;
+ int fd;
+
dup2(0, fd);
dup2(1, fd);
dup2(2, fd);
@@ -115,4 +117,9 @@ int Daemon::run(const char *user, const char* group)
// exit(0);
return 0;
}
+ */
+
+ // Glibc to do all of the above
+ daemon(0,0);
+ return daemon_main();
}