lock.c (59300) | lock.c (92914) |
---|---|
1/* lock.c: The opielock() library function. 2 3%%% portions-copyright-cmetz-96 | 1/* lock.c: The opielock() library function. 2 3%%% portions-copyright-cmetz-96 |
4Portions of this software are Copyright 1996-1998 by Craig Metz, All Rights | 4Portions of this software are Copyright 1996-1999 by Craig Metz, All Rights |
5Reserved. The Inner Net License Version 2 applies to these portions of 6the software. 7You should have received a copy of the license with this software. If 8you didn't get a copy, you may request one from <license@inner.net>. 9 10Portions of this software are Copyright 1995 by Randall Atkinson and Dan 11McDonald, All Rights Reserved. All Rights under this copyright are assigned 12to the U.S. Naval Research Laboratory (NRL). The NRL Copyright Notice and 13License Agreement applies to this software. 14 15 History: 16 | 5Reserved. The Inner Net License Version 2 applies to these portions of 6the software. 7You should have received a copy of the license with this software. If 8you didn't get a copy, you may request one from <license@inner.net>. 9 10Portions of this software are Copyright 1995 by Randall Atkinson and Dan 11McDonald, All Rights Reserved. All Rights under this copyright are assigned 12to the U.S. Naval Research Laboratory (NRL). The NRL Copyright Notice and 13License Agreement applies to this software. 14 15 History: 16 |
17 Modified by cmetz for OPIE 2.4. Use snprintf. |
|
17 Modified by cmetz for OPIE 2.31. Put locks in a separate dir. 18 Bug fixes. 19 Modified by cmetz for OPIE 2.3. Do refcounts whether or not we 20 actually lock. Fixed USER_LOCKING=0 case. 21 Modified by cmetz for OPIE 2.22. Added reference count for locks. 22 Changed lock filename/refcount symbol names to better indicate 23 that they're not user serviceable. 24 Modified by cmetz for OPIE 2.2. Use FUNCTION declaration et al. 25 Use "principal" instead of "name" to make it clearer. 26 Ifdef around some headers, be more careful about allowed 27 error return values. Check open() return value properly. 28 Avoid NULL. 29 Created at NRL for OPIE 2.2 from opiesubr2.c 30 | 18 Modified by cmetz for OPIE 2.31. Put locks in a separate dir. 19 Bug fixes. 20 Modified by cmetz for OPIE 2.3. Do refcounts whether or not we 21 actually lock. Fixed USER_LOCKING=0 case. 22 Modified by cmetz for OPIE 2.22. Added reference count for locks. 23 Changed lock filename/refcount symbol names to better indicate 24 that they're not user serviceable. 25 Modified by cmetz for OPIE 2.2. Use FUNCTION declaration et al. 26 Use "principal" instead of "name" to make it clearer. 27 Ifdef around some headers, be more careful about allowed 28 error return values. Check open() return value properly. 29 Avoid NULL. 30 Created at NRL for OPIE 2.2 from opiesubr2.c 31 |
31$FreeBSD: head/contrib/opie/libopie/lock.c 59300 2000-04-17 00:01:23Z kris $ | 32$FreeBSD: head/contrib/opie/libopie/lock.c 92914 2002-03-21 23:42:52Z markm $ |
32*/ 33#include "opie_cfg.h" 34#if HAVE_STRING_H 35#include <string.h> 36#endif /* HAVE_STRING_H */ 37#if HAVE_UNISTD_H 38#include <unistd.h> 39#endif /* HAVE_UNISTD_H */ --- 156 unchanged lines hidden (view full) --- 196 197 if (lstat(__opie_lockfilename, &statbuf[0]) < 0) 198 goto lockret; 199 if (fstat(fh, &statbuf[1]) < 0) 200 goto lockret; 201 if (!S_ISREG(statbuf[0].st_mode) || (statbuf[0].st_mode != statbuf[1].st_mode) || (statbuf[0].st_ino != statbuf[1].st_ino)) 202 goto lockret; 203 | 33*/ 34#include "opie_cfg.h" 35#if HAVE_STRING_H 36#include <string.h> 37#endif /* HAVE_STRING_H */ 38#if HAVE_UNISTD_H 39#include <unistd.h> 40#endif /* HAVE_UNISTD_H */ --- 156 unchanged lines hidden (view full) --- 197 198 if (lstat(__opie_lockfilename, &statbuf[0]) < 0) 199 goto lockret; 200 if (fstat(fh, &statbuf[1]) < 0) 201 goto lockret; 202 if (!S_ISREG(statbuf[0].st_mode) || (statbuf[0].st_mode != statbuf[1].st_mode) || (statbuf[0].st_ino != statbuf[1].st_ino)) 203 goto lockret; 204 |
204 sprintf(buffer, "%d\n%d\n", getpid(), time(0)); | 205 if (snprintf(buffer, sizeof(buffer), "%d\n%d\n", getpid(), time(0)) >= sizeof(buffer)) 206 goto lockret; 207 |
205 i = strlen(buffer) + 1; 206 if (lseek(fh, 0, SEEK_SET)) { 207 close(fh); 208 unlink(__opie_lockfilename); 209 fh = 0; 210 goto lockret; 211 }; 212 if (write(fh, buffer, i) != i) { --- 40 unchanged lines hidden --- | 208 i = strlen(buffer) + 1; 209 if (lseek(fh, 0, SEEK_SET)) { 210 close(fh); 211 unlink(__opie_lockfilename); 212 fh = 0; 213 goto lockret; 214 }; 215 if (write(fh, buffer, i) != i) { --- 40 unchanged lines hidden --- |