Why close() system call returns bad status or -9 on Red Hat Enterprise Linux 5. 6 containg kernel 2.6.33.9-rt31.64.el5rt?

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Linux 5.6
  • Kernel 2.6.33.9-rt31.64.el5rt , SMP PREEMPT RT

Issue

  • Why close() system call returns bad status or -9 on Red Hat Enterprise Linux 5. 6 containg kernel 2.6.33.9-rt31.64.el5rt?
  • Kernel 2.6.24.7-149.el5rt has been upgraded to 2.6.33.9-rt31.64.el5rt. After that, xinetd exited and it can't be used any more.
  • Different behaviours has been observed on system built in RHEL5.6 with kernel 2.6.33.9-rt31.64.el5rt.

Example of code and its execution :

cat close.c 
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>

int main()
{
  int fd;
  int first,second;

  if ( (fd = open("/proc/mounts", O_RDONLY)) != -1 ){
    printf("File descriptor : %d\n",fd);
    first=close(fd);
    perror("first");
    second=close(fd);
    perror("second");
    printf("first = %d\nsecond = %d\n",first,second);
  }
  else {
    printf("Unable to open file\n");
  }
}

close() syscall return bad status concerning bad file descriptor :

File descriptor : 3
first: Success
second: Illegal seek
first = 0
second = -9

Expected result :

File descriptor : 3
first: Success
second: Bad file descriptor
first = 0
second = -1
  • This problem causes some applications to exit for bad reasons.

Resolution

Contact Solarflare for fix.

Root Cause

onload module from Solarflare seems to be causing the issue.

Diagnostic Steps

  • It has been observed in the kernel code that in some case close() syscall can return -EBADF(=-9) and 4294967287 is the two's complement of -9.
  • Compiling the code for 32 bits systems with -m32 gcc option can return correct out put ie -1.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments