int makeWritable (const char *path) { if (!isWritable(path)) { char command[0X100]; snprintf(command, sizeof(command), "su -c 'chmod 666 %s'", path); int status = executeHostCommand(command); if (status != 0) return 0; } return 1; }
int installKernelModule (const char *name, int *status) { if (status && *status) return *status == 2; { const char *command = "modprobe"; char buffer[0X100]; if (status) ++*status; { const char *path = "/proc/sys/kernel/modprobe"; FILE *stream = fopen(path, "r"); if (stream) { char *line = fgets(buffer, sizeof(buffer), stream); if (line) { size_t length = strlen(line); if (length && (line[length-1] == '\n')) line[--length] = 0; if (length) command = line; } fclose(stream); } else { logMessage(LOG_WARNING, "cannot open %s: %s", path, strerror(errno)); } } { const char *const arguments[] = {command, "-q", name, NULL}; int ok = executeHostCommand(arguments) == 0; if (!ok) { logMessage(LOG_WARNING, "kernel module not installed: %s", name); return 0; } if (status) ++*status; } } return 1; }
static int doScreenCommand (const char *command, ...) { va_list args; int count = 0; va_start(args, command); while (va_arg(args, char *)) ++count; va_end(args); { char window[0X10]; const char *argv[count + 6]; const char **arg = argv; *arg++ = "screen"; *arg++ = "-p"; snprintf(window, sizeof(window), "%d", currentVirtualTerminal_ScreenScreen()); *arg++ = window; *arg++ = "-X"; *arg++ = command; va_start(args, command); while ((*arg++ = va_arg(args, char *))); va_end(args); { int result = executeHostCommand(argv); if (result == 0) return 1; logMessage(LOG_ERR, "screen error: %d", result); } } return 0; }