mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-07-23 18:19:39 +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>
107 lines
1.9 KiB
C
107 lines
1.9 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 external sockets\n";
|
|
const char *test_author = "Andrey Vagin <avagin@openvz.org";
|
|
|
|
#define SK_DATA "packet"
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
struct sockaddr_un addr;
|
|
unsigned int addrlen;
|
|
task_waiter_t lock;
|
|
|
|
char dir[] = "/tmp/zdtm.unix.sock.XXXXXX";
|
|
char *path;
|
|
pid_t pid;
|
|
int ret, sk;
|
|
|
|
if (mkdtemp(dir) < 0) {
|
|
pr_perror("mkdtemp(%s) failed", dir);
|
|
return 1;
|
|
}
|
|
addr.sun_family = AF_UNIX;
|
|
snprintf(addr.sun_path, sizeof(addr.sun_path),
|
|
"%s/%s", dir, "sock");
|
|
path = addr.sun_path;
|
|
addrlen = sizeof(addr.sun_family) + strlen(path);
|
|
|
|
task_waiter_init(&lock);
|
|
|
|
pid = fork();
|
|
if (pid < 0) {
|
|
pr_perror("fork() failed");
|
|
return 1;
|
|
} else if (pid == 0) {
|
|
char c;
|
|
test_ext_init(argc, argv);
|
|
|
|
sk = socket(AF_UNIX, SOCK_DGRAM, 0);
|
|
if (sk < 0) {
|
|
pr_perror("Can't create socket");
|
|
return 1;
|
|
}
|
|
ret = bind(sk, &addr, addrlen);
|
|
if (ret < 0) {
|
|
pr_perror("Can't bind socket to %s", path);
|
|
return 1;
|
|
}
|
|
chmod(dir, 0777);
|
|
chmod(path, 0777);
|
|
test_msg("The external socket %s\n", path);
|
|
task_waiter_complete(&lock, 1);
|
|
task_waiter_fini(&lock);
|
|
|
|
recv(sk, &c, sizeof(c), 0);
|
|
|
|
return 0;
|
|
}
|
|
|
|
task_waiter_wait4(&lock, 1);
|
|
task_waiter_fini(&lock);
|
|
|
|
test_init(argc, argv);
|
|
|
|
sk = socket(AF_UNIX, SOCK_DGRAM, 0);
|
|
if (sk < 0) {
|
|
pr_perror("Can't create socket");
|
|
return 1;
|
|
}
|
|
|
|
ret = connect(sk, &addr, addrlen);
|
|
if (ret < 0) {
|
|
pr_perror("Can't connect socket");
|
|
return 1;
|
|
}
|
|
|
|
|
|
test_daemon();
|
|
test_waitsig();
|
|
|
|
unlink(path);
|
|
unlink(dir);
|
|
|
|
ret = send(sk, "H", 1, 0);
|
|
if (ret != 1) {
|
|
pr_perror("Can't send a symbol");
|
|
fail();
|
|
return 1;
|
|
}
|
|
|
|
pass();
|
|
return 0;
|
|
}
|