Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.busybox.net/busybox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-10-27 20:07:20 +0400
committerDenis Vlasenko <vda.linux@googlemail.com>2006-10-27 20:07:20 +0400
commit51b4c92f80dc232b9d34985f99a4479393644433 (patch)
treee62b6e2b809db8135d640e3b8222cfd4d52d9098 /coreutils/chmod.c
parentfefb279ace2da131cad369a3cc6983a1bc220a4a (diff)
chown: add -vcf support if CONFIG_DESKTOP
chmod: stop following symlinks
Diffstat (limited to 'coreutils/chmod.c')
-rw-r--r--coreutils/chmod.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/coreutils/chmod.c b/coreutils/chmod.c
index 18334b8bb..c4f8fa0b2 100644
--- a/coreutils/chmod.c
+++ b/coreutils/chmod.c
@@ -22,9 +22,23 @@
#define OPT_QUIET (USE_DESKTOP(option_mask32 & 8) SKIP_DESKTOP(0))
#define OPT_STR ("-R" USE_DESKTOP("vcf"))
+/* TODO:
+ * chmod never changes the permissions of symbolic links; the chmod
+ * system call cannot change their permissions. This is not a problem
+ * since the permissions of symbolic links are never used.
+ * However, for each symbolic link listed on the command line, chmod changes
+ * the permissions of the pointed-to file. In contrast, chmod ignores
+ * symbolic links encountered during recursive directory traversals.
+ */
+
static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
{
mode_t newmode = statbuf->st_mode;
+
+ // TODO: match GNU behavior:
+ // if (depth > 0 && S_ISLNK(statbuf->st_mode)) return TRUE;
+ // if (depth == 0) follow link
+
if (!bb_parse_mode((char *)junk, &newmode))
bb_error_msg_and_die("invalid mode: %s", (char *)junk);
@@ -33,7 +47,7 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
|| (OPT_CHANGED && statbuf->st_mode != newmode)
) {
printf("mode of '%s' changed to %04o (%s)\n", fileName,
- newmode & 7777, bb_mode_string(newmode)+1);
+ newmode & 07777, bb_mode_string(newmode)+1);
}
return TRUE;
}
@@ -48,10 +62,11 @@ int chmod_main(int argc, char **argv)
char *arg, **argp;
char *smode;
- /* Convert first encountered -r into a-r, etc */
+ /* Convert first encountered -r into a-r, -w into a-w etc */
argp = argv + 1;
while ((arg = *argp)) {
- /* Protect against mishandling e.g. "chmod 644 -r" */
+ /* Mode spec must be the first arg (sans -R etc) */
+ /* (protect against mishandling e.g. "chmod 644 -r") */
if (arg[0] != '-')
break;
/* An option. Not a -- or valid option? */
@@ -72,8 +87,14 @@ int chmod_main(int argc, char **argv)
/* Ok, ready to do the deed now */
do {
- if (!recursive_action(*argv, OPT_RECURSE, TRUE, FALSE,
- fileAction, fileAction, smode)) {
+ if (!recursive_action(*argv,
+ OPT_RECURSE, // recurse
+ FALSE, // follow links: GNU doesn't
+ FALSE, // depth first
+ fileAction, // file action
+ fileAction, // dir action
+ smode) // user data
+ ) {
retval = EXIT_FAILURE;
}
} while (*++argv);