From: Jarkko Sakkinen Date: Sun, 11 Dec 2011 17:02:49 +0000 (+0200) Subject: utils: stdin support for smackload X-Git-Tag: accepted/trunk/20130107.204027~32 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4d432fcae281e64c2a8677a0c5f2236cd384bbc1;p=platform%2Fupstream%2Fsmack.git utils: stdin support for smackload --- diff --git a/utils/common.c b/utils/common.c index 76cbad4..bf9d2f7 100644 --- a/utils/common.c +++ b/utils/common.c @@ -59,16 +59,13 @@ struct cipso { struct cipso_mapping *last; }; -static int apply_rules_file(int fd, int clear); static int apply_rules_cb(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf); - static int apply_cipso_file(const char *path); static int apply_cipso_cb(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf); static struct cipso *cipso_new(const char *path); static void cipso_free(struct cipso *cipso); static int cipso_apply(struct cipso *cipso); - int is_smackfs_mounted(void) { struct statfs sfs; @@ -146,7 +143,7 @@ int apply_cipso(const char *path) return 0; } -static int apply_rules_file(int fd, int clear) +int apply_rules_file(int fd, int clear) { struct smack_accesses *rules = NULL; int ret = 0; diff --git a/utils/common.h b/utils/common.h index 43ebb91..cde6209 100644 --- a/utils/common.h +++ b/utils/common.h @@ -36,5 +36,6 @@ int clear(void); int is_smackfs_mounted(void); int apply_rules(const char *path, int clear); int apply_cipso(const char *path); +int apply_rules_file(int fd, int clear); #endif // COMMON_H diff --git a/utils/smackload.c b/utils/smackload.c index fad0e0b..5374552 100644 --- a/utils/smackload.c +++ b/utils/smackload.c @@ -19,6 +19,7 @@ * * Authors: * Brian McGillion + * Jarkko Sakkinen */ #include "common.h" @@ -37,6 +38,11 @@ int main(int argc, char **argv) int clear = 0; int c; + if (is_smackfs_mounted() != 1) { + fprintf(stderr, "SmackFS is not mounted.\n"); + exit(1); + } + while ((c = getopt(argc, argv, "c")) != -1) { switch (c) { case 'c': @@ -47,17 +53,16 @@ int main(int argc, char **argv) } } - if (optind == argc) - usage(argv[0]); - - if (is_smackfs_mounted() != 1) { - fprintf(stderr, "SmackFS is not mounted.\n"); - exit(1); - } - - if (apply_rules(argv[optind], clear)) { - perror("apply_rules"); - exit(1); + if (optind == argc) { + if (apply_rules_file(STDIN_FILENO, clear)) { + perror("apply_rules_file"); + exit(1); + } + } else { + if (apply_rules(argv[optind], clear)) { + perror("apply_rules"); + exit(1); + } } exit(0);