|
Lines 73-90
Link Here
|
| 73 |
setvbuf(LOGFILE, NULL, _IOLBF, 0); |
73 |
setvbuf(LOGFILE, NULL, _IOLBF, 0); |
| 74 |
} |
74 |
} |
| 75 |
|
75 |
|
| 76 |
if (flag_pid && !flag_nopid) { |
|
|
| 77 |
if (pid_file_name==NULL) pid_file_name=set_string("/var/run/netams.pid"); |
| 78 |
FILE *pidfile = fopen(pid_file_name, "wt"); |
| 79 |
|
| 80 |
if (pidfile!=NULL) { |
| 81 |
fprintf(pidfile, "%u\n", getpid()); |
| 82 |
fclose(pidfile); |
| 83 |
} else { |
| 84 |
fprintf(stderr, "Can't create pid-file: %s\n", strerror(errno)); |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
if (flag_syslog) openlog("netams", 0, LOG_DAEMON); |
76 |
if (flag_syslog) openlog("netams", 0, LOG_DAEMON); |
| 89 |
if (!flag_quiet) aShowVersion(stdout); |
77 |
if (!flag_quiet) aShowVersion(stdout); |
| 90 |
if (flag_log) aShowVersion(LOGFILE); |
78 |
if (flag_log) aShowVersion(LOGFILE); |
|
Lines 99-108
Link Here
|
| 99 |
if(chdir(RUN_PATH)<0) |
87 |
if(chdir(RUN_PATH)<0) |
| 100 |
aLog(D_CRIT, "Cannot chdir to directory %s: %s\n",RUN_PATH,strerror(errno)); |
88 |
aLog(D_CRIT, "Cannot chdir to directory %s: %s\n",RUN_PATH,strerror(errno)); |
| 101 |
aLog(D_INFO, "Becoming a daemon...\n"); |
89 |
aLog(D_INFO, "Becoming a daemon...\n"); |
| 102 |
daemon(1, 1); |
90 |
daemon(1, !flag_quiet); |
| 103 |
} else |
91 |
} else |
| 104 |
aLog(D_INFO, "Stay in debug mode...\n"); |
92 |
aLog(D_INFO, "Stay in debug mode...\n"); |
| 105 |
|
93 |
|
|
|
94 |
if (flag_pid && !flag_nopid) { |
| 95 |
if (pid_file_name==NULL) pid_file_name=set_string("/var/run/netams.pid"); |
| 96 |
FILE *pidfile = fopen(pid_file_name, "wt"); |
| 97 |
|
| 98 |
if (pidfile!=NULL) { |
| 99 |
fprintf(pidfile, "%u\n", getpid()); |
| 100 |
fclose(pidfile); |
| 101 |
} else { |
| 102 |
fprintf(stderr, "Can't create pid-file: %s\n", strerror(errno)); |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
// handling signals |
106 |
// handling signals |
| 107 |
signal(SIGHUP, (sig_t)logrotate); |
107 |
signal(SIGHUP, (sig_t)logrotate); |
| 108 |
signal(SIGQUIT, (sig_t)termination); |
108 |
signal(SIGQUIT, (sig_t)termination); |