예제 #1
0
파일: utils.c 프로젝트: junwuwei/nbp
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;
}
예제 #2
0
파일: sys_linux.c 프로젝트: Banzay40/brltty
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;
}
예제 #3
0
파일: screen.c 프로젝트: junwuwei/brltty
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;
}