]> git.ipfire.org Git - thirdparty/glibc.git/blame - nptl/tst-oddstacklimit.c
Update copyright notices with scripts/update-copyrights
[thirdparty/glibc.git] / nptl / tst-oddstacklimit.c
CommitLineData
0bf57f87 1/* Test NPTL with stack limit that is not a multiple of the page size.
d4697bc9 2 Copyright (C) 2012-2014 Free Software Foundation, Inc.
0bf57f87
JM
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19#include <errno.h>
20#include <stdio.h>
21#include <string.h>
22#include <sys/resource.h>
23#include <sys/wait.h>
ace4acc8 24#include <stdlib.h>
0bf57f87
JM
25
26/* This sets the stack resource limit to 1023kb, which is not a multiple
27 of the page size since every architecture's page size is > 1k. */
28#ifndef ODD_STACK_LIMIT
29# define ODD_STACK_LIMIT (1023 * 1024)
30#endif
31
32static const char *command;
33
34static int
35do_test (void)
36{
37 int ret;
38 struct rlimit rlim;
39
40 ret = getrlimit (RLIMIT_STACK, &rlim);
41 if (ret != 0)
42 {
43 printf ("getrlimit failed: %s\n", strerror (errno));
44 return 1;
45 }
46 rlim.rlim_cur = ODD_STACK_LIMIT;
47 ret = setrlimit (RLIMIT_STACK, &rlim);
48 if (ret != 0)
49 {
50 printf ("setrlimit failed: %s\n", strerror (errno));
51 return 1;
52 }
53 ret = system (command);
54 if (ret == -1)
55 {
56 printf ("system failed: %s\n", strerror (errno));
57 return 1;
58 }
59 if (WIFEXITED (ret))
60 return WEXITSTATUS (ret);
61 else
62 return 1;
63}
64
65#define OPT_COMMAND 10000
66#define CMDLINE_OPTIONS \
67 { "command", required_argument, NULL, OPT_COMMAND },
68#define CMDLINE_PROCESS \
69 case OPT_COMMAND: \
70 command = optarg; \
71 break;
72#define TEST_FUNCTION do_test ()
73#include "../test-skeleton.c"