tools/testing/selftests/proc/proc-fsconfig-hidepid.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/proc/proc-fsconfig-hidepid.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/proc/proc-fsconfig-hidepid.c
Extension
.c
Size
1591 bytes
Lines
51
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

#include <assert.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <linux/mount.h>
#include <linux/unistd.h>

static inline int fsopen(const char *fsname, unsigned int flags)
{
	return syscall(__NR_fsopen, fsname, flags);
}

static inline int fsconfig(int fd, unsigned int cmd, const char *key, const void *val, int aux)
{
	return syscall(__NR_fsconfig, fd, cmd, key, val, aux);
}

int main(void)
{
	int fsfd, ret;
	int hidepid = 2;

	assert((fsfd = fsopen("proc", 0)) != -1);

	ret = fsconfig(fsfd, FSCONFIG_SET_BINARY, "hidepid", &hidepid, 0);
	assert(ret == -1);
	assert(errno == EINVAL);

	assert(!fsconfig(fsfd, FSCONFIG_SET_STRING, "hidepid", "2", 0));
	assert(!fsconfig(fsfd, FSCONFIG_SET_STRING, "hidepid", "invisible", 0));

	assert(!close(fsfd));

	return 0;
}

Annotation

Implementation Notes