src/solaris/native/sun/management/OperatingSystemImpl.c

Print this page
rev 8975 : 8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests


 416         free(fds);
 417         throw_internal_error(env, "proc_pidinfo failed for PROC_PIDLISTFDS");
 418         return -1;
 419     }
 420     nfiles = res / sizeof(struct proc_fdinfo);
 421     free(fds);
 422 
 423     return nfiles;
 424 #elif defined(_ALLBSD_SOURCE)
 425     /*
 426      * XXXBSD: there's no way available to do it in FreeBSD, AFAIK.
 427      */
 428     // throw_internal_error(env, "Unimplemented in FreeBSD");
 429     return (100);
 430 #else /* solaris/linux */
 431     DIR *dirp;
 432     struct dirent dbuf;
 433     struct dirent* dentp;
 434     jlong fds = 0;
 435 
 436     dirp = opendir("/proc/self/fd");









 437     if (dirp == NULL) {
 438         throw_internal_error(env, "Unable to open directory /proc/self/fd");
 439         return -1;
 440     }
 441 
 442     // iterate through directory entries, skipping '.' and '..'
 443     // each entry represents an open file descriptor.
 444     while ((dentp = read_dir(dirp, &dbuf)) != NULL) {
 445         if (isdigit(dentp->d_name[0])) {
 446             fds++;
 447         }
 448     }
 449 
 450     closedir(dirp);
 451     // subtract by 1 which was the fd open for this implementation
 452     return (fds - 1);
 453 #endif
 454 }
 455 
 456 JNIEXPORT jlong JNICALL


 416         free(fds);
 417         throw_internal_error(env, "proc_pidinfo failed for PROC_PIDLISTFDS");
 418         return -1;
 419     }
 420     nfiles = res / sizeof(struct proc_fdinfo);
 421     free(fds);
 422 
 423     return nfiles;
 424 #elif defined(_ALLBSD_SOURCE)
 425     /*
 426      * XXXBSD: there's no way available to do it in FreeBSD, AFAIK.
 427      */
 428     // throw_internal_error(env, "Unimplemented in FreeBSD");
 429     return (100);
 430 #else /* solaris/linux */
 431     DIR *dirp;
 432     struct dirent dbuf;
 433     struct dirent* dentp;
 434     jlong fds = 0;
 435 
 436 #if defined(_AIX)
 437 /* AIX does not understand '/proc/self' - it requires the real process ID */
 438 #define FD_DIR aix_fd_dir
 439     char aix_fd_dir[32];     /* the pid has at most 19 digits */
 440     snprintf(aix_fd_dir, 32, "/proc/%d/fd", getpid());
 441 #else
 442 #define FD_DIR "/proc/self/fd"
 443 #endif
 444 
 445     dirp = opendir(FD_DIR);
 446     if (dirp == NULL) {
 447         throw_internal_error(env, "Unable to open directory /proc/self/fd");
 448         return -1;
 449     }
 450 
 451     // iterate through directory entries, skipping '.' and '..'
 452     // each entry represents an open file descriptor.
 453     while ((dentp = read_dir(dirp, &dbuf)) != NULL) {
 454         if (isdigit(dentp->d_name[0])) {
 455             fds++;
 456         }
 457     }
 458 
 459     closedir(dirp);
 460     // subtract by 1 which was the fd open for this implementation
 461     return (fds - 1);
 462 #endif
 463 }
 464 
 465 JNIEXPORT jlong JNICALL