Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/lib/librumphijack Return from main() and use EXIT_FAIL...



details:   https://anonhg.NetBSD.org/src/rev/969d4a7b60be
branches:  trunk
changeset: 778852:969d4a7b60be
user:      jruoho <jruoho%NetBSD.org@localhost>
date:      Tue Apr 17 09:23:21 2012 +0000

description:
Return from main() and use EXIT_FAILURE/EXIT_SUCCESS from stdlib(3).

diffstat:

 tests/lib/librumphijack/h_client.c |  41 +++++++++++++++--------------
 tests/lib/librumphijack/h_cwd.c    |  51 +++++++++++++++++++------------------
 tests/lib/librumphijack/h_netget.c |  22 ++++++++--------
 3 files changed, 58 insertions(+), 56 deletions(-)

diffs (truncated from 304 to 300 lines):

diff -r 71cfca95c6e6 -r 969d4a7b60be tests/lib/librumphijack/h_client.c
--- a/tests/lib/librumphijack/h_client.c        Tue Apr 17 09:12:08 2012 +0000
+++ b/tests/lib/librumphijack/h_client.c        Tue Apr 17 09:23:21 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: h_client.c,v 1.6 2011/03/14 15:56:40 pooka Exp $       */
+/*     $NetBSD: h_client.c,v 1.7 2012/04/17 09:23:21 jruoho Exp $      */
 
 /*
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -57,19 +57,19 @@
                tv.tv_usec = 1;
 
                if (pipe(pipefd) == -1)
-                       err(1, "pipe");
+                       err(EXIT_FAILURE, "pipe");
                FD_ZERO(&rfds);
                FD_SET(pipefd[0], &rfds);
 
                rv = select(pipefd[0]+1, &rfds, NULL, NULL, &tv);
                if (rv == -1)
-                       err(1, "select");
+                       err(EXIT_FAILURE, "select");
                if (rv != 0)
-                       errx(1, "select succesful");
+                       errx(EXIT_FAILURE, "select succesful");
 
                if (FD_ISSET(pipefd[0], &rfds))
-                       errx(1, "stdin fileno is still set");
-               exit(0);
+                       errx(EXIT_FAILURE, "stdin fileno is still set");
+               return EXIT_SUCCESS;
        } else if (strcmp(argv[1], "select_allunset") == 0) {
                fd_set fds;
                struct timeval tv;
@@ -82,24 +82,24 @@
 
                rv = select(100, &fds, &fds, &fds, &tv);
                if (rv == -1)
-                       err(1, "select");
+                       err(EXIT_FAILURE, "select");
                if (rv != 0)
-                       errx(1, "select succesful");
+                       errx(EXIT_FAILURE, "select succesful");
 
                rv = select(0, NULL, NULL, NULL, &tv);
                if (rv == -1)
-                       err(1, "select2");
+                       err(EXIT_FAILURE, "select2");
                if (rv != 0)
-                       errx(1, "select2 succesful");
+                       errx(EXIT_FAILURE, "select2 succesful");
 
-               exit(0);
+               return EXIT_SUCCESS;
        } else if (strcmp(argv[1], "invafd") == 0) {
                struct pollfd pfd[2];
                int fd, rv;
 
                fd = open("/rump/dev/null", O_RDWR);
                if (fd == -1)
-                       err(1, "open");
+                       err(EXIT_FAILURE, "open");
                close(fd);
 
                pfd[0].fd = STDIN_FILENO;
@@ -108,26 +108,27 @@
                pfd[1].events = POLLIN;
 
                if ((rv = poll(pfd, 2, INFTIM)) != 1)
-                       errx(1, "poll unexpected rv %d (%d)", rv, errno);
+                       errx(EXIT_FAILURE, "poll unexpected rv %d (%d)",
+                           rv, errno);
                if (pfd[1].revents != POLLNVAL || pfd[0].revents != 0)
-                       errx(1, "poll unexpected revents");
+                       errx(EXIT_FAILURE, "poll unexpected revents");
 
-               exit(0);
+               return EXIT_SUCCESS;
        } else if (strcmp(argv[1], "fdoff8") == 0) {
                int fd;
 
                do
                        if ((fd = open("/dev/null", O_RDWR)) == -1)
-                               err(1, "open1");
+                               err(EXIT_FAILURE, "open1");
                while (fd < 7);
                fd = open("/dev/null", O_RDWR);
                if (fd != -1 || errno != ENFILE)
-                       errx(1, "unexpected fd8 %d %d", fd, errno);
+                       errx(EXIT_FAILURE, "unexpected fd8 %d %d", fd, errno);
                if (fcntl(0, F_MAXFD) != 7)
-                       errx(1, "fd leak?");
+                       errx(EXIT_FAILURE, "fd leak?");
                if ((fd = open("/rump/dev/null", O_RDWR)) != 8)
-                       errx(1, "rump open %d %d", fd, errno);
-               exit(0);
+                       errx(EXIT_FAILURE, "rump open %d %d", fd, errno);
+               return EXIT_SUCCESS;
        } else {
                return ENOTSUP;
        }
diff -r 71cfca95c6e6 -r 969d4a7b60be tests/lib/librumphijack/h_cwd.c
--- a/tests/lib/librumphijack/h_cwd.c   Tue Apr 17 09:12:08 2012 +0000
+++ b/tests/lib/librumphijack/h_cwd.c   Tue Apr 17 09:23:21 2012 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: h_cwd.c,v 1.2 2011/02/19 19:57:28 pooka Exp $ */
+/*      $NetBSD: h_cwd.c,v 1.3 2012/04/17 09:23:21 jruoho Exp $        */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -33,6 +33,7 @@
 #include <err.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 
@@ -58,7 +59,7 @@
 {
 
        if (chdir(path) == -1)
-               err(1, "%s", errmsg);
+               err(EXIT_FAILURE, "%s", errmsg);
 }
 
 static void
@@ -68,9 +69,9 @@
 
        fd = open(path, O_RDONLY);
        if (fd == -1)
-               err(1, "open %s", errmsg);
+               err(EXIT_FAILURE, "open %s", errmsg);
        if (fchdir(fd) == -1)
-               err(1, "fchdir %s", errmsg);
+               err(EXIT_FAILURE, "fchdir %s", errmsg);
        close(fd);
 }
 static void (*thechdir)(const char *, const char *);
@@ -81,44 +82,44 @@
 
        thechdir(prefix, "chdir1");
        if (getcwd(pwd, sizeof(pwd)) == NULL)
-               err(1, "getcwd1");
+               err(EXIT_FAILURE, "getcwd1");
        if (strcmp(pwd, prefix) != 0)
-               errx(1, "strcmp1");
+               errx(EXIT_FAILURE, "strcmp1");
 
        if (mkdir("dir", 0777) == -1)
-               err(1, "mkdir2");
+               err(EXIT_FAILURE, "mkdir2");
        thechdir("dir", "chdir2");
        if (getcwd(pwd, sizeof(pwd)) == NULL)
-               err(1, "getcwd2");
+               err(EXIT_FAILURE, "getcwd2");
        if (strcmp(pwd, makepath("dir")) != 0)
-               errx(1, "strcmp2");
+               errx(EXIT_FAILURE, "strcmp2");
 
        if (mkdir("dir", 0777) == -1)
-               err(1, "mkdir3");
+               err(EXIT_FAILURE, "mkdir3");
        thechdir("dir", "chdir3");
        if (getcwd(pwd, sizeof(pwd)) == NULL)
-               err(1, "getcwd3");
+               err(EXIT_FAILURE, "getcwd3");
        if (strcmp(pwd, makepath("dir/dir")) != 0)
-               errx(1, "strcmp3");
+               errx(EXIT_FAILURE, "strcmp3");
 
        thechdir("..", "chdir4");
        if (getcwd(pwd, sizeof(pwd)) == NULL)
-               err(1, "getcwd4");
+               err(EXIT_FAILURE, "getcwd4");
        if (strcmp(pwd, makepath("dir")) != 0)
-               errx(1, "strcmp4");
+               errx(EXIT_FAILURE, "strcmp4");
 
 
        thechdir("../../../../../../..", "chdir5");
        if (getcwd(pwd, sizeof(pwd)) == NULL)
-               err(1, "getcwd5");
+               err(EXIT_FAILURE, "getcwd5");
        if (strcmp(pwd, prefix) != 0)
-               errx(1, "strcmp5");
+               errx(EXIT_FAILURE, "strcmp5");
 
        thechdir("/", "chdir6");
        if (getcwd(pwd, sizeof(pwd)) == NULL)
-               err(1, "getcwd6");
+               err(EXIT_FAILURE, "getcwd6");
        if (strcmp(pwd, "/") != 0)
-               errx(1, "strcmp6");
+               errx(EXIT_FAILURE, "strcmp6");
 }
 
 static void
@@ -127,18 +128,18 @@
 
        thechdir(prefix, "chdir1");
        if (mkdir("adir", 0777) == -1)
-               err(1, "mkdir1");
+               err(EXIT_FAILURE, "mkdir1");
        if (mkdir("anotherdir", 0777) == -1)
-               err(1, "mkdir2");
+               err(EXIT_FAILURE, "mkdir2");
 
        if (symlink("/adir", "anotherdir/lincthesink") == -1)
-               err(1, "symlink");
+               err(EXIT_FAILURE, "symlink");
 
        thechdir("anotherdir/lincthesink", "chdir2");
        if (getcwd(pwd, sizeof(pwd)) == NULL)
-               err(1, "getcwd");
+               err(EXIT_FAILURE, "getcwd");
        if (strcmp(pwd, makepath("adir")) != 0)
-               errx(1, "strcmp");
+               errx(EXIT_FAILURE, "strcmp");
 }
 
 int
@@ -156,12 +157,12 @@
        else if (strcmp(argv[3], "fchdir") == 0)
                thechdir = dofchdir;
        else
-               errx(1, "invalid chdir type");
+               errx(EXIT_FAILURE, "invalid chdir type");
 
        if (strcmp(argv[2], "simple") == 0)
                simple();
        if (strcmp(argv[2], "symlink") == 0)
                symlinktest();
 
-       return 0;
+       return EXIT_SUCCESS;
 }
diff -r 71cfca95c6e6 -r 969d4a7b60be tests/lib/librumphijack/h_netget.c
--- a/tests/lib/librumphijack/h_netget.c        Tue Apr 17 09:12:08 2012 +0000
+++ b/tests/lib/librumphijack/h_netget.c        Tue Apr 17 09:23:21 2012 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: h_netget.c,v 1.1 2011/02/06 18:44:29 pooka Exp $      */
+/*      $NetBSD: h_netget.c,v 1.2 2012/04/17 09:23:21 jruoho Exp $     */
 
 /*-
  * Copyright (c) 2011 Antti Kantee.  All Rights Reserved.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: h_netget.c,v 1.1 2011/02/06 18:44:29 pooka Exp $");
+__RCSID("$NetBSD: h_netget.c,v 1.2 2012/04/17 09:23:21 jruoho Exp $");
 
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -61,12 +61,12 @@
        if (argc != 4) {
                fprintf(stderr, "usage: %s address port savefile\n",
                    getprogname());
-               exit(1);
+               return EXIT_FAILURE;
        }
 
        s = socket(PF_INET, SOCK_STREAM, 0);
        if (s == -1)
-               err(1, "socket");
+               err(EXIT_FAILURE, "socket");
 
        memset(&sin, 0, sizeof(sin));
        sin.sin_len = sizeof(sin);
@@ -76,26 +76,26 @@
 
        fd = open(argv[3], O_CREAT | O_RDWR, 0644);
        if (fd == -1)
-               err(1, "open");
+               err(EXIT_FAILURE, "open");
        if (ftruncate(fd, 0) == -1)
-               err(1, "ftruncate savefile");
+               err(EXIT_FAILURE, "ftruncate savefile");
 
        if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) == -1)
-               err(1, "connect");
+               err(EXIT_FAILURE, "connect");
 
        if (write(s, GETSTR, strlen(GETSTR)) != strlen(GETSTR))
-               err(1, "socket write");
+               err(EXIT_FAILURE, "socket write");
 
        for (;;) {
                n = read(s, buf, sizeof(buf));
                if (n == 0)
                        break;
                if (n == -1)
-                       err(1, "socket read");
+                       err(EXIT_FAILURE, "socket read");
 
                if (write(fd, buf, n) != n)
-                       err(1, "write file");
+                       err(EXIT_FAILURE, "write file");
        }



Home | Main Index | Thread Index | Old Index