?
Solved

Passing File Descriptor between Processes HPUX

Posted on 2002-03-20
8
Medium Priority
?
657 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
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
LVL 5

Accepted Solution

by:
ecw earned 675 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

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

719 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