patch-pppd_main_c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. --- ppp-2.4.4.orig/pppd/main.c 2006-06-04 05:52:50.000000000 +0200
  2. +++ ppp-2.4.4/pppd/main.c 2009-06-05 19:12:00.000000000 +0200
  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. @@ -227,6 +228,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. @@ -529,6 +531,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. @@ -1262,6 +1265,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. @@ -1332,6 +1365,8 @@ calltimeout()
  59. {
  60. struct callout *p;
  61. + check_time();
  62. +
  63. while (callout != NULL) {
  64. p = callout;
  65. @@ -1359,6 +1394,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;