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