Exemple #1
0
  public static String[] getCurrentDns(String defaultPrimary, String defaultSecondary) {
    // Get current DNS name servers
    String dns[] = {null, null};

    dns[0] = CoreTask.getProp("net.dns1");
    dns[1] = CoreTask.getProp("net.dns2");

    if (dns[0] == null || dns[0].length() <= 0 || dns[0].equals("undefined")) {
      dns[0] = defaultPrimary;
    }

    if (dns[1] == null || dns[1].length() <= 0 || dns[1].equals("undefined")) {
      dns[1] = defaultSecondary;
    }

    return dns;
  }
Exemple #2
0
  public static boolean isProcessRunning(String processName) throws Exception {
    boolean processIsRunning = false;
    Hashtable<String, String> tmpRunningProcesses = new Hashtable<String, String>();
    File procDir = new File("/proc");
    FilenameFilter filter =
        new FilenameFilter() {
          public boolean accept(File dir, String name) {
            try {
              Integer.parseInt(name);
            } catch (NumberFormatException ex) {
              return false;
            }
            return true;
          }
        };

    synchronized (CoreTask.runningProcesses) {
      File[] processes = procDir.listFiles(filter);
      for (File process : processes) {
        String cmdLine = "";

        // Search for a known known process
        if (CoreTask.runningProcesses.containsKey(process.getAbsoluteFile().toString())) {
          cmdLine = CoreTask.runningProcesses.get(process.getAbsoluteFile().toString());
        } else {
          ArrayList<String> cmdlineContent =
              CoreTask.readLinesFromFile(process.getAbsoluteFile() + "/cmdline");
          if (cmdlineContent != null && cmdlineContent.size() > 0) {
            cmdLine = cmdlineContent.get(0);
          }
        }
        // Adding to tmp-Hashtable
        tmpRunningProcesses.put(process.getAbsoluteFile().toString(), cmdLine);

        // Checking if processName matches
        if (cmdLine.startsWith(processName)) {
          processIsRunning = true;
        }
      }

      // Overwriting runningProcesses
      CoreTask.runningProcesses = tmpRunningProcesses;
    }

    return processIsRunning;
  }