samples/check-exec/set-exec.c

Source file repositories/reference/linux-study-clean/samples/check-exec/set-exec.c

File Facts

System
Linux kernel
Corpus path
samples/check-exec/set-exec.c
Extension
.c
Size
2084 bytes
Lines
86
Domain
Support Tooling And Documentation
Bucket
samples
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

switch (opt) {
		case 'f':
			secbits_new |= SECBIT_EXEC_RESTRICT_FILE |
				       SECBIT_EXEC_RESTRICT_FILE_LOCKED;
			has_policy = true;
			break;
		case 'i':
			secbits_new |= SECBIT_EXEC_DENY_INTERACTIVE |
				       SECBIT_EXEC_DENY_INTERACTIVE_LOCKED;
			has_policy = true;
			break;
		default:
			print_usage(argv[0]);
			return 1;
		}
	}

	if (!argv[optind] || !has_policy) {
		print_usage(argv[0]);
		return 1;
	}

	if (secbits_cur != secbits_new &&
	    prctl(PR_SET_SECUREBITS, secbits_new)) {
		perror("Failed to set secure bit(s).");
		fprintf(stderr,
			"Hint: The running kernel may not support this feature.\n");
		return 1;
	}

	cmd_path = argv[optind];
	cmd_argv = argv + optind;
	fprintf(stderr, "Executing command...\n");
	execvpe(cmd_path, cmd_argv, envp);
	fprintf(stderr, "Failed to execute \"%s\": %s\n", cmd_path,
		strerror(errno));
	return 1;
}

Annotation

Implementation Notes