aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-08-04 14:28:16 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-08-04 14:28:16 +0200
commit49e6bf2db92d896a71d08eb364069ba50fa82781 (patch)
treeb0940fde4d99a73e1a27c7ad0b610fe7e3f1be0c /docs
parent3346b4afc5c81d53eae4e7fc7e12ebd6fa573a4e (diff)
downloadbusybox-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.txt24
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
78Currently, ash shell signal handling is implemented in a way that signals
79have non-SA_RESTARTed handlers. This means that system calls can
80return EINTR. An example of such problem is "yes" applet:
81it is implemented so that it has a writing loop, this loop is exited on
82any write error, and in the case of user pressing ^C the error was EINTR.
83The problem is, the error causes stdout FILE* object to get into error
84state, needing clearerr() - or else subsequent shell output will also
85not work. ("yes" has been downgraded to NOEXEC, since hush signal handling
86does not have this problem - which makes "yes" to not exit on ^C (bug).
87But stray EINTRs can be seen in any NOFORK under ash, until ash is fixed).
76 88
77NOFORK applets give the most of speed advantage, but are trickiest 89NOFORK applets give the most of speed advantage, but are trickiest
78to implement. In order to minimize amount of bugs and maintenance, 90to implement. In order to minimize amount of bugs and maintenance,
@@ -82,6 +94,8 @@ frequently executed from shell/find/xargs, particularly in shell
82script loops. Applets which mess with signal handlers, termios etc 94script loops. Applets which mess with signal handlers, termios etc
83are probably not worth the effort. 95are probably not worth the effort.
84 96
97Applets which must be interruptible by ^C in shells can not be NOFORKs.
98
85Any NOFORK applet is also a NOEXEC applet. 99Any 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
95First one is directly used by shells if FEATURE_SH_NOFORK=y. 109First one is directly used by shells if FEATURE_SH_NOFORK=y.
96Second one is used by many applets, but main users are xargs and find. 110Second one is used by many applets, but main users are xargs and find.
97It itself calls run_nofork_applet(), if argv[0] turned out to be a name 111It itself calls run_nofork_applet(), if argv[0] is a name
98of a NOFORK applet. 112of a NOFORK applet.
99 113
100run_nofork_applet() saves/inits/restores option parsing, xfunc_error_retval, 114run_nofork_applet() saves/inits/restores option parsing, xfunc_error_retval,