diff --git a/src/main.c b/src/main.c index 6e2cfc5..83883f7 100644 --- a/src/main.c +++ b/src/main.c @@ -19,6 +19,10 @@ static inline bool cpu_setter(uint32_t id, bool nstate, uint8_t opts) { return false; } +static inline void print_cpu_count(int32_t mcpus) { + printf("%i/%i cpus enabled.\n", get_nprocs(), mcpus); // get the number of available processors +} + int32_t main(int32_t argc, char** argv) { if (geteuid() != 0) fatal("must be executed as the root user!"); @@ -26,6 +30,11 @@ int32_t main(int32_t argc, char** argv) { uint8_t opts = getoptions(argc, argv, &ncpus); // the options to use int32_t mcpus = get_nprocs_conf(); // the max number of CPUs that are available + if (opts & OPT_LIST_CORES && ncpus < 0) { + print_cpu_count(mcpus); + return 0; + } + if (opts & OPT_INVERT) ncpus = mcpus - ncpus; @@ -48,7 +57,7 @@ int32_t main(int32_t argc, char** argv) { } if ((opts & OPT_LIST_CORES) || (opts & OPT_VERBOSE)) - printf("%i/%i cpus enabled\n", ncpus, mcpus); + print_cpu_count(mcpus); return 0; } diff --git a/src/opts.c b/src/opts.c index 52787a2..172fb18 100644 --- a/src/opts.c +++ b/src/opts.c @@ -37,7 +37,10 @@ uint8_t getoptions(int32_t argc, char* const* argv, int32_t* ncpus) { if (optind < argc) { char* num = argv[optind]; *ncpus = atoi(num); - } else fatal("you must provide a number!"); + } else if (opts & OPT_LIST_CORES) { + *ncpus = -1; + } else + fatal("must execute with either a number or [-l]"); return opts; }