
/*
 * A very simple daemon to give impulsions to clockspeed
 * with exponential delay.
 * 
 * (C)opyleft -Jedi/Sector One <j@4u.net> .
 */

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

#define TAICLOCK "/usr/local/bin/taiclock" /* You can use sntpclock instead */
#define CLOCKADD "/usr/local/bin/clockadd"
#define ADJUST "/usr/local/adjust"

int main(int a, const char *b[])
{
    static char buf[LINE_MAX];
    unsigned int c;
    unsigned int d = 0U;
    
    if (*b == NULL || b[1] == NULL) {
        puts("Usage: clockspeed-agent <server ip>");          
        return 0;                
    }
    sleep(10);
    b++;
    for (;;) {
        snprintf(buf, sizeof buf, TAICLOCK " %s | " CLOCKADD, *b);    
        system(buf);
        if (d > 2500000U) {            /* it won't happen tomorrow... */
            d = 0U;
        }
        c = 0U;        
        do {
            d++;
            c += d;                
            sleep(c);
            snprintf(buf, sizeof buf, TAICLOCK " %s > " ADJUST, *b);
            system(buf);
        } while (c < 5000000U);
    }
   
    return 0;
}
