title: Running Cygwin application as a Windows Service
body: <p>I am working on WinDRBD (<a href="https://github.com/LINBIT/windrbd" rel="nofollow noreferrer">https://github.com/LINBIT/windrbd</a>) a port of the Linux DRBD driver to Microsoft Windows.</p>
  
  <p>We want to run the user mode helper as a Windows Service (DRBD sometimes calls user space applications with call_usermodehelper(), which we emulate by a daemon that retrieves those request from the kernel driver, runs them and returns the exit status to the kernel).</p>
  
  <p>When we run the daemon in a cygwin shell, everything works fine. However when running the daemon as a Windows Service it seems that cygwin cannot find its installation directory (which is C:\cygwin64 on my machines).</p>
  
  <p>The registry entry (HKLM/Software/CygWin/setup/rootdir) points to the correct location, but I am not sure if it can also be accessed by the Windows Service? </p>
  
  <p>/bin/sh isn't found by the service, however /cygdrive/c/cygwin64/bin/sh
  exists, so when I run the shell with that path it can start
  (and also finds the DLLs it requires to run). However shell
  complains with:</p>
  
  <p>bash.exe: warning: could not find /tmp, please create!</p>
  
  <p>which definitely exists when running cygwin the normal way.</p>
  
  <p>Has anyone ever tried to run a CygWin compiled EXE as a Windows
  Service? Here is the output of sc query windrbdum:</p>
  
  <pre><code>SERVICE_NAME: windrbdum 
      TYPE               : 10  WIN32_OWN_PROCESS  
      STATE              : 4  RUNNING 
                              (STOPPABLE, NOT_PAUSABLE, IGNORES_SHUTDOWN)
      WIN32_EXIT_CODE    : 0  (0x0)
      SERVICE_EXIT_CODE  : 0  (0x0)
      CHECKPOINT         : 0x0
      WAIT_HINT          : 0x0
  </code></pre>
  
  <p>(um is for user mode).</p>
  
  <p>Thanks for any insights, </p>
  
  <ul>
  <li>Johannes</li>
  </ul>