diff options
author | Gray Wolf <wolf@wolfsden.cz> | 2020-06-13 02:00:48 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2020-07-11 17:02:37 +0200 |
commit | 051665ef69568cf16a445a86a43d5ae74d303add (patch) | |
tree | e87eaedf959b41ab2c9ce5b318225b1e2a1684e6 | |
parent | d21a63f9fca8eb16f79de9b72d4a3484dfaec1fc (diff) | |
download | busybox-w32-051665ef69568cf16a445a86a43d5ae74d303add.tar.gz busybox-w32-051665ef69568cf16a445a86a43d5ae74d303add.tar.bz2 busybox-w32-051665ef69568cf16a445a86a43d5ae74d303add.zip |
crontab: Fix -e with editors saving using renaming strategy
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@wolfsden.cz>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | miscutils/crontab.c | 6 |
1 files changed, 5 insertions, 1 deletions
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) | |||
165 | close(fd); | 165 | close(fd); |
166 | xlseek(src_fd, 0, SEEK_SET); | 166 | xlseek(src_fd, 0, SEEK_SET); |
167 | } | 167 | } |
168 | close_on_exec_on(src_fd); /* don't want editor to see this fd */ | 168 | close(src_fd); |
169 | edit_file(pas, tmp_fname); | 169 | edit_file(pas, tmp_fname); |
170 | /* The src_fd needs to be reopened to handle editors that do | ||
171 | * save the buffer as new file and rename it to tmp_fname (so | ||
172 | * for example vim). */ | ||
173 | src_fd = xopen3(tmp_fname, O_RDONLY, 0600); | ||
170 | /* fall through */ | 174 | /* fall through */ |
171 | 175 | ||
172 | case 0: /* Replace (no -l, -e, or -r were given) */ | 176 | case 0: /* Replace (no -l, -e, or -r were given) */ |