summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2010-10-31 15:37:35 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2010-10-31 15:37:35 +0000
commit8e4a343572aa68e38a3936eb72fc7c81f7e52797 (patch)
tree62e01f4d220ea1a10c080d590793b0a3b688d55f
parent45451c0cba4d5bcad865bc91daabf8783a94a81d (diff)
init was passing a writable file descriptor into rcs_open which was then
failing to fdopen() it as readable. It doesn't need to pass in the fd at all, so just change it to pass -1 which makes cvs init work again. In fact, the fd should never need to be writable - it is only used for reading. RCS_WRITE triggers a rewrite on the file on rcs_close() but this is done by using a temporary and rename(2) (RCS_WRITE is a poor name for the flag). So while here, add a couple of comments to hopefully make it a little clearer. There is some confusion about how this is used in other places but checking those is a separate issue. with and ok tobias
-rw-r--r--usr.bin/cvs/init.c4
-rw-r--r--usr.bin/cvs/rcs.c6
-rw-r--r--usr.bin/cvs/rcs.h4
3 files changed, 9 insertions, 5 deletions
diff --git a/usr.bin/cvs/init.c b/usr.bin/cvs/init.c
index 14694061035..513db507c26 100644
--- a/usr.bin/cvs/init.c
+++ b/usr.bin/cvs/init.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: init.c,v 1.37 2010/07/23 21:46:05 ray Exp $ */
+/* $OpenBSD: init.c,v 1.38 2010/10/31 15:37:34 nicm Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* Copyright (c) 2006 Xavier Santolaria <xsa@openbsd.org>
@@ -174,7 +174,7 @@ init_mkfile(char *path, const char **content)
(void)xsnprintf(rpath, MAXPATHLEN, "%s%s", path, RCS_FILE_EXT);
- if ((file = rcs_open(rpath, fd, rcsflags, 0444)) == NULL)
+ if ((file = rcs_open(rpath, -1, rcsflags, 0444)) == NULL)
fatal("failed to create RCS file for `%s'", path);
b = buf_load(path);
diff --git a/usr.bin/cvs/rcs.c b/usr.bin/cvs/rcs.c
index 84adf7d7be3..fa8ff39cdd0 100644
--- a/usr.bin/cvs/rcs.c
+++ b/usr.bin/cvs/rcs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcs.c,v 1.306 2010/10/27 08:35:45 tobias Exp $ */
+/* $OpenBSD: rcs.c,v 1.307 2010/10/31 15:37:34 nicm Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -144,6 +144,10 @@ static void rcs_strprint(const u_char *, size_t, FILE *);
static void rcs_kwexp_line(char *, struct rcs_delta *, struct rcs_lines *,
struct rcs_line *, int mode);
+/*
+ * Prepare RCSFILE for parsing. The given file descriptor (if any) must be
+ * read-only and is closed on rcs_close().
+ */
RCSFILE *
rcs_open(const char *path, int fd, int flags, ...)
{
diff --git a/usr.bin/cvs/rcs.h b/usr.bin/cvs/rcs.h
index 98b20eeae8a..a60a14996b2 100644
--- a/usr.bin/cvs/rcs.h
+++ b/usr.bin/cvs/rcs.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcs.h,v 1.97 2010/10/20 19:53:53 tobias Exp $ */
+/* $OpenBSD: rcs.h,v 1.98 2010/10/31 15:37:34 nicm Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -106,7 +106,7 @@ struct rcs_kw {
/* file flags */
#define RCS_READ (1<<0)
-#define RCS_WRITE (1<<1)
+#define RCS_WRITE (1<<1) /* flush changes on rcs_close() */
#define RCS_CREATE (1<<2) /* create the file */
#define RCS_PARSE_FULLY (1<<3) /* fully parse it on open */