criu/test/zdtm/static/deleted_dev.c
Adrian Reber 9a5ff1a075 zdtm: fix '"makedev" is defined by <sys/sysmacros.h>'
Compiling zdtm on the latest Fedora rawhide gives errors like this:

ns.c: In function ‘prepare_mntns’:
ns.c:122:13: error: In the GNU C Library, "makedev" is defined
 by <sys/sysmacros.h>. For historical compatibility, it is
 currently defined by <sys/types.h> as well, but we plan to
 remove this soon. To use "makedev", include <sys/sysmacros.h>
 directly. If you did not intend to use a system-defined macro
 "makedev", you should undefine it after including <sys/types.h>. [-Werror]
   if (mknod("/dev/ptmx", 0666 | S_IFCHR, makedev(5, 2)) == 0) {
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

This commit fixes those errors.

travis-ci: success for zdtm: fix '"makedev" is defined by <sys/sysmacros.h>'
Signed-off-by: Adrian Reber <areber@redhat.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2017-01-12 18:28:43 +03:00

76 lines
1.5 KiB
C

#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/sysmacros.h>
#include "zdtmtst.h"
const char *test_doc = "Check that we can migrate with a device special file "
"open and unlinked before migration";
const char *test_author = "Roman Kagan <rkagan@parallels.com>";
char *filename;
TEST_OPTION(filename, string, "file name", 1);
int main(int argc, char **argv)
{
int fd;
struct stat st;
/* /dev/null params - sure to exist in a VPS */
mode_t mode = S_IFCHR | 0700;
dev_t dev = makedev(1, 3);
test_init(argc, argv);
if (mknod(filename, mode, dev)) {
pr_perror("can't make device file \"%s\"", filename);
exit(1);
}
fd = open(filename, O_RDWR);
if (fd < 0) {
pr_perror("can't open %s", filename);
goto out;
}
if (unlink(filename) < 0) {
pr_perror("can't unlink %s", filename);
goto out;
}
test_daemon();
test_waitsig();
if (fstat(fd, &st) < 0) {
fail("can't stat %s: %m", filename);
goto out;
}
if (st.st_mode != mode || st.st_rdev != dev) {
fail("%s is no longer the device file we had", filename);
test_msg("mode %x want %x, dev %llx want %llx\n",
st.st_mode, mode,
(long long unsigned)st.st_rdev,
(long long unsigned)dev);
goto out;
}
if (close(fd) < 0) {
fail("can't close %s: %m", filename);
goto out;
}
if (unlink(filename) != -1 || errno != ENOENT) {
fail("file %s should have been deleted before migration: unlink: %m\n", filename);
goto out;
}
pass();
out:
close(fd);
unlink(filename);
return 0;
}