Revision: 2864
          http://ipcop.svn.sourceforge.net/ipcop/?rev=2864&view=rev
Author:   owes
Date:     2009-05-16 11:37:58 +0000 (Sat, 16 May 2009)

Log Message:
-----------
Return to ntpdate.

ntpdate may be obsolete, depecrated, ...
But ntpd simply does not provide a good solution when it comes to IPCop booting 
in a reasonable time (especially without internet connection) and having a 
useable time.

Modified Paths:
--------------
    ipcop/trunk/config/rootfiles/common/ntp
    ipcop/trunk/src/misc-progs/restartntpd.c

Modified: ipcop/trunk/config/rootfiles/common/ntp
===================================================================
--- ipcop/trunk/config/rootfiles/common/ntp     2009-05-16 11:32:58 UTC (rev 
2863)
+++ ipcop/trunk/config/rootfiles/common/ntp     2009-05-16 11:37:58 UTC (rev 
2864)
@@ -5,7 +5,7 @@
 #usr/bin/ntp-keygen
 #usr/bin/ntp-wait
 usr/bin/ntpd
-#usr/bin/ntpdate
+usr/bin/ntpdate
 #usr/bin/ntpdc
 usr/bin/ntpq
 #usr/bin/ntptime

Modified: ipcop/trunk/src/misc-progs/restartntpd.c
===================================================================
--- ipcop/trunk/src/misc-progs/restartntpd.c    2009-05-16 11:32:58 UTC (rev 
2863)
+++ ipcop/trunk/src/misc-progs/restartntpd.c    2009-05-16 11:37:58 UTC (rev 
2864)
@@ -39,6 +39,9 @@
 #include "setuid.h"
 
 
+#define MAX_SERVER 3
+
+
 void usage(char *prg, int exit_code)
 {
     printf("Usage: %s [OPTION]\n\n", prg);
@@ -57,6 +60,8 @@
     int flag_boot = 0;
     int flag_quick = 0;
     int enabled = 0;
+    int rc = 0;
+    char ntp_server[MAX_SERVER+1][STRING_SIZE];
 
     static struct option long_options[] =
     {
@@ -104,7 +109,6 @@
     else {
         verbose_printf(2, "NTPd not enabled\n");
     }
-    free_kv(&kv);
 
     /* Stop ntpd if running */
     if (access("/var/run/ntpd.pid", 0) != -1) {
@@ -128,22 +132,46 @@
 
     /* Synchronise clock now! */
     if (enabled && (flag_boot || flag_quick)) {
-        /* ntpd -q produces some output which we may want to know about */
+        int i;
+        char command[STRING_SIZE_LARGE];
+
         if (flag_verbose) {
-            verbose_printf(1, "Starting NTPd quick sync ... \n");
-            safe_system("/usr/bin/ntpd -q");
+            strcpy(command, "/usr/bin/ntpdate -u");
         }
         else {
-            if (safe_system("/usr/bin/ntpd -q >/dev/null 2>/dev/null")) {
-                verbose_printf(1, "ntpd -q failed\n");
-            }
+            strcpy(command, "/usr/bin/ntpdate -su");
         }
+
+        /* Initialize and retrieve NTP servers */
+        for (i = 1; i <= MAX_SERVER; i++) {
+            char key[STRING_SIZE];
+
+            strcpy(ntp_server[i], "");
+            snprintf(key, STRING_SIZE, "NTP_ADDR_%i", i);
+            find_kv_default(kv, key, ntp_server[i]);
+            strcat(command, " ");
+            strcat(command, ntp_server[i]);
+        }
+
+        if (!flag_verbose) {
+            /* Silence ntpdate, even with -s it can still produce messages in 
case RED down */
+            strcat(command, " >/dev/null 2>/dev/null");
+        }
+        verbose_printf(1, "Starting NTP quick sync ... \n");
+        rc = safe_system(command);
+        if (flag_boot && rc) {
+            /* Add some output to indicate ntpdate failed and we possibly have 
wrong time */
+            verbose_printf(0, "ntpdate failed");
+        }
     }
 
     /* Start ntpd if enabled */
     if (enabled) {
         verbose_printf(1, "Starting NTPd ... \n");
-        safe_system("/usr/bin/ntpd -p /var/run/ntpd.pid -u ntp:ntp");
+        rc = safe_system("/usr/bin/ntpd -p /var/run/ntpd.pid -u ntp:ntp");
     }
-    return 0;
+
+    free_kv(&kv);
+
+    return rc;
 }


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables 
unlimited royalty-free distribution of the report engine 
for externally facing server and web deployment. 
http://p.sf.net/sfu/businessobjects
_______________________________________________
Ipcop-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ipcop-svn

Reply via email to