[git commit] crontab: Fix -e with editors saving using renaming strategy
Denys Vlasenko
vda.linux at googlemail.com
Sat Jul 11 15:02:37 UTC 2020
commit: https://git.busybox.net/busybox/commit/?id=051665ef69568cf16a445a86a43d5ae74d303add
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master
Some editors (like vim) use renaming strategy to save file. That means
they save a file to some random name and then rename it to final
location. The advantage is that such save is atomic.
However, crontab -e holds open fd to the temporary file, meaning it
never sees the changes. The temporary file needs to be re-opened after
the editor terminates for the changes to properly save.
Fixes #12491
Signed-off-by: Gray Wolf <wolf at wolfsden.cz>
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
miscutils/crontab.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/miscutils/crontab.c b/miscutils/crontab.c
index c71d914fc..411a18a50 100644
--- a/miscutils/crontab.c
+++ b/miscutils/crontab.c
@@ -165,8 +165,12 @@ int crontab_main(int argc UNUSED_PARAM, char **argv)
close(fd);
xlseek(src_fd, 0, SEEK_SET);
}
- close_on_exec_on(src_fd); /* don't want editor to see this fd */
+ close(src_fd);
edit_file(pas, tmp_fname);
+ /* The src_fd needs to be reopened to handle editors that do
+ * save the buffer as new file and rename it to tmp_fname (so
+ * for example vim). */
+ src_fd = xopen3(tmp_fname, O_RDONLY, 0600);
/* fall through */
case 0: /* Replace (no -l, -e, or -r were given) */
More information about the busybox-cvs
mailing list