Skip to content

Commit 82002d8

Browse files
committed
add option to chdir or not
1 parent ff6f4e7 commit 82002d8

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

daemonize.nim

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ proc onStop(sig: cint) {.noconv.} =
1818

1919
quit(QuitSuccess)
2020

21-
template daemonize*(pidfile, si, so, se: string, body: stmt): stmt {.immediate.} =
21+
template daemonize*(pidfile, si, so, se, cd: string,body: stmt): stmt {.immediate.} =
2222
## deamonizer
2323
##
2424
## pidfile: path to file where pid will be stored
2525
## si: standard input for daemonzied process
2626
## so: standard output for daemonzied process
2727
## se: standard ouput for daemonzied process
28+
## cd: directory to switch to, nil or empty to stay
2829

2930
if fileExists(pidfile):
3031
raise newException(IOError, "pidfile " & pidfile & " already exist, daemon already running?")
@@ -34,7 +35,8 @@ template daemonize*(pidfile, si, so, se: string, body: stmt): stmt {.immediate.}
3435
if pid > 0:
3536
quit(QuitSuccess)
3637

37-
discard chdir("/")
38+
if not isNilorEmpty(cd):
39+
discard chdir(cd)
3840
discard setsid()
3941
discard umask(0)
4042

daemonize.nimble

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[Package]
22
name = "daemonize"
3-
version = "0.0.2"
3+
version = "0.0.3"
44
author = "Huy Doan"
55
description = "This library makes your code run as a daemon process on Unix-like systems"
66
license = "MIT"

0 commit comments

Comments
 (0)