This is the mail archive of the cygwin-developers@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

problem with fork/exec in Cygwin DLL called from non-Cygwin EXE



I recently stumbled across a problem that I'm just
starting to dig into.  For now, all I can really do
is describe it and hope for some suggestions.

First, here's the example:

main.c:

  #include <windows.h>
  
  int
  main()
  {
      HINSTANCE libref;
      FARPROC symref;
      void (*func)();
  
      libref = LoadLibraryExA("lib.dll", NULL,
LOAD_WITH_ALTERED_SEARCH_PATH);
      symref = GetProcAddress(libref, "func1");
      func = (void *) symref;
      func();
  
      exit(0);
  }

lib.c:

  #include <stdio.h>
  #include <unistd.h>
  #include <sys/wait.h>
  
  void
  func1()
  {
      FILE *fp;
      int status;
      char buf[512];
      fprintf(stderr, "start func1\n");
  
  #if 0
      if(fork() == 0) {
        fprintf(stderr, "child\n");
        execl("/bin/cat.exe", "cat", "lib.c", 0);
        exit(1);
      }
      wait(&status);
  #else
      fp = popen("cat lib.c", "r");
      while(fgets(buf, sizeof(buf), fp)) {
        fprintf(stderr, "func1: %s", buf);
      }
      pclose(fp);
  #endif
  
      fprintf(stderr, "end func1\n");
  }

Makefile:

  all: main lib.dll
  
  main: main.c
        gcc -Wall -g -o main -mno-cygwin main.c
  
  lib.dll: lib.c
        gcc -Wall -g -c lib.c
        dllwrap --export-all --output-def lib.def -o lib.dll lib.o \
            --entry __cygwin_noncygwin_dll_entry@12

And, you'll need an .xls but all it really contains
is a VB stub so you can call func1():

	Public Declare Function func1 Lib "<win32-path>\lib.dll" ()

Given the above code this is what I'm seeing:

  + main.exe,  lib.c fork/exec:

    Seems to work fine, but a very long delay until the cat finishes.

  + main.exe,  lib.c popen:

    Basically works, but get this message:

     0    [proc] main 30311 wait_subproc: wait failed. nchildren 1, wait
500, Win32 error 6
     8135 [proc] main 30311 wait_subproc: event[1] 0x94, Win32 error 6

  + excel.exe, lib.c fork/exec:
  + excel.exe, lib.c popen:

    Same in both these cases, you get a second Excel instance
    (first is paused) and when you close the second Excel you
    get this message and the first Excel dies too:
    
       0 [main] excel 30304 sync_with_child: child 528(0x1C0) died before
initialization with status code 0x0
    5866 [main] excel 30304 sync_with_child: *** child state waiting for
longjmp
    8769 [sig]  excel 30304 stackdump: Dumping stack trace to
excel.exe.stackdump

Any thoughts on what is happening here?

I'm using the Feb-28 snapshot.

Thanks.

Eric Fifer




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]