diff options
Diffstat (limited to 'miscutils/crontab.c')
-rw-r--r-- | miscutils/crontab.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/miscutils/crontab.c b/miscutils/crontab.c index 94d69f032..dc3179dac 100644 --- a/miscutils/crontab.c +++ b/miscutils/crontab.c | |||
@@ -18,9 +18,6 @@ | |||
18 | #ifndef CRONUPDATE | 18 | #ifndef CRONUPDATE |
19 | #define CRONUPDATE "cron.update" | 19 | #define CRONUPDATE "cron.update" |
20 | #endif | 20 | #endif |
21 | #ifndef PATH_VI | ||
22 | #define PATH_VI "/bin/vi" /* location of vi */ | ||
23 | #endif | ||
24 | 21 | ||
25 | static void change_user(const struct passwd *pas) | 22 | static void change_user(const struct passwd *pas) |
26 | { | 23 | { |
@@ -56,7 +53,7 @@ static void edit_file(const struct passwd *pas, const char *file) | |||
56 | if (!ptr) { | 53 | if (!ptr) { |
57 | ptr = getenv("EDITOR"); | 54 | ptr = getenv("EDITOR"); |
58 | if (!ptr) | 55 | if (!ptr) |
59 | ptr = PATH_VI; | 56 | ptr = "vi"; |
60 | } | 57 | } |
61 | 58 | ||
62 | BB_EXECLP(ptr, ptr, file, NULL); | 59 | BB_EXECLP(ptr, ptr, file, NULL); |
@@ -181,14 +178,16 @@ int crontab_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
181 | 178 | ||
182 | case OPT_e: /* Edit */ | 179 | case OPT_e: /* Edit */ |
183 | tmp_fname = xasprintf("%s.%u", crontab_dir, (unsigned)getpid()); | 180 | tmp_fname = xasprintf("%s.%u", crontab_dir, (unsigned)getpid()); |
184 | fd = xopen3(tmp_fname, O_RDWR|O_CREAT|O_TRUNC|O_EXCL, 0600); | 181 | /* No O_EXCL: we don't want to be stuck if earlier crontabs |
182 | * were killed, leaving stale temp file behind */ | ||
183 | fd = xopen3(tmp_fname, O_RDWR|O_CREAT|O_TRUNC, 0600); | ||
185 | xmove_fd(fd, STDIN_FILENO); | 184 | xmove_fd(fd, STDIN_FILENO); |
185 | fchown(STDIN_FILENO, pas->pw_uid, pas->pw_gid); | ||
186 | fd = open(pas->pw_name, O_RDONLY); | 186 | fd = open(pas->pw_name, O_RDONLY); |
187 | if (fd >= 0) { | 187 | if (fd >= 0) { |
188 | bb_copyfd_eof(fd, STDIN_FILENO); | 188 | bb_copyfd_eof(fd, STDIN_FILENO); |
189 | close(fd); | 189 | close(fd); |
190 | } | 190 | } |
191 | fchown(STDIN_FILENO, pas->pw_uid, pas->pw_gid); | ||
192 | edit_file(pas, tmp_fname); | 191 | edit_file(pas, tmp_fname); |
193 | xlseek(STDIN_FILENO, 0, SEEK_SET); | 192 | xlseek(STDIN_FILENO, 0, SEEK_SET); |
194 | /* fall through */ | 193 | /* fall through */ |