Browse Source

Fixed service context detection when built with VS2013.

Visual Studio 2013 includes a C runtime which assigns stdin, stdout and
stderr the file descriptors 0, 1 and 2 - just like UNIX does - even if
there are no streams available.  Thus we can no longer use "_fileno(stdin)
< 0" as a check for running in a service context.

Instead we check for "GetStdHandle(STD_INPUT_HANDLE) == 0" which works
when compiled with older or newer versions of Visual Studio.

Thanks Czenda Czendov.
Iain Patterson 8 years ago
parent
commit
997e224304
1 changed files with 1 additions and 1 deletions
  1. 1 1
      nssm.cpp

+ 1 - 1
nssm.cpp

@@ -136,7 +136,7 @@ int _tmain(int argc, TCHAR **argv) {
     actually running as a service.
     This will save time when running with no arguments from a command prompt.
   */
-  if (_fileno(stdin) < 0) {
+  if (! GetStdHandle(STD_INPUT_HANDLE)) {
     /* Set up function pointers. */
     if (get_imports()) exit(111);