| 167 | } |
| 168 | |
| 169 | void log_init(int restart) |
| 170 | { |
| 171 | if (log_initialised) { |
| 172 | if (!restart) /* Note: a restart only happens with am_daemon */ |
| 173 | return; |
| 174 | assert(logfile_name); /* all am_daemon procs got at least an empty string */ |
| 175 | if (strcmp(logfile_name, lp_log_file(module_id)) != 0) { |
| 176 | if (logfile_fp) { |
| 177 | fclose(logfile_fp); |
| 178 | logfile_fp = NULL; |
| 179 | } else |
| 180 | closelog(); |
| 181 | logfile_name = NULL; |
| 182 | } else if (*logfile_name) |
| 183 | return; /* unchanged, non-empty "log file" names */ |
| 184 | else if (lp_syslog_facility(-1) != lp_syslog_facility(module_id) |
| 185 | || strcmp(lp_syslog_tag(-1), lp_syslog_tag(module_id)) != 0) |
| 186 | closelog(); |
| 187 | else |
| 188 | return; /* unchanged syslog settings */ |
| 189 | } else |
| 190 | log_initialised = 1; |
| 191 | |
| 192 | /* This looks pointless, but it is needed in order for the |
| 193 | * C library on some systems to fetch the timezone info |
| 194 | * before the chroot. */ |
| 195 | timestring(time(NULL)); |
| 196 | |
| 197 | /* Optionally use a log file instead of syslog. (Non-daemon |
| 198 | * rsyncs will have already set logfile_name, as needed.) */ |
| 199 | if (am_daemon && !logfile_name) |
| 200 | logfile_name = lp_log_file(module_id); |
| 201 | if (logfile_name && *logfile_name) |
| 202 | logfile_open(); |
| 203 | else |
| 204 | syslog_init(); |
| 205 | } |
| 206 | |
| 207 | /* Note that this close & reopen idiom intentionally ignores syslog logging. */ |
| 208 | void logfile_close(void) |
no test coverage detected