patch-pppd_main_c 5.6 KB

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