1*1c6c4d11SAlexey Gladkov /*
2*1c6c4d11SAlexey Gladkov  * Copyright © 2020 Alexey Gladkov <gladkov.alexey@gmail.com>
3*1c6c4d11SAlexey Gladkov  *
4*1c6c4d11SAlexey Gladkov  * Permission to use, copy, modify, and distribute this software for any
5*1c6c4d11SAlexey Gladkov  * purpose with or without fee is hereby granted, provided that the above
6*1c6c4d11SAlexey Gladkov  * copyright notice and this permission notice appear in all copies.
7*1c6c4d11SAlexey Gladkov  *
8*1c6c4d11SAlexey Gladkov  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9*1c6c4d11SAlexey Gladkov  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10*1c6c4d11SAlexey Gladkov  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11*1c6c4d11SAlexey Gladkov  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12*1c6c4d11SAlexey Gladkov  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13*1c6c4d11SAlexey Gladkov  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14*1c6c4d11SAlexey Gladkov  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15*1c6c4d11SAlexey Gladkov  */
16*1c6c4d11SAlexey Gladkov #include <assert.h>
17*1c6c4d11SAlexey Gladkov #include <unistd.h>
18*1c6c4d11SAlexey Gladkov #include <stdlib.h>
19*1c6c4d11SAlexey Gladkov #include <errno.h>
20*1c6c4d11SAlexey Gladkov #include <linux/mount.h>
21*1c6c4d11SAlexey Gladkov #include <linux/unistd.h>
22*1c6c4d11SAlexey Gladkov 
fsopen(const char * fsname,unsigned int flags)23*1c6c4d11SAlexey Gladkov static inline int fsopen(const char *fsname, unsigned int flags)
24*1c6c4d11SAlexey Gladkov {
25*1c6c4d11SAlexey Gladkov 	return syscall(__NR_fsopen, fsname, flags);
26*1c6c4d11SAlexey Gladkov }
27*1c6c4d11SAlexey Gladkov 
fsconfig(int fd,unsigned int cmd,const char * key,const void * val,int aux)28*1c6c4d11SAlexey Gladkov static inline int fsconfig(int fd, unsigned int cmd, const char *key, const void *val, int aux)
29*1c6c4d11SAlexey Gladkov {
30*1c6c4d11SAlexey Gladkov 	return syscall(__NR_fsconfig, fd, cmd, key, val, aux);
31*1c6c4d11SAlexey Gladkov }
32*1c6c4d11SAlexey Gladkov 
main(void)33*1c6c4d11SAlexey Gladkov int main(void)
34*1c6c4d11SAlexey Gladkov {
35*1c6c4d11SAlexey Gladkov 	int fsfd, ret;
36*1c6c4d11SAlexey Gladkov 	int hidepid = 2;
37*1c6c4d11SAlexey Gladkov 
38*1c6c4d11SAlexey Gladkov 	assert((fsfd = fsopen("proc", 0)) != -1);
39*1c6c4d11SAlexey Gladkov 
40*1c6c4d11SAlexey Gladkov 	ret = fsconfig(fsfd, FSCONFIG_SET_BINARY, "hidepid", &hidepid, 0);
41*1c6c4d11SAlexey Gladkov 	assert(ret == -1);
42*1c6c4d11SAlexey Gladkov 	assert(errno == EINVAL);
43*1c6c4d11SAlexey Gladkov 
44*1c6c4d11SAlexey Gladkov 	assert(!fsconfig(fsfd, FSCONFIG_SET_STRING, "hidepid", "2", 0));
45*1c6c4d11SAlexey Gladkov 	assert(!fsconfig(fsfd, FSCONFIG_SET_STRING, "hidepid", "invisible", 0));
46*1c6c4d11SAlexey Gladkov 
47*1c6c4d11SAlexey Gladkov 	assert(!close(fsfd));
48*1c6c4d11SAlexey Gladkov 
49*1c6c4d11SAlexey Gladkov 	return 0;
50*1c6c4d11SAlexey Gladkov }
51