summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2019-03-23 00:20:56 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2019-03-23 00:20:56 +0000
commit243c2eab1732166d1821e842f9fe17647677de70 (patch)
tree23e158a207acfcb784b8ec5a90d026d97f8d828e /usr.bin
parent17e7728c49b73a5919d767877ffc329ffe4bc664 (diff)
repair exit codes, slightly broken after last commit (please do not go
to an enum, that's just alien). Documents the return values in each function and unifies the protocol incompatibility error message. from kristaps
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/rsync/client.c21
-rw-r--r--usr.bin/rsync/main.c20
-rw-r--r--usr.bin/rsync/server.c13
-rw-r--r--usr.bin/rsync/socket.c24
4 files changed, 41 insertions, 37 deletions
diff --git a/usr.bin/rsync/client.c b/usr.bin/rsync/client.c
index 57e51807af9..83bef820edc 100644
--- a/usr.bin/rsync/client.c
+++ b/usr.bin/rsync/client.c
@@ -1,4 +1,4 @@
-/* $Id: client.c,v 1.12 2019/03/18 15:33:21 deraadt Exp $ */
+/* $Id: client.c,v 1.13 2019/03/23 00:20:55 deraadt Exp $ */
/*
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -30,17 +30,14 @@
* It can either be in sender or receiver mode.
* In the former, it synchronises local files from a remote sink.
* In the latter, the remote sink synchronses to the local files.
- *
- * Pledges: stdio, rpath, wpath, cpath, unveil, fattr, chown.
- *
- * Pledges (dry-run): -cpath, -wpath, -fattr, chown.
- * Pledges (!preserve_times): -fattr.
+ * Returns exit code 0 on success, 1 on failure, 2 on failure with
+ * incompatible protocols.
*/
int
rsync_client(const struct opts *opts, int fd, const struct fargs *f)
{
struct sess sess;
- int rc = 0;
+ int rc = 1;
/* Standard rsync preamble, sender side. */
@@ -64,10 +61,10 @@ rsync_client(const struct opts *opts, int fd, const struct fargs *f)
}
if (sess.rver < sess.lver) {
- ERRX(&sess, "remote protocol is older "
- "than our own (%" PRId32 " < %" PRId32 "): "
- "this is not supported",
- sess.rver, sess.lver);
+ ERRX(&sess,
+ "remote protocol %d is older than our own %d: unsupported",
+ sess.rver, sess.lver);
+ rc = 2;
goto out;
}
@@ -105,7 +102,7 @@ rsync_client(const struct opts *opts, int fd, const struct fargs *f)
WARNX(&sess, "data remains in read pipe");
#endif
- rc = 1;
+ rc = 0;
out:
return rc;
}
diff --git a/usr.bin/rsync/main.c b/usr.bin/rsync/main.c
index 25f63656db3..738565eb60c 100644
--- a/usr.bin/rsync/main.c
+++ b/usr.bin/rsync/main.c
@@ -1,4 +1,4 @@
-/* $Id: main.c,v 1.33 2019/03/18 08:11:11 jmc Exp $ */
+/* $Id: main.c,v 1.34 2019/03/23 00:20:55 deraadt Exp $ */
/*
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -273,7 +273,7 @@ main(int argc, char *argv[])
{
struct opts opts;
pid_t child;
- int fds[2], rc = 0, c, st, i;
+ int fds[2], rc, c, st, i;
struct sess sess;
struct fargs *fargs;
char **args;
@@ -478,13 +478,23 @@ main(int argc, char *argv[])
* So close the connection here so that they don't hang.
*/
- if (!rc)
+ if (rc)
close(fds[0]);
if (waitpid(child, &st, 0) == -1)
err(1, "waitpid");
- if (!(WIFEXITED(st) && WEXITSTATUS(st) == 0))
- rc = 0;
+
+ /*
+ * If we don't already have an error (rc == 0), then inherit the
+ * error code of rsync_server() if it has exited.
+ * If it hasn't exited, it overrides our return value.
+ */
+
+ if (WIFEXITED(st) && rc == 0)
+ rc = WEXITSTATUS(st);
+ else if (!WIFEXITED(st))
+ rc = 1;
+
exit(rc);
usage:
fprintf(stderr, "usage: %s [-aDglnoprtv] [-e program] [--archive] [--delete] [--devices]\n"
diff --git a/usr.bin/rsync/server.c b/usr.bin/rsync/server.c
index 34459cd0cda..6d7835a82be 100644
--- a/usr.bin/rsync/server.c
+++ b/usr.bin/rsync/server.c
@@ -1,4 +1,4 @@
-/* $Id: server.c,v 1.8 2019/03/06 18:37:22 deraadt Exp $ */
+/* $Id: server.c,v 1.9 2019/03/23 00:20:55 deraadt Exp $ */
/*
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -45,18 +45,15 @@ fcntl_nonblock(struct sess *sess, int fd)
* The server (remote) side of the system.
* This parses the arguments given it by the remote shell then moves
* into receiver or sender mode depending upon those arguments.
- *
- * Pledges: unveil rpath, cpath, wpath, stdio, fattr.
- *
- * Pledges (dry-run): -cpath, -wpath, -fattr.
- * Pledges (!preserve_times): -fattr.
+ * Returns exit code 0 on success, 1 on failure, 2 on failure with
+ * incompatible protocols.
*/
int
rsync_server(const struct opts *opts, size_t argc, char *argv[])
{
struct sess sess;
int fdin = STDIN_FILENO,
- fdout = STDOUT_FILENO, rc = 0;
+ fdout = STDOUT_FILENO, rc = 1;
if (pledge("stdio unix rpath wpath cpath dpath fattr chown getpw unveil",
NULL) == -1)
@@ -161,7 +158,7 @@ rsync_server(const struct opts *opts, size_t argc, char *argv[])
WARNX(&sess, "data remains in read pipe");
#endif
- rc = 1;
+ rc = 0;
out:
return rc;
}
diff --git a/usr.bin/rsync/socket.c b/usr.bin/rsync/socket.c
index afb90e260ce..59089d769ac 100644
--- a/usr.bin/rsync/socket.c
+++ b/usr.bin/rsync/socket.c
@@ -1,4 +1,4 @@
-/* $Id: socket.c,v 1.19 2019/03/06 18:37:22 deraadt Exp $ */
+/* $Id: socket.c,v 1.20 2019/03/23 00:20:55 deraadt Exp $ */
/*
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -232,10 +232,9 @@ protocol_line(struct sess *sess, const char *host, const char *cp)
}
/*
- * Pledges: dns, inet, unix, unveil, rpath, cpath, wpath, stdio, fattr, chown.
- *
- * Pledges (dry-run): -unix, -cpath, -wpath, -fattr, -chown.
- * Pledges (!preserve_times): -fattr.
+ * Talk to a remote rsync://-enabled server sender.
+ * Returns exit code 0 on success, 1 on failure, 2 on failure with
+ * incompatible protocols.
*/
int
rsync_socket(const struct opts *opts, const struct fargs *f)
@@ -243,7 +242,7 @@ rsync_socket(const struct opts *opts, const struct fargs *f)
struct sess sess;
struct source *src = NULL;
size_t i, srcsz = 0;
- int sd = -1, rc = 0;
+ int sd = -1, rc = 1, c;
char **args, buf[BUFSIZ];
uint8_t byte;
@@ -286,11 +285,11 @@ rsync_socket(const struct opts *opts, const struct fargs *f)
assert(srcsz);
for (i = 0; i < srcsz; i++) {
- rc = inet_connect(&sess, &sd, &src[i], f->host);
- if (rc < 0) {
+ c = inet_connect(&sess, &sd, &src[i], f->host);
+ if (c < 0) {
ERRX1(&sess, "inet_connect");
goto out;
- } else if (rc > 0)
+ } else if (c > 0)
break;
}
@@ -357,10 +356,10 @@ rsync_socket(const struct opts *opts, const struct fargs *f)
if (buf[i - 1] == '\r')
buf[i - 1] = '\0';
- if ((rc = protocol_line(&sess, f->host, buf)) < 0) {
+ if ((c = protocol_line(&sess, f->host, buf)) < 0) {
ERRX1(&sess, "protocol_line");
goto out;
- } else if (rc > 0)
+ } else if (c > 0)
break;
}
@@ -407,6 +406,7 @@ rsync_socket(const struct opts *opts, const struct fargs *f)
"than our own (%" PRId32 " < %" PRId32 "): "
"this is not supported",
sess.rver, sess.lver);
+ rc = 2;
goto out;
}
@@ -431,7 +431,7 @@ rsync_socket(const struct opts *opts, const struct fargs *f)
WARNX(&sess, "data remains in read pipe");
#endif
- rc = 1;
+ rc = 0;
out:
free(src);
free(args);