Solved

Passing File Descriptor between Processes HPUX

Posted on 2002-03-20
8
649 Views
Last Modified: 2013-12-26
I need the ability to pass a open file descriptor (or to be more precise, a socket descriptor) from one process to another.

I am on HPUX 11 using GCC as my compiler.  In the books Ive read, they suggest using ioctl to send file descriptors over stream pipes.  Problem is once I open a pipe, and try to call ioctl using I_SENDFD, I get an error 25 NOTTY (Not valid operation on this device).

1) Does anyone have a better method? or

2) Can someone point me in some sort of direction to help me fix this problem?

P.S. - I get the same error using the ANSI CC compiler we purchased from HP.

0
Comment
Question by:CodeWizrd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 
LVL 5

Expert Comment

by:ecw
ID: 6883567
By default, pipe on ux11 are old style, ie. not STREAMS based.  Change the kernel paramamter "streampipes" to non zero, and mkae sure pipedev and pipemod are in /stand/system.  See streampipes(5) man page.
0
 
LVL 1

Author Comment

by:CodeWizrd
ID: 6886774
Ok.  I've checked and the kernel parameter "streampipes" is set to 1, and pipedev and pipemod are both in /stand/system.

Here is the code as I have it:

    if (fd >= 0) {
        if (ioctl(clifd, I_SENDFD, sock_fd) < 0) {
            printf("errno is %d\n",errno);
            *retval = -2;
            return;
        }
    }

clifd is a named pipe (FIFO) and sock_fd is an open socket descriptor.

Again, this is a killer for me, I really need to pass an open socket descriptor to another process.  I got some more question points and increased the value to all I have currently (200).  Please help!!!!
0
 
LVL 1

Author Comment

by:CodeWizrd
ID: 6886785

Oops...the first if statement reads if (sock_fd > 0) (typo) so the function REALLY is:

    if (sock_fd >= 0) {
        if (ioctl(clifd, I_SENDFD, sock_fd) < 0) {
            printf("errno is %d\n",errno);
            *retval = -2;
            return;
        }
    }
0
Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

 
LVL 5

Accepted Solution

by:
ecw earned 225 total points
ID: 6889213
I'm not sure, having not touched an HP for a year, but I don't think named pipes are ever STREAMS based.  If you need to pass an fd around using something that exists in filesystem namespace, why not use Unix domain sockets?
0
 
LVL 1

Author Comment

by:CodeWizrd
ID: 6889275
I have also tried to create a stream pipe , and then push connld onto the pipe head, but that isnt working either.

I dont -NEED- to pass the descriptor through the filesystem.  I have 2 seperate processes (actually, many more, but two will suffice for wehat I need).  They each know who the other is (ie, they do know what the other's PID is).  I need to be able to have one pass an open socket descriptor to another.  But I do not want a CONSTANT connection open between them.  I want to be able to open a connection, send the descriptor, then bot sides can close the connection and go about thier merry ways.

Anyone?

0
 
LVL 2

Expert Comment

by:kejin
ID: 6892543
On HP, you can use sendmsg/recvmsg() on unix domain socket to pass file descriptor between
processes. See Steven's book.
0
 
LVL 1

Author Comment

by:CodeWizrd
ID: 6894386

I've got Richard Stevens books Advanced Programming in the Unix Environment and Unix network programming.  Brand new editions I bought from Amazon about 2 weeks ago.

The only way I saw them work in the text is using ioctl() with the I_SENDFD and I_RECVFD parameters.

Now, I was trying to do this with a named (FIFO) pipe at first, and keep getting a 25 error.  So I kept reading and it says that I can created a named STREAM pipe by opening a pipe and then using ioctl() using I_PUSH to push "connld" onto the streamhead, which would then let me fattach() a name to the pipe.  I'm getting a 22 error (Invalid Argument), I believe on the "connld" part.

I'm adding more question points (all I have)! I rerally need to get this working...
0
 
LVL 1

Author Comment

by:CodeWizrd
ID: 6903162
Took me awhile to figure it out, but I got it working through unix domain sockets.  It would have been helpfull to realize that HPUX does not support SVR4 streams completely, and that it's support for unix domain sockets is limited to 4.3BSD.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question