Browse Source

Although Unix compilers accept more than one definition of a global

symbol, follow the guidelines from K&R: only one definition of a
global symbol (and possibly more declarations).  Rename some vars
here and there to avoid shadowing. ok henning@
OPENBSD_4_1
otto 18 years ago
parent
commit
1f8bd32eb8
5 changed files with 42 additions and 44 deletions
  1. +2
    -2
      src/usr.sbin/ntpd/ntp.c
  2. +21
    -21
      src/usr.sbin/ntpd/ntpd.c
  3. +3
    -2
      src/usr.sbin/ntpd/ntpd.h
  4. +2
    -5
      src/usr.sbin/ntpd/sensors.c
  5. +14
    -14
      src/usr.sbin/ntpd/server.c

+ 2
- 2
src/usr.sbin/ntpd/ntp.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: ntp.c,v 1.97 2007/01/14 19:20:09 otto Exp $ */
/* $OpenBSD: ntp.c,v 1.98 2007/01/15 08:19:11 otto Exp $ */
/* /*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -165,7 +165,7 @@ ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf)
conf->status.precision = a; conf->status.precision = a;
conf->scale = 1; conf->scale = 1;
sensor_init(conf);
sensor_init();
log_info("ntp engine ready"); log_info("ntp engine ready");


+ 21
- 21
src/usr.sbin/ntpd/ntpd.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: ntpd.c,v 1.48 2006/06/30 16:52:13 deraadt Exp $ */
/* $OpenBSD: ntpd.c,v 1.49 2007/01/15 08:19:11 otto Exp $ */
/* /*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -81,7 +81,7 @@ usage(void)
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
struct ntpd_conf conf;
struct ntpd_conf lconf;
struct pollfd pfd[POLL_MAX]; struct pollfd pfd[POLL_MAX];
pid_t chld_pid = 0, pid; pid_t chld_pid = 0, pid;
const char *conffile; const char *conffile;
@ -90,7 +90,7 @@ main(int argc, char *argv[])
conffile = CONFFILE; conffile = CONFFILE;
bzero(&conf, sizeof(conf));
bzero(&lconf, sizeof(lconf));
log_init(1); /* log to stderr until daemonized */ log_init(1); /* log to stderr until daemonized */
res_init(); /* XXX */ res_init(); /* XXX */
@ -98,16 +98,16 @@ main(int argc, char *argv[])
while ((ch = getopt(argc, argv, "df:sS")) != -1) { while ((ch = getopt(argc, argv, "df:sS")) != -1) {
switch (ch) { switch (ch) {
case 'd': case 'd':
conf.debug = 1;
lconf.debug = 1;
break; break;
case 'f': case 'f':
conffile = optarg; conffile = optarg;
break; break;
case 's': case 's':
conf.settime = 1;
lconf.settime = 1;
break; break;
case 'S': case 'S':
conf.settime = 0;
lconf.settime = 0;
break; break;
default: default:
usage(); usage();
@ -115,7 +115,7 @@ main(int argc, char *argv[])
} }
} }
if (parse_config(conffile, &conf))
if (parse_config(conffile, &lconf))
exit(1); exit(1);
if (geteuid()) { if (geteuid()) {
@ -130,9 +130,9 @@ main(int argc, char *argv[])
endpwent(); endpwent();
reset_adjtime(); reset_adjtime();
if (!conf.settime) {
log_init(conf.debug);
if (!conf.debug)
if (!lconf.settime) {
log_init(lconf.debug);
if (!lconf.debug)
if (daemon(1, 0)) if (daemon(1, 0))
fatal("daemon"); fatal("daemon");
} else } else
@ -143,7 +143,7 @@ main(int argc, char *argv[])
signal(SIGCHLD, sighdlr); signal(SIGCHLD, sighdlr);
/* fork child process */ /* fork child process */
chld_pid = ntp_main(pipe_chld, &conf);
chld_pid = ntp_main(pipe_chld, &lconf);
setproctitle("[priv]"); setproctitle("[priv]");
readfreq(); readfreq();
@ -170,13 +170,13 @@ main(int argc, char *argv[])
quit = 1; quit = 1;
} }
if (nfds == 0 && conf.settime) {
conf.settime = 0;
if (nfds == 0 && lconf.settime) {
lconf.settime = 0;
timeout = INFTIM; timeout = INFTIM;
log_init(conf.debug);
log_init(lconf.debug);
log_debug("no reply received in time, skipping initial " log_debug("no reply received in time, skipping initial "
"time setting"); "time setting");
if (!conf.debug)
if (!lconf.debug)
if (daemon(1, 0)) if (daemon(1, 0))
fatal("daemon"); fatal("daemon");
} }
@ -189,7 +189,7 @@ main(int argc, char *argv[])
if (nfds > 0 && pfd[PFD_PIPE].revents & POLLIN) { if (nfds > 0 && pfd[PFD_PIPE].revents & POLLIN) {
nfds--; nfds--;
if (dispatch_imsg(&conf) == -1)
if (dispatch_imsg(&lconf) == -1)
quit = 1; quit = 1;
} }
@ -244,7 +244,7 @@ check_child(pid_t pid, const char *pname)
} }
int int
dispatch_imsg(struct ntpd_conf *conf)
dispatch_imsg(struct ntpd_conf *lconf)
{ {
struct imsg imsg; struct imsg imsg;
int n, cnt; int n, cnt;
@ -285,16 +285,16 @@ dispatch_imsg(struct ntpd_conf *conf)
case IMSG_SETTIME: case IMSG_SETTIME:
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(d)) if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(d))
fatalx("invalid IMSG_SETTIME received"); fatalx("invalid IMSG_SETTIME received");
if (!conf->settime)
if (!lconf->settime)
break; break;
log_init(conf->debug);
log_init(lconf->debug);
memcpy(&d, imsg.data, sizeof(d)); memcpy(&d, imsg.data, sizeof(d));
ntpd_settime(d); ntpd_settime(d);
/* daemonize now */ /* daemonize now */
if (!conf->debug)
if (!lconf->debug)
if (daemon(1, 0)) if (daemon(1, 0))
fatal("daemon"); fatal("daemon");
conf->settime = 0;
lconf->settime = 0;
break; break;
case IMSG_HOST_DNS: case IMSG_HOST_DNS:
name = imsg.data; name = imsg.data;


+ 3
- 2
src/usr.sbin/ntpd/ntpd.h View File

@ -1,4 +1,4 @@
/* $OpenBSD: ntpd.h,v 1.80 2006/12/23 17:49:53 deraadt Exp $ */
/* $OpenBSD: ntpd.h,v 1.81 2007/01/15 08:19:11 otto Exp $ */
/* /*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -263,6 +263,7 @@ int priv_adjtime(void);
void priv_settime(double); void priv_settime(double);
void priv_host_dns(char *, u_int32_t); void priv_host_dns(char *, u_int32_t);
int offset_compare(const void *, const void *); int offset_compare(const void *, const void *);
extern struct ntpd_conf *conf;
/* parse.y */ /* parse.y */
int parse_config(const char *, struct ntpd_conf *); int parse_config(const char *, struct ntpd_conf *);
@ -306,7 +307,7 @@ double sfp_to_d(struct s_fixedpt);
struct s_fixedpt d_to_sfp(double); struct s_fixedpt d_to_sfp(double);
/* sensors.c */ /* sensors.c */
void sensor_init(struct ntpd_conf *);
void sensor_init(void);
void sensor_scan(void); void sensor_scan(void);
void sensor_query(struct ntp_sensor *); void sensor_query(struct ntp_sensor *);
int sensor_hotplugfd(void); int sensor_hotplugfd(void);


+ 2
- 5
src/usr.sbin/ntpd/sensors.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: sensors.c,v 1.29 2007/01/14 19:18:12 otto Exp $ */
/* $OpenBSD: sensors.c,v 1.30 2007/01/15 08:19:11 otto Exp $ */
/* /*
* Copyright (c) 2006 Henning Brauer <henning@openbsd.org> * Copyright (c) 2006 Henning Brauer <henning@openbsd.org>
@ -39,12 +39,9 @@ void sensor_add(int, char *);
void sensor_remove(struct ntp_sensor *); void sensor_remove(struct ntp_sensor *);
void sensor_update(struct ntp_sensor *); void sensor_update(struct ntp_sensor *);
struct ntpd_conf *conf;
void void
sensor_init(struct ntpd_conf *c)
sensor_init(void)
{ {
conf = c;
TAILQ_INIT(&conf->ntp_sensors); TAILQ_INIT(&conf->ntp_sensors);
} }


+ 14
- 14
src/usr.sbin/ntpd/server.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: server.c,v 1.30 2006/07/01 18:52:46 otto Exp $ */
/* $OpenBSD: server.c,v 1.31 2007/01/15 08:19:11 otto Exp $ */
/* /*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -28,7 +28,7 @@
#include "ntpd.h" #include "ntpd.h"
int int
setup_listeners(struct servent *se, struct ntpd_conf *conf, u_int *cnt)
setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
{ {
struct listen_addr *la; struct listen_addr *la;
struct ifaddrs *ifa, *ifap; struct ifaddrs *ifa, *ifap;
@ -38,7 +38,7 @@ setup_listeners(struct servent *se, struct ntpd_conf *conf, u_int *cnt)
u_int new_cnt = 0; u_int new_cnt = 0;
int tos = IPTOS_LOWDELAY; int tos = IPTOS_LOWDELAY;
if (conf->listen_all) {
if (lconf->listen_all) {
if (getifaddrs(&ifa) == -1) if (getifaddrs(&ifa) == -1)
fatal("getifaddrs"); fatal("getifaddrs");
@ -69,13 +69,13 @@ setup_listeners(struct servent *se, struct ntpd_conf *conf, u_int *cnt)
fatal("setup_listeners calloc"); fatal("setup_listeners calloc");
memcpy(&la->sa, sa, SA_LEN(sa)); memcpy(&la->sa, sa, SA_LEN(sa));
TAILQ_INSERT_TAIL(&conf->listen_addrs, la, entry);
TAILQ_INSERT_TAIL(&lconf->listen_addrs, la, entry);
} }
freeifaddrs(ifa); freeifaddrs(ifa);
} }
TAILQ_FOREACH(la, &conf->listen_addrs, entry) {
TAILQ_FOREACH(la, &lconf->listen_addrs, entry) {
new_cnt++; new_cnt++;
switch (la->sa.ss_family) { switch (la->sa.ss_family) {
@ -114,7 +114,7 @@ setup_listeners(struct servent *se, struct ntpd_conf *conf, u_int *cnt)
} }
int int
server_dispatch(int fd, struct ntpd_conf *conf)
server_dispatch(int fd, struct ntpd_conf *lconf)
{ {
ssize_t size; ssize_t size;
u_int8_t version; u_int8_t version;
@ -144,8 +144,8 @@ server_dispatch(int fd, struct ntpd_conf *conf)
version = (query.status & VERSIONMASK) >> 3; version = (query.status & VERSIONMASK) >> 3;
bzero(&reply, sizeof(reply)); bzero(&reply, sizeof(reply));
if (conf->status.synced)
reply.status = conf->status.leap;
if (lconf->status.synced)
reply.status = lconf->status.leap;
else else
reply.status = LI_ALARM; reply.status = LI_ALARM;
reply.status |= (query.status & VERSIONMASK); reply.status |= (query.status & VERSIONMASK);
@ -154,19 +154,19 @@ server_dispatch(int fd, struct ntpd_conf *conf)
else else
reply.status |= MODE_SYM_PAS; reply.status |= MODE_SYM_PAS;
reply.stratum = conf->status.stratum;
reply.stratum = lconf->status.stratum;
reply.ppoll = query.ppoll; reply.ppoll = query.ppoll;
reply.precision = conf->status.precision;
reply.precision = lconf->status.precision;
reply.rectime = d_to_lfp(rectime); reply.rectime = d_to_lfp(rectime);
reply.reftime = d_to_lfp(conf->status.reftime);
reply.reftime = d_to_lfp(lconf->status.reftime);
reply.xmttime = d_to_lfp(gettime_corrected()); reply.xmttime = d_to_lfp(gettime_corrected());
reply.orgtime = query.xmttime; reply.orgtime = query.xmttime;
reply.rootdelay = d_to_sfp(conf->status.rootdelay);
reply.rootdelay = d_to_sfp(lconf->status.rootdelay);
if (version > 3) if (version > 3)
reply.refid = conf->status.refid4;
reply.refid = lconf->status.refid4;
else else
reply.refid = conf->status.refid;
reply.refid = lconf->status.refid;
ntp_sendmsg(fd, (struct sockaddr *)&fsa, &reply, size, 0); ntp_sendmsg(fd, (struct sockaddr *)&fsa, &reply, size, 0);
return (0); return (0);


Loading…
Cancel
Save