|
|
1.1 ! root 1: /* ! 2: * Logging of RCS commands co and ci ! 3: */ ! 4: #ifndef lint ! 5: static char rcsid[]= ! 6: "$Header: /usr/src/local/bin/rcs/src/RCS/snoop.c,v 4.4 89/05/01 15:14:00 narten Exp $ Purdue CS"; ! 7: #endif ! 8: /******************************************************************* ! 9: * This program appends argv[1] to the file SNOOPFILE. ! 10: * To avoid overlaps, it creates a lockfile with name lock in the same ! 11: * directory as SNOOPFILE. SNOOPFILE must be defined in the cc command. ! 12: * Prints an error message if lockfile doesn't get deleted after ! 13: * MAXTRIES tries. ! 14: ******************************************************************* ! 15: */ ! 16: ! 17: /* Copyright (C) 1982, 1988, 1989 Walter Tichy ! 18: * All rights reserved. ! 19: * ! 20: * Redistribution and use in source and binary forms are permitted ! 21: * provided that the above copyright notice and this paragraph are ! 22: * duplicated in all such forms and that any documentation, ! 23: * advertising materials, and other materials related to such ! 24: * distribution and use acknowledge that the software was developed ! 25: * by Walter Tichy. ! 26: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR ! 27: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED ! 28: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 29: * ! 30: * Report all problems and direct all questions to: ! 31: * [email protected] ! 32: * ! 33: ! 34: ! 35: ! 36: ! 37: ! 38: ! 39: ! 40: */ ! 41: ! 42: ! 43: /* $Log: snoop.c,v $ ! 44: * Revision 4.4 89/05/01 15:14:00 narten ! 45: * changed copyright header to reflect current distribution rules ! 46: * ! 47: * Revision 4.3 87/12/18 11:46:52 narten ! 48: * more lint cleanups (Guy Harris) ! 49: * ! 50: * Revision 4.2 87/10/18 10:41:47 narten ! 51: * Changing version numbers. Changes relative to 1.1 actually relative to ! 52: * 4.1 ! 53: * ! 54: * Revision 1.2 87/09/24 14:01:41 narten ! 55: * Sources now pass through lint (if you ignore printf/sprintf/fprintf ! 56: * warnings) ! 57: * ! 58: * Revision 1.1 84/01/23 14:50:49 kcs ! 59: * Initial revision ! 60: * ! 61: * Revision 4.1 83/03/28 13:23:42 wft ! 62: * No change; just new revision number. ! 63: * ! 64: * Revision 3.2 82/12/04 17:14:31 wft ! 65: * Added rcsbase.h, changed SNOOPDIR to SNOOPFILE, reintroduced ! 66: * error message in case of permanent locking. ! 67: * ! 68: * Revision 3.1 82/10/18 21:22:03 wft ! 69: * Number of polls now 20, no error message if critical section can't ! 70: * be entered. ! 71: * ! 72: * Revision 2.3 82/07/01 23:49:28 wft ! 73: * changed copyright notice only. ! 74: * ! 75: * Revision 2.2 82/06/03 20:00:10 wft ! 76: * changed name from rcslog to snoop, replaced LOGDIR with SNOOPDIR. ! 77: * ! 78: * Revision 2.1 82/05/06 17:55:54 wft ! 79: * Initial revision ! 80: * ! 81: */ ! 82: ! 83: ! 84: #include "rcsbase.h" ! 85: #define fflsbuf _flsbuf ! 86: /* undo redefinition of putc in rcsbase.h */ ! 87: ! 88: char lockfname[NCPPN]; ! 89: FILE * logfile; ! 90: int lockfile; ! 91: ! 92: #define MAXTRIES 20 ! 93: ! 94: main(argc,argv) ! 95: int argc; char * argv[]; ! 96: /* writes argv[1] to SNOOPFILE and appends a newline. Invoked as follows: ! 97: * rcslog logmessage ! 98: */ ! 99: { int tries; ! 100: register char * lastslash, *sp; ! 101: ! 102: VOID strcpy(lockfname,(char *) SNOOPFILE); ! 103: lastslash = sp = lockfname; ! 104: while (*sp) if (*sp++ =='/') lastslash=sp; /* points beyond / */ ! 105: VOID strcpy(lastslash,",lockfile"); ! 106: tries=0; ! 107: while (((lockfile=creat(lockfname, 000)) == -1) && (tries<=MAXTRIES)) { ! 108: tries++; ! 109: sleep(5); ! 110: } ! 111: if (tries<=MAXTRIES) { ! 112: VOID close(lockfile); ! 113: if ((logfile=fopen(SNOOPFILE,"a")) ==NULL) { ! 114: VOID fprintf(stderr,"Can't open logfile %s\n",SNOOPFILE); ! 115: } else { ! 116: VOID fputs(argv[1],logfile); ! 117: VOID putc('\n',logfile); ! 118: VOID fclose(logfile); ! 119: } ! 120: VOID unlink(lockfname); ! 121: } else { ! 122: VOID fprintf(stderr,"RCS logfile %s seems permanently locked.\n",SNOOPFILE); ! 123: VOID fprintf(stderr,"Please alert system administrator\n"); ! 124: } ! 125: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.