Re: [squid-users] running squid on VERY low-end devices

From: John Doe <jdmls_at_yahoo.com>
Date: Wed, 24 Sep 2008 02:04:32 -0700 (PDT)

> i have written a small external helper in perl and it seems to do the trick.
>
> --------------------------------
> #!/usr/bin/microperl
>
> while () {
>
> ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek,
> $dayOfYear, $daylightSavings) = localtime();
> $year =3D 1900 + $yearOffset;
>
> if ($year < 2008) {
> print "ERR\n";
> } else {
> print "OK\n";
> }
> }
> --------------------------------
>
> i know perl isnt the most optimized language .... but as the= external acl
> is started on squid startup and keeps running until squid exits, i dont think
> that will be a problem.
>
> anyway, i would love to see something similar in C that could be compiled
> and run with less memory than perl requires .... unfortunelly i cant code even a
> 'hello world' in C !!! But i'll try that ..... shouldnt be too difficult.

Here's a basic C example:

#include <stdio.h>
#include <time.h>

#define INPUTSIZE 256

int main(int argc, char *argv[]) {

  char input[INPUTSIZE];
  char *cp;
  struct tm *local;
  time_t t;
  int year;

  while (fgets(input, sizeof(input), stdin)) {
    t = time(NULL);
    local = localtime(&t);
    year = local->tm_year + 1900;
    if (year < 2008) { printf("ERR\n"); } else { printf("OK\n"); }
    fflush(stdout);
  }

}

JD

PS: I put a "small" INPUTSIZE and do not check for overflow...

      
Received on Wed Sep 24 2008 - 09:04:45 MDT

This archive was generated by hypermail 2.2.0 : Wed Sep 24 2008 - 12:00:03 MDT