Solved

Passing File Descriptor between Processes HPUX

Posted on 2002-03-20
8
640 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
Industry Leaders: 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Suggested Solutions

Title # Comments Views Activity
List out all word 7 359
centeredAverage challenge 8 188
Use of condition with 'serial' in ansible 2 102
Trying to run powershell  in a batch file. How do I do this? 8 124
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

751 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