Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/rdist check some more syscall return values. use mk...
details: https://anonhg.NetBSD.org/src/rev/1b53e039934c
branches: trunk
changeset: 472075:1b53e039934c
user: mrg <mrg%NetBSD.org@localhost>
date: Tue Apr 20 07:53:02 1999 +0000
description:
check some more syscall return values. use mkstemp.
diffstat:
usr.bin/rdist/docmd.c | 11 ++++--
usr.bin/rdist/main.c | 11 +++++--
usr.bin/rdist/server.c | 75 ++++++++++++++++++++++++++++++++++----------------
3 files changed, 66 insertions(+), 31 deletions(-)
diffs (284 lines):
diff -r 9bbd31ad8249 -r 1b53e039934c usr.bin/rdist/docmd.c
--- a/usr.bin/rdist/docmd.c Tue Apr 20 07:24:49 1999 +0000
+++ b/usr.bin/rdist/docmd.c Tue Apr 20 07:53:02 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: docmd.c,v 1.18 1998/12/19 20:32:17 christos Exp $ */
+/* $NetBSD: docmd.c,v 1.19 1999/04/20 07:53:02 mrg Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)docmd.c 8.1 (Berkeley) 6/9/93";
#else
-__RCSID("$NetBSD: docmd.c,v 1.18 1998/12/19 20:32:17 christos Exp $");
+__RCSID("$NetBSD: docmd.c,v 1.19 1999/04/20 07:53:02 mrg Exp $");
#endif
#endif /* not lint */
@@ -313,7 +313,9 @@
printf("closeconn()\n");
if (rem >= 0) {
- (void) write(rem, "\2\n", 2);
+ if (write(rem, "\2\n", 2) < 0 && debug)
+ printf("write failed on fd %d: %s\n", rem,
+ strerror(errno));
(void) close(rem);
(void) close(remerr);
rem = -1;
@@ -607,7 +609,8 @@
putc('\n', pf);
while ((len = read(fd, buf, BUFSIZ)) > 0)
- (void) fwrite(buf, 1, len, pf);
+ if (fwrite(buf, 1, len, pf) < 1)
+ error("%s: %s\n", file, strerror(errno));
(void) close(fd);
(void) pclose(pf);
}
diff -r 9bbd31ad8249 -r 1b53e039934c usr.bin/rdist/main.c
--- a/usr.bin/rdist/main.c Tue Apr 20 07:24:49 1999 +0000
+++ b/usr.bin/rdist/main.c Tue Apr 20 07:53:02 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.9 1999/01/31 10:02:25 mrg Exp $ */
+/* $NetBSD: main.c,v 1.10 1999/04/20 07:53:02 mrg Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -43,12 +43,13 @@
#if 0
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/9/93";
#else
-__RCSID("$NetBSD: main.c,v 1.9 1999/01/31 10:02:25 mrg Exp $");
+__RCSID("$NetBSD: main.c,v 1.10 1999/04/20 07:53:02 mrg Exp $");
#endif
#endif /* not lint */
#include <sys/types.h>
+#include <err.h>
#include <errno.h>
#include <pwd.h>
@@ -95,6 +96,7 @@
char *arg;
int cmdargs = 0;
char *dhosts[NHOSTS], **hp = dhosts;
+ int fd;
pw = getpwuid(userid = getuid());
if (pw == NULL) {
@@ -203,7 +205,10 @@
*hp = NULL;
seteuid(userid);
- mktemp(tempfile);
+ fd = mkstemp(tempfile);
+ if (fd == -1)
+ err(1, "could not make a temporary file");
+ close (fd);
if (iamremote) {
server();
diff -r 9bbd31ad8249 -r 1b53e039934c usr.bin/rdist/server.c
--- a/usr.bin/rdist/server.c Tue Apr 20 07:24:49 1999 +0000
+++ b/usr.bin/rdist/server.c Tue Apr 20 07:53:02 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: server.c,v 1.17 1998/12/19 20:34:53 christos Exp $ */
+/* $NetBSD: server.c,v 1.18 1999/04/20 07:53:02 mrg Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)server.c 8.1 (Berkeley) 6/9/93";
#else
-__RCSID("$NetBSD: server.c,v 1.17 1998/12/19 20:34:53 christos Exp $");
+__RCSID("$NetBSD: server.c,v 1.18 1999/04/20 07:53:02 mrg Exp $");
#endif
#endif /* not lint */
@@ -52,8 +52,8 @@
#include "defs.h"
-#define ack() (void) write(rem, "\0\n", 2)
-#define err() (void) write(rem, "\1\n", 2)
+#define ack() do { if (write(rem, "\0\n", 2) < 0) error("ack failed: %s\n", strerror(errno)); } while (0)
+#define err() do { if (write(rem, "\1\n", 2) < 0) error("err failed: %s\n", strerror(errno)); } while (0)
struct linkbuf *ihead; /* list of files with more than one link */
char buf[BUFSIZ]; /* general purpose buffer */
@@ -105,7 +105,9 @@
rem = 0;
oumask = umask(0);
(void) snprintf(buf, sizeof(buf), "V%d\n", VERSION);
- (void) write(rem, buf, strlen(buf));
+ if (write(rem, buf, strlen(buf)) < 0)
+ error("server: could not write remote end: %s\n",
+ strerror(errno));
for (;;) {
cp = cmdbuf;
@@ -292,7 +294,9 @@
(void) snprintf(buf, sizeof(buf), "%c%s\n", destdir ? 'T' : 't', dest);
if (debug)
printf("buf = %s", buf);
- (void) write(rem, buf, strlen(buf));
+ if (write(rem, buf, strlen(buf)) < 0)
+ error("could not pass filename to remote: %s\n",
+ strerror(errno));
if (response() < 0)
return;
@@ -376,7 +380,10 @@
rname);
if (debug)
printf("buf = %s", buf);
- (void) write(rem, buf, strlen(buf));
+ if (write(rem, buf, strlen(buf)) < 0)
+ error("can not write dir spec to remote: %s\n",
+ strerror(errno));
+
if (response() < 0) {
closedir(d);
return;
@@ -405,7 +412,9 @@
sendf(dp->d_name, opts);
}
closedir(d);
- (void) write(rem, "E\n", 2);
+ if (write(rem, "E\n", 2) < 0)
+ error("can not write E to remote: %s\n",
+ strerror(errno));
(void) response();
tp = otp;
*tp = '\0';
@@ -428,7 +437,9 @@
lp->pathname, rname);
if (debug)
printf("buf = %s", buf);
- (void) write(rem, buf, strlen(buf));
+ if (write(rem, buf, strlen(buf)) < 0)
+ error("can not write link spec to remote: %s\n",
+ strerror(errno));
(void) response();
return;
}
@@ -438,11 +449,15 @@
(u_long)stb.st_mtime, protoname(), protogroup(), rname);
if (debug)
printf("buf = %s", buf);
- (void) write(rem, buf, strlen(buf));
+ if (write(rem, buf, strlen(buf)) < 0)
+ error("can not write link spec to remote: %s\n",
+ strerror(errno));
if (response() < 0)
return;
sizerr = (readlink(target, buf, BUFSIZ) != stb.st_size);
- (void) write(rem, buf, stb.st_size);
+ if (write(rem, buf, stb.st_size) < 0)
+ error("can not write link name to remote: %s\n",
+ strerror(errno));
if (debug)
printf("readlink = %.*s\n", (int)stb.st_size, buf);
goto done;
@@ -476,7 +491,9 @@
opts, lp->target, lp->pathname, rname);
if (debug)
printf("buf = %s", buf);
- (void) write(rem, buf, strlen(buf));
+ if (write(rem, buf, strlen(buf)) <0)
+ error("write of file name failed: %s\n",
+ strerror(errno));
(void) response();
return;
}
@@ -491,7 +508,8 @@
(u_long)stb.st_mtime, protoname(), protogroup(), rname);
if (debug)
printf("buf = %s", buf);
- (void) write(rem, buf, strlen(buf));
+ if (write(rem, buf, strlen(buf)) < 0)
+ error("write of file name failed: %s\n", strerror(errno));
if (response() < 0) {
(void) close(f);
return;
@@ -503,7 +521,8 @@
amt = stb.st_size - i;
if (sizerr == 0 && read(f, buf, amt) != amt)
sizerr = 1;
- (void) write(rem, buf, amt);
+ if (write(rem, buf, amt) < 0)
+ error("write of file data failed: %s\n", strerror(errno));
}
(void) close(f);
done:
@@ -528,7 +547,8 @@
sc->sc_name);
if (debug)
printf("buf = %s", buf);
- (void) write(rem, buf, strlen(buf));
+ if (write(rem, buf, strlen(buf)) < 0)
+ error("write of special failed: %s\n", strerror(errno));
while (response() > 0)
;
}
@@ -587,7 +607,8 @@
(void) snprintf(buf, sizeof(buf), "Q%s\n", rname);
if (debug)
printf("buf = %s", buf);
- (void) write(rem, buf, strlen(buf));
+ if (write(rem, buf, strlen(buf)) < 0)
+ error("write to remote failed: %s\n", strerror(errno));
again:
cp = s = buf;
do {
@@ -679,9 +700,11 @@
"/%s", name);
if (lstat(target, &stb) < 0) {
- if (errno == ENOENT)
- (void) write(rem, "N\n", 2);
- else
+ if (errno == ENOENT) {
+ if (write(rem, "N\n", 2) < 0)
+ error("write to remote failed: %s\n",
+ strerror(errno));
+ } else
error("%s:%s: %s\n", host, target, strerror(errno));
*tp = '\0';
return;
@@ -691,12 +714,14 @@
case S_IFREG:
(void)snprintf(buf, sizeof(buf), "Y%qd %ld\n",
(unsigned long long)stb.st_size, (u_long)stb.st_mtime);
- (void)write(rem, buf, strlen(buf));
+ if (write(rem, buf, strlen(buf)) < 0)
+ error("write to remote failed: %s\n", strerror(errno));
break;
case S_IFLNK:
case S_IFDIR:
- (void) write(rem, "Y\n", 2);
+ if (write(rem, "Y\n", 2) < 0)
+ error("write to remote failed: %s\n", strerror(errno));
break;
default:
@@ -790,9 +815,11 @@
}
buf[0] = '\0';
(void) snprintf(buf + 1, sizeof(buf) - 1,
- "%s: Warning: remote mode %o != local mode %o\n",
- target, stb.st_mode & 07777, mode);
- (void) write(rem, buf, strlen(buf + 1) + 1);
+ "%s: Warning: remote mode %o != local mode %o\n",
+ target, stb.st_mode & 07777, mode);
+ if (write(rem, buf, strlen(buf + 1) + 1) < 0)
+ error("write to remote failed: %s\n",
+ strerror(errno));
return;
}
errno = ENOTDIR;
Home |
Main Index |
Thread Index |
Old Index