From: Zofia Abramowska Date: Tue, 6 Aug 2013 13:42:33 +0000 (+0200) Subject: Cleaning error logs for rules applying utilities X-Git-Tag: v1.0.2~31 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=72ef04e318607567bb60bcf4f534c859cd7b572c;p=platform%2Fupstream%2Fsmack.git Cleaning error logs for rules applying utilities Removed perror logs from main utilities files. Moved error logs inside /utils/common.c. Errors are logged from I/O operations and applying rules/cipso from files. (cherry picked from commit bcaf9018f41809cb93aaccf9e9fb49b59750dc7e) --- diff --git a/utils/common.c b/utils/common.c index 4700821..5ea22fe 100644 --- a/utils/common.c +++ b/utils/common.c @@ -55,8 +55,10 @@ int clear(void) snprintf(path, sizeof path, "%s/load2", smack_mnt); fd = open(path, O_RDONLY); - if (fd < 0) + if (fd < 0) { + fprintf(stderr, "open() failed for '%s' : %s\n", path, strerror(errno)); return -1; + } ret = apply_rules_file(fd, 1); close(fd); @@ -69,18 +71,23 @@ int apply_rules(const char *path, int clear) int fd; int ret; - errno = 0; - if (stat(path, &sbuf)) + if (stat(path, &sbuf)) { + fprintf(stderr, "stat() failed for '%s' : %s\n", path, strerror(errno)); return -1; + } if (S_ISDIR(sbuf.st_mode)) return nftw(path, apply_rules_cb, 1, FTW_PHYS|FTW_ACTIONRETVAL); fd = open(path, O_RDONLY); - if (fd < 0) + if (fd < 0) { + fprintf(stderr, "open() failed for '%s' : %s\n", path, strerror(errno)); return -1; + } ret = apply_rules_file(fd, clear); + if (ret) + fprintf(stderr, "Applying rules failed for '%s'.\n", path); close(fd); return ret; } @@ -91,18 +98,23 @@ int apply_cipso(const char *path) int fd; int ret; - errno = 0; - if (stat(path, &sbuf)) + if (stat(path, &sbuf)) { + fprintf(stderr, "stat() failed for '%s' : %s\n", path, strerror(errno)); return -1; + } if (S_ISDIR(sbuf.st_mode)) return nftw(path, apply_cipso_cb, 1, FTW_PHYS|FTW_ACTIONRETVAL); fd = open(path, O_RDONLY); - if (fd < 0) + if (fd < 0) { + fprintf(stderr, "open() failed for '%s' : %s\n", path, strerror(errno)); return -1; + } ret = apply_cipso_file(fd); + if (ret) + fprintf(stderr, "Applying rules failed for '%s'.\n", path); close(fd); return ret; } @@ -164,10 +176,14 @@ static int apply_rules_cb(const char *fpath, const struct stat *sb, int typeflag return FTW_STOP; fd = open(fpath, O_RDONLY); - if (fd < 0) + if (fd < 0) { + fprintf(stderr, "open() failed for '%s' : %s\n", fpath, strerror(errno)); return -1; + } ret = apply_rules_file(fd, 0) ? FTW_STOP : FTW_CONTINUE; + if (ret == FTW_STOP) + fprintf(stderr, "Applying rules failed for '%s'.\n", fpath); close(fd); return ret; } @@ -183,10 +199,14 @@ static int apply_cipso_cb(const char *fpath, const struct stat *sb, int typeflag return FTW_STOP; fd = open(fpath, O_RDONLY); - if (fd < 0) + if (fd < 0) { + fprintf(stderr, "open() failed for '%s' : %s\n", fpath, strerror(errno)); return -1; + } ret = apply_cipso_file(fd) ? FTW_STOP : FTW_CONTINUE; + if (ret == FTW_STOP) + fprintf(stderr, "Applying rules failed for '%s'.\n", fpath); close(fd); return ret; } diff --git a/utils/smackcipso.c b/utils/smackcipso.c index 6e500d2..6c548b3 100644 --- a/utils/smackcipso.c +++ b/utils/smackcipso.c @@ -36,15 +36,11 @@ int main(int argc, char **argv) } if (argc == 1) { - if (apply_cipso_file(STDIN_FILENO)) { - perror("apply_cipso_file"); + if (apply_cipso_file(STDIN_FILENO)) exit(1); - } } else { - if (apply_cipso(argv[1])) { - perror("apply_cipso"); + if (apply_cipso(argv[1])) exit(1); - } } exit(0); diff --git a/utils/smackctl.c b/utils/smackctl.c index 69b5b9a..d5a0a79 100644 --- a/utils/smackctl.c +++ b/utils/smackctl.c @@ -20,6 +20,7 @@ #include "common.h" #include +#include #include #include #include @@ -35,10 +36,10 @@ static int apply_all(void) return -1; if (apply_rules(ACCESSES_D_PATH, 0)) - perror("apply_rules"); + return -1; if (apply_cipso(CIPSO_D_PATH)) - perror("apply_cipso"); + return -1; return 0; } @@ -48,24 +49,24 @@ int main(int argc, char **argv) const char *tmp = smack_smackfs_path(); if (argc < 2) { fprintf(stderr, "Usage: %s \n", argv[0]); - return 1; + exit(1); } if (!strcmp(argv[1], "apply")) { if (apply_all()) - return 1; + exit(1); } else if (!strcmp(argv[1], "clear")) { if (clear()) - return 1; + exit(1); } else if (!strcmp(argv[1], "status")) { if (smack_smackfs_path()) printf("SmackFS is mounted to %s.\n", smack_smackfs_path()); else printf("SmackFS is not mounted.\n"); - return 0; + exit(0); } fprintf(stderr, "Uknown action: %s\n", argv[1]); - return 1; + exit(1); } diff --git a/utils/smackload.c b/utils/smackload.c index cc62a66..7d68846 100644 --- a/utils/smackload.c +++ b/utils/smackload.c @@ -50,15 +50,11 @@ int main(int argc, char **argv) } if (optind == argc) { - if (apply_rules_file(STDIN_FILENO, clear)) { - perror("apply_rules_file"); + if (apply_rules_file(STDIN_FILENO, clear)) exit(1); - } } else { - if (apply_rules(argv[optind], clear)) { - perror("apply_rules"); + if (apply_rules(argv[optind], clear)) exit(1); - } } exit(0);