From: Dominique Martinet <dominique.marti...@atmark-techno.com> sed would currently not error if write failed when modifying a file.
This can be reproduced with the following 'script': $ sudo mount -t tmpfs tmpfs -o size=1M /tmp/m $ sudo chmod 777 /tmp/m $ echo foo > /tmp/m/foo $ dd if=/dev/zero of=/tmp/m/fill bs=4k dd: error writing '/tmp/m/fill': No space left on device 256+0 records in 255+0 records out 1044480 bytes (1.0 MB, 1020 KiB) copied, 0.00234567 s, 445 MB/s $ busybox sed -i -e 's/.*/bar/' /tmp/m/foo $ echo $? 0 $ cat /tmp/m/foo <empty> new behaviour: $ echo foo > /tmp/m/foo $ ./busybox sed -i -e 's/.*/bar/' /tmp/m/foo sed: write error $ echo $? 4 $ cat /tmp/m/foo foo function old new delta sed_main 765 788 +23 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/0 up/down: 23/0) Total: 23 bytes text data bss dec hex filename 793709 14340 1976 810025 c5c29 busybox_old 793732 14340 1976 810048 c5c40 busybox_unstripped Signed-off-by: Dominique Martinet <dominique.marti...@atmark-techno.com> --- There are other places where we're not checking return codes when I think we should, but that fixes my immediate problem. Resend from my personal mail address as mails are only allowed from subscribers on the list... Sorry for double mail Denys. editors/sed.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/editors/sed.c b/editors/sed.c index 32a4b61f6d4c..31ade17477ca 100644 --- a/editors/sed.c +++ b/editors/sed.c @@ -1639,7 +1639,10 @@ int sed_main(int argc UNUSED_PARAM, char **argv) fchown(nonstdoutfd, statbuf.st_uid, statbuf.st_gid); process_files(); - fclose(G.nonstdout); + if (fclose(G.nonstdout)) { + xfunc_error_retval = 4; /* It's what gnu sed exits with... */ + bb_simple_error_msg_and_die(bb_msg_write_error); + } G.nonstdout = stdout; if (opt_i) { -- 2.35.1 _______________________________________________ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox