Solved

Passing File Descriptor between Processes HPUX

Posted on 2002-03-20
8
617 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
  • 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
How to calculate times for developing software? 8 60
post4 challenge 28 83
Fibonacci challenge 11 84
mapBully challenge 6 92
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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…
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.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now