On Tue, Dec 15, 2009 at 09:47:05AM +0100, Jim Meyering wrote:
Without this, and with updated gnulib, "make syntax-check"
would fail, complaining about exit(1), exit(0), exit(77).
It's no big deal, but slightly better for readability to use
EXIT_SUCCESS, EXIT_FAILURE, and the new, made-up/defined EXIT_AM_SKIP.
The only semantic change was to convert the "exit(2)" and "exit(3)"
in tests/conftest.c to "exit(EXIT_FAILURE);". That seems ok, since
the sole invoker of that test program cares only about success/failure,
and not about the precise exit code.
>From 8dba638f597b50f295f3f9b5628002f39b16d776 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Tue, 15 Dec 2009 09:43:29 +0100
Subject: [PATCH] avoid calling exit with a constant; use EXIT_* instead
This appeases a new gnulib-provided "syntax-check".
* daemon/libvirtd.c (main): Use EXIT_FAILURE, not 1.
* proxy/libvirt_proxy.c (main): Likewise, and EXIT_SUCCESS, not 0.
* tests/conftest.c (main): Likewise.
* tests/reconnect.c (main): Likewise.
* tests/testutils.h (EXIT_AM_SKIP): Define.
* tests/nodeinfotest.c (mymain): Use EXIT_AM_SKIP, not 77.
* tests/qemuargv2xmltest.c: Likewise.
* tests/qemuxml2xmltest.c: Likewise.
* tests/virshtest.c (mymain): Likewise.
---
daemon/libvirtd.c | 2 +-
proxy/libvirt_proxy.c | 10 +++++-----
tests/conftest.c | 10 +++++-----
tests/nodeinfotest.c | 2 +-
tests/qemuargv2xmltest.c | 2 +-
tests/qemuxml2xmltest.c | 2 +-
tests/reconnect.c | 10 +++++-----
tests/testutils.h | 4 +++-
tests/virshtest.c | 2 +-
9 files changed, 23 insertions(+), 21 deletions(-)
diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
index de6fc27..281a46a 100644
--- a/daemon/libvirtd.c
+++ b/daemon/libvirtd.c
@@ -3036,7 +3036,7 @@ int main(int argc, char **argv) {
default:
fprintf (stderr, "libvirtd: internal error: unknown flag: %c\n",
c);
- exit (1);
+ exit (EXIT_FAILURE);
}
}
diff --git a/proxy/libvirt_proxy.c b/proxy/libvirt_proxy.c
index e5298fd..375966c 100644
--- a/proxy/libvirt_proxy.c
+++ b/proxy/libvirt_proxy.c
@@ -816,14 +816,14 @@ int main(int argc, char **argv) {
persist = 1;
} else {
usage(argv[0]);
- exit(1);
+ exit(EXIT_FAILURE);
}
}
if (geteuid() != 0) {
fprintf(stderr, "%s must be run as root or suid\n", argv[0]);
- /* exit(1); */
+ /* exit(EXIT_FAILURE); */
}
/*
@@ -838,19 +838,19 @@ int main(int argc, char **argv) {
* failure.
*/
if (proxyListenUnixSocket(PROXY_SOCKET_PATH) < 0)
- exit(0);
+ exit(EXIT_SUCCESS);
if (proxyInitXen() == 0)
proxyMainLoop();
sleep(1);
proxyCloseUnixSocket();
- exit(0);
+ exit(EXIT_SUCCESS);
}
#else /* WITHOUT_XEN */
int main(void) {
fprintf(stderr, "libvirt was compiled without Xen support\n");
- exit(1);
+ exit(EXIT_FAILURE);
}
#endif /* WITH_XEN */
diff --git a/tests/conftest.c b/tests/conftest.c
index d265de2..a7977bb 100644
--- a/tests/conftest.c
+++ b/tests/conftest.c
@@ -15,23 +15,23 @@ int main(int argc, char **argv) {
if (argc != 2) {
fprintf(stderr, "Usage: %s conf_file\n", argv[0]);
- exit(1);
+ exit(EXIT_FAILURE);
}
conf = virConfReadFile(argv[1], 0);
if (conf == NULL) {
fprintf(stderr, "Failed to process %s\n", argv[1]);
- exit(2);
+ exit(EXIT_FAILURE);
}
ret = virConfWriteMem(&buffer[0], &len, conf);
if (ret < 0) {
fprintf(stderr, "Failed to serialize %s back\n", argv[1]);
- exit(3);
+ exit(EXIT_FAILURE);
}
virConfFree(conf);
if (fwrite(buffer, 1, len, stdout) != len) {
fprintf(stderr, "Write failed: %s\n", strerror (errno));
- exit(1);
+ exit(EXIT_FAILURE);
}
- exit(0);
+ exit(EXIT_SUCCESS);
}
diff --git a/tests/nodeinfotest.c b/tests/nodeinfotest.c
index 608a056..4cb248a 100644
--- a/tests/nodeinfotest.c
+++ b/tests/nodeinfotest.c
@@ -15,7 +15,7 @@
static int
mymain(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
{
- exit (77); /* means 'test skipped' for automake */
+ exit (EXIT_AM_SKIP);
}
#else
diff --git a/tests/qemuargv2xmltest.c b/tests/qemuargv2xmltest.c
index 5602df0..7f62bac 100644
--- a/tests/qemuargv2xmltest.c
+++ b/tests/qemuargv2xmltest.c
@@ -232,6 +232,6 @@ VIRT_TEST_MAIN(mymain)
#else
-int main (void) { return (77); /* means 'test skipped' for automake */ }
+int main (void) { return (EXIT_AM_SKIP); }
#endif /* WITH_QEMU */
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 793900c..e5900a2 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -146,6 +146,6 @@ VIRT_TEST_MAIN(mymain)
#else
-int main (void) { exit (77); /* means 'test skipped' to automake */ }
+int main (void) { exit (EXIT_AM_SKIP); }
#endif /* WITH_QEMU */
diff --git a/tests/reconnect.c b/tests/reconnect.c
index 33af2cc..63877fc 100644
--- a/tests/reconnect.c
+++ b/tests/reconnect.c
@@ -24,12 +24,12 @@ int main(void) {
}
if (conn == NULL) {
fprintf(stderr, "First virConnectOpen() failed\n");
- exit(1);
+ exit(EXIT_FAILURE);
}
dom = virDomainLookupByID(conn, id);
if (dom == NULL) {
fprintf(stderr, "First lookup for domain %d failed\n", id);
- exit(1);
+ exit(EXIT_FAILURE);
}
virDomainFree(dom);
virConnectClose(conn);
@@ -39,16 +39,16 @@ int main(void) {
conn = virConnectOpen(NULL);
if (conn == NULL) {
fprintf(stderr, "Second virConnectOpen() failed\n");
- exit(1);
+ exit(EXIT_FAILURE);
}
dom = virDomainLookupByID(conn, id);
if (dom == NULL) {
fprintf(stderr, "Second lookup for domain %d failed\n", id);
- exit(1);
+ exit(EXIT_FAILURE);
}
virDomainFree(dom);
virConnectClose(conn);
printf("OK\n");
- exit(0);
+ exit(EXIT_SUCCESS);
}
diff --git a/tests/testutils.h b/tests/testutils.h
index aef1179..e5d5750 100644
--- a/tests/testutils.h
+++ b/tests/testutils.h
@@ -1,7 +1,7 @@
/*
* utils.c: test utils
*
- * Copyright (C) 2005, 2008 Red Hat, Inc.
+ * Copyright (C) 2005, 2008-2009 Red Hat, Inc.
*
* See COPYING.LIB for the License of this software
*
@@ -13,6 +13,8 @@
#include <stdio.h>
+#define EXIT_AM_SKIP 77 /* tell Automake we're skipping a test */
+
double virtTestCountAverage(double *items,
int nitems);
diff --git a/tests/virshtest.c b/tests/virshtest.c
index ef760e2..ad3e2fc 100644
--- a/tests/virshtest.c
+++ b/tests/virshtest.c
@@ -231,7 +231,7 @@ mymain(int argc, char **argv)
abs_srcdir = getcwd(cwd, sizeof(cwd));
#ifdef WIN32
- exit (77); /* means 'test skipped' for automake */
+ exit (EXIT_AM_SKIP);
#endif
snprintf(buffer, PATH_MAX-1,
"test://%s/../examples/xml/test/testnode.xml", abs_srcdir);
--
ACK
Daniel
--
|: Red Hat, Engineering, London -o-
http://people.redhat.com/berrange/ :|
|:
http://libvirt.org -o-
http://virt-manager.org -o-
http://ovirt.org :|
|:
http://autobuild.org -o-
http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|