summaryrefslogtreecommitdiffhomepage
path: root/loginutils
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-05-26 16:45:28 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-05-26 16:45:28 +0200
commit13d72c3fd979a047179b1342dcae026379af0617 (patch)
tree4467f3b31f7dafd596f7044bd6652618dd1f5212 /loginutils
parentf5470419404d643070db99d058405b714695b817 (diff)
add/remove-shell: copy /etc/shells mode to new file
function old new delta add_remove_shell_main 259 300 +41 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'loginutils')
-rw-r--r--loginutils/add-remove-shell.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/loginutils/add-remove-shell.c b/loginutils/add-remove-shell.c
index af7c31779..922b3333d 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++;
}