diff options
Diffstat (limited to 'server/src/pracrod.cc')
-rw-r--r-- | server/src/pracrod.cc | 73 |
1 files changed, 17 insertions, 56 deletions
diff --git a/server/src/pracrod.cc b/server/src/pracrod.cc index cd5bfe7..134b212 100644 --- a/server/src/pracrod.cc +++ b/server/src/pracrod.cc @@ -27,6 +27,8 @@ // For ETC #include <config.h> +#include "daemon.h" + // For setuid and setgid #include <sys/types.h> #include <unistd.h> @@ -93,6 +95,19 @@ void reload(int fisk) } } +class PracroDaemon : public Daemon { +private: + int daemon_main(); +}; + +int PracroDaemon::daemon_main() +{ + // Activate the server main loop. + server(); + + return 0; +} + int main(int argc, char *argv[]) { int c; @@ -152,9 +167,6 @@ int main(int argc, char *argv[]) } } - //std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>] - //std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>] - char *cfname = NULL; if(!configfile) cfname = ETC"/pracrod.conf"; else cfname = configfile; @@ -170,24 +182,6 @@ int main(int argc, char *argv[]) } } - if(user) { - // Fetch user id - int uid = -1; - struct passwd *p = getpwent(); - while(p) { - if(strcmp(p->pw_name, user) == 0) uid = p->pw_uid; - p = getpwent(); - } - if(uid == -1) { - fprintf(stderr, "Could not find user \"%s\" in /etc/passwd file.\n", user); - return 1; - } - - if(setuid(uid) == -1) { - fprintf(stderr, "Could not switch to user %s: %s\n", user, strerror(errno)); - return 1; - } - } if(!group) { std::string groupstr; @@ -199,41 +193,8 @@ int main(int argc, char *argv[]) } - if(group) { - // Fetch group id - int gid = -1; - struct group *g = getgrent(); - while(g) { - if(strcmp(g->gr_name, group) == 0) gid = g->gr_gid; - g = getgrent(); - } - if(gid == -1) { - fprintf(stderr, "Could not find group \"%s\" in /etc/group file.\n", group); - return 1; - } - - if(setgid(gid) == -1) { - fprintf(stderr, "Could not switch to group %s: %s\n", group, strerror(errno)); - return 1; - } - } - - if(!foreground) { - daemon(0,0); - signal (SIGTERM, SIG_IGN); - signal (SIGINT, SIG_IGN); - } else { - printf("Running in foreground mode.\n"); - } - - // Create callback to reload conf files. - signal (SIGHUP, reload); - - signal(SIGCLD, SIG_IGN); // Ved SIGCHILD til IGNORE maa wait/waitpid ikke kaldes - // (ellers kommer der kernel-brok) - - // Activate the server main loop. - server(); + PracroDaemon daemon; + daemon.run(user, group, !foreground); // Clean up if(configfile) free(configfile); |