summaryrefslogtreecommitdiff
path: root/package/ppp/patches/patch-pppd_main_c
blob: 48232482b708ba8a050f6bc4a0fb8f395201f926 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
--- ppp-2.4.6.orig/pppd/main.c	2014-01-02 05:42:08.000000000 +0100
+++ ppp-2.4.6/pppd/main.c	2014-06-05 20:42:29.000000000 +0200
@@ -90,6 +90,7 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
+#include <sys/sysinfo.h>
 
 #include "pppd.h"
 #include "magic.h"
@@ -159,10 +160,10 @@ TDB_CONTEXT *pppdb;		/* database for sto
 
 char db_key[32];
 
-int (*holdoff_hook) __P((void)) = NULL;
-int (*new_phase_hook) __P((int)) = NULL;
-void (*snoop_recv_hook) __P((unsigned char *p, int len)) = NULL;
-void (*snoop_send_hook) __P((unsigned char *p, int len)) = NULL;
+int (*holdoff_hook) (void) = NULL;
+int (*new_phase_hook) (int) = NULL;
+void (*snoop_recv_hook) (unsigned char *p, int len) = NULL;
+void (*snoop_send_hook) (unsigned char *p, int len) = NULL;
 
 static int conn_running;	/* we have a [dis]connector running */
 static int fd_loop;		/* fd for getting demand-dial packets */
@@ -218,7 +219,7 @@ bool bundle_terminating;
 struct subprocess {
     pid_t	pid;
     char	*prog;
-    void	(*done) __P((void *));
+    void	(*done) (void *);
     void	*arg;
     int		killable;
     struct subprocess *next;
@@ -228,38 +229,39 @@ static struct subprocess *children;
 
 /* Prototypes for procedures local to this file. */
 
-static void setup_signals __P((void));
-static void create_pidfile __P((int pid));
-static void create_linkpidfile __P((int pid));
-static void cleanup __P((void));
-static void get_input __P((void));
-static void calltimeout __P((void));
-static struct timeval *timeleft __P((struct timeval *));
-static void kill_my_pg __P((int));
-static void hup __P((int));
-static void term __P((int));
-static void chld __P((int));
-static void toggle_debug __P((int));
-static void open_ccp __P((int));
-static void bad_signal __P((int));
-static void holdoff_end __P((void *));
-static void forget_child __P((int pid, int status));
-static int reap_kids __P((void));
-static void childwait_end __P((void *));
+static void check_time(void);
+static void setup_signals (void);
+static void create_pidfile (int pid);
+static void create_linkpidfile (int pid);
+static void cleanup (void);
+static void get_input (void);
+static void calltimeout (void);
+static struct timeval *timeleft (struct timeval *);
+static void kill_my_pg (int);
+static void hup (int);
+static void term (int);
+static void chld (int);
+static void toggle_debug (int);
+static void open_ccp (int);
+static void bad_signal (int);
+static void holdoff_end (void *);
+static void forget_child (int pid, int status);
+static int reap_kids (void);
+static void childwait_end (void *);
 
 #ifdef USE_TDB
-static void update_db_entry __P((void));
-static void add_db_key __P((const char *));
-static void delete_db_key __P((const char *));
-static void cleanup_db __P((void));
+static void update_db_entry (void);
+static void add_db_key (const char *);
+static void delete_db_key (const char *);
+static void cleanup_db (void);
 #endif
 
-static void handle_events __P((void));
-void print_link_stats __P((void));
+static void handle_events (void);
+void print_link_stats (void);
 
-extern	char	*ttyname __P((int));
-extern	char	*getlogin __P((void));
-int main __P((int, char *[]));
+extern	char	*ttyname (int);
+extern	char	*getlogin (void);
+int main (int, char *[]);
 
 #ifdef ultrix
 #undef	O_NONBLOCK
@@ -530,6 +532,7 @@ main(argc, argv)
 	    info("Starting link");
 	}
 
+	check_time();
 	gettimeofday(&start_time, NULL);
 	script_unsetenv("CONNECT_TIME");
 	script_unsetenv("BYTES_SENT");
@@ -1257,19 +1260,49 @@ update_link_stats(u)
 struct	callout {
     struct timeval	c_time;		/* time at which to call routine */
     void		*c_arg;		/* argument to routine */
-    void		(*c_func) __P((void *)); /* routine */
+    void		(*c_func) (void *); /* routine */
     struct		callout *c_next;
 };
 
 static struct callout *callout = NULL;	/* Callout list */
 static struct timeval timenow;		/* Current time */
+static long uptime_diff = 0;
+static int uptime_diff_set = 0;
+
+static void check_time(void)
+{
+	long new_diff;
+	struct timeval t;
+	struct sysinfo i;
+    struct callout *p;
+	
+	gettimeofday(&t, NULL);
+	sysinfo(&i);
+	new_diff = t.tv_sec - i.uptime;
+	
+	if (!uptime_diff_set) {
+		uptime_diff = new_diff;
+		uptime_diff_set = 1;
+		return;
+	}
+
+	if ((new_diff - 5 > uptime_diff) || (new_diff + 5 < uptime_diff)) {
+		/* system time has changed, update counters and timeouts */
+		info("System time change detected.");
+		start_time.tv_sec += new_diff - uptime_diff;
+		
+    	for (p = callout; p != NULL; p = p->c_next)
+			p->c_time.tv_sec += new_diff - uptime_diff;
+	}
+	uptime_diff = new_diff;
+}
 
 /*
  * timeout - Schedule a timeout.
  */
 void
 timeout(func, arg, secs, usecs)
-    void (*func) __P((void *));
+    void (*func) (void *);
     void *arg;
     int secs, usecs;
 {
@@ -1308,7 +1341,7 @@ timeout(func, arg, secs, usecs)
  */
 void
 untimeout(func, arg)
-    void (*func) __P((void *));
+    void (*func) (void *);
     void *arg;
 {
     struct callout **copp, *freep;
@@ -1333,6 +1366,8 @@ calltimeout()
 {
     struct callout *p;
 
+	check_time();
+	
     while (callout != NULL) {
 	p = callout;
 
@@ -1360,6 +1395,8 @@ timeleft(tvp)
 {
     if (callout == NULL)
 	return NULL;
+	
+	check_time();
 
     gettimeofday(&timenow, NULL);
     tvp->tv_sec = callout->c_time.tv_sec - timenow.tv_sec;
@@ -1777,7 +1814,7 @@ run_program(prog, args, must_exist, done
     char *prog;
     char **args;
     int must_exist;
-    void (*done) __P((void *));
+    void (*done) (void *);
     void *arg;
     int wait;
 {
@@ -1853,7 +1890,7 @@ void
 record_child(pid, prog, done, arg, killable)
     int pid;
     char *prog;
-    void (*done) __P((void *));
+    void (*done) (void *);
     void *arg;
     int killable;
 {