criu/test/zdtm/static/clone_fs.c
Dmitry Safonov 3bdaf5a9d8 zdtm: rely on -D_GNU_SOURCE passed from Makefiles
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>
2017-04-11 09:01:08 +03:00

104 lines
1.9 KiB
C

#include <stdlib.h>
#include <syscall.h>
#include <pthread.h>
#include "zdtmtst.h"
const char *test_doc = "Check that shared FS is migrated properly";
const char *test_author = "Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>";
enum kcmp_type {
KCMP_FILE,
KCMP_VM,
KCMP_FILES,
KCMP_FS,
KCMP_SIGHAND,
KCMP_IO,
KCMP_SYSVSEM,
KCMP_TYPES,
};
static int kcmp(int type, pid_t pid1, pid_t pid2, unsigned long idx1, unsigned long idx2)
{
int ret;
ret = syscall(SYS_kcmp, pid1, pid2, type, idx1, idx2);
switch (ret) {
case 0:
break;
case 1:
case 2:
test_msg("FS for pids %d and %d doesn't match: %d\n", pid1, pid2, ret);
break;
case -1:
pr_err("kcmp (type: %d, pid1: %d, pid2: %d, "
"idx1: %ld, idx2: %ld) failed: %d\n",
type, pid1, pid2, idx1, idx2, errno);
break;
default:
pr_err("kcmp (type: %d, pid1: %d, pid2: %d, "
"idx1: %ld, idx2: %ld) returned %d\n",
type, pid1, pid2, idx1, idx2, ret);
break;
}
return ret;
}
#define gettid(code) \
syscall(__NR_gettid)
static pthread_mutex_t init_lock;
static pthread_mutex_t exit_lock;
static void *thread_func(void *tid2)
{
*(int *)tid2 = gettid();
pthread_mutex_unlock(&init_lock);
pthread_mutex_lock(&exit_lock);
return NULL;
}
int main(int argc, char **argv)
{
pid_t tid;
int ret;
pthread_t th;
test_init(argc, argv);
pthread_mutex_init(&init_lock, NULL);
pthread_mutex_lock(&init_lock);
pthread_mutex_init(&exit_lock, NULL);
pthread_mutex_lock(&exit_lock);
if (pthread_create(&th, NULL, thread_func, &tid)) {
fail("Can't pthread_create");
return 1;
}
pthread_mutex_lock(&init_lock);
ret = kcmp(KCMP_FS, gettid(), tid, 0, 0);
if (ret)
exit(1);
test_daemon();
test_waitsig();
ret = kcmp(KCMP_FS, gettid(), tid, 0, 0);
if (ret) {
fail();
exit(1);
}
pthread_mutex_unlock(&exit_lock);
pthread_join(th, NULL);
pass();
return 0;
}