int loadModule(char * modName) {
char * objName;
int status;
pid_t childpid;
objName = alloca(strlen(modName) + 5 + strlen(MODULES_PATH));
strcpy(objName, MODULES_PATH);
strcat(objName, modName);
strcat(objName, ".o");
if (testing) {
messageWindow("Module", "Installing module %s now", modName);
return 0;
}
logMessage("running command: insmod %s", objName);
if (!(childpid = fork())) {
close(1);
close(2);
dup2(logfd, 1);
dup2(logfd, 2);
execl("/bin/insmod", "/bin/insmod", objName, NULL);
exit(1);
}
waitpid(childpid, &status, 0);
if (!WIFEXITED(status) || WEXITSTATUS(status)) {
logMessage("insmod failed!");
return 1;
}
return 0;
}