Commit | Line | Data |
---|---|---|
82a61035 C |
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 | * rcs-bugs@cs.purdue.edu | |
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 | #ifdef _FSTDIO | |
86 | #undef putc | |
87 | #define putc __sputc | |
88 | #define fflsbuf _flsbuf | |
89 | #endif | |
90 | /* undo redefinition of putc in rcsbase.h */ | |
91 | ||
92 | char lockfname[NCPPN]; | |
93 | FILE * logfile; | |
94 | int lockfile; | |
95 | ||
96 | #define MAXTRIES 20 | |
97 | ||
98 | main(argc,argv) | |
99 | int argc; char * argv[]; | |
100 | /* writes argv[1] to SNOOPFILE and appends a newline. Invoked as follows: | |
101 | * rcslog logmessage | |
102 | */ | |
103 | { int tries; | |
104 | register char * lastslash, *sp; | |
105 | ||
106 | VOID strcpy(lockfname,(char *) SNOOPFILE); | |
107 | lastslash = sp = lockfname; | |
108 | while (*sp) if (*sp++ =='/') lastslash=sp; /* points beyond / */ | |
109 | VOID strcpy(lastslash,",lockfile"); | |
110 | tries=0; | |
111 | while (((lockfile=creat(lockfname, 000)) == -1) && (tries<=MAXTRIES)) { | |
112 | tries++; | |
113 | sleep(5); | |
114 | } | |
115 | if (tries<=MAXTRIES) { | |
116 | VOID close(lockfile); | |
117 | if ((logfile=fopen(SNOOPFILE,"a")) ==NULL) { | |
118 | VOID fprintf(stderr,"Can't open logfile %s\n",SNOOPFILE); | |
119 | } else { | |
120 | VOID fputs(argv[1],logfile); | |
121 | VOID putc('\n',logfile); | |
122 | VOID fclose(logfile); | |
123 | } | |
124 | VOID unlink(lockfname); | |
125 | } else { | |
126 | VOID fprintf(stderr,"RCS logfile %s seems permanently locked.\n",SNOOPFILE); | |
127 | VOID fprintf(stderr,"Please alert system administrator\n"); | |
128 | } | |
129 | } |