Some tidying up is needed in order to reuse do_open(). This patch
eliminates the chance of returning 0 due to errno being not set. It also
adjusts the file string to be const.

Signed-off-by: Tyler Hicks <[email protected]>
---
 tests/regression/apparmor/changehat.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tests/regression/apparmor/changehat.h 
b/tests/regression/apparmor/changehat.h
index 8a050e9..02c6bf5 100644
--- a/tests/regression/apparmor/changehat.h
+++ b/tests/regression/apparmor/changehat.h
@@ -4,7 +4,7 @@
 
 #define SD_ID_MAGIC     0x8c235e38
 
-static inline int do_open (char * file)
+static inline int do_open (const char * file)
 {
        int fd, rc;
        char buf[128];
@@ -23,7 +23,7 @@ static inline int do_open (char * file)
         if (rc != strlen(data)){
                 fprintf(stderr, "FAIL: write failed - %s\n",
                         strerror(errno));
-                return errno;
+                return rc == -1 ? errno : EINVAL;
         }
 
         (void)lseek(fd, 0, SEEK_SET);
@@ -32,13 +32,13 @@ static inline int do_open (char * file)
         if (rc != strlen(data)){
                 fprintf(stderr, "FAIL: read failed - %s\n",
                         strerror(errno));
-                return errno;
+                return rc == -1 ? errno : EINVAL;
         }
 
         if (memcmp(buf, data, strlen(data)) != 0){
                 fprintf(stderr, "FAIL: comparison failed - %s\n",
                         strerror(errno));
-                return errno;
+                return EINVAL;
         }
 
        close(fd);
-- 
2.7.3


-- 
AppArmor mailing list
[email protected]
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/apparmor

Reply via email to