1
0

patch-pppd_main_c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 2011-01-16 15:51:05.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. @@ -228,6 +229,7 @@ static struct subprocess *children;
  11. /* Prototypes for procedures local to this file. */
  12. +static void check_time(void);
  13. static void setup_signals __P((void));
  14. static void create_pidfile __P((int pid));
  15. static void create_linkpidfile __P((int pid));
  16. @@ -530,6 +532,7 @@ main(argc, argv)
  17. info("Starting link");
  18. }
  19. + check_time();
  20. gettimeofday(&start_time, NULL);
  21. script_unsetenv("CONNECT_TIME");
  22. script_unsetenv("BYTES_SENT");
  23. @@ -1263,6 +1266,36 @@ struct callout {
  24. static struct callout *callout = NULL; /* Callout list */
  25. static struct timeval timenow; /* Current time */
  26. +static long uptime_diff = 0;
  27. +static int uptime_diff_set = 0;
  28. +
  29. +static void check_time(void)
  30. +{
  31. + long new_diff;
  32. + struct timeval t;
  33. + struct sysinfo i;
  34. + struct callout *p;
  35. +
  36. + gettimeofday(&t, NULL);
  37. + sysinfo(&i);
  38. + new_diff = t.tv_sec - i.uptime;
  39. +
  40. + if (!uptime_diff_set) {
  41. + uptime_diff = new_diff;
  42. + uptime_diff_set = 1;
  43. + return;
  44. + }
  45. +
  46. + if ((new_diff - 5 > uptime_diff) || (new_diff + 5 < uptime_diff)) {
  47. + /* system time has changed, update counters and timeouts */
  48. + info("System time change detected.");
  49. + start_time.tv_sec += new_diff - uptime_diff;
  50. +
  51. + for (p = callout; p != NULL; p = p->c_next)
  52. + p->c_time.tv_sec += new_diff - uptime_diff;
  53. + }
  54. + uptime_diff = new_diff;
  55. +}
  56. /*
  57. * timeout - Schedule a timeout.
  58. @@ -1333,6 +1366,8 @@ calltimeout()
  59. {
  60. struct callout *p;
  61. + check_time();
  62. +
  63. while (callout != NULL) {
  64. p = callout;
  65. @@ -1360,6 +1395,8 @@ timeleft(tvp)
  66. {
  67. if (callout == NULL)
  68. return NULL;
  69. +
  70. + check_time();
  71. gettimeofday(&timenow, NULL);
  72. tvp->tv_sec = callout->c_time.tv_sec - timenow.tv_sec;