author | Olivier Brunel
<jjk@jjacky.com> 2015-03-30 17:35:40 UTC |
committer | Olivier Brunel
<jjk@jjacky.com> 2015-04-04 12:47:36 UTC |
parent | ecab22210948099b18e02c6aae6f93eaf2588feb |
doc/aa-test.pod | +9 | -1 |
src/utils/aa-test.c | +10 | -10 |
diff --git a/doc/aa-test.pod b/doc/aa-test.pod index a1558ad..409935f 100644 --- a/doc/aa-test.pod +++ b/doc/aa-test.pod @@ -64,4 +64,12 @@ Test whether I<FILE> exists and execute (search) permission is granted =head1 DESCRIPTION B<aa-test>(1) is a simple tool to check file types/permissions as specified, and -return 0 when true, else 1. +return 0 when true, else: + +1: Syntax error (e.g. invalid option) + +2: System error (e.g. permission denied) + +3: I<FILE> doesn't exist + +4: I<File> exists, but the rest of the test failed (e.g. wrong type) diff --git a/src/utils/aa-test.c b/src/utils/aa-test.c index a321122..1156fa8 100644 --- a/src/utils/aa-test.c +++ b/src/utils/aa-test.c @@ -111,37 +111,37 @@ main (int argc, char * const argv[]) if (lstat (argv[0], &st) < 0) { if (errno != ENOENT) - strerr_diefu2sys (1, "stat ", argv[0]); + strerr_diefu2sys (2, "stat ", argv[0]); else - return 1; + return 3; } switch (test) { case 'b': - return (S_ISBLK (st.st_mode)) ? 0 : 1; + return (S_ISBLK (st.st_mode)) ? 0 : 4; case 'd': - return (S_ISDIR (st.st_mode)) ? 0 : 1; + return (S_ISDIR (st.st_mode)) ? 0 : 4; case 'e': return 0; case 'f': - return (S_ISREG (st.st_mode)) ? 0 : 1; + return (S_ISREG (st.st_mode)) ? 0 : 4; case 'L': - return (S_ISLNK (st.st_mode)) ? 0 : 1; + return (S_ISLNK (st.st_mode)) ? 0 : 4; case 'p': - return (S_ISFIFO (st.st_mode)) ? 0 : 1; + return (S_ISFIFO (st.st_mode)) ? 0 : 4; case 'r': mode = R_OK; break; case 'S': - return (S_ISSOCK (st.st_mode)) ? 0 : 1; + return (S_ISSOCK (st.st_mode)) ? 0 : 4; case 'w': mode = W_OK; @@ -162,7 +162,7 @@ main (int argc, char * const argv[]) else if (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) return 0; else - return 1; + return 4; } if (st.st_uid == euid) @@ -170,5 +170,5 @@ main (int argc, char * const argv[]) else if (is_group_member (st.st_gid)) mode <<= 3; - return (st.st_mode & mode) ? 0 : 1; + return (st.st_mode & mode) ? 0 : 4; }