mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-07-23 10:09:57 +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>
95 lines
1.6 KiB
C
95 lines
1.6 KiB
C
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <stdarg.h>
|
|
#include <errno.h>
|
|
#include <unistd.h>
|
|
#include <limits.h>
|
|
|
|
#include "zdtmtst.h"
|
|
#include "fs.h"
|
|
|
|
mnt_info_t *mnt_info_alloc(void)
|
|
{
|
|
mnt_info_t *m = malloc(sizeof(*m));
|
|
if (m)
|
|
memset(m, 0, sizeof(*m));
|
|
return m;
|
|
}
|
|
|
|
void mnt_info_free(mnt_info_t **m)
|
|
{
|
|
if (m && *m) {
|
|
free(*m);
|
|
*m = NULL;
|
|
}
|
|
}
|
|
|
|
mnt_info_t *get_cwd_mnt_info(void)
|
|
{
|
|
int mnt_id, parent_mnt_id;
|
|
unsigned int kmaj, kmin;
|
|
char str[1024], *cwd;
|
|
int ret;
|
|
FILE *f;
|
|
|
|
mnt_info_t *m = NULL;
|
|
|
|
char mountpoint[PATH_MAX];
|
|
char root[PATH_MAX];
|
|
|
|
char *fsname = NULL;
|
|
size_t len = 0, best_len = 0;
|
|
|
|
f = fopen("/proc/self/mountinfo", "r");
|
|
if (!f)
|
|
return NULL;
|
|
|
|
cwd = get_current_dir_name();
|
|
if (!cwd)
|
|
goto err;
|
|
|
|
m = mnt_info_alloc();
|
|
if (!m)
|
|
goto err;
|
|
|
|
while (fgets(str, sizeof(str), f)) {
|
|
char *hyphen = strchr(str, '-');
|
|
ret = sscanf(str, "%i %i %u:%u %s %s",
|
|
&mnt_id, &parent_mnt_id,
|
|
&kmaj, &kmin,
|
|
root, mountpoint);
|
|
if (ret != 6 || !hyphen)
|
|
goto err;
|
|
ret = sscanf(hyphen + 1, " %ms", &fsname);
|
|
if (ret != 1)
|
|
goto err;
|
|
|
|
len = strlen(mountpoint);
|
|
if (!strncmp(mountpoint, cwd, len)) {
|
|
if (len > best_len) {
|
|
best_len = len;
|
|
|
|
m->mnt_id = mnt_id;
|
|
m->parent_mnt_id = parent_mnt_id;
|
|
m->s_dev = MKKDEV(kmaj, kmin);
|
|
|
|
strncpy(m->root, root, sizeof(m->root));
|
|
strncpy(m->mountpoint, mountpoint, sizeof(m->mountpoint));
|
|
strncpy(m->fsname, fsname, sizeof(m->fsname));
|
|
}
|
|
}
|
|
|
|
free(fsname);
|
|
fsname = NULL;
|
|
}
|
|
|
|
out:
|
|
free(cwd);
|
|
fclose(f);
|
|
|
|
return m;
|
|
|
|
err:
|
|
mnt_info_free(&m);
|
|
goto out;
|
|
}
|