Solved

Passing File Descriptor between Processes HPUX

Posted on 2002-03-20
8
634 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

740 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