diff options
author | deva <deva> | 2006-07-20 17:53:04 +0000 |
---|---|---|
committer | deva <deva> | 2006-07-20 17:53:04 +0000 |
commit | c8df40b62cf30029a4acd1a57c8c54add54dda9b (patch) | |
tree | 42d06a4d502c6e0fd0cdbf7f836fdaffd847efa5 /lib/daemon.cc | |
parent | a09f1b932560f11caf34a567ee226446a496a584 (diff) |
Utilized the global info object.
Utilized the global info object.
Diffstat (limited to 'lib/daemon.cc')
-rw-r--r-- | lib/daemon.cc | 19 |
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(); } |