Close stdin/out after child is forked

Testcase:

{ sleep 1; yes | head -n99999; } | strace -o/dev/null sh -c 'exec <&-; sleep 9'

The writer (head) will be able to perform writes to write end of the pipe.
With strace call removed, head will immediately get SIGPIPE.

This change fixes this: now writer immediately gets SIGPIPE with strace too.

* strace.c (startup_child): Close stdin/out and reopen them to /dev/null.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
1 file changed
tree: f9a3076f725d0077e01a33f6a47339a5216adc2c
  1. debian/
  2. linux/
  3. m4/
  4. maint/
  5. qemu_multiarch_testing/
  6. test/
  7. tests/
  8. xlat/
  9. .gitignore
  10. .mailmap
  11. .travis.yml
  12. access.c
  13. affinity.c
  14. aio.c
  15. alpha.c
  16. AUTHORS
  17. bjm.c
  18. block.c
  19. bootstrap
  20. bpf.c
  21. build_static_example.sh
  22. cacheflush.c
  23. capability.c
  24. caps0.h
  25. caps1.h
  26. ChangeLog-CVS
  27. chdir.c
  28. chmod.c
  29. clone.c
  30. configure.ac
  31. COPYING
  32. count.c
  33. CREDITS.in
  34. defs.h
  35. desc.c
  36. dirent.c
  37. dirent64.c
  38. empty.h
  39. epoll.c
  40. errnoent.sh
  41. evdev.c
  42. eventfd.c
  43. execve.c
  44. exit.c
  45. fadvise.c
  46. fallocate.c
  47. fanotify.c
  48. fchownat.c
  49. fcntl.c
  50. fetch_seccomp_fprog.c
  51. fetch_struct_flock.c
  52. file.c
  53. file_handle.c
  54. flock.c
  55. flock.h
  56. futex.c
  57. gcc_compat.h
  58. generate_mpers_am.sh
  59. generate_sen.sh
  60. generate_xlat_in.sh
  61. get_robust_list.c
  62. getcpu.c
  63. getcwd.c
  64. getrandom.c
  65. git-set-file-times
  66. git-version-gen
  67. gitlog-to-changelog
  68. HACKING-scripts
  69. hostname.c
  70. inotify.c
  71. INSTALL
  72. io.c
  73. ioctl.c
  74. ioctlsort.c
  75. ioperm.c
  76. iopl.c
  77. ioprio.c
  78. ipc_defs.h
  79. ipc_msg.c
  80. ipc_msgctl.c
  81. ipc_sem.c
  82. ipc_shm.c
  83. ipc_shmctl.c
  84. kcmp.c
  85. kernel_types.h
  86. kexec.c
  87. keyctl.c
  88. ldt.c
  89. link.c
  90. lookup_dcookie.c
  91. loop.c
  92. lseek.c
  93. make-dist
  94. Makefile.am
  95. mem.c
  96. membarrier.c
  97. memfd_create.c
  98. mknod.c
  99. mount.c
  100. mpers.awk
  101. mpers.sh
  102. mpers_test.sh
  103. mpers_type.h
  104. mq.c
  105. mtd.c
  106. native_defs.h
  107. net.c
  108. NEWS
  109. open.c
  110. or1k_atomic.c
  111. pathtrace.c
  112. perf.c
  113. personality.c
  114. poll.c
  115. prctl.c
  116. print_mq_attr.c
  117. print_msgbuf.c
  118. print_sigevent.c
  119. print_time.c
  120. print_timex.c
  121. printmode.c
  122. printrusage.c
  123. printsiginfo.c
  124. printsiginfo.h
  125. printstat.h
  126. process.c
  127. process_vm.c
  128. ptp.c
  129. ptrace.h
  130. quota.c
  131. readahead.c
  132. readlink.c
  133. README
  134. README-hacking
  135. README-linux-ptrace
  136. README-mpers
  137. README.md
  138. reboot.c
  139. regs.h
  140. renameat.c
  141. resource.c
  142. rtc.c
  143. sched.c
  144. scsi.c
  145. seccomp.c
  146. seccomp_fprog.h
  147. sendfile.c
  148. sigaltstack.c
  149. sigevent.h
  150. signal.c
  151. signalent.sh
  152. signalfd.c
  153. sigreturn.c
  154. sock.c
  155. socketutils.c
  156. sram_alloc.c
  157. statfs.c
  158. strace-graph
  159. strace-log-merge
  160. strace.1
  161. strace.c
  162. strace.spec
  163. swapon.c
  164. sync_file_range.c
  165. syscall.c
  166. syscallent.sh
  167. sysctl.c
  168. sysinfo.c
  169. syslog.c
  170. sysmips.c
  171. term.c
  172. time.c
  173. times.c
  174. travis-ci.sh
  175. truncate.c
  176. uid.c
  177. uid16.c
  178. umask.c
  179. umount.c
  180. uname.c
  181. unwind.c
  182. userfaultfd.c
  183. util.c
  184. utime.c
  185. utimes.c
  186. v4l2.c
  187. vsprintf.c
  188. wait.c
  189. xattr.c
  190. xlate.el
  191. xmalloc.c
README.md

This is strace -- a diagnostic, debugging and instructional userspace utility for Linux. It is used to monitor interactions between processes and the Linux kernel, which include system calls, signal deliveries, and changes of process state. The operation of strace is made possible by the kernel feature known as ptrace.

strace is released under a Berkeley-style license at the request of Paul Kranenburg; see the file COPYING for details.

See the file NEWS for information on what has changed in recent versions.

Please send bug reports and enhancements to the strace mailing list.

Build Status Code Coverage