diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-08-04 14:28:16 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-08-04 14:28:16 +0200 |
commit | 49e6bf2db92d896a71d08eb364069ba50fa82781 (patch) | |
tree | b0940fde4d99a73e1a27c7ad0b610fe7e3f1be0c /docs | |
parent | 3346b4afc5c81d53eae4e7fc7e12ebd6fa573a4e (diff) | |
download | busybox-w32-49e6bf2db92d896a71d08eb364069ba50fa82781.tar.gz busybox-w32-49e6bf2db92d896a71d08eb364069ba50fa82781.tar.bz2 busybox-w32-49e6bf2db92d896a71d08eb364069ba50fa82781.zip |
sheel: improve comments on signal handling
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'docs')
-rw-r--r-- | docs/nofork_noexec.txt | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/docs/nofork_noexec.txt b/docs/nofork_noexec.txt index cfb02145a..b45a4be89 100644 --- a/docs/nofork_noexec.txt +++ b/docs/nofork_noexec.txt | |||
@@ -64,15 +64,27 @@ This poses much more serious limitations on what applet can do: | |||
64 | * do not use shared global data, or save/restore shared global data | 64 | * do not use shared global data, or save/restore shared global data |
65 | (e.g. bb_common_bufsiz1) prior to returning. | 65 | (e.g. bb_common_bufsiz1) prior to returning. |
66 | - getopt32() is ok to use. You do not need to save/restore option_mask32, | 66 | - getopt32() is ok to use. You do not need to save/restore option_mask32, |
67 | it is already done by core code. | 67 | xfunc_error_retval, and logmode - it is already done by core code. |
68 | * if you allocate memory, you can use xmalloc() only on the very first | 68 | * if you allocate memory, you can use xmalloc() only on the very first |
69 | allocation. All other allocations should use malloc[_or_warn](). | 69 | allocation. All other allocations should use malloc[_or_warn](). |
70 | After first allocation, you cannot use any xfuncs. | 70 | After first allocation, you cannot use any xfuncs. |
71 | Otherwise, failing xfunc will return to caller applet | 71 | Otherwise, failing xfunc will return to caller applet |
72 | without freeing malloced data! | 72 | without freeing malloced data! |
73 | * All allocated data, opened files, signal handlers, termios settings, | 73 | * the same applies to other resources, such as open fds: no xfuncs after |
74 | O_NONBLOCK flags etc should be freed/closed/restored prior to return. | 74 | acquiring them! |
75 | * ... | 75 | * All allocated data, opened files, signal handlers, termios settings |
76 | etc should be freed/closed/restored prior to return. | ||
77 | |||
78 | Currently, ash shell signal handling is implemented in a way that signals | ||
79 | have non-SA_RESTARTed handlers. This means that system calls can | ||
80 | return EINTR. An example of such problem is "yes" applet: | ||
81 | it is implemented so that it has a writing loop, this loop is exited on | ||
82 | any write error, and in the case of user pressing ^C the error was EINTR. | ||
83 | The problem is, the error causes stdout FILE* object to get into error | ||
84 | state, needing clearerr() - or else subsequent shell output will also | ||
85 | not work. ("yes" has been downgraded to NOEXEC, since hush signal handling | ||
86 | does not have this problem - which makes "yes" to not exit on ^C (bug). | ||
87 | But stray EINTRs can be seen in any NOFORK under ash, until ash is fixed). | ||
76 | 88 | ||
77 | NOFORK applets give the most of speed advantage, but are trickiest | 89 | NOFORK applets give the most of speed advantage, but are trickiest |
78 | to implement. In order to minimize amount of bugs and maintenance, | 90 | to implement. In order to minimize amount of bugs and maintenance, |
@@ -82,6 +94,8 @@ frequently executed from shell/find/xargs, particularly in shell | |||
82 | script loops. Applets which mess with signal handlers, termios etc | 94 | script loops. Applets which mess with signal handlers, termios etc |
83 | are probably not worth the effort. | 95 | are probably not worth the effort. |
84 | 96 | ||
97 | Applets which must be interruptible by ^C in shells can not be NOFORKs. | ||
98 | |||
85 | Any NOFORK applet is also a NOEXEC applet. | 99 | Any NOFORK applet is also a NOEXEC applet. |
86 | 100 | ||
87 | 101 | ||
@@ -94,7 +108,7 @@ API to call NOFORK applets is two functions: | |||
94 | 108 | ||
95 | First one is directly used by shells if FEATURE_SH_NOFORK=y. | 109 | First one is directly used by shells if FEATURE_SH_NOFORK=y. |
96 | Second one is used by many applets, but main users are xargs and find. | 110 | Second one is used by many applets, but main users are xargs and find. |
97 | It itself calls run_nofork_applet(), if argv[0] turned out to be a name | 111 | It itself calls run_nofork_applet(), if argv[0] is a name |
98 | of a NOFORK applet. | 112 | of a NOFORK applet. |
99 | 113 | ||
100 | run_nofork_applet() saves/inits/restores option parsing, xfunc_error_retval, | 114 | run_nofork_applet() saves/inits/restores option parsing, xfunc_error_retval, |