src/t_immutable: add ftruncate to append only tests
authorAmir Goldstein <amir73il@gmail.com>
Fri, 7 Apr 2017 09:15:39 +0000 (12:15 +0300)
committerEryu Guan <eguan@redhat.com>
Sat, 8 Apr 2017 15:22:58 +0000 (23:22 +0800)
The truncate and ftruncate syscalls check the IS_APPEND() flag
in 2 different vfs code paths and I had to fix both in order to
fix overlayfs IS_APPEND() violations.

Add the ftruncate test to t_immutable, so overlay/030 can verify
the fix.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Reviewed-by: Eryu Guan <eguan@redhat.com>
Signed-off-by: Eryu Guan <eguan@redhat.com>
src/t_immutable.c

index 8a12d2c303281cbaf58867303af629588e2673ac..7a7195e43f88f2e717f5c86466b317425cff1e09 100644 (file)
@@ -891,6 +891,21 @@ static int test_append(const char *dir)
           fail++;
      }
 
+     errno = 0;
+     if ((fd = open(path, O_RDWR|O_APPEND)) == -1) {
+         fprintf(stderr, "open(%s, O_RDWR|O_APPEND) failed: %s\n", path, strerror(errno));
+         fail++;
+     } else {
+            if (ftruncate(fd, 0) != -1) {
+                    fprintf(stderr, "ftruncate(%s, 0) did not fail\n", path);
+                    fail++;
+            } else if (errno != EPERM) {
+                    fprintf(stderr, "ftruncate(%s, 0) did not set errno == EPERM\n", path);
+                    fail++;
+            }
+            close(fd);
+     }
+
      errno = 0;
      if (truncate(path, 0) != -1) {
          fprintf(stderr, "truncate(%s, 0) did not fail\n", path);