summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--lib/pure/osproc.nim14
-rw-r--r--lib/pure/times.nim24
-rw-r--r--tests/osproc/texitcode.nim5
3 files changed, 33 insertions, 10 deletions
diff --git a/lib/pure/osproc.nim b/lib/pure/osproc.nim
index 76bd2dfe1..1d43bb321 100644
--- a/lib/pure/osproc.nim
+++ b/lib/pure/osproc.nim
@@ -965,10 +965,16 @@ elif not defined(useNimRtl):
     var ret : int
     var status : cint = 1
     ret = waitpid(p.id, status, WNOHANG)
-    if WIFEXITED(status):
-      p.exitStatus = status
-    if ret == 0: return true # Can't establish status. Assume running.
-    result = ret == int(p.id)
+    if ret == int(p.id):
+      if WIFEXITED(status):
+        p.exitStatus = status
+        return false
+      else:
+        return true
+    elif ret == 0:
+      return true # Can't establish status. Assume running.
+    else:
+      return false
 
   proc terminate(p: Process) =
     if kill(p.id, SIGTERM) != 0'i32:
diff --git a/lib/pure/times.nim b/lib/pure/times.nim
index 248d397a7..99fdb5b0e 100644
--- a/lib/pure/times.nim
+++ b/lib/pure/times.nim
@@ -436,6 +436,11 @@ when not defined(JS):
     TimeInfoPtr = ptr StructTM
     Clock {.importc: "clock_t".} = distinct int
 
+  when not defined(windows):
+    # This is not ANSI C, but common enough
+    proc timegm(t: StructTM): Time {.
+      importc: "timegm", header: "<time.h>", tags: [].}
+
   proc localtime(timer: ptr Time): TimeInfoPtr {.
     importc: "localtime", header: "<time.h>", tags: [].}
   proc gmtime(timer: ptr Time): TimeInfoPtr {.
@@ -515,12 +520,19 @@ when not defined(JS):
     # the conversion is not expensive
 
   proc toTime(timeInfo: TimeInfo): Time =
-    var cTimeInfo = timeInfo # for C++ we have to make a copy,
+    var cTimeInfo = timeInfo # for C++ we have to make a copy
     # because the header of mktime is broken in my version of libc
-    result = mktime(timeInfoToTM(cTimeInfo))
-    # mktime is defined to interpret the input as local time. As timeInfoToTM
-    # does ignore the timezone, we need to adjust this here.
-    result = Time(TimeImpl(result) - getTimezone() + timeInfo.timezone)
+
+    when defined(windows):
+      # On Windows `mktime` is broken enough to make this work.
+      result = mktime(timeInfoToTM(cTimeInfo))
+      # mktime is defined to interpret the input as local time. As timeInfoToTM
+      # does ignore the timezone, we need to adjust this here.
+      result = Time(TimeImpl(result) - getTimezone() + timeInfo.timezone)
+    else:
+      result = timegm(timeInfoToTM(cTimeInfo))
+      # As timeInfoToTM does ignore the timezone, we need to adjust this here.
+      result = Time(TimeImpl(result) + timeInfo.timezone)
 
   proc timeInfoToTime(timeInfo: TimeInfo): Time = toTime(timeInfo)
 
@@ -603,7 +615,7 @@ elif defined(JS):
     result.weekday = weekDays[t.getUTCDay()]
     result.yearday = 0
 
-  proc timeInfoToTime*(timeInfo: TimeInfo): Time = toTime(timeInfo)
+  proc timeInfoToTime(timeInfo: TimeInfo): Time = toTime(timeInfo)
 
   proc toTime*(timeInfo: TimeInfo): Time =
     result = internGetTime()
diff --git a/tests/osproc/texitcode.nim b/tests/osproc/texitcode.nim
index 1e83658c2..4eaab6da2 100644
--- a/tests/osproc/texitcode.nim
+++ b/tests/osproc/texitcode.nim
@@ -16,3 +16,8 @@ var running = true
 while running:
   running = running(p)
 doAssert(waitForExit(p) == QuitFailure)
+
+# make sure that first call to running() after process exit returns false
+p = startProcess(filename, dir)
+os.sleep(500)
+doAssert(not running(p))