Skip to content

Commit

Permalink
[Fix #117] eliminate redundant exec() in check_requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
dgraziotin committed Jun 21, 2017
1 parent f20a227 commit 5f2da79
Showing 1 changed file with 14 additions and 28 deletions.
42 changes: 14 additions & 28 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void check_requirements()

/**
* Check for root
*/
*/

uid_t uid=getuid(), euid=geteuid();

Expand All @@ -71,42 +71,28 @@ void check_requirements()

/**
* Check for coretemp and applesmc modules
* Credits: -http://stackoverflow.com/questions/12978794
*/
FILE *fd = popen("lsmod | grep coretemp", "r");
char buf[16];

if (!(fread (buf, 1, sizeof (buf), fd) > 0)) {
DIR* dir = opendir(CORETEMP_PATH);

if (ENOENT == errno) {
syslog(LOG_ERR, "%s needs coretemp support. Please either load it or build it into the kernel. Exiting.", PROGRAM_NAME);
printf("%s needs coretemp module.\nPlease either load it or build it into the kernel. Exiting.\n", PROGRAM_NAME);
exit(EXIT_FAILURE);
}

closedir(dir);
DIR* dir = opendir(CORETEMP_PATH);

if (ENOENT == errno) {
syslog(LOG_ERR, "%s needs coretemp support. Please either load it or build it into the kernel. Exiting.", PROGRAM_NAME);
printf("%s needs coretemp module.\nPlease either load it or build it into the kernel. Exiting.\n", PROGRAM_NAME);
exit(EXIT_FAILURE);
}

pclose(fd);
closedir(dir);

fd = popen("lsmod | grep applesmc", "r");

if (!(fread (buf, 1, sizeof (buf), fd) > 0)) {
DIR* dir = opendir(APPLESMC_PATH);

if (ENOENT == errno) {
syslog(LOG_ERR, "%s needs applesmc support. Please either load it or build it into the kernel. Exiting.", PROGRAM_NAME);
printf("%s needs applesmc module.\nPlease either load it or build it into the kernel. Exiting.\n", PROGRAM_NAME);
exit(EXIT_FAILURE);
}

closedir(dir);
dir = opendir(APPLESMC_PATH);

if (ENOENT == errno) {
syslog(LOG_ERR, "%s needs applesmc support. Please either load it or build it into the kernel. Exiting.", PROGRAM_NAME);
printf("%s needs applesmc module.\nPlease either load it or build it into the kernel. Exiting.\n", PROGRAM_NAME);
exit(EXIT_FAILURE);
}

pclose(fd);
closedir(dir);


}

Expand Down

0 comments on commit 5f2da79

Please sign in to comment.