1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- #define _GNU_SOURCE
- #include "governors-query.h"
- #include "logging.h"
- #include <ctype.h>
- #include <sys/types.h>
- static void set_gov_state(const char *value)
- {
- char governors[MAX_GOVERNORS][MAX_GOVERNOR_LENGTH] = { { 0 } };
- int num = fetch_governors(governors);
- LOG_MSG("Setting governors to %s\n", value);
- for (int i = 0; i < num; i++) {
- const char *gov = governors[i];
- FILE *f = fopen(gov, "w");
- if (!f) {
- LOG_ERROR("Failed to open file for write %s\n", gov);
- continue;
- }
- fprintf(f, "%s\n", value);
- fclose(f);
- }
- }
- int main(int argc, char *argv[])
- {
- if (argc < 2) {
- fprintf(stderr, "usage: cpugovctl [get] [set VALUE]\n");
- return EXIT_FAILURE;
- }
- if (strncmp(argv[1], "get", 3) == 0) {
- printf("%s", get_gov_state());
- } else if (strncmp(argv[1], "set", 3) == 0) {
- const char *value = argv[2];
-
- if (geteuid() != 0) {
- fprintf(stderr, "This program must be run as root\n");
- return EXIT_FAILURE;
- }
- set_gov_state(value);
- } else {
- return EXIT_FAILURE;
- }
- return EXIT_SUCCESS;
- }
|