More wicontrol(8) removal.
[dragonfly.git] / usr.sbin / ntpd / patches / ntpd.c.patch
1 $DragonFly: src/usr.sbin/ntpd/patches/Attic/ntpd.c.patch,v 1.7 2005/04/22 08:35:04 joerg Exp $
2
3 --- ntpd.c.orig 2004-11-09 20:39:54.000000000 +0100
4 +++ ntpd.c      2004-11-09 20:40:48.000000000 +0100
5 @@ -18,6 +18,7 @@
6  
7  #include <sys/types.h>
8  #include <sys/socket.h>
9 +#include <sys/sysctl.h>
10  #include <sys/wait.h>
11  #include <netinet/in.h>
12  #include <errno.h>
13 @@ -33,11 +34,12 @@
14  #include "ntpd.h"
15  
16  void           sighdlr(int);
17 -__dead void    usage(void);
18 +void           usage(void) __dead2;
19  int            main(int, char *[]);
20  int            check_child(pid_t, const char *);
21  int            dispatch_imsg(struct ntpd_conf *);
22  void           ntpd_adjtime(double);
23 +void           ntpd_adjfreq(double);
24  void           ntpd_settime(double);
25  
26  volatile sig_atomic_t   quit = 0;
27 @@ -62,12 +64,10 @@
28         }
29  }
30  
31 -__dead void
32 +void
33  usage(void)
34  {
35 -       extern char *__progname;
36 -
37 -       fprintf(stderr, "usage: %s [-dSs] [-f file]\n", __progname);
38 +       fprintf(stderr, "usage: %s [-dSs] [-f file]\n", getprogname());
39         exit(1);
40  }
41  
42 @@ -266,6 +266,12 @@
43                         memcpy(&d, imsg.data, sizeof(d));
44                         ntpd_adjtime(d);
45                         break;
46 +               case IMSG_ADJFREQ:
47 +                       if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(d))
48 +                               fatalx("invalid IMSG_ADJFREQ received");
49 +                       memcpy(&d, imsg.data, sizeof(d));
50 +                       ntpd_adjfreq(d);
51 +                       break;
52                 case IMSG_SETTIME:
53                         if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(d))
54                                 fatalx("invalid IMSG_SETTIME received");
55 @@ -311,16 +317,37 @@
56  void
57  ntpd_adjtime(double d)
58  {
59 -       struct timeval  tv;
60 +       int64_t adjust;
61  
62         if (d >= (double)LOG_NEGLIGEE / 1000 ||
63             d <= -1 * (double)LOG_NEGLIGEE / 1000)
64                 log_info("adjusting local clock by %fs", d);
65         else
66                 log_debug("adjusting local clock by %fs", d);
67 -       d_to_tv(d, &tv);
68 -       if (adjtime(&tv, NULL) == -1)
69 -               log_warn("adjtime failed");
70 +       adjust = d * 1e9;
71 +
72 +       if (sysctlbyname("kern.ntp.adjust", NULL, NULL, &adjust,
73 +                        sizeof(adjust)))
74 +               log_info("adjtime failed");
75 +}
76 +
77 +void
78 +ntpd_adjfreq(double relfreq)
79 +{
80 +       int64_t curfreq;
81 +       size_t len = sizeof(curfreq);
82
83 +       if (sysctlbyname("kern.ntp.permanent", &curfreq, &len, NULL, 0) ||
84 +           len != sizeof(curfreq)) {
85 +               log_warn("adjfreq failed");
86 +               return;
87 +       }
88 +
89 +       curfreq += relfreq * 1e9 * (1ll << 32);
90 +
91 +       if (sysctlbyname("kern.ntp.permanent", NULL, NULL, &curfreq,
92 +                        sizeof(curfreq)))
93 +               log_warn("adjfreq failed");
94  }
95  
96  void