delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/07/02/09:53:20

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Reply-To: <johny AT heuristics DOT com DOT au>
From: "John Ypsilantis" <johny AT heuristics DOT com DOT au>
To: <cygwin AT cygwin DOT com>
Subject: Shmget() fails when run within a program that is started by inetd. Has anyone else encountered this?
Date: Sat, 2 Jul 2005 23:52:34 +1000
Message-ID: <000001c57f0d$4f5ca060$1100a8c0@delfin>
MIME-Version: 1.0

I have come across what may be a problem with the interaction of the
shared memory subsystem with networking code that is run up by inetd.
The following program runs to completion when started interactively and
under (x)inetd control for FC3. While it also runs to completion when
started interactively under Cygwin, it crashes silently within the
shmget() call when it is run up under inetd.

The program should be run on a system with shared segment with key=1
absent.

------------------------------------------------------------------------
------------------

Code
------
(filename: testseg.c, compile as a standalone)

#include <stdio.h>
#include <cygipc/sys/ipc.h>	/* use <sys/ipc.h> for FC3 */
#include <cygipc/sys/shm.h>	/* use <sys/shm.h> for FC3>


int main()
{
    int segid;                  /* segment ID */
    struct shseg *ptr;                  /* dereference the segment */

    /* Attach to the shared segment as read-only, fail if segment not
present */
    fprintf(stdout, "About to call shmget()\n");
    fflush(stdout);
    segid = shmget(1, 1024, SHM_R); /* Process dies here under inetd */
    fprintf(stdout, "Returned from call to shmget()\n");
    fflush(stdout);

    /* Get to here if run interactively under user acct */
    ptr = (struct shseg *)shmat(segid, (char *) 0, SHM_RDONLY);
    if ((int)ptr == -1) {
        fprintf(stdout, "Segment is not defined\n");
        fflush(stdout);
        return; /* cannot process further */
    }
    shmdt((char *)ptr);
}

Configuration fragment for /etc/inetd.conf:
-------------------------------------------

testseg stream  tcp     nowait  root    /home/testacct/testseg  testseg

Configuration fragment for /etc/services:
-----------------------------------------

testseg         9190/tcp        #Test interaction of shmget and inetd

Results under FC3:
------------------

$ ./testseg
About to call shmget()
Returned from call to shmget()
Segment is not defined

$ telnet localhost testseg
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
About to call shmget()
Returned from call to shmget()
Segment is not defined
Connection closed by foreign host.

Results under Cygwin:
---------------------

$ ./testseg.exe
About to call shmget()
Returned from call to shmget()
Segment is not defined

$ telnet localhost testseg
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
About to call shmget()
Connection closed by foreign host.

------------------------------------------------------------------------
---

Has anyone else encountered this problem?

Regards,

John



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

- Raw text -


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