diff options
author | Joris Vink <joris@cvs.openbsd.org> | 2006-04-26 21:55:23 +0000 |
---|---|---|
committer | Joris Vink <joris@cvs.openbsd.org> | 2006-04-26 21:55:23 +0000 |
commit | df3a4e509cd581d1f7a20e485d02335219e83daf (patch) | |
tree | 624a5f81ee4938e5d6e948c5b9864f1921dcfcf4 /usr.bin/rcs/rcsclean.c | |
parent | 3822e490767df6f6d16147268ba0f10c37a1e54c (diff) |
prevent file races by obtaining an fd for the RCS file and
do our operations on that, this is safe and guarantees we
can operate on the file until we close(2) it.
a fix is coming for the remaining races in our diff code.
okay niallo@ and ray@
Diffstat (limited to 'usr.bin/rcs/rcsclean.c')
-rw-r--r-- | usr.bin/rcs/rcsclean.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/usr.bin/rcs/rcsclean.c b/usr.bin/rcs/rcsclean.c index 9e20f1e55dc..6dc3b225110 100644 --- a/usr.bin/rcs/rcsclean.c +++ b/usr.bin/rcs/rcsclean.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rcsclean.c,v 1.44 2006/04/26 02:55:13 joris Exp $ */ +/* $OpenBSD: rcsclean.c,v 1.45 2006/04/26 21:55:22 joris Exp $ */ /* * Copyright (c) 2005 Joris Vink <joris@openbsd.org> * All rights reserved. @@ -127,7 +127,7 @@ rcsclean_usage(void) static void rcsclean_file(char *fname, const char *rev_str) { - int match; + int fd, match; RCSFILE *file; char fpath[MAXPATHLEN], numb[64]; RCSNUM *rev; @@ -138,14 +138,14 @@ rcsclean_file(char *fname, const char *rev_str) file = NULL; rev = NULL; - if (rcs_statfile(fname, fpath, sizeof(fpath), flags) < 0) + if ((fd = rcs_statfile(fname, fpath, sizeof(fpath), flags)) < 0) goto out; - if ((file = rcs_open(fpath, RCS_RDWR)) == NULL) + if ((file = rcs_open(fpath, fd, RCS_RDWR)) == NULL) goto out; if (flags & PRESERVETIME) - rcs_mtime = rcs_get_mtime(file->rf_path); + rcs_mtime = rcs_get_mtime(file); rcs_kwexp_set(file, kflag); @@ -200,8 +200,9 @@ rcsclean_file(char *fname, const char *rev_str) } } + rcs_write(file); if (flags & PRESERVETIME) - rcs_set_mtime(fpath, rcs_mtime); + rcs_set_mtime(file, rcs_mtime); out: if (b1 != NULL) |