source: trunk/package/ppp/patches/206-compensate_time_change.patch @ 15958

Last change on this file since 15958 was 15958, checked in by hauke, 8 years ago

[ppp] refresh patches

File size: 1.8 KB
  • pppd/main.c

    a b  
    9090#include <sys/socket.h> 
    9191#include <netinet/in.h> 
    9292#include <arpa/inet.h> 
     93#include <sys/sysinfo.h> 
    9394 
    9495#include "pppd.h" 
    9596#include "magic.h" 
    static struct subprocess *children; 
    227228 
    228229/* Prototypes for procedures local to this file. */ 
    229230 
     231static void check_time(void); 
    230232static void setup_signals __P((void)); 
    231233static void create_pidfile __P((int pid)); 
    232234static void create_linkpidfile __P((int pid)); 
    main(argc, argv) 
    532534            info("Starting link"); 
    533535        } 
    534536 
     537        check_time(); 
    535538        gettimeofday(&start_time, NULL); 
    536539        script_unsetenv("CONNECT_TIME"); 
    537540        script_unsetenv("BYTES_SENT"); 
    struct callout { 
    12641267 
    12651268static struct callout *callout = NULL;  /* Callout list */ 
    12661269static struct timeval timenow;          /* Current time */ 
     1270static long uptime_diff = 0; 
     1271static int uptime_diff_set = 0; 
     1272 
     1273static void check_time(void) 
     1274{ 
     1275        long new_diff; 
     1276        struct timeval t; 
     1277        struct sysinfo i; 
     1278    struct callout *p; 
     1279         
     1280        gettimeofday(&t, NULL); 
     1281        sysinfo(&i); 
     1282        new_diff = t.tv_sec - i.uptime; 
     1283         
     1284        if (!uptime_diff_set) { 
     1285                uptime_diff = new_diff; 
     1286                uptime_diff_set = 1; 
     1287                return; 
     1288        } 
     1289 
     1290        if ((new_diff - 5 > uptime_diff) || (new_diff + 5 < uptime_diff)) { 
     1291                /* system time has changed, update counters and timeouts */ 
     1292                info("System time change detected."); 
     1293                start_time.tv_sec += new_diff - uptime_diff; 
     1294                 
     1295        for (p = callout; p != NULL; p = p->c_next) 
     1296                        p->c_time.tv_sec += new_diff - uptime_diff; 
     1297        } 
     1298        uptime_diff = new_diff; 
     1299} 
    12671300 
    12681301/* 
    12691302 * timeout - Schedule a timeout. 
    calltimeout() 
    13341367{ 
    13351368    struct callout *p; 
    13361369 
     1370        check_time(); 
     1371         
    13371372    while (callout != NULL) { 
    13381373        p = callout; 
    13391374 
    timeleft(tvp) 
    13611396{ 
    13621397    if (callout == NULL) 
    13631398        return NULL; 
     1399         
     1400        check_time(); 
    13641401 
    13651402    gettimeofday(&timenow, NULL); 
    13661403    tvp->tv_sec = callout->c_time.tv_sec - timenow.tv_sec; 
Note: See TracBrowser for help on using the repository browser.