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@strace.io>
6 * Copyright (c) 2016-2021 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 "scno.h"
14
15 #include <stdio.h>
16 #include <unistd.h>
17 #include <linux/utsname.h>
18
19 int
20 main(void)
21 {
22 kernel_ulong_t len;
23 long rc;
24
25 len = __NEW_UTS_LEN;
26 rc = syscall(__NR_sethostname, 0, len);
27 printf("sethostname(NULL, %u) = %s\n",
28 (unsigned) len, sprintrc(rc));
29
30 if (F8ILL_KULONG_MASK) {
31 len |= F8ILL_KULONG_MASK;
32 rc = syscall(__NR_sethostname, 0, len);
33 printf("sethostname(NULL, %u) = %s\n",
34 (unsigned) len, sprintrc(rc));
35 }
36
37 len = __NEW_UTS_LEN + 1;
38 void *const p = tail_alloc(len);
39 rc = syscall(__NR_sethostname, p, len);
40 printf("sethostname(%p, %u) = %s\n",
41 p, (unsigned) len, sprintrc(rc));
42
43 puts("+++ exited with 0 +++");
44 return 0;
45 }