aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <dvlasenk@redhat.com>2010-10-20 15:14:32 +0200
committerDenys Vlasenko <dvlasenk@redhat.com>2010-10-20 15:14:32 +0200
commitff19d525a98418915e5e10e0e0bb6e40f7259b76 (patch)
tree0df2deb1b3aa79ddd2e6002606dc28aa3322259a
parent5be79ff27a5852567a9bdec80d67b061ad828290 (diff)
downloadbusybox-w32-ff19d525a98418915e5e10e0e0bb6e40f7259b76.tar.gz
busybox-w32-ff19d525a98418915e5e10e0e0bb6e40f7259b76.tar.bz2
busybox-w32-ff19d525a98418915e5e10e0e0bb6e40f7259b76.zip
add/remove-shell: use O_TRUNC instead of O_EXCL
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
-rw-r--r--loginutils/add-remove-shell.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/loginutils/add-remove-shell.c b/loginutils/add-remove-shell.c
index 986fe57c5..757e50503 100644
--- a/loginutils/add-remove-shell.c
+++ b/loginutils/add-remove-shell.c
@@ -63,11 +63,19 @@ int add_remove_shell_main(int argc UNUSED_PARAM, char **argv)
63 orig_fp = fopen_for_read(orig_fn); 63 orig_fp = fopen_for_read(orig_fn);
64 64
65 new_fn = xasprintf("%s.tmp", orig_fn); 65 new_fn = xasprintf("%s.tmp", orig_fn);
66 xmove_fd(xopen(new_fn, O_WRONLY | O_CREAT | O_EXCL), STDOUT_FILENO); 66 /*
67 * O_TRUNC or O_EXCL? At the first glance, O_EXCL looks better,
68 * since it prevents races. But: (1) it requires a retry loop,
69 * (2) if /etc/shells.tmp is *stale*, then retry loop
70 * with O_EXCL will never succeed - it should have a timeout,
71 * after which it should revert to O_TRUNC.
72 * For now, I settle for O_TRUNC instead.
73 */
74 xmove_fd(xopen(new_fn, O_WRONLY | O_CREAT | O_TRUNC), STDOUT_FILENO);
67 75
68 /* TODO: 76 /* TODO:
69 struct stat sb; 77 struct stat sb;
70 fstat(fileno(orig_fp), &sb); 78 xfstat(fileno(orig_fp), &sb);
71 xfchown(STDOUT_FILENO, sb.st_uid, sb.st_gid); 79 xfchown(STDOUT_FILENO, sb.st_uid, sb.st_gid);
72 xfchmod(STDOUT_FILENO, sb.st_mode); 80 xfchmod(STDOUT_FILENO, sb.st_mode);
73 */ 81 */