bug-fileutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: mknod for type 'SOCKET'


From: Raghuprasad Govindarao
Subject: RE: mknod for type 'SOCKET'
Date: Wed, 5 Jun 2002 16:07:18 -0400

Hello Bob,
For More info. Please compile and run the following program.
This Program shows 
1.      What is the file it creates in /tmp (The bi-product file.. Not the
socket).
2.      What is the type of file (SOCKET or otherwise)
3.      The Failure to create the Socket Type of file by the process...(As
HP does not allow this mode of creation)
This will explain why I am able to backup, but unable to restore in the
product scenerio.
Thanks 
Raghu
Program Follows:
================
/*      aCC -g -o unix_sock unix_sock.C
        On HP Machines, the following program creates This
        srwxrwxrwx   1 root       sys              0 May 24 11:58
rags_unix_sock
        on /tmp.... This is done when we do a bind() on Unix Socket.*/

#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <errno.h>
#include <sys/types.h> 
#include <sys/stat.h>

int main() {
        int sock;
        if (  (sock=socket(AF_UNIX, SOCK_STREAM, 0)) < 0 ) {
                perror("socket failed\n");
                return -1;
        }

        struct sockaddr_un unix_sock_addr;
        char ux_path[] = "/tmp/rags_unix_sock";
        bzero((void *) &unix_sock_addr, sizeof(unix_sock_addr));
        unlink(ux_path);
        unix_sock_addr.sun_family = AF_UNIX;
        strcpy(unix_sock_addr.sun_path, ux_path);
        int len = strlen(unix_sock_addr.sun_path)+
                        sizeof(unix_sock_addr.sun_family);
        if (bind(sock, (struct sockaddr_un *) &unix_sock_addr, len) < 0) {
                perror("bind failed\n");
                return -2;
        }
                /* I am trying to work on this bi product tmp file */
                struct stat st;
                if ( (stat(     ux_path, &st) != 0)) {
                        perror("stat failed\n");
                }
                if (( st.st_mode & S_IFMT) == S_IFSOCK) {
                        printf ("Mode Socket\n");
                        if ( (mknod("/tmp/Raghu_Sock_mode", S_IFSOCK, 0) !=
0)) {
                                printf ("Creation of /tmp/Raghu_Sock_mode
failed err = %s\n",
                                                strerror(errno));
                        }       else {
                                printf ("Creation of /tmp/Raghu_Sock_mode
Succeeded\n");
                        }
                } else {
                        printf ("Mode NonSocket\n");
                }
        return 0;
}
-----Original Message-----
From: Raghuprasad Govindarao 
Sent: Wednesday, June 05, 2002 3:27 PM
To: 'Bob Proulx'; Raghuprasad Govindarao
Cc: 'address@hidden'
Subject: RE: mknod for type 'SOCKET'


Hi,
Thanks for your response.

You totally misunderstood what I had to say(Rather I was not clear)...
We Use scoket(2) system call to create the sockets...no doubt about it. 
I DID NOT AND CAN NOT USE mknod() to create a socket.  But his file
/tmp/<socket_path_name> is 
a by-product of this socket() call for Unix domain socket. User does not
create this empty filr, but the 
system does(on HP). The whole discussion is about this bi-product /tmp/???
file... not the socket at all.
The mode in which this by-product file is created is "SOCKET" mode. FYI.

What I said is when we restore such a file, what simply we do is to call
mknod(2) syscall, which does
not allow us to go through successfully if the file type is "SOCKET"....
Hope its clear now.
If you have any way of creating a file with "SOCKET" type on HP, please let
me know.
Thanks,
Raghu

-----Original Message-----
From: Bob Proulx [mailto:address@hidden
Sent: Wednesday, June 05, 2002 12:34 PM
To: Raghuprasad Govindarao
Cc: 'address@hidden'
Subject: Re: mknod for type 'SOCKET'


> Hi there,
> Facts:
> 1.    Our product is a Backup-Restore product. 
> 2.    On HP11.00 Platforms, when Unix Domain Sockets are created, there is
> a /tmp/<socket_path_name> created for the UNIX PATH.
> 
> Issue: Our Backup Products are able to backup this empty file with type
> "SOCK" (I_ISSOCK = TRUE). But when we restore, the same file, system
> does not let us create a file with MODE as SOCKET... (As that is what is

How are you trying to create the socket?  You are using the the
socket(2) system call?  That is the normal way to create unix domain
sockets.  I personally had never considered it possible to create unix
domain sockets with mknod, either system call or shell command.

I am shocked and amazed that you are trying to do this with shell
scripts and are using the external GNU mknod(1) command and not using
a C program which would use the operating system kernel's mknod(2) or
socket(2) commands.  That is truly remarkable!  The GNU mknod(1)
command just calls the kernel mknod(2) command and will do whatever
the kernel allows it to do.

> backed up). But what we find from our experience is: the same types are
> able to be restored successfully on Solaris and Linux. WHy we can't do
that
> on HP or is there any way of doing it?

Could you furnish an example of creating a unix domain socket using
the standalone GNU mknod command?  That sounds interesting and I did
not realize that was possible.  On the systems where this works can
you furnish the version of the command that you are using?

While the mknod command was designed to make 'special files' the BSD
folks who created BSD network sockets created their own interface and
I don't think any of that interface ever made it back into the mknod
command.  I am probably wrong here, though.  It just does not seem too
useful to create a unix domain socket using a shell command since you
would not be able to keep hold of the file descriptor.  You would need
to create an interface where it passed the file descriptor to child
processes or some such and that gets messy really fast.  Unix domain
sockets are not like pipes where you can just open and close them
later on by random processes.

Thanks
Bob



reply via email to

[Prev in Thread] Current Thread [Next in Thread]