delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin-developers/2000/03/02/13:48:41

Mailing-List: contact cygwin-developers-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-developers-subscribe AT sourceware DOT cygnus DOT com>
List-Archive: <http://sourceware.cygnus.com/ml/cygwin-developers/>
List-Post: <mailto:cygwin-developers AT sourceware DOT cygnus DOT com>
List-Help: <mailto:cygwin-developers-help AT sourceware DOT cygnus DOT com>, <http://sourceware.cygnus.com/ml/#faqs>
Sender: cygwin-developers-owner AT sourceware DOT cygnus DOT com
Delivered-To: mailing list cygwin-developers AT sourceware DOT cygnus DOT com
Message-ID: <779F20BCCE5AD31186A50008C75D99791716F2@SILLDN_MAIL1>
From: "Fifer, Eric" <EFifer AT sanwaint DOT com>
To: cygwin-developers AT sourceware DOT cygnus DOT com
Subject: problem with fork/exec in Cygwin DLL called from non-Cygwin EXE
Date: Thu, 2 Mar 2000 17:45:49 -0000
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.5.2448.0)

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 AT 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



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019