summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/cvs/buf.c59
-rw-r--r--usr.bin/cvs/rcs.c33
-rw-r--r--usr.bin/cvs/root.c65
-rw-r--r--usr.bin/cvs/server.c30
4 files changed, 66 insertions, 121 deletions
diff --git a/usr.bin/cvs/buf.c b/usr.bin/cvs/buf.c
index 7645a093ac9..9b7efc22667 100644
--- a/usr.bin/cvs/buf.c
+++ b/usr.bin/cvs/buf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: buf.c,v 1.19 2005/12/10 20:27:45 joris Exp $ */
+/* $OpenBSD: buf.c,v 1.20 2005/12/20 16:55:21 xsa Exp $ */
/*
* Copyright (c) 2003 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -94,7 +94,7 @@ cvs_buf_alloc(size_t len, u_int flags)
*
* Open the file specified by <path> and load all of its contents into a
* buffer.
- * Returns the loaded buffer on success, or NULL on failure.
+ * Returns the loaded buffer on success.
*/
BUF *
cvs_buf_load(const char *path, u_int flags)
@@ -106,32 +106,21 @@ cvs_buf_load(const char *path, u_int flags)
struct stat st;
BUF *buf;
- fd = open(path, O_RDONLY, 0600);
- if (fd == -1) {
- cvs_log(LP_ERRNO, "failed to open buffer source");
- return (NULL);
- }
+ if ((fd = open(path, O_RDONLY, 0600)) == -1)
+ fatal("cvs_buf_load: open: `%s': %s", path, strerror(errno));
- if (fstat(fd, &st) == -1) {
- cvs_log(LP_ERRNO, "failed to stat buffer source");
- (void)close(fd);
- return (NULL);
- }
+ if (fstat(fd, &st) == -1)
+ fatal("cvs_buf_load: fstat: %s", strerror(errno));
- buf = cvs_buf_alloc((size_t)st.st_size, flags);
- if (buf == NULL) {
- (void)close(fd);
- return (NULL);
- }
+ if ((buf = cvs_buf_alloc((size_t)st.st_size, flags)) == NULL)
+ fatal("cvs_buf_load: cvs_buf_alloc failed");
for (bp = buf->cb_cur; ; bp += (size_t)ret) {
len = SIZE_LEFT(buf);
ret = read(fd, bp, len);
if (ret == -1) {
- cvs_log(LP_ERRNO, "read failed from buffer source");
- (void)close(fd);
cvs_buf_free(buf);
- return (NULL);
+ fatal("cvs_buf_load: read: %s", strerror(errno));
} else if (ret == 0)
break;
@@ -224,9 +213,9 @@ cvs_buf_set(BUF *b, const void *src, size_t len, size_t off)
size_t rlen;
if (b->cb_size < (len + off)) {
- if ((b->cb_flags & BUF_AUTOEXT) && (cvs_buf_grow(b,
- len + off - b->cb_size) < 0))
- return (-1);
+ if ((b->cb_flags & BUF_AUTOEXT) &&
+ (cvs_buf_grow(b, len + off - b->cb_size) < 0))
+ fatal("cvs_buf_set failed");
else
rlen = b->cb_size - off;
} else
@@ -295,7 +284,7 @@ cvs_buf_append(BUF *b, const void *data, size_t len)
if (left < len) {
if (b->cb_flags & BUF_AUTOEXT) {
if (cvs_buf_grow(b, len - left) < 0)
- return (-1);
+ fatal("cvs_buf_append failed");
bp = b->cb_cur + b->cb_len;
} else
rlen = bep - bp;
@@ -323,10 +312,8 @@ cvs_buf_fappend(BUF *b, const char *fmt, ...)
ret = vasprintf(&str, fmt, vap);
va_end(vap);
- if (ret == -1) {
- cvs_log(LP_ERRNO, "failed to format data");
- return (-1);
- }
+ if (ret == -1)
+ fatal("cvs_buf_fappend: failed to format data");
ret = cvs_buf_append(b, str, (size_t)ret);
xfree(str);
@@ -381,7 +368,7 @@ cvs_buf_write_fd(BUF *b, int fd)
if (ret == -1) {
if (errno == EINTR || errno == EAGAIN)
continue;
- return (-1);
+ fatal("cvs_buf_write_fd failed");
}
len -= (size_t)ret;
@@ -403,11 +390,8 @@ cvs_buf_write(BUF *b, const char *path, mode_t mode)
{
int ret, fd;
- fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, mode);
- if (fd == -1) {
- cvs_log(LP_ERRNO, "failed to open file `%s'", path);
- return (-1);
- }
+ if ((fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, mode)) == -1)
+ fatal("open: `%s': %s", path, strerror(errno));
ret = cvs_buf_write_fd(b, fd);
if (ret == -1) {
@@ -432,11 +416,8 @@ cvs_buf_write_stmp(BUF *b, char *template, mode_t mode)
{
int ret, fd;
- fd = mkstemp(template);
- if (fd == -1) {
- cvs_log(LP_ERRNO, "failed to mkstemp file `%s'", template);
- return (-1);
- }
+ if ((fd = mkstemp(template)) == -1)
+ fatal("mkstemp: `%s': %s", template, strerror(errno));
ret = cvs_buf_write_fd(b, fd);
if (ret == -1) {
diff --git a/usr.bin/cvs/rcs.c b/usr.bin/cvs/rcs.c
index 05bd3e45b3e..3681a4e600b 100644
--- a/usr.bin/cvs/rcs.c
+++ b/usr.bin/cvs/rcs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcs.c,v 1.112 2005/12/19 17:43:01 xsa Exp $ */
+/* $OpenBSD: rcs.c,v 1.113 2005/12/20 16:55:21 xsa Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -457,16 +457,13 @@ rcs_write(RCSFILE *rfp)
return (0);
strlcpy(fn, "/tmp/rcs.XXXXXXXXXX", sizeof(fn));
- if ((fd = mkstemp(fn)) == -1 ||
- (fp = fdopen(fd, "w+")) == NULL) {
- if (fd != -1) {
- unlink(fn);
- close(fd);
- }
- rcs_errno = RCS_ERR_ERRNO;
- cvs_log(LP_ERRNO, "failed to open temp RCS output file `%s'",
- fn);
- return (-1);
+ if ((fd = mkstemp(fn)) == -1)
+ fatal("mkstemp: `%s': %s", fn, strerror(errno));
+
+ if ((fp = fdopen(fd, "w+")) == NULL) {
+ fd = errno;
+ unlink(fn);
+ fatal("fdopen: %s", strerror(fd));
}
if (rfp->rf_head != NULL)
@@ -584,9 +581,8 @@ rcs_write(RCSFILE *rfp)
/* rename() not supported so we have to copy. */
if ((chmod(rfp->rf_path, S_IWUSR) == -1)
&& !(rfp->rf_flags & RCS_CREATE)) {
- cvs_log(LP_ERRNO, "failed to chmod `%s'",
- rfp->rf_path);
- return (-1);
+ fatal("chmod(%s, 0%o) failed",
+ rfp->rf_path, S_IWUSR);
}
if ((from_fd = open(fn, O_RDONLY)) == -1) {
@@ -1609,13 +1605,8 @@ rcs_parse(RCSFILE *rfp)
pdp->rp_lines = 0;
pdp->rp_pttype = RCS_TOK_ERR;
- pdp->rp_file = fopen(rfp->rf_path, "r");
- if (pdp->rp_file == NULL) {
- rcs_errno = RCS_ERR_ERRNO;
- cvs_log(LP_ERRNO, "failed to open RCS file `%s'", rfp->rf_path);
- rcs_freepdata(pdp);
- return (-1);
- }
+ if ((pdp->rp_file = fopen(rfp->rf_path, "r")) == NULL)
+ fatal("fopen: `%s': %s", rfp->rf_path, strerror(errno));
pdp->rp_buf = (char *)xmalloc((size_t)RCS_BUFSIZE);
pdp->rp_blen = RCS_BUFSIZE;
diff --git a/usr.bin/cvs/root.c b/usr.bin/cvs/root.c
index 0feff924e95..d198abafbd7 100644
--- a/usr.bin/cvs/root.c
+++ b/usr.bin/cvs/root.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: root.c,v 1.26 2005/12/10 20:27:45 joris Exp $ */
+/* $OpenBSD: root.c,v 1.27 2005/12/20 16:55:21 xsa Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -115,13 +115,9 @@ cvsroot_parse(const char *str)
cp = root->cr_buf;
if (*sp == ':') {
sp++;
- cp = strchr(sp, ':');
- if (cp == NULL) {
- cvs_log(LP_ERR, "failed to parse CVSROOT: "
- "unterminated method");
- cvsroot_free(root);
- return (NULL);
- }
+ if ((cp = strchr(sp, ':')) == NULL)
+ fatal("failed to parse CVSROOT: unterminated method");
+
*(cp++) = '\0';
for (i = 0; i < CVS_NBMETHODS; i++) {
@@ -130,20 +126,13 @@ cvsroot_parse(const char *str)
break;
}
}
- if (i == CVS_NBMETHODS) {
- cvs_log(LP_ERR, "unknown method `%s'", sp);
- cvsroot_free(root);
- return (NULL);
- }
+ if (i == CVS_NBMETHODS)
+ fatal("cvsroot_parse: unknown method `%s'", sp);
}
/* find the start of the actual path */
- sp = strchr(cp, '/');
- if (sp == NULL) {
- cvs_log(LP_ERR, "no path specification in CVSROOT");
- cvsroot_free(root);
- return (NULL);
- }
+ if ((sp = strchr(cp, '/')) == NULL)
+ fatal("no path specification in CVSROOT");
root->cr_dir = sp;
if (sp == cp) {
@@ -154,11 +143,9 @@ cvsroot_parse(const char *str)
return (root);
}
- if (*(sp - 1) != ':') {
- cvs_log(LP_ERR, "missing host/path delimiter in CVS root");
- cvsroot_free(root);
- return (NULL);
- }
+ if (*(sp - 1) != ':')
+ fatal("missing host/path delimiter in CVSROOT");
+
*(sp - 1) = '\0';
/*
@@ -184,12 +171,8 @@ cvsroot_parse(const char *str)
if (pp != NULL) {
*(pp++) = '\0';
root->cr_port = (u_int)strtol(pp, &cp, 10);
- if (*cp != '\0' || root->cr_port > 65535) {
- cvs_log(LP_ERR,
- "invalid port specification in CVSROOT");
- cvsroot_free(root);
- return (NULL);
- }
+ if ((*cp != '\0') || (root->cr_port > 65535))
+ fatal("invalid port specification in CVSROOT");
}
@@ -265,31 +248,25 @@ cvsroot_get(const char *dir)
l = snprintf(rootpath, sizeof(rootpath), "%s/" CVS_PATH_ROOTSPEC, dir);
if (l == -1 || l >= (int)sizeof(rootpath)) {
errno = ENAMETOOLONG;
- cvs_log(LP_ERRNO, "%s", rootpath);
- return (NULL);
+ fatal("cvsroot_get: %s: %s", rootpath, strerror(errno));
}
- fp = fopen(rootpath, "r");
- if (fp == NULL) {
+ if ((fp = fopen(rootpath, "r")) == NULL) {
if (errno == ENOENT) {
/* try env as a last resort */
if ((rootstr = getenv("CVSROOT")) != NULL)
return cvsroot_parse(rootstr);
else
- return (NULL);
+ fatal("cvsroot_get: empty CVSROOT variable");
} else {
- cvs_log(LP_ERRNO, "failed to open %s",
- CVS_PATH_ROOTSPEC);
- return (NULL);
+ fatal("cvsroot_get: fopen: `%s': %s",
+ CVS_PATH_ROOTSPEC, strerror(errno));
}
}
- if (fgets(line, (int)sizeof(line), fp) == NULL) {
- cvs_log(LP_ERR, "failed to read line from %s",
- CVS_PATH_ROOTSPEC);
- (void)fclose(fp);
- return (NULL);
- }
+ if (fgets(line, (int)sizeof(line), fp) == NULL)
+ fatal("cvsroot_get: fgets: `%s'", CVS_PATH_ROOTSPEC);
+
(void)fclose(fp);
len = strlen(line);
diff --git a/usr.bin/cvs/server.c b/usr.bin/cvs/server.c
index 3c211309833..60f82d9d83d 100644
--- a/usr.bin/cvs/server.c
+++ b/usr.bin/cvs/server.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: server.c,v 1.24 2005/10/14 13:46:36 moritz Exp $ */
+/* $OpenBSD: server.c,v 1.25 2005/12/20 16:55:21 xsa Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -76,9 +76,8 @@ cvs_server(int argc, char **argv)
size_t len;
char reqbuf[512];
- if (argc != 1) {
+ if (argc != 1)
return (CVS_EX_USAGE);
- }
/* make sure standard in and standard out are line-buffered */
(void)setvbuf(stdin, NULL, _IOLBF, (size_t)0);
@@ -89,19 +88,17 @@ cvs_server(int argc, char **argv)
"%s/cvs-serv%d", cvs_tmpdir, getpid());
if (l == -1 || l >= (int)sizeof(cvs_server_tmpdir)) {
errno = ENAMETOOLONG;
- cvs_log(LP_ERRNO, "%s", cvs_server_tmpdir);
- return (CVS_EX_DATA);
- }
-
- if (mkdir(cvs_server_tmpdir, 0700) == -1) {
- cvs_log(LP_ERRNO, "failed to create temporary directory '%s'",
+ fatal("cvs_server: tmpdir path too long: `%s'",
cvs_server_tmpdir);
- return (CVS_EX_FILE);
}
+ if (mkdir(cvs_server_tmpdir, 0700) == -1)
+ fatal("cvs_server: mkdir: `%s': %s",
+ cvs_server_tmpdir, strerror(errno));
+
if (cvs_chdir(cvs_server_tmpdir) == -1) {
- cvs_rmdir(cvs_server_tmpdir);
- return (CVS_EX_FILE);
+ (void)cvs_rmdir(cvs_server_tmpdir);
+ fatal("cvs_server: cvs_chdir failed");
}
for (;;) {
@@ -109,8 +106,8 @@ cvs_server(int argc, char **argv)
if (feof(stdin))
break;
else if (ferror(stdin)) {
- cvs_rmdir(cvs_server_tmpdir);
- return (CVS_EX_DATA);
+ (void)cvs_rmdir(cvs_server_tmpdir);
+ fatal("cvs_server: fgets failed");
}
}
@@ -118,9 +115,8 @@ cvs_server(int argc, char **argv)
if (len == 0)
continue;
else if (reqbuf[len - 1] != '\n') {
- cvs_log(LP_ERR, "truncated request");
- cvs_rmdir(cvs_server_tmpdir);
- return (CVS_EX_PROTO);
+ (void)cvs_rmdir(cvs_server_tmpdir);
+ fatal("cvs_server: truncated request");
}
reqbuf[--len] = '\0';