kqueue freezing 5.1R on kevent call

Krishna N. Ramachandran krishna at cs.ucsb.edu
Tue Aug 19 11:08:48 PDT 2003


Hi,
    The sample program given below freezes my 5.1R installation. This
program is from a bug report - kern/54331. That bug report
(http://lists.freebsd.org/pipermail/freebsd-bugs/2003-July/001608.html) is
for the shutdown function call, whereas my machine basically just freezes
up and reboots on kevent itself. I am also noticing this problem with
another program i wrote (but too long to include here). 

Here is my uname output
FreeBSD marvin 5.1-RELEASE FreeBSD 5.1-RELEASE #0: Fri Aug  1 16:14:43
GMT 2003     root@:/usr/obj/usr/src/sys/EC5  i386

thank you in advance,
Krishna

Sample Program: 

#include <stdio.h>
#include <sys/types.h>
#include <sys/event.h>
#include <unistd.h>
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>


int
main( int argc, char **argv )
{
   int queue, sock, i;
   struct sockaddr_in addr;
   struct kevent events[ 10 ];
   struct timespec ktime;

   queue = kqueue();
   if( queue == -1 ) {
      perror( "kqueue() failure" );
      exit( 1 );
   }

   sock = socket( AF_INET, SOCK_STREAM, 0 );
   /* NOTE: None of this bind() and listen() code is necessary for the
crash,
    * I'm including it to show the crash in 'normal operation'
    */
   memset( &addr, 0, sizeof( addr ));
   addr.sin_family = AF_INET;
   addr.sin_port = htons( 3456 );
   addr.sin_addr.s_addr = INADDR_ANY;
   if( bind( sock, (struct sockaddr *) &addr, sizeof( addr )) < 0 ) {
      perror( "bind" );
      exit( 1 );
   }
   if( listen( sock, 32 ) < 0 ) {
      perror( "listen" );
      exit( 1 );
   }

   /* Must add the socket to the kqueue for it to crash */
   events[ 0 ].ident  = sock;
   events[ 0 ].udata  = 0;
   events[ 0 ].filter = EVFILT_READ;
   events[ 0 ].flags  = EV_ADD;

   ktime.tv_sec = 1;
   ktime.tv_nsec = 0;

   /* CRASHES HERE ITSELF */
   i = kevent( queue, events, 1, events, 10, &ktime );
   printf( "kevent() returned %d\n", i );

   printf( "Closing socket\n" );

   /* CRASH!!! Must be a shutdown() call, close() alone won't do it. */
   shutdown( sock, SHUT_RDWR );
   close( sock );

   /* Cleanup if we survive */
   printf( "Closing queue\n" );
   close( queue );

   return 0;
}






More information about the freebsd-stable mailing list