diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-17 14:30:03 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-17 14:30:03 +0000 |
commit | 03b4c14bd4815f7d0f4b91d90985dfcd8a352025 (patch) | |
tree | e22013535132cf276facc5946e346bc38f277474 /miscutils | |
parent | b3b0753593abaf307c961bd45f5e2385a852a076 (diff) | |
download | busybox-03b4c14bd4815f7d0f4b91d90985dfcd8a352025.tar.gz |
crontab: stop using remove() - use unlink() instead
Diffstat (limited to 'miscutils')
-rw-r--r-- | miscutils/crontab.c | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/miscutils/crontab.c b/miscutils/crontab.c index a1fe2c5a5..bc7f56a22 100644 --- a/miscutils/crontab.c +++ b/miscutils/crontab.c @@ -65,33 +65,26 @@ static void edit_file(const struct passwd *pas, const char *file) static int open_as_user(const struct passwd *pas, const char *file) { - struct fd_pair filedes; pid_t pid; char c; - xpiped_pair(filedes); pid = vfork(); if (pid < 0) /* ERROR */ bb_perror_msg_and_die("vfork"); if (pid) { /* PARENT */ - int n = safe_read(filedes.rd, &c, 1); - close(filedes.rd); - close(filedes.wr); - if (n > 0) /* child says it can read */ + if (wait4pid(pid) == 0) { + /* exitcode 0: child says it can read */ return open(file, O_RDONLY); + } return -1; } /* CHILD */ - /* initgroups, setgid, setuid */ change_identity(pas); - - /* We just try to read one byte. If that works, file is readable - * under this user. We signal that by sending one byte to parent. */ - if (safe_read(xopen(file, O_RDONLY), &c, 1) == 1) - safe_write(filedes.wr, &c, 1); /* "papa, I can read!" */ - _exit(0); + /* We just try to read one byte. If it works, file is readable + * under this user. We signal that by exiting with 0. */ + _exit(safe_read(xopen(file, O_RDONLY), &c, 1) < 0); } int crontab_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; @@ -180,7 +173,7 @@ int crontab_main(int argc, char **argv) switch (opt_ler) { default: /* case OPT_r: Delete */ - remove(pas->pw_name); + unlink(pas->pw_name); break; case OPT_l: /* List */ @@ -211,13 +204,13 @@ int crontab_main(int argc, char **argv) if (fd >= 0) { bb_copyfd_eof(STDIN_FILENO, fd); close(fd); - rename(new_fname, pas->pw_name); + xrename(new_fname, pas->pw_name); } else { bb_error_msg("cannot create %s/%s", crontab_dir, new_fname); } if (tmp_fname) - remove(tmp_fname); + unlink(tmp_fname); /*free(tmp_fname);*/ /*free(new_fname);*/ |