This is bug 1171830. | Document ID: 1171830 | Title: bug 1171830 | Synopsis: select/poll hangs when the standard input is /dev/null | Update Date: Thu Feb 25 11:43:00 MST 1999 | | Bug ID: 1171830 | | Synopsis: select/poll hangs when the standard input is /dev/null | | Category: kernel | | Subcategory: other | | State: integrated | | Priority: | | Responsible Manager: | | Responsible Engineer: | | Description: | | The select / poll call hangs when the standard input is /dev/null. The test | program follows | | | #include | #include | #include | | int main() | { | while (1) | { | fd_set rfds; | FD_ZERO(&rfds); | FD_SET(0, &rfds); /* stdin */ | | select(1, &rfds, 0, &rfds, 0); /* wait for input */ | | if (FD_ISSET(0, &rfds)) | { | char buf[1024]; | int n = read(0, buf, sizeof buf); | if (n < 1) | return n; | write(1, buf, n); | } | } | } | | truss output | ---------- | address@hidden>120: truss ./sel < /dev/null | execve("./sel", 0xEFFFFA78, 0xEFFFFA80) argc = 1 | open("/usr/openwin/lib/libc.so.1", O_RDONLY, 035737751470) Err#2 ENOENT | open("/usr/lib/libc.so.1", O_RDONLY, 035737751470) = 3 | mmap(0x00000000, 4096, PROT_READ, MAP_SHARED, 3, 0) = 0xEF7F9000 | fstat(3, 0xEFFFF6A0) = 0 | mmap(0x00000000, 495616, PROT_READ|PROT_EXEC, MAP_SHARED, 3, 0) = 0xEF740000 | mmap(0xEF740000, 390807, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 3, 0) = | 0xEF740000 | munmap(0xEF7A0000, 61440) = 0 | mmap(0xEF7AF000, 21904, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, | 3, 389120) = 0xEF7AF000 | open("/dev/zero", O_RDONLY, 036000000000) = 5 | mmap(0xEF7B5000, 13532, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, | 5, 0) = 0xEF7B5000 | close(3) = 0 | munmap(0xEF7F9000, 4096) = 0 | open("/usr/openwin/lib/libdl.so.1", O_RDONLY, 035737752210) Err#2 ENOENT | open("/usr/lib/libdl.so.1", O_RDONLY, 035737752210) = 3 | mmap(0x00000000, 4096, PROT_READ, MAP_SHARED, 3, 0) = 0xEF7F9000 | fstat(3, 0xEFFFF6A0) = 0 | mmap(0x00000000, 69632, PROT_READ|PROT_EXEC, MAP_SHARED, 3, 0) = 0xEF7C9000 | munmap(0xEF7C9000, 69632) = 0 | mmap(0x00000000, 135168, PROT_READ|PROT_EXEC, MAP_SHARED, 3, 0) = 0xEF71D000 | munmap(0xEF71D000, 12288) = 0 | mmap(0xEF720000, 1248, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 3, 0) = | 0xEF720000 | munmap(0xEF721000, 118784) = 0 | close(3) = 0 | close(5) = 0 | poll(0xEFFFD538, 1, -1) (sleeping...) | | Patches Installed | ------------- | | 101231-02 | 101294-01 | 101306-01 | 101316-01 | 101317-06 | 101318-41 | 101318-42 | 101318-44 | 101318-45 | 101318-48 | 101318-49 | 101327-05 | 101329-11 | 101331-03 | 101344-05 | 101345-02 | 101347-01 | 101359-01 | 101362-11 | 101362-13 | 101362-14 | 101362-16 | 101378-02 | 101409-03 | 101411-04 | 101415-02 | 101416-01 | 101428-09 | 101429-02 | 101429-03 | 101448-01 | 101489-04 | 101493-01 | 101494-01 | 101495-01 | 101500-02 | 101512-07 | 101512-08 | 101513-01 | 101514-01 | 101515-02 | 101517-01 | 101520-01 | 101543-01 | 101578-01 | 101599-01 | 101605-01 | 101636-04 | 101647-01 | 101653-01 | | The user wants this problem to be resolved in future releases, since, | one of their applications was using this feature. under SunOS 4.1.3. | | The description field as copied from bug report 1163571 follows: | | Customer hsas observed that programs using select(3c) block "forever". | The short program below will demostrate this phenomenum if you invoke | as follows: | | % test | #include | #include | | | main() | { | | fd_set rmask; | | FD_ZERO(&rmask); | FD_SET(STDIN_FILENO, &rmask); | | | select(STDIN_FILENO+1, &rmask, NULL, NULL, NULL); | printf("all done\\n"); | } | | This test works well under 4.x and the manpage seems to be _VERY_ | similar thus one expects that it would return on first pass and print | the message. THe following is truss output for this test: | | %[62] test