209-compensate_time_change.patch 1.9 KB

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