aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2015-02-08 16:38:11 -0600
committerRob Landley <rob@landley.net>2015-02-08 16:38:11 -0600
commit36a06d36c9865695090a17fd1a1d532d6e0f8997 (patch)
treebe8ff5b25c4ab191ec079d3af7c637d858084ba7 /toys
parent9628107532c705b69a211e0f595815a33d390724 (diff)
downloadtoybox-36a06d36c9865695090a17fd1a1d532d6e0f8997.tar.gz
Cleanup pass on chcon.
Diffstat (limited to 'toys')
-rw-r--r--toys/pending/chcon.c23
1 files changed, 8 insertions, 15 deletions
diff --git a/toys/pending/chcon.c b/toys/pending/chcon.c
index 0ef4e1e5..a2bbb66c 100644
--- a/toys/pending/chcon.c
+++ b/toys/pending/chcon.c
@@ -2,7 +2,7 @@
*
* Copyright 2014 The Android Open Source Project
-USE_CHCON(NEWTOY(chcon, "<1hRv", TOYFLAG_USR|TOYFLAG_BIN))
+USE_CHCON(NEWTOY(chcon, "<2hvR", TOYFLAG_USR|TOYFLAG_BIN))
config CHCON
bool "chcon"
@@ -11,7 +11,7 @@ config CHCON
help
usage: chcon [-hRv] CONTEXT FILE...
- Change the SELinux security context of listed file[s] (recursively with -R).
+ Change the SELinux security context of listed file[s].
-h change symlinks instead of what they point to.
-R recurse into subdirectories.
@@ -21,30 +21,23 @@ config CHCON
#define FOR_chcon
#include "toys.h"
-GLOBALS(
- char *context;
-)
-
int do_chcon(struct dirtree *try)
{
- int ret;
+ char *path, *con = *toys.optargs;
if (!dirtree_notdotdot(try)) return 0;
- char *path = dirtree_path(try, 0);
- if (toys.optflags & FLAG_v)
- printf("chcon '%s' to %s\n", path, TT.context);
- ret = ((toys.optflags&FLAG_h) ? lsetfilecon : setfilecon)(path, TT.context);
- if (ret == -1)
- perror_msg("'%s' to %s", path, TT.context);
+ path = dirtree_path(try, 0);
+ if (toys.optflags & FLAG_v) printf("chcon '%s' to %s\n", path, con);
+ if (-1 == ((toys.optflags & FLAG_h) ? lsetfilecon : setfilecon)(path, con))
+ perror_msg("'%s' to %s", path, con);
free(path);
- return (toys.optflags & FLAG_R) ? DIRTREE_RECURSE : 0;
+ return (toys.optflags & FLAG_R)*DIRTREE_RECURSE;
}
void chcon_main(void)
{
- TT.context = *toys.optargs;
char **file;
for (file = toys.optargs+1; *file; file++) dirtree_read(*file, do_chcon);