From: <ow...@us...> - 2008-08-31 17:27:38
|
Revision: 1762 http://ipcop.svn.sourceforge.net/ipcop/?rev=1762&view=rev Author: owes Date: 2008-08-31 17:27:47 +0000 (Sun, 31 Aug 2008) Log Message: ----------- apply CodingStyle Modified Paths: -------------- ipcop/trunk/src/misc-progs/restartntpd.c Modified: ipcop/trunk/src/misc-progs/restartntpd.c =================================================================== --- ipcop/trunk/src/misc-progs/restartntpd.c 2008-08-31 16:03:11 UTC (rev 1761) +++ ipcop/trunk/src/misc-progs/restartntpd.c 2008-08-31 17:27:47 UTC (rev 1762) @@ -26,7 +26,7 @@ * $Id$ * */ - + #include <errno.h> #include <stdio.h> #include <signal.h> @@ -45,109 +45,92 @@ int main(int argc, char *argv[]) { - int fd, pid; - char buffer[STRING_SIZE]; - NODEKV *kv = NULL; - int enable = 0; - int boot = 0; - int syncnow = 0; - char server_1[STRING_SIZE]; - char server_2[STRING_SIZE]; + int fd, pid; + char buffer[STRING_SIZE]; + NODEKV *kv = NULL; + int enable = 0; + int boot = 0; + int syncnow = 0; + char server_1[STRING_SIZE]; + char server_2[STRING_SIZE]; - if ( !(initsetuid()) ) - exit(1); + if (!(initsetuid())) + exit(1); - /* verify parameters */ - if ( argc == 1 ) - { - /* no parameters, kill ntpd if running and restart if enabled */ - } - else if ( (argc == 2) && (strcmp(argv[1], PARA_BOOT) == 0) ) - { - boot = 1; - } - else if ( (argc == 2) && (strcmp(argv[1], PARA_SYNCNOW) == 0) ) - { - syncnow = 1; - } - else - { - fprintf (stderr, "Bad parameter!\n"); - return 1; - } + /* verify parameters */ + if (argc == 1) { + /* no parameters, kill ntpd if running and restart if enabled */ + } + else if ((argc == 2) && (strcmp(argv[1], PARA_BOOT) == 0)) { + boot = 1; + } + else if ((argc == 2) && (strcmp(argv[1], PARA_SYNCNOW) == 0)) { + syncnow = 1; + } + else { + fprintf(stderr, "Bad parameter!\n"); + return 1; + } - /* Get configuration settings */ - if (read_kv_from_file(&kv, "/var/ipcop/time/settings") != SUCCESS) - { - fprintf(stderr, "Cannot read time settings\n"); - return 1; - } - if (test_kv(kv, "ENABLED_NTP", "on") == SUCCESS) - { - enable = 1; - } - find_kv_default(kv, "NTP_ADDR_1", server_1); - find_kv_default(kv, "NTP_ADDR_2", server_2); - free_kv(&kv); + /* Get configuration settings */ + if (read_kv_from_file(&kv, "/var/ipcop/time/settings") != SUCCESS) { + fprintf(stderr, "Cannot read time settings\n"); + return 1; + } + if (test_kv(kv, "ENABLED_NTP", "on") == SUCCESS) { + enable = 1; + } + find_kv_default(kv, "NTP_ADDR_1", server_1); + find_kv_default(kv, "NTP_ADDR_2", server_2); + free_kv(&kv); - /* Kill ntpd if running */ - if ( (fd = open("/var/run/ntpd.pid", O_RDONLY)) != -1 ) - { - if ( read(fd, buffer, STRING_SIZE_LARGE - 1) == -1 ) - fprintf(stderr, "Couldn't read from pid file\n"); - else - { - pid = atoi(buffer); - if ( pid <= 1 ) - fprintf(stderr, "Bad pid value\n"); - else - { - if ( kill(pid, SIGTERM) == -1 ) - fprintf(stderr, "Unable to send SIGTERM\n"); - else - { - unlink("/var/run/ntpd.pid"); - if ( enable ) - { - // small delay between kill and start - sleep(1); - } - } - } - } - close(fd); - } - else - { - if ( errno != ENOENT ) - { - perror("Unable to open pid file"); - exit(1); - } - } + /* Kill ntpd if running */ + if ((fd = open("/var/run/ntpd.pid", O_RDONLY)) != -1) { + if (read(fd, buffer, STRING_SIZE_LARGE - 1) == -1) + fprintf(stderr, "Couldn't read from pid file\n"); + else { + pid = atoi(buffer); + if (pid <= 1) + fprintf(stderr, "Bad pid value\n"); + else { + if (kill(pid, SIGTERM) == -1) + fprintf(stderr, "Unable to send SIGTERM\n"); + else { + unlink("/var/run/ntpd.pid"); + if (enable) { + // small delay between kill and start + sleep(1); + } + } + } + } + close(fd); + } + else { + if (errno != ENOENT) { + perror("Unable to open pid file"); + exit(1); + } + } - /* Forced sync */ - /* do not test for red active, NTP server could be anywhere, let ppp dialup block connection */ + /* Forced sync */ + /* do not test for red active, NTP server could be anywhere, let ppp dialup block connection */ #if USE_FORCE_SYNC - if ( syncnow || (boot && enable) ) - { - snprintf(buffer, STRING_SIZE, "/usr/bin/ntpdate -U ntp -su %s %s", server_1, server_2); - if ( !safe_system(buffer) ) - { - safe_system("/usr/bin/logger -t ipcop \"ntpdate synchronisation event\""); - safe_system("/sbin/hwclock --systohc"); - } - else - { - safe_system("/usr/bin/logger -t ipcop \"ntpdate error\""); - } - } + if (syncnow || (boot && enable)) { + snprintf(buffer, STRING_SIZE, "/usr/bin/ntpdate -U ntp -su %s %s", server_1, server_2); + if (!safe_system(buffer)) { + safe_system("/usr/bin/logger -t ipcop \"ntpdate synchronisation event\""); + safe_system("/sbin/hwclock --systohc"); + } + else { + safe_system("/usr/bin/logger -t ipcop \"ntpdate error\""); + } + } #endif - /* Start ntpd if enabled */ - if ( enable ) - { - safe_system("/usr/bin/ntpd -p /var/run/ntpd.pid -u ntp:ntp"); - } - return 0; + /* Start ntpd if enabled */ + if (enable) { + safe_system("/usr/bin/ntpd -p /var/run/ntpd.pid -u ntp:ntp"); + } + return 0; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |