Skip to content
This repository has been archived by the owner on Oct 3, 2019. It is now read-only.

Commit

Permalink
- fix sys.exit() but (issue 7)
Browse files Browse the repository at this point in the history
  • Loading branch information
lomaxfrog committed Jun 5, 2014
1 parent 654ba2b commit 82627ed
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package net.es.enos.kernel.security;

/**
* This class is used to distinguish a SecurityException generated by checkExit() from other SecurityException.
* This allows the python interpreter to exit without displaying an error message
*/
public class ExitSecurityException extends SecurityException {
public ExitSecurityException(String s) {
super(s);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ public KernelSecurityManager() {
this.rootPath = Paths.get(rootdir).normalize();
}

@Override
public boolean getInCheck() {
return super.getInCheck();
}

@Override
public void checkAccess(Thread t) throws SecurityException {
// System.out.println("checkAccess(Thread current= " + Thread.currentThread().getName() + " t = " + t.getName());
Expand Down Expand Up @@ -283,4 +278,17 @@ private void initializePreAuthorized() {

}
}

@Override
public void checkExit(int status) {
throw new SecurityException("Cannot quit the JVM");
}

@Override
public void checkExec(String cmd) {
if (KernelThread.getCurrentKernelThread().isPrivileged()) {
return;
}
throw new ExitSecurityException("Cannot execute UNIX processes");
}
}
41 changes: 21 additions & 20 deletions base/src/main/java/net/es/enos/python/PythonShell.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import jline.console.ENOSConsoleReader;
import net.es.enos.boot.BootStrap;
import net.es.enos.kernel.exec.KernelThread;
import net.es.enos.kernel.security.ExitSecurityException;
import net.es.enos.kernel.users.User;
import net.es.enos.shell.ShellInputStream;;
import net.es.enos.shell.annotations.ShellCommand;
Expand Down Expand Up @@ -85,31 +86,31 @@ public static void startPython (String[] args, InputStream in, OutputStream out,

} else {
// This is an interactive session
try {
InteractiveConsole console = new InteractiveConsole(sessionLocals);
if (System.getProperty("python.home") == null) {
System.setProperty("python.home", "");
}
InteractiveConsole.initialize(System.getProperties(),
null, new String[0]);

console.setOut(out);
console.setErr(err);
console.setIn(in);
// Start the interactive session
console.interact();
} catch (Exception e) {
// Nothing has to be done. This happens when the jython shell exits, obviously not too gracefully.
e.printStackTrace();
InteractiveConsole console = new InteractiveConsole(sessionLocals);
if (System.getProperty("python.home") == null) {
System.setProperty("python.home", "");
}
InteractiveConsole.initialize(System.getProperties(),
null, new String[0]);

console.setOut(out);
console.setErr(err);
console.setIn(in);
// Start the interactive session
console.interact();
}
} catch (Exception e) {
try {
err.write(e.toString().getBytes());
} catch (IOException e1) {
e1.printStackTrace();
if ((e instanceof ExitSecurityException) || (e.toString().contains("SystemExit"))) {
// This is simply due to sys.exit(). Ignore.
} else {
try {
err.write(e.toString().getBytes());
} catch (IOException e1) {
e1.printStackTrace();
}
e.printStackTrace();
}
e.printStackTrace();
}
try {
err.flush();
Expand Down
19 changes: 13 additions & 6 deletions base/src/main/python/topology/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
from net.es.enos.esnet import ESnetTopology,OSCARSReservations
from org.joda.time import DateTime



if command_args != 4:
# Syntax error
print "Syntax error: path src@domain dst@domain"
exit()

topology = TopologyFactory.instance()
topo = topology.retrieveTopologyProvider("localLayer2")

Expand All @@ -26,21 +33,21 @@
maxReservable = -1

for link in path:
nodes = nodesByLink.get(link)
nodes = nodesByLink.get(link)
ports = portsByLink.get(link)
port = ports[0] # Assume only one port per link
portReservation = reserved.get(port)
if portReservation == None:
print "No portReservation for link " + link.getId() + " port= " + " " + port.getId()
print "No portReservation for link " + link.getId() + " port= " + port.getId()
continue
remainTo = portReservation.maxReservable - portReservation.alreadyReserved[0]
remainFrom = portReservation.maxReservable - portReservation.alreadyReserved[1]
print "Node= " + nodes[0].getId() + "\tlinkId= " + link.getId() + "\tReservableTo= " + str(remainTo) + "\tReservableFrom= " + str(remainFrom)
if (maxReservable == -1) || (maxReservable > remainTo):
maxReservable = remainTo;
print "Node= " + nodes[0].getId() + "\tlinkId= " + link.getId()
if (maxReservable == -1) or (maxReservable > remainTo):
maxReservable = remainTo;

print "End Node= " + dstNode.getId()
print "Max. reservable= " + maxReservable
print "Max. reservable= " + str(maxReservable)



0 comments on commit 82627ed

Please sign in to comment.