[PATCH] Prevent unintentionally running as root

Robert C. Helling helling at atdotde.de
Fri Mar 25 01:27:45 PDT 2016

From: "Robert C. Helling" <helling at atdotde.de>

Some users try to run Subsurface as root for example to get around
permission problems with dive computer devices. This is a bad idea
since config files get touched as root and then cannot be read
as normal user anymore.

This patch allows running as root only with verbose option on. We can
assume if somebody manages to start subsurface as root this happens
from the command line.

For some reason, I couldn't get translation working at this stage.

Signed-off-by: Robert C. Helling <helling at atdotde.de>
 subsurface-desktop-main.cpp | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/subsurface-desktop-main.cpp b/subsurface-desktop-main.cpp
index 2b7bf89..d02e90a 100644
--- a/subsurface-desktop-main.cpp
+++ b/subsurface-desktop-main.cpp
@@ -20,6 +20,7 @@
 #include <QApplication>
 #include <QLoggingCategory>
 #include <git2.h>
+#include <unistd.h>
 QTranslator *qtTranslator, *ssrfTranslator;
@@ -59,6 +60,11 @@ int main(int argc, char **argv)
+	if ((getegid() == 0) && !verbose) {
+		printf("You are running Subsurface as root. This is not recommended.\n");
+		printf("If you insist to do so, run with option -v.\n");
+		exit(0);
+	}
2.5.4 (Apple Git-61)

More information about the subsurface mailing list