Fix: priority functionality not working properly (#232)
This commit is contained in:
@@ -21,6 +21,7 @@ package com.sheepit.client.os;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -30,11 +31,10 @@ import com.sheepit.client.hardware.cpu.CPU;
|
||||
|
||||
public class Mac extends OS {
|
||||
private final String NICE_BINARY_PATH = "nice";
|
||||
private Boolean hasNiceBinary;
|
||||
private final String ID_COMMAND_INVOCATION = "id -u";
|
||||
|
||||
public Mac() {
|
||||
super();
|
||||
this.hasNiceBinary = null;
|
||||
}
|
||||
|
||||
public String name() {
|
||||
@@ -143,10 +143,7 @@ public class Mac extends OS {
|
||||
|
||||
@Override public Process exec(List<String> command, Map<String, String> env) throws IOException {
|
||||
List<String> actual_command = command;
|
||||
if (this.hasNiceBinary == null) {
|
||||
this.checkNiceAvailability();
|
||||
}
|
||||
if (this.hasNiceBinary.booleanValue()) {
|
||||
if (checkNiceAvailability()) {
|
||||
// launch the process in lowest priority
|
||||
if (env != null) {
|
||||
actual_command.add(0, env.get("PRIORITY"));
|
||||
@@ -172,17 +169,42 @@ public class Mac extends OS {
|
||||
return "/usr/local/cuda/lib/libcuda.dylib";
|
||||
}
|
||||
|
||||
protected void checkNiceAvailability() {
|
||||
@Override public boolean getSupportHighPriority() {
|
||||
try {
|
||||
ProcessBuilder builder = new ProcessBuilder();
|
||||
builder.command("bash", "-c", ID_COMMAND_INVOCATION);
|
||||
builder.redirectErrorStream(true);
|
||||
|
||||
Process process = builder.start();
|
||||
InputStream is = process.getInputStream();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||
|
||||
String userLevel = null;
|
||||
if ((userLevel = reader.readLine()) != null) {
|
||||
// Root user in *ix systems -independently of the alias used to login- has a id value of 0. On top of being a user with root capabilities,
|
||||
// to support changing the priority the nice tool must be accessible from the current user
|
||||
return (userLevel.equals("0")) & checkNiceAvailability();
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
System.err.println(String.format("ERROR Mac::getSupportHighPriority Unable to execute id command. IOException %s", e.getMessage()));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public boolean checkNiceAvailability() {
|
||||
ProcessBuilder builder = new ProcessBuilder();
|
||||
builder.command(NICE_BINARY_PATH);
|
||||
builder.redirectErrorStream(true);
|
||||
|
||||
Process process = null;
|
||||
boolean hasNiceBinary = false;
|
||||
try {
|
||||
process = builder.start();
|
||||
this.hasNiceBinary = true;
|
||||
hasNiceBinary = true;
|
||||
}
|
||||
catch (IOException e) {
|
||||
this.hasNiceBinary = false;
|
||||
Log.getInstance(null).error("Failed to find low priority binary, will not launch renderer in normal priority (" + e + ")");
|
||||
}
|
||||
finally {
|
||||
@@ -190,5 +212,6 @@ public class Mac extends OS {
|
||||
process.destroy();
|
||||
}
|
||||
}
|
||||
return hasNiceBinary;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user