]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 1848] make check ntpd --saveconfigquit clutters syslog.
authorDave Hart <hart@ntp.org>
Wed, 16 Mar 2011 02:09:56 +0000 (02:09 +0000)
committerDave Hart <hart@ntp.org>
Wed, 16 Mar 2011 02:09:56 +0000 (02:09 +0000)
bk: 4d801bf4QT5QewwJFrm6uvqf_0MlgA

ChangeLog
include/ntp_stdlib.h
libntp/msyslog.c
ntpd/ntp_config.c
ntpd/ntpd.c
sntp/log.c

index 60565fa1917037302ba4681e8d35a7bae41d5b77..5ed8a2ae0ed80caec2ea626dd737c7dd0f9e51aa 100644 (file)
--- 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 <stenn@ntp.org>
 * [Bug 1846] MacOSX: debug symbol not found by propdelay or tickadj.
 (4.2.7p137) 2011/03/07 Released by Harlan Stenn <stenn@ntp.org>
 * [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.
index c6c6e95932d3a7d74f2f7863ed1ef59679e9aaf9..aaac4d57bcd908242da18c274ffcb49e6e3efbd6 100644 (file)
@@ -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
index c0114fb1d196ba4ed91a43e44773c908e400ded3..01c5c45477c7edd45e1c107e8112c3268f407978 100644 (file)
@@ -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);
 }
index 695a0db33ee2789119231dcf839f172b340afec4..8419c21ff15647f5ebc5ed7a08db48e1520b46a5 100644 (file)
@@ -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);
index c26cc41f863ba517abb61e3de0a0b9d03777736f..19a1074c30d8db6b74ed76498d073405f8a07f3b 100644 (file)
@@ -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!");
index 8770b02bc3cc82ed487f2da6fd4eb832edcccf15..50741eb75d0802685a887d5ba447830730e0b71e 100644 (file)
@@ -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);
 }