@Override public boolean shutdown() { try { // Force dismount of FUSE and then remove the mount point directory. Runtime.getRuntime().exec("fusermount -u -z " + mountPoint).waitFor(); Runtime.getRuntime().exec("rm -r " + mountPoint).waitFor(); return true; } catch (Exception exception) { Logger.getLogger(LinuxFUSE.class.getName()).log(Level.SEVERE, null, exception); return false; } }
@Override public boolean launch(String arguments) { if (arguments == null) { return false; } try { localHostAddress = InetAddress.getLocalHost().getHostAddress(); localHostName = InetAddress.getLocalHost().getHostName(); } catch (Exception ex) { localHostAddress = null; localHostName = null; Logger.getLogger(LinuxFUSE.class.getName()).log(Level.WARNING, null, ex); } try { BufferedReader confReader = new BufferedReader(new FileReader("/etc/fuse.conf")); String line; boolean found = false; while ((line = confReader.readLine()) != null) { // Check if the line "user_allow_other" exists in the config file. if (line.trim().equalsIgnoreCase("user_allow_other")) { found = true; break; } } if (!found) { // File /etc/fuse.conf not configured correctly. return false; } } catch (Exception ex) { // File /etc/fuse.conf does not exist or is configured incorrectly. Logger.getLogger(LinuxFUSE.class.getName()).log(Level.WARNING, null, ex); return false; } try { // The argument to this reporter is the mount point for FUSE. mountPoint = arguments; localCache = Collections.synchronizedMap(new HashMap<String, AbstractVertex>()); links = Collections.synchronizedMap(new HashMap<String, String>()); // Create a new directory as the mount point for FUSE. java.io.File mount = new java.io.File(mountPoint); if (mount.exists()) { return false; } else { int exitValue = Runtime.getRuntime().exec("mkdir " + mountPoint).waitFor(); if (exitValue != 0) { return false; } } mountPath = (new java.io.File(mountPoint)).getAbsolutePath(); myPID = ManagementFactory.getRuntimeMXBean().getName().split("@")[0].trim(); // Load the native library. System.loadLibrary("LinuxFUSE"); // Get the system boot time from the proc filesystem. boottime = 0; try { BufferedReader boottimeReader = new BufferedReader(new FileReader("/proc/stat")); String line; while ((line = boottimeReader.readLine()) != null) { StringTokenizer st = new StringTokenizer(line); if (st.nextToken().equals("btime")) { boottime = Long.parseLong(st.nextToken()) * 1000; break; } else { continue; } } boottimeReader.close(); } catch (Exception exception) { Logger.getLogger(LinuxFUSE.class.getName()).log(Level.SEVERE, null, exception); } // Create an initial root vertex which will be used as the root of the // process tree. Program rootVertex = new Program(); rootVertex.addAnnotation("pidname", "System"); rootVertex.addAnnotation("pid", "0"); rootVertex.addAnnotation("ppid", "0"); String stime_readable = new java.text.SimpleDateFormat(simpleDatePattern).format(new java.util.Date(boottime)); String stime = Long.toString(boottime); rootVertex.addAnnotation("boottime_unix", stime); rootVertex.addAnnotation("boottime_simple", stime_readable); localCache.put("0", rootVertex); putVertex(rootVertex); String path = "/proc"; String currentProgram; java.io.File folder = new java.io.File(path); java.io.File[] listOfFiles = folder.listFiles(); // Build the process tree using the directories under /proc/. Directories // which have a numeric name represent processes. for (int i = 0; i < listOfFiles.length; i++) { if (listOfFiles[i].isDirectory()) { currentProgram = listOfFiles[i].getName(); try { Integer.parseInt(currentProgram); Program processVertex = createProgramVertex(currentProgram); String ppid = (String) processVertex.getAnnotation("ppid"); localCache.put(currentProgram, processVertex); putVertex(processVertex); if (Integer.parseInt(ppid) >= 0) { if (((Program) localCache.get(ppid) != null) && (processVertex != null)) { WasTriggeredBy triggerEdge = new WasTriggeredBy(processVertex, (Program) localCache.get(ppid)); putEdge(triggerEdge); } } } catch (Exception exception) { continue; } } } Runnable FUSEThread = new Runnable() { public void run() { try { // Launch FUSE from the native library. launchFUSE(mountPoint); } catch (Exception exception) { Logger.getLogger(LinuxFUSE.class.getName()).log(Level.SEVERE, null, exception); } } }; new Thread(FUSEThread, "LinuxFUSE-Thread").start(); } catch (Exception exception) { Logger.getLogger(LinuxFUSE.class.getName()).log(Level.SEVERE, null, exception); return false; } return true; }