aboutsummaryrefslogtreecommitdiff
path: root/src/utils.nim
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils.nim')
-rw-r--r--src/utils.nim11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/utils.nim b/src/utils.nim
index b480ce9..7dcf620 100644
--- a/src/utils.nim
+++ b/src/utils.nim
@@ -285,6 +285,17 @@ proc dropPrivileges*(): bool =
else:
return true
+proc checkExec(file: string): bool =
+ var statv: Stat
+ stat(file, statv) == 0 and (statv.st_mode and S_IXUSR) == S_IXUSR
+
+let sudoPrefix*: seq[string] = if checkExec(sudoCmd):
+ @[sudoCmd]
+ elif checkExec(suCmd):
+ @[suCmd, "root", "-c", "exec \"$@\"", "--", "sh"]
+ else:
+ @[]
+
var intSigact: SigAction
intSigact.sa_handler = SIG_DFL
discard sigaction(SIGINT, intSigact)