Sophie

Sophie

distrib > Mandriva > 2006.0 > x86_64 > by-pkgid > 23fcd86b8f6bdf6d1463505ad3db7b3b > files > 534

apcupsd-3.10.18-3.1.20060mdk.x86_64.rpm

/*
 * Dumb little program to read named pipe written
 * by apcupsd and to print what it got.
 *
 * The default file is /var/log/apcupsd.status
 *
 * To make: make readfifo
 *    
 * called
 *
 *    ./readfifo <named pipe>
 *
 *  it exits after printing 200 records
 *
 */
#include <stdio.h>

main(int argc, char *argv[])
{
   int i;
   int rfd;
   char buf[200];
   char *file = "/var/log/apcupsd.status";

   if (argc > 1) {
      file = argv[1];
   }

  if ((rfd = open(file, 0)) < 0) {     /* open named pipe read only */
      printf("Could not open named pipe %s\n", file);
      exit(1);
   } else {
/*    printf("Fifo opened as %d\n"); */
   }
   for (i=0; i<200; i++) {
      int n;
      n = read(rfd, buf, sizeof buf);
      buf[n] = 0;
/*    printf("%d bytes read from %s\n", n, argv[1]);    */
      printf(buf);
  }
}