[Closed] TestFile#test_statfs = Bad System Call on Solaris

Issue #9788 has been updated by Naohisa G…

Status changed from Open to Closed
% Done changed from 0 to 100

Applied in changeset r45768.


  • file.c (FSTATFS): check availability of struct statfs and
    struct statvfs in addition to fstatfs(2) and fstatvfs(2).
    This fixes error in Solaris. [Bug #9788] [ruby-dev:48145]

Bug #9788: TestFile#test_statfs = Bad System Call on Solaris

  • Author: Naohisa G.
  • Status: Closed
  • Priority: Normal
  • Assignee:
  • Category:
  • Target version:
  • ruby -v: ruby 2.2.0dev (2014-04-30) [sparc64-solaris2.10]
  • Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN

Solaris 10 にて、make test-all が以下のエラーで中断します。(r45759 で確認。)

 TestFile#test_statfs = Bad System Call
 make: *** [yes-test-all] Error 140

以下のように、statfsメソッド内にて呼んでいるfstatfsシステムコールがSIGSYSを発生させているようです。

 % truss ruby -e 'f = open("/bin/ls"); p f.statfs'
 (前略)
 /1:     open("/bin/ls", O_RDONLY)                       = 7
 /1:     fcntl(7, F_GETFD, 0x000001B6)                   = 0
 /1:     fcntl(7, F_SETFD, 0x00000001)                   = 0
 /1:     ioctl(7, TCGETA, 0xFFFFFFFF7FFFC91C)            Err#25 ENOTTY
 /1:     fstatfs()                                       Err#89 ENOSYS
 /1:         Received signal #12, SIGSYS [default]

configureの関連する出力を抜き出すと以下になります。

 checking for struct statfs... no
 checking for struct statvfs... yes
 checking for struct statvfs.f_fstypename... no
 (略)
 checking for fstatfs... yes
 checking for fstatvfs... yes

関連するコンパイル時のwarningを以下に示します。

 cc -xO1 -xtarget=sparc64viiplus -m64 -DRUBY_EXPORT 
-I/usr/local/64/lib/libffi-3.0.10/include -I/usr/local/64/include   -I. 
-I.ext/include/sparc64-solaris2.10 -I./include -I. -o file.o -c file.c
 "file.c", line 1157: warning: implicit function declaration: fstatfs

Solaris 10 では、fstatfs(2) は存在しますが、/usr/include/sys/statfs.h
をincludeしないと定義が読み込まれません。また、/usr/include/sys/statfs.h 内には

/*

  • Structure returned by statfs(2) and fstatfs(2).
  • This structure and associated system calls have been replaced
  • by statvfs(2) and fstatvfs(2) and will be removed from the system
  • in a near-future release.
    */

という記述があり、現在のSolaris10では、削除はされていないものの、呼んでもSIGSYSかENOSYSを返してまともに動作しないようです。(または、未確認ですが、UFSなど昔からあるファイルシステムでのみ有効なのかもしれない?)

そして、現在の file.c では #if defined(HAVE_FSTATFS) の場合には必ず fstatfs()
を呼ぶため、上記のエラーが発生したようです。

幸い、struct statfs は(sys/statfs.h
を明示的にincludeしない限り)定義されないため、以下のように、fstatfs と同時に struct statfs
の有無をチェックするようにしたら、エラーで make test-all が中断されることはなくなりました。ついでに、struct statvfs
の有無もチェックするようにしています。

 --- file.c  (revision 45760)
 +++ file.c  (working copy)
 @@ -92,9 +92,9 @@
  #endif
  #ifndef WITHOUT_STATFS
  static VALUE rb_statfs_new(const statfs_t *st);
 -#if defined(HAVE_FSTATFS)
 +#if defined(HAVE_FSTATFS) && defined(HAVE_STRUCT_STATFS)
  #define FSTATFS(f, s) fstatfs((f), (s))
 -#elif defined(HAVE_FSTATVFS)
 +#elif defined(HAVE_FSTATVFS) && defined(HAVE_STRUCT_STATVFS)
  #define FSTATFS(f, s) fstatvfs((f), (s))
  #endif
  #endif