1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- #define _GNU_SOURCE
- #include <unistd.h>
- #include "common-logging.h"
- static bool write_value(char *key, char *value)
- {
- FILE *f = fopen(key, "w");
- if (!f) {
- if (errno != ENOENT)
- LOG_ERROR("Couldn't open file at %s (%s)\n", key, strerror(errno));
- return false;
- }
- if (fputs(value, f) == EOF) {
- LOG_ERROR("Couldn't write to file at %s (%s)\n", key, strerror(errno));
- fclose(f);
- return false;
- }
- fclose(f);
- return true;
- }
- int main(int argc, char *argv[])
- {
- if (geteuid() != 0) {
- LOG_ERROR("This program must be run as root\n");
- return EXIT_FAILURE;
- }
- if (argc == 3) {
- if (strcmp(argv[1], "split_lock_mitigate") == 0) {
- if (!write_value("/proc/sys/kernel/split_lock_mitigate", argv[2]))
- return EXIT_FAILURE;
- return EXIT_SUCCESS;
- } else {
- fprintf(stderr, "unsupported key: '%s'\n", argv[1]);
- return EXIT_FAILURE;
- }
- }
- fprintf(stderr, "usage: procsysctl KEY VALUE\n");
- fprintf(stderr, "where KEY can by any of 'split_lock_mitigate'\n");
- return EXIT_FAILURE;
- }
|