All pastes #19670 Raw Edit

Untitled

public text v1 · immutable
#19670 ·published 2005-08-10 04:36 UTC
rendered paste body
#include <syslog.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/time.h>
#include <unistd.h>

void secwait(int s);

int main()
{
  FILE *fp, *out;
  char temp[1024];
  int sec = 0;

  fp = fopen("/var/log/messages", "r");
  out = fopen("/dev/tty", "w");

  if (fp == NULL)
  {
    syslog(LOG_WARNING, "Could not open pppd log file: %s", "/var/log/messages");
    return 0;
  }

  fseek(fp, 0L, SEEK_END);

  secwait(1);
  syslog(LOG_NOTICE, "New entry.\n");

  while(sec < 10)
  {
    if (fgets(temp, 1024, fp) == NULL)
    {
      //sec++;
      secwait(1);
    }
    else
    {
      fprintf(out, "TTY: %s\n", temp);
    }
  }


//        fprintf(tester, "w = %d, x = %d, feof is %d\n", w, x, feof(tester));
//        fprintf(tester, "w is %d, errno is %d.  bad stream is %d.  whence is %d$

  fclose(fp);
  fclose(out);

  return 1;
}

void secwait(int s)
{
  struct timeval tv;
  tv.tv_sec = s;
  tv.tv_usec = 0;
  select(0, NULL, NULL, NULL, &tv);
}