|
Packit |
6c4009 |
/* Test sysconf with an empty chroot.
|
|
Packit |
6c4009 |
Copyright (C) 2017-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <stdio.h>
|
|
Packit |
6c4009 |
#include <stdlib.h>
|
|
Packit |
6c4009 |
#include <support/check.h>
|
|
Packit |
6c4009 |
#include <support/namespace.h>
|
|
Packit |
6c4009 |
#include <support/support.h>
|
|
Packit |
6c4009 |
#include <support/temp_file.h>
|
|
Packit |
6c4009 |
#include <support/test-driver.h>
|
|
Packit |
6c4009 |
#include <support/xunistd.h>
|
|
Packit |
6c4009 |
#include <unistd.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Check for an SMP system in a forked process, so that the parent
|
|
Packit |
6c4009 |
process does not cache the value. */
|
|
Packit |
6c4009 |
static void
|
|
Packit |
6c4009 |
is_smp_callback (void *closure)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
bool *result = closure;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
long cpus = sysconf (_SC_NPROCESSORS_ONLN);
|
|
Packit |
6c4009 |
TEST_VERIFY_EXIT (cpus > 0);
|
|
Packit |
6c4009 |
*result = cpus != 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static bool
|
|
Packit |
6c4009 |
is_smp (void)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
bool *result = support_shared_allocate (sizeof (*result));
|
|
Packit |
6c4009 |
support_isolate_in_subprocess (is_smp_callback, result);
|
|
Packit |
6c4009 |
bool result_copy = *result;
|
|
Packit |
6c4009 |
support_shared_free (result);
|
|
Packit |
6c4009 |
return result_copy;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static char *path_chroot;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Prepare an empty directory, to be used as a chroot. */
|
|
Packit |
6c4009 |
static void
|
|
Packit |
6c4009 |
prepare (int argc, char **argv)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
path_chroot = xasprintf ("%s/tst-resolv-res_init-XXXXXX", test_dir);
|
|
Packit |
6c4009 |
if (mkdtemp (path_chroot) == NULL)
|
|
Packit |
6c4009 |
FAIL_EXIT1 ("mkdtemp (\"%s\"): %m", path_chroot);
|
|
Packit |
6c4009 |
add_temp_file (path_chroot);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* The actual test. Run it in a subprocess, so that the test harness
|
|
Packit |
6c4009 |
can remove the temporary directory in --direct mode. */
|
|
Packit |
6c4009 |
static void
|
|
Packit |
6c4009 |
chroot_callback (void *closure)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
xchroot (path_chroot);
|
|
Packit |
6c4009 |
long cpus = sysconf (_SC_NPROCESSORS_ONLN);
|
|
Packit |
6c4009 |
printf ("info: sysconf (_SC_NPROCESSORS_ONLN) in chroot: %ld\n", cpus);
|
|
Packit |
6c4009 |
TEST_VERIFY (cpus > 0);
|
|
Packit |
6c4009 |
TEST_VERIFY (cpus != 1);
|
|
Packit |
6c4009 |
_exit (0);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static int
|
|
Packit |
6c4009 |
do_test (void)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
if (!is_smp ())
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf ("warning: test not supported on uniprocessor system\n");
|
|
Packit |
6c4009 |
return EXIT_UNSUPPORTED;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
support_become_root ();
|
|
Packit |
6c4009 |
if (!support_can_chroot ())
|
|
Packit |
6c4009 |
return EXIT_UNSUPPORTED;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
support_isolate_in_subprocess (chroot_callback, NULL);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
return 0;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#define PREPARE prepare
|
|
Packit |
6c4009 |
#include <support/test-driver.c>
|