Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright © 2020 Alexey Gladkov <gladkov.alexey@gmail.com>
0003  *
0004  * Permission to use, copy, modify, and distribute this software for any
0005  * purpose with or without fee is hereby granted, provided that the above
0006  * copyright notice and this permission notice appear in all copies.
0007  *
0008  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
0009  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
0010  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
0011  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
0012  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
0013  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
0014  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
0015  */
0016 #include <assert.h>
0017 #include <unistd.h>
0018 #include <stdlib.h>
0019 #include <errno.h>
0020 #include <linux/mount.h>
0021 #include <linux/unistd.h>
0022 
0023 static inline int fsopen(const char *fsname, unsigned int flags)
0024 {
0025     return syscall(__NR_fsopen, fsname, flags);
0026 }
0027 
0028 static inline int fsconfig(int fd, unsigned int cmd, const char *key, const void *val, int aux)
0029 {
0030     return syscall(__NR_fsconfig, fd, cmd, key, val, aux);
0031 }
0032 
0033 int main(void)
0034 {
0035     int fsfd, ret;
0036     int hidepid = 2;
0037 
0038     assert((fsfd = fsopen("proc", 0)) != -1);
0039 
0040     ret = fsconfig(fsfd, FSCONFIG_SET_BINARY, "hidepid", &hidepid, 0);
0041     assert(ret == -1);
0042     assert(errno == EINVAL);
0043 
0044     assert(!fsconfig(fsfd, FSCONFIG_SET_STRING, "hidepid", "2", 0));
0045     assert(!fsconfig(fsfd, FSCONFIG_SET_STRING, "hidepid", "invisible", 0));
0046 
0047     assert(!close(fsfd));
0048 
0049     return 0;
0050 }