From: Dave Hart Date: Wed, 16 Mar 2011 02:09:56 +0000 (+0000) Subject: [Bug 1848] make check ntpd --saveconfigquit clutters syslog. X-Git-Tag: NTP_4_2_7P139~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0d3b2a5a64d43246589fe20655d57803259827ac;p=thirdparty%2Fntp.git [Bug 1848] make check ntpd --saveconfigquit clutters syslog. bk: 4d801bf4QT5QewwJFrm6uvqf_0MlgA --- diff --git a/ChangeLog b/ChangeLog index 60565fa19..5ed8a2ae0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ +* [Bug 1848] make check ntpd --saveconfigquit clutters syslog. (4.2.7p138) 2011/03/08 Released by Harlan Stenn * [Bug 1846] MacOSX: debug symbol not found by propdelay or tickadj. (4.2.7p137) 2011/03/07 Released by Harlan Stenn @@ -1191,7 +1192,7 @@ * [Bug 1343] ntpd/ntp_io.c close_fd() does not compile on Solaris 7. * [Bug 1353] ntpq "rv 0 settimeofday" always shows UNKNOWN on unix. * Do not attempt to execute built binaries from ntpd/Makefile when - cross-compiling (keyword-gen and ntpd --saveconfigquit). + cross-compiling (keyword-gen and ntpd --saveconfigqui). * sntp/main.c: Remove duplicate global adr_buf[] (also defined in networking.c) which Piotr Grudzinski identified breaking his build. * Correct in6addr_any test in configure.ac to attempt link too. diff --git a/include/ntp_stdlib.h b/include/ntp_stdlib.h index c6c6e9593..aaac4d57b 100644 --- a/include/ntp_stdlib.h +++ b/include/ntp_stdlib.h @@ -49,10 +49,9 @@ extern int msnprintf(char *, size_t, const char *, ...) __attribute__((__format__(__printf__, 3, 4))); extern void msyslog(int, const char *, ...) __attribute__((__format__(__printf__, 2, 3))); -extern void init_logging (const char *, u_long, const char *, - int); -extern int change_logfile (const char *, const char *); -extern void setup_logfile (const char *, const char *); +extern void init_logging (const char *, u_long, int); +extern int change_logfile (const char *, int); +extern void setup_logfile (const char *); #ifndef errno_to_str extern void errno_to_str(int, char *, size_t); #endif diff --git a/libntp/msyslog.c b/libntp/msyslog.c index c0114fb1d..01c5c4547 100644 --- a/libntp/msyslog.c +++ b/libntp/msyslog.c @@ -335,7 +335,6 @@ void init_logging( const char * name, u_long def_syslogmask, - const char * version_str, int is_daemon ) { @@ -394,9 +393,6 @@ init_logging( setlogmask(LOG_UPTO(LOG_DEBUG)); /* @@@ was INFO */ # endif /* LOG_DAEMON */ #endif /* !VMS */ - - if (NULL != version_str) - msyslog(LOG_NOTICE, "%s", version_str); } @@ -412,7 +408,7 @@ init_logging( int change_logfile( const char * fname, - const char * version_str + int leave_crumbs ) { FILE * new_file; @@ -481,7 +477,7 @@ change_logfile( } /* leave a pointer in the old log */ - if (syslogit || log_fname != syslog_abs_fname) + if (leave_crumbs && (syslogit || log_fname != syslog_abs_fname)) msyslog(LOG_NOTICE, "switching logging to file %s", abs_fname); @@ -500,8 +496,6 @@ change_logfile( syslog_abs_fname = abs_fname; } syslogit = FALSE; - if (NULL != version_str) - msyslog(LOG_NOTICE, "%s", version_str); return 0; } @@ -525,12 +519,11 @@ change_logfile( */ void setup_logfile( - const char * name, - const char * version_str + const char * name ) { if (NULL == syslog_fname && NULL != name) { - if (-1 == change_logfile(name, version_str)) + if (-1 == change_logfile(name, TRUE)) msyslog(LOG_ERR, "Cannot open log file %s, %m", name); return ; @@ -538,7 +531,7 @@ setup_logfile( if (NULL == syslog_fname) return; - if (-1 == change_logfile(syslog_fname, version_str)) + if (-1 == change_logfile(syslog_fname, FALSE)) msyslog(LOG_ERR, "Cannot reopen log file %s, %m", syslog_fname); } diff --git a/ntpd/ntp_config.c b/ntpd/ntp_config.c index 695a0db33..8419c21ff 100644 --- a/ntpd/ntp_config.c +++ b/ntpd/ntp_config.c @@ -3378,7 +3378,7 @@ config_vars( break; case T_Logfile: - if (-1 == change_logfile(curr_var->value.s, 0)) + if (-1 == change_logfile(curr_var->value.s, TRUE)) msyslog(LOG_ERR, "Cannot open logfile %s: %m", curr_var->value.s); diff --git a/ntpd/ntpd.c b/ntpd/ntpd.c index c26cc41f8..19a1074c3 100644 --- a/ntpd/ntpd.c +++ b/ntpd/ntpd.c @@ -455,13 +455,44 @@ ntpdmain( # ifdef HAVE_SETRLIMIT struct rlimit rl; # endif +# endif +# ifdef HAVE_UMASK + uv = umask(0); + if (uv) + umask(uv); + else + umask(022); # endif progname = argv[0]; initializing = TRUE; /* mark that we are initializing */ parse_cmdline_opts(&argc, &argv); - /* Open the log file */ - init_logging(progname, NLOG_SYNCMASK, Version, TRUE); +# ifdef DEBUG + debug = DESC(DEBUG_LEVEL).optOccCt; +# endif + + if (HAVE_OPT(NOFORK) || HAVE_OPT(QUIT) +# ifdef DEBUG + || debug +# endif + || HAVE_OPT(SAVECONFIGQUIT)) + nofork = TRUE; + + init_logging(progname, NLOG_SYNCMASK, TRUE); + /* honor -l/--logfile option to log to a file */ + if (HAVE_OPT(LOGFILE)) { + logfilename = OPT_ARG(LOGFILE); + syslogit = FALSE; + change_logfile(logfilename, FALSE); + } else { + logfilename = NULL; + if (nofork) { + msyslog_term = FALSE; + syslogit = FALSE; + change_logfile("stderr", FALSE); + } + } + msyslog(LOG_NOTICE, "%s\n", Version); /* * Install trap handlers to log errors and assertion failures. @@ -471,38 +502,17 @@ ntpdmain( isc_error_setfatal(library_fatal_error); isc_error_setunexpected(library_unexpected_error); -# ifdef HAVE_UMASK - uv = umask(0); - if (uv) - umask(uv); - else - umask(022); -# endif - /* MPE lacks the concept of root */ # if defined(HAVE_GETUID) && !defined(MPE) uid = getuid(); if (uid && !HAVE_OPT( SAVECONFIGQUIT )) { + msyslog_term = TRUE; msyslog(LOG_ERR, "must be run as root, not uid %ld", (long)uid); - printf("%s must be run as root, not uid %ld\n", - progname, (long)uid); exit(1); } # endif -# ifdef DEBUG - debug = DESC(DEBUG_LEVEL).optOccCt; - DPRINTF(1, ("%s\n", Version)); -# endif - - /* honor -l/--logfile option to log to a file */ - if (HAVE_OPT(LOGFILE)) - logfilename = OPT_ARG(LOGFILE); - else - logfilename = NULL; - setup_logfile(logfilename, Version); - /* * Enable the Multi-Media Timer for Windows? */ @@ -511,16 +521,6 @@ ntpdmain( set_mm_timer(MM_TIMER_HIRES); # endif - if (HAVE_OPT( NOFORK ) || HAVE_OPT( QUIT ) -# ifdef DEBUG - || debug -# endif - || HAVE_OPT( SAVECONFIGQUIT )) { - nofork = 1; - /* duplicate all syslog to stdout */ - msyslog_term = TRUE; - } - if (HAVE_OPT( NOVIRTUALIPS )) listen_to_virtual_ips = 0; @@ -623,9 +623,9 @@ ntpdmain( dup2(0, 1); dup2(0, 2); - init_logging(progname, 0, NULL, TRUE); + init_logging(progname, 0, TRUE); /* we lost our logfile (if any) daemonizing */ - setup_logfile(logfilename, NULL); + setup_logfile(logfilename); # ifdef SYS_DOMAINOS { @@ -693,7 +693,7 @@ ntpdmain( /* * The default RLIMIT_MEMLOCK is very low on Linux systems. * Unless we increase this limit malloc calls are likely to - * fail if we drop root privlege. To be useful the value + * fail if we drop root privilege. To be useful the value * has to be larger than the largest ntpd resident set size. */ rl.rlim_cur = rl.rlim_max = 32 * 1024 * 1024; @@ -704,7 +704,8 @@ ntpdmain( /* * lock the process into memory */ - if (mlockall(MCL_CURRENT|MCL_FUTURE) < 0) + if (!HAVE_OPT(SAVECONFIGQUIT) && + 0 != mlockall(MCL_CURRENT|MCL_FUTURE)) msyslog(LOG_ERR, "mlockall(): %m"); # else /* !HAVE_MLOCKALL || !MCL_CURRENT || !MCL_FUTURE follows */ # ifdef HAVE_PLOCK @@ -721,14 +722,14 @@ ntpdmain( /* * lock the process into memory */ - if (plock(PROCLOCK) < 0) + if (!HAVE_OPT(SAVECONFIGQUIT) && 0 != plock(PROCLOCK)) msyslog(LOG_ERR, "plock(PROCLOCK): %m"); # else /* !PROCLOCK follows */ # ifdef TXTLOCK /* * Lock text into ram */ - if (plock(TXTLOCK) < 0) + if (!HAVE_OPT(SAVECONFIGQUIT) && 0 != plock(TXTLOCK)) msyslog(LOG_ERR, "plock(TXTLOCK) error: %m"); # else /* !TXTLOCK follows */ msyslog(LOG_ERR, "plock() - don't know what to lock!"); diff --git a/sntp/log.c b/sntp/log.c index 8770b02bc..50741eb75 100644 --- a/sntp/log.c +++ b/sntp/log.c @@ -12,7 +12,7 @@ sntp_init_logging( ) { msyslog_term = TRUE; - init_logging(prog, 0, NULL, FALSE); + init_logging(prog, 0, FALSE); } @@ -21,7 +21,8 @@ open_logfile( const char *logfile ) { - change_logfile(logfile, Version); + change_logfile(logfile, FALSE); + msyslog(LOG_NOTICE, "%s\n", Version); atexit(cleanup_log); }