From aa73cae19608873cc4d1f712c4a0f8f8435f1ffa Mon Sep 17 00:00:00 2001 From: christos Date: Sun, 27 Feb 2005 01:34:07 +0000 Subject: [PATCH] Add a few lines of code to print the output from the remotely executed program. --- libexec/rexecd/unit-tests/rexec.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/libexec/rexecd/unit-tests/rexec.c b/libexec/rexecd/unit-tests/rexec.c index fa7c907f95ab..d354cf32345c 100644 --- a/libexec/rexecd/unit-tests/rexec.c +++ b/libexec/rexecd/unit-tests/rexec.c @@ -1,4 +1,4 @@ -/* $NetBSD: rexec.c,v 1.1 2005/02/23 01:27:32 christos Exp $ */ +/* $NetBSD: rexec.c,v 1.2 2005/02/27 01:34:07 christos Exp $ */ /*- * Copyright (c) 2005 The NetBSD Foundation, Inc. @@ -36,7 +36,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: rexec.c,v 1.1 2005/02/23 01:27:32 christos Exp $"); +__RCSID("$NetBSD: rexec.c,v 1.2 2005/02/27 01:34:07 christos Exp $"); #include #include @@ -51,12 +51,14 @@ int rexec(char **, int, char *, char *, char *, int *); int main(int argc, char **argv) { - int c; + int c, s; + ssize_t nr; struct servent *sv; char *host = __UNCONST("localhost"); char *user = __UNCONST("root"); char *pass = __UNCONST("h@x0R"); char *cmd = __UNCONST("ls"); + char line[BUFSIZ]; while ((c = getopt(argc, argv, "h:u:p:c:")) != -1) switch (c) { @@ -79,8 +81,12 @@ main(int argc, char **argv) if ((sv = getservbyname("exec", "tcp")) == NULL) errx(1, "Cannot find service exec/tcp"); - if (rexec(&host, sv->s_port, user, pass, cmd, NULL) == -1) + if ((s = rexec(&host, sv->s_port, user, pass, cmd, NULL)) == -1) return 1; + while ((nr = read(s, line, sizeof(line))) > 0) + (void)write(STDOUT_FILENO, line, nr); + if (nr == -1) + err(1, "read failed"); return 0; }