public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Lenci Damien <dlenci@sopragroup.com>
To: "cygwin@cygwin.com" <cygwin@cygwin.com>
Subject: Re: problem with fork() and temp dlls
Date: Fri, 29 Jun 2012 09:57:00 -0000	[thread overview]
Message-ID: <7925_1340963812_4FED7BE3_7925_5434_2_B03025C959FD1A4796D42DC68C9C0823046C652B@wancyexmbx01.ancy.fr.sopra> (raw)

> Looks like fork problems to me.  Perhaps you need to rebase the DLLs you're
> building?  See the link below for more info:

I've already done that, sorry I should have mentioned it.
I made a simple testcase reproducing the module loading algorithm of nagios :

File mydll.c is only:
int testvar = 42;


Compiled with :
gcc -shared -o mydll.dll mydll.c


File mymain.c :
 
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dlfcn.h>
#include <fcntl.h>
#include <stdlib.h>

int main (void){

        char output_file[80];
        int dest_fd;
        int source_file;
        void *buf;
        struct stat st;

        void *dllhandle;
        int *testvar;

        snprintf(output_file, sizeof(output_file) - 1, "nebmodXXXXXX");
        dest_fd = mkstemp(output_file);
        source_file = open("mydll.dll",O_RDONLY, 0644);

        fstat(source_file, &st);
        int buf_size = st.st_size;
        buf = malloc(buf_size);

        read( source_file, buf, buf_size);
        write(dest_fd, buf, buf_size);

        free(buf);

        fchmod(dest_fd, S_IRWXU);
        close(dest_fd);
        dllhandle = dlopen(output_file, RTLD_NOW | RTLD_GLOBAL);

        if (dllhandle == NULL) {
                printf("Unable to load dll : %s\n", dlerror());
                return 1;
        }

        unlink(output_file);

        if (fork()){
                testvar = (int *)dlsym(dllhandle, "testvar");
                printf("parent : %d\n", *testvar);
        }
        else{
                testvar = (int *)dlsym(dllhandle, "testvar");
                printf("child : %d\n", *testvar);
        }

}

Compiled with :
gcc -o mymain mymain.c

If I run this I got :
$ ./mymain.exe
      0 [main] mymain 6040 child_info_fork::abort: unable to map XXXXXX\tmp\dllforktest\nebmod5Ix5re, Win32 error 126
parent : 42

If I change the dlopen to load the original dll:
dllhandle = dlopen("mydll.dll", RTLD_NOW | RTLD_GLOBAL);

It works fine...

That means fork() try to reload the dll from file while it is already loaded by the parent process and I'm wondering why.
Is it a normal and wanted behavior? (don't think so, it works fine on debian)
Is it not wanted but normal (windows restriction maybe)?
Or is it some kind of bug in the fork implementation?

Thanks,

Damien Lenci

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

             reply	other threads:[~2012-06-29  9:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-29  9:57 Lenci Damien [this message]
2012-06-29 10:16 ` marco atzeri
  -- strict thread matches above, loose matches on Subject: below --
2012-06-29 12:08 Lenci Damien
2012-06-29 15:36 ` marco atzeri
2012-06-28  9:08 Lenci Damien
2012-06-28 14:55 ` Larry Hall (Cygwin)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7925_1340963812_4FED7BE3_7925_5434_2_B03025C959FD1A4796D42DC68C9C0823046C652B@wancyexmbx01.ancy.fr.sopra \
    --to=dlenci@sopragroup.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).