[package] nvram: handle nvram at varying offsets within the eraseblock (fixes Edimax...
[openwrt.git] / package / ppp / patches / 206-compensate_time_change.patch
1 --- a/pppd/main.c
2 +++ b/pppd/main.c
3 @@ -90,6 +90,7 @@
4 #include <sys/socket.h>
5 #include <netinet/in.h>
6 #include <arpa/inet.h>
7 +#include <sys/sysinfo.h>
8
9 #include "pppd.h"
10 #include "magic.h"
11 @@ -227,6 +228,7 @@ static struct subprocess *children;
12
13 /* Prototypes for procedures local to this file. */
14
15 +static void check_time(void);
16 static void setup_signals __P((void));
17 static void create_pidfile __P((int pid));
18 static void create_linkpidfile __P((int pid));
19 @@ -532,6 +534,7 @@ main(argc, argv)
20 info("Starting link");
21 }
22
23 + check_time();
24 gettimeofday(&start_time, NULL);
25 script_unsetenv("CONNECT_TIME");
26 script_unsetenv("BYTES_SENT");
27 @@ -1264,6 +1267,36 @@ struct callout {
28
29 static struct callout *callout = NULL; /* Callout list */
30 static struct timeval timenow; /* Current time */
31 +static long uptime_diff = 0;
32 +static int uptime_diff_set = 0;
33 +
34 +static void check_time(void)
35 +{
36 + long new_diff;
37 + struct timeval t;
38 + struct sysinfo i;
39 + struct callout *p;
40 +
41 + gettimeofday(&t, NULL);
42 + sysinfo(&i);
43 + new_diff = t.tv_sec - i.uptime;
44 +
45 + if (!uptime_diff_set) {
46 + uptime_diff = new_diff;
47 + uptime_diff_set = 1;
48 + return;
49 + }
50 +
51 + if ((new_diff - 5 > uptime_diff) || (new_diff + 5 < uptime_diff)) {
52 + /* system time has changed, update counters and timeouts */
53 + info("System time change detected.");
54 + start_time.tv_sec += new_diff - uptime_diff;
55 +
56 + for (p = callout; p != NULL; p = p->c_next)
57 + p->c_time.tv_sec += new_diff - uptime_diff;
58 + }
59 + uptime_diff = new_diff;
60 +}
61
62 /*
63 * timeout - Schedule a timeout.
64 @@ -1334,6 +1367,8 @@ calltimeout()
65 {
66 struct callout *p;
67
68 + check_time();
69 +
70 while (callout != NULL) {
71 p = callout;
72
73 @@ -1361,6 +1396,8 @@ timeleft(tvp)
74 {
75 if (callout == NULL)
76 return NULL;
77 +
78 + check_time();
79
80 gettimeofday(&timenow, NULL);
81 tvp->tv_sec = callout->c_time.tv_sec - timenow.tv_sec;
This page took 0.052857 seconds and 5 git commands to generate.