#include #include #include #include #include #include /* * Simple program that tails /var/log/tvlog, looking for a line containing * the string "LineupUpdate::DoUpdates() has completed" and that runs * channel_map to remap things back. */ #define PATH_TVLOG "/var/log/tvlog" #define PATH_REMAPPER "/var/hack/bin/channel_map" int main(int argc, char **argv) { char buf[2048]; struct stat sb, osb; FILE *fp; daemon(0, 0); for (;;) { fp = fopen(PATH_TVLOG, "r"); if (fp == NULL) { sleep(1); continue; } /* stash stat info */ if (fstat(fileno(fp), &osb) == -1) { fclose(fp); continue; } /* seek to end */ fseek(fp, 0L, SEEK_END); for (;;) { /* XXX - assumes string we are searching for will appear in a single write */ if (fgets(buf, sizeof(buf), fp) == NULL) { if (ferror(fp)) break; /* check to see if the file was replaced */ if (stat(PATH_TVLOG, &sb) == 0) { if (sb.st_ino != osb.st_ino || sb.st_size < osb.st_size) break; /* replaced, re-open */ } /* nothing to read yet, sleep and continue */ clearerr(fp); sleep(1); continue; } if (strstr(buf, "LineupUpdate::DoUpdates() has completed")) { system(PATH_REMAPPER); } } fclose(fp); } }