mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-07-25 02:58:54 +00:00
After the commit
02c763939c10 ("test/zdtm: unify common code")
CFLAGS with -D_GNU_SOURCE defined in the top Makefile
are being passed to tests Makefiles.
As _GNU_SOURCE is also defined by tests, that resulted in
zdtm tests build failures:
make[2]: Entering directory `/home/criu/test/zdtm/lib'
CC test.o
test.c:1:0: error: "_GNU_SOURCE" redefined [-Werror]
#define _GNU_SOURCE
^
<command-line>:0:0: note: this is the location of the previous definition
cc1: all warnings being treated as errors
make[2]: *** [test.o] Error 1
However, we didn't catch this in time by Travis-CI, as zdtm.py doesn't
do `make zdtm`, rather it does `make -C test/zdtm/{lib,static,transition}`.
By calling middle makefile this way, it doesn't have _GNU_SOURCE in
CFLAGS from top-Makefile.
I think the right thing to do here - is following CRIU's way:
rely on definition of _GNU_SOURCE by Makefiles.
This patch is almost fully generated with
find test/zdtm/ -name '*.c' -type f \
-exec sed -i '/define _GNU_SOURCE/{n;/^$/d;}' '{}' \; \
-exec sed -i '/define _GNU_SOURCE/d' '{}' \;
With an exception for adding -D_GNU_SOURCE in tests Makefile.inc for
keeping the same behaviour for zdtm.py.
Also changed utsname.c to use utsname::domainname, rather private
utsname::__domainname, as now it's uncovered (from sys/utsname.h):
> struct utsname
> {
...
> # ifdef __USE_GNU
> char domainname[_UTSNAME_DOMAIN_LENGTH];
> # else
> char __domainname[_UTSNAME_DOMAIN_LENGTH];
> # endif
Reported-by: Adrian Reber <areber@redhat.com>
Cc: Kir Kolyshkin <kir@openvz.org>
Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
148 lines
3.2 KiB
C
148 lines
3.2 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <ctype.h>
|
|
#include <errno.h>
|
|
#include <unistd.h>
|
|
#include <sys/types.h>
|
|
#include <sys/socket.h>
|
|
#include <sys/wait.h>
|
|
#include <sys/un.h>
|
|
#include <sys/stat.h>
|
|
#include <limits.h>
|
|
#include <fcntl.h>
|
|
|
|
#include "zdtmtst.h"
|
|
|
|
const char *test_doc = "Test unix sockets shutdown";
|
|
const char *test_author = "Pavel Emelyanov <xemul@parallels.com>";
|
|
|
|
#define fin(msg) do { pr_perror(msg); exit(1); } while (0)
|
|
#define ffin(msg) do { fail(msg); exit(1); } while (0)
|
|
|
|
#define TEST_MSG "test-message"
|
|
static char buf[sizeof(TEST_MSG)];
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
int spu[2], spb[2], dpu[2], dpb[2], dpd[2];
|
|
int ret;
|
|
|
|
test_init(argc, argv);
|
|
|
|
signal(SIGPIPE, SIG_IGN);
|
|
|
|
/* spu -- stream pair, unidirectional shutdown */
|
|
if (socketpair(PF_UNIX, SOCK_STREAM, 0, spu) < 0)
|
|
fin("no stream pair 1");
|
|
|
|
if (shutdown(spu[0], SHUT_RD) < 0)
|
|
fin("no stream shutdown 1");
|
|
|
|
/* spb -- stream pair, bidirectional shutdown */
|
|
if (socketpair(PF_UNIX, SOCK_STREAM, 0, spb) < 0)
|
|
fin("no stream pair 2");
|
|
|
|
if (shutdown(spb[0], SHUT_RDWR) < 0)
|
|
fin("no stream shutdown 2");
|
|
|
|
/* dpu -- dgram pair, one end read shutdown */
|
|
if (socketpair(PF_UNIX, SOCK_DGRAM, 0, dpu) < 0)
|
|
fin("no dgram pair 1");
|
|
|
|
if (shutdown(dpu[0], SHUT_RD) < 0)
|
|
fin("no dgram shutdown 1");
|
|
|
|
/* dpb -- dgram pair, one end read-write shutdown */
|
|
if (socketpair(PF_UNIX, SOCK_DGRAM, 0, dpb) < 0)
|
|
fin("no dgram pair 2");
|
|
|
|
if (shutdown(dpb[0], SHUT_RDWR) < 0)
|
|
fin("no dgram shutdown 2");
|
|
|
|
/* dpd -- dgram pair, one end write shutdown with data */
|
|
if (socketpair(PF_UNIX, SOCK_DGRAM, 0, dpd) < 0)
|
|
fin("no dgram pair 3");
|
|
|
|
if (write(dpd[0], TEST_MSG, sizeof(TEST_MSG)) < 0)
|
|
fin("no dgram write");
|
|
|
|
if (shutdown(dpd[0], SHUT_WR) < 0)
|
|
fin("no dgram shutdown 3");
|
|
|
|
test_daemon();
|
|
test_waitsig();
|
|
|
|
/*
|
|
* spu -- check that one direction is blocked and
|
|
* the other one is not
|
|
*/
|
|
|
|
ret = write(spu[0], TEST_MSG, sizeof(TEST_MSG));
|
|
if (ret < 0)
|
|
ffin("SU shutdown broken 1");
|
|
|
|
ret = read(spu[1], buf, sizeof(buf));
|
|
if (ret < 0)
|
|
ffin("SU shutdown broken 2");
|
|
|
|
ret = write(spu[1], TEST_MSG, sizeof(TEST_MSG));
|
|
if (ret >= 0)
|
|
ffin("SU shutdown broken 3");
|
|
|
|
/*
|
|
* spb -- check that both ends are off
|
|
*/
|
|
|
|
ret = write(spb[0], TEST_MSG, sizeof(TEST_MSG));
|
|
if (ret >= 0)
|
|
ffin("SB shutdown broken 1");
|
|
|
|
ret = write(spb[1], TEST_MSG, sizeof(TEST_MSG));
|
|
if (ret >= 0)
|
|
ffin("SB shutdown broken 2");
|
|
|
|
/*
|
|
* dpu -- check that one direction works, and
|
|
* the other does not
|
|
*/
|
|
|
|
ret = write(dpu[0], TEST_MSG, sizeof(TEST_MSG));
|
|
if (ret < 0)
|
|
ffin("DU shutdown broken 1");
|
|
|
|
ret = read(dpu[1], buf, sizeof(buf));
|
|
if (ret < 0)
|
|
ffin("DU shutdown broken 2");
|
|
|
|
ret = write(dpu[1], TEST_MSG, sizeof(TEST_MSG));
|
|
if (ret >= 0)
|
|
ffin("DU shutdown broken 3");
|
|
|
|
/*
|
|
* dpb -- check that both ends are read
|
|
*/
|
|
|
|
ret = write(dpb[0], TEST_MSG, sizeof(TEST_MSG));
|
|
if (ret >= 0)
|
|
ffin("DB shutdown broken 1");
|
|
|
|
ret = write(dpb[1], TEST_MSG, sizeof(TEST_MSG));
|
|
if (ret >= 0)
|
|
ffin("DB shutdown broken 2");
|
|
|
|
/*
|
|
* dpd -- check that data is in there, but can't
|
|
* feed more
|
|
*/
|
|
|
|
ret = read(dpd[1], buf, sizeof(buf));
|
|
if (ret < 0)
|
|
ffin("DD shutdown nodata");
|
|
|
|
ret = write(dpd[0], TEST_MSG, sizeof(buf));
|
|
if (ret >= 0)
|
|
ffin("DB shutdown broken");
|
|
|
|
pass();
|
|
return 0;
|
|
}
|