On linux, only the root can create process with high priority, so don't display the option is the client is launched as regular user

This commit is contained in:
Laurent Clouet
2017-03-19 18:14:33 +01:00
parent d4db1670a1
commit 0a68a3357c
3 changed files with 23 additions and 3 deletions

View File

@@ -167,6 +167,19 @@ public class Linux extends OS {
return builder.start(); return builder.start();
} }
@Override
public boolean getSupportHighPriority() {
// only the root user can create process with high (negative nice) value
String logname = System.getenv("LOGNAME");
String user = System.getenv("USER");
if ((logname != null && logname.equals("root")) || (user != null && user.equals("root"))) {
return true;
}
return false;
}
protected void checkNiceAvailability() { protected void checkNiceAvailability() {
ProcessBuilder builder = new ProcessBuilder(); ProcessBuilder builder = new ProcessBuilder();
builder.command(NICE_BINARY_PATH); builder.command(NICE_BINARY_PATH);

View File

@@ -37,6 +37,10 @@ public abstract class OS {
return null; return null;
} }
public boolean getSupportHighPriority() {
return true;
}
public Process exec(List<String> command, Map<String, String> env) throws IOException { public Process exec(List<String> command, Map<String, String> env) throws IOException {
ProcessBuilder builder = new ProcessBuilder(command); ProcessBuilder builder = new ProcessBuilder(command);
builder.redirectErrorStream(true); builder.redirectErrorStream(true);

View File

@@ -51,6 +51,7 @@ import com.sheepit.client.hardware.cpu.CPU;
import com.sheepit.client.hardware.gpu.GPU; import com.sheepit.client.hardware.gpu.GPU;
import com.sheepit.client.hardware.gpu.GPUDevice; import com.sheepit.client.hardware.gpu.GPUDevice;
import com.sheepit.client.network.Proxy; import com.sheepit.client.network.Proxy;
import com.sheepit.client.os.OS;
import com.sheepit.client.standalone.GuiSwing; import com.sheepit.client.standalone.GuiSwing;
public class Settings implements Activity { public class Settings implements Activity {
@@ -240,13 +241,15 @@ public class Settings implements Activity {
} }
// priority // priority
priority = new JSlider(-19, 19); OS os = OS.getOS();
priority.setMajorTickSpacing(5); boolean high_priority_support = os.getSupportHighPriority();
priority = new JSlider(high_priority_support ? -19 : 0, 19);
priority.setMajorTickSpacing(19);
priority.setMinorTickSpacing(1); priority.setMinorTickSpacing(1);
priority.setPaintTicks(true); priority.setPaintTicks(true);
priority.setPaintLabels(true); priority.setPaintLabels(true);
priority.setValue(config.getPriority()); priority.setValue(config.getPriority());
JLabel priorityLabel = new JLabel("Priority (High <-> Low):"); JLabel priorityLabel = new JLabel(high_priority_support ? "Priority (High <-> Low):" : "Priority (Normal <-> Low):" );
compute_devices_constraints.weightx = 1.0 / gpus.size(); compute_devices_constraints.weightx = 1.0 / gpus.size();
compute_devices_constraints.gridx = 0; compute_devices_constraints.gridx = 0;