1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) 2019 Petr Vorel <petr.vorel@gmail.com>
4 */
5
6 #ifndef SETDOMAINNAME_H__
7 #define SETDOMAINNAME_H__
8
9 #include <string.h>
10 #include "lapi/utsname.h"
11 #include "lapi/syscalls.h"
12 #include "tst_test.h"
13
14 #define TST_VALID_DOMAIN_NAME "test_dom"
15
16 #ifdef TEST_SETHOSTNAME
17 # define GET_SYSCALL gethostname
18 # define SET_SYSCALL sethostname
19 # define SYSCALL_NAME "hostname"
20 # define SYSCALL_NR __NR_sethostname
21 #else
22 # define GET_SYSCALL getdomainname
23 # define SET_SYSCALL setdomainname
24 # define SYSCALL_NAME "domainname"
25 # define SYSCALL_NR __NR_setdomainname
26 #endif
27
28 static char backup[_UTSNAME_DOMAIN_LENGTH];
29
30 #define TEST_VARIANTS 2
31
setdomainname_info(void)32 static void setdomainname_info(void)
33 {
34 switch (tst_variant) {
35 case 0:
36 tst_res(TINFO, "Testing libc set" SYSCALL_NAME "()");
37 break;
38 case 1:
39 tst_res(TINFO, "Testing __NR_set" SYSCALL_NAME " syscall");
40 break;
41 }
42 }
43
do_setdomainname(char * new,size_t len)44 static int do_setdomainname(char *new, size_t len)
45 {
46 switch (tst_variant) {
47 case 0:
48 return SET_SYSCALL(new, len);
49 break;
50 case 1:
51 return tst_syscall(SYSCALL_NR, new, len);
52 }
53
54 return -1;
55 }
56
setup(void)57 static void setup(void)
58 {
59 setdomainname_info();
60 if ((GET_SYSCALL(backup, sizeof(backup))) < 0)
61 tst_brk(TBROK | TERRNO, "get" SYSCALL_NAME "() failed");
62 }
63
cleanup(void)64 static void cleanup(void)
65 {
66 if ((SET_SYSCALL(backup, strlen(backup))) < 0)
67 tst_res(TWARN | TERRNO, "set" SYSCALL_NAME "() failed ('%s')", backup);
68 }
69
70 #endif /* SETDOMAINNAME_H__ */
71