[git commit] add/remove-shell: copy /etc/shells mode to new file
Denys Vlasenko
vda.linux at googlemail.com
Fri May 26 14:45:28 UTC 2017
commit: https://git.busybox.net/busybox/commit/?id=13d72c3fd979a047179b1342dcae026379af0617
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master
function old new delta
add_remove_shell_main 259 300 +41
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
loginutils/add-remove-shell.c | 20 +++++++++-----------
1 file changed, 9 insertions(+), 11 deletions(-)
diff --git a/loginutils/add-remove-shell.c b/loginutils/add-remove-shell.c
index af7c317..922b333 100644
--- a/loginutils/add-remove-shell.c
+++ b/loginutils/add-remove-shell.c
@@ -43,10 +43,7 @@
#define REMOVE_SHELL (ENABLE_REMOVE_SHELL && (!ENABLE_ADD_SHELL || applet_name[0] == 'r'))
#define ADD_SHELL (ENABLE_ADD_SHELL && (!ENABLE_REMOVE_SHELL || applet_name[0] == 'a'))
-/* NB: we use the _address_, not the value, of this string
- * as a "special value of pointer" in the code.
- */
-static const char dont_add[] ALIGN1 = "\n";
+#define dont_add ((char*)(uintptr_t)1)
int add_remove_shell_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int add_remove_shell_main(int argc UNUSED_PARAM, char **argv)
@@ -54,6 +51,9 @@ int add_remove_shell_main(int argc UNUSED_PARAM, char **argv)
FILE *orig_fp;
char *orig_fn;
char *new_fn;
+ struct stat sb;
+
+ sb.st_mode = 0666;
argv++;
@@ -61,6 +61,8 @@ int add_remove_shell_main(int argc UNUSED_PARAM, char **argv)
if (!orig_fn)
return EXIT_FAILURE;
orig_fp = fopen_for_read(orig_fn);
+ if (orig_fp)
+ xfstat(fileno(orig_fp), &sb, orig_fn);
new_fn = xasprintf("%s.tmp", orig_fn);
/*
@@ -71,13 +73,9 @@ int add_remove_shell_main(int argc UNUSED_PARAM, char **argv)
* after which it should revert to O_TRUNC.
* For now, I settle for O_TRUNC instead.
*/
- xmove_fd(xopen(new_fn, O_WRONLY | O_CREAT | O_TRUNC), STDOUT_FILENO);
-
- /* TODO:
- struct stat sb;
- xfstat(fileno(orig_fp), &sb);
+ xmove_fd(xopen3(new_fn, O_WRONLY | O_CREAT | O_TRUNC, sb.st_mode), STDOUT_FILENO);
+ /* TODO?
xfchown(STDOUT_FILENO, sb.st_uid, sb.st_gid);
- xfchmod(STDOUT_FILENO, sb.st_mode);
*/
if (orig_fp) {
@@ -95,7 +93,7 @@ int add_remove_shell_main(int argc UNUSED_PARAM, char **argv)
}
/* we are add-shell */
/* mark this name as "do not add" */
- *cpp = (char*)dont_add;
+ *cpp = dont_add;
}
cpp++;
}
More information about the busybox-cvs
mailing list