File: readfifo.c

package info (click to toggle)
apcupsd 3.8.5-1.1.1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 7,012 kB
  • ctags: 2,783
  • sloc: ansic: 26,374; sh: 3,012; makefile: 1,860; cpp: 1,713; perl: 191; sed: 93
file content (42 lines) | stat: -rw-r--r-- 831 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
 * 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);
  }
}