]> granicus.if.org Git - strace/blob - tests/sethostname.c
Update copyright headers
[strace] / tests / sethostname.c
1 /*
2  * Check decoding of sethostname syscall.
3  *
4  * Copyright (c) 2016 Fei Jie <feij.fnst@cn.fujitsu.com>
5  * Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
6  * Copyright (c) 2016-2018 The strace developers.
7  * All rights reserved.
8  *
9  * SPDX-License-Identifier: GPL-2.0-or-later
10  */
11
12 #include "tests.h"
13 #include <asm/unistd.h>
14
15 #ifdef __NR_sethostname
16
17 # include <stdio.h>
18 # include <unistd.h>
19
20 #ifdef HAVE_LINUX_UTSNAME_H
21 # include <linux/utsname.h>
22 #endif
23
24 #ifndef __NEW_UTS_LEN
25 # define __NEW_UTS_LEN 64
26 #endif
27
28 int
29 main(void)
30 {
31         kernel_ulong_t len;
32         long rc;
33
34         len = __NEW_UTS_LEN;
35         rc = syscall(__NR_sethostname, 0, len);
36         printf("sethostname(NULL, %u) = %s\n",
37                (unsigned) len, sprintrc(rc));
38
39         if (F8ILL_KULONG_MASK) {
40                 len |= F8ILL_KULONG_MASK;
41                 rc = syscall(__NR_sethostname, 0, len);
42                 printf("sethostname(NULL, %u) = %s\n",
43                        (unsigned) len, sprintrc(rc));
44         }
45
46         len = __NEW_UTS_LEN + 1;
47         void *const p = tail_alloc(len);
48         rc = syscall(__NR_sethostname, p, len);
49         printf("sethostname(%p, %u) = %s\n",
50                p, (unsigned) len, sprintrc(rc));
51
52         puts("+++ exited with 0 +++");
53         return 0;
54 }
55
56 #else
57
58 SKIP_MAIN_UNDEFINED("__NR_sethostname")
59
60 #endif