138c67bf   
   From: barmar@alum.mit.edu   
      
   In article   
   ,   
    Prakash wrote:   
      
   > Hello,   
   >   
   > I am migrating the c application from Solaris 9 SPARC to RHEL 5.x   
   > x86_64 platform.   
   >   
   > Here are the platform details:   
   > -------------------------------------------   
   > 1. OS: Red Hat Linux 5.x, kernel 2.6.x   
   > 2. gcc compiler : 4.1.2.x V   
   >   
   > ioctl() call on Linux returning errno as EFAULT (Bad Address). I have   
   > simulated the problem with below sample program. Can I know what is   
   > going wrong on Linux with this program.   
      
   Your program call printf() before checking the value of errno. Printf()   
   can modify errno, so you're printing the value that printf() set it to,   
   not what ioctl() set it to.   
      
   BTW, you seem to be going to a lot of work to reinvent perror(), which   
   prints the error message associated with errno.   
      
   >   
   > --------------   
   > /* Sample program to test the ioctl() call which sets the read mode to   
   > message-nondiscard mode.   
   > * For some reason this sample is not working on Linux x84_64, gcc :   
   > 4.1.x V and Red Hat 5.x.   
   > * However this code works on Solaris SPARC.   
   > */   
   >   
   > # include    
   > # include    
   > # include    
   > # include    
   > # include    
   > # include    
   > # include    
   > # include    
   > # include / macros I_SRDOPT and RMSGN are defined */   
   >   
   >   
   > int   
   > main(){   
   >   
   > int fd[2];   
   >   
   > int fd_read;   
   > int fd_write;   
   >   
   > fd_read= fd_write = -1; /* Initila value */   
   >   
   > /* Create unnamed socket pairs */   
   > if ( socketpair(AF_UNIX, SOCK_STREAM,0,fd) == -1 ){   
   > fprintf(stdout, "socketpair call failed with errno: %d   
   > \n", errno);   
   > exit(1);   
   > }   
   >   
   > fd_read = fd[0];   
   > fd_write = fd[1];   
   >   
   > /* fcntl code comes here to set non blocking read */   
   >   
   > if ( ioctl(fd_read, I_SRDOPT, RMSGN ) == -1 ){ /* set read   
   > mode to message -nondiscard mode */   
   > fprintf(stdout, "ioctl call failed with below error:   
   > \n" );   
   >   
   > if ( errno == EBADF )   
   > fprintf(stdout, "EBADF:The fildes argument is   
   > not a valid open file descriptor. errno: %d\n", errno );   
   > if ( errno == EFAULT )   
   > fprintf(stdout, "EFAULT:The argp is   
   > referencing an inaccessible memory area.errno: %d\n", errno );   
   > if ( errno == EAGAIN )   
   > fprintf(stdout, "EAGAIN:Unable to allocate   
   > buffers for the acknowledgement message. errno: %d\n", errno );   
   > if ( errno == EINTR )   
   > fprintf(stdout, "EINTR:A signal was caught   
   > during the ioctl() operation. errno: %d\n", errno );   
   > if ( errno == EINVAL )   
   > fprintf(stdout, "EINVAL:The request or arg   
   > argument is not valid for this device. errno: %d\n", errno );   
   > if ( errno == EIO )   
   > fprintf(stdout, "EIO:Some physical I/O error   
   > has occurred.errno: %d\n", errno );   
   > if ( errno == ENOTTY )   
   > fprintf(stdout, "ENOTTY:The fildes argument   
   > is not associated with a STREAMS device that accepts control   
   > functions. errno: %d\n", errno );   
   > if ( errno == ENXIO )   
   > fprintf(stdout, "ENXIO: The request and arg arguments are valid   
   > for this device driver, but the service requested cannot be performed   
   > on this particu- lar sub-device. errno: %d\n", errno );   
   > if ( errno == ENODEV )   
   > fprintf(stdout, "ENODEV:The fildes argument   
   > refers to a valid STREAMS device, but the corresponding device   
   > driver does not support the ioctl() func- tion. errno: %d\n", errno);   
   > exit(1);   
   > }else   
   > fprintf(stdout, "ioctl works!\n");   
   >   
   >   
   > return 0;   
   > }// main() ends   
   >   
   > Thanks in Advance.   
      
   --   
   Barry Margolin, barmar@alum.mit.edu   
   Arlington, MA   
   *** PLEASE don't copy me on replies, I'll read them in the group ***   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|