+++ /dev/null
-/* pending.c - reusable stuff awaiting review
- *
- * new lib entries for stuff in toys/pending
- */
-
-#include "toys.h"
-
-void daemonize(void)
-{
- int fd = open("/dev/null", O_RDWR);
- if (fd < 0) fd = xcreate("/", O_RDONLY, 0666);
-
- pid_t pid = fork();
- if (pid < 0) perror_exit("DAEMON: failed to fork");
- if (pid) exit(EXIT_SUCCESS);
-
- setsid();
- dup2(fd, 0);
- dup2(fd, 1);
- dup2(fd, 2);
- if (fd > 2) close(fd);
-}
void is_valid_username(const char *name);
int read_password(char * buff, int buflen, char* mesg);
int update_password(char *filename, char* username, char* encrypted);
-
-// cut helper functions
-void daemonize(void);
infomode = LOG_CONSOLE;
if (!(flag_chk(FLAG_f))) {
- daemonize();
+ daemon(0,0);
infomode = LOG_SILENT;
}
if (flag_chk(FLAG_S)) {
sigatexit(handle_signal);
if (toys.optflags & FLAG_c) set_log_level(TT.level); //set log level
- if (!(toys.optflags & FLAG_n)) daemonize(); //Make it daemon
+ if (!(toys.optflags & FLAG_n)) daemon(0, 0); //Make it daemon
if (CFG_KLOGD_SOURCE_RING_BUFFER) {
syslog(LOG_NOTICE, "KLOGD: started with Kernel ring buffer as log source\n");
if (parse_config_file() == -1) goto clean_and_exit;
open_logfiles();
if (!(toys.optflags & FLAG_n)) {
- daemonize();
+ daemon(0, 0);
//don't daemonize again if SIGHUP received.
toys.optflags |= FLAG_n;
}
master_fd = listen_socket();
fcntl(master_fd, F_SETFD, FD_CLOEXEC);
if (master_fd > TT.gmax_fd) TT.gmax_fd = master_fd;
- if (!(toys.optflags & FLAG_F)) daemonize();
+ if (!(toys.optflags & FLAG_F)) daemon(0, 0);
} else {
pty_fd = new_session(master_fd); //master_fd = 0
if (pty_fd > TT.gmax_fd) TT.gmax_fd = pty_fd;