diff --git a/lustre/tests/openfile.c b/lustre/tests/openfile.c
index 81236b085a0dd8890f4f8c2b065fc1c17f183932..d494b4a4fe075db69803c8aa40ed31e34a60cfc4 100644
--- a/lustre/tests/openfile.c
+++ b/lustre/tests/openfile.c
@@ -53,7 +53,7 @@ int main(int argc, char** argv)
 {
         int    fd;
         int    flags=0;
-        mode_t mode=0;
+        mode_t mode=0644;
         char*  fname=NULL;
         int    mode_set=0;
         int    flag_set=0;
@@ -131,7 +131,7 @@ int main(int argc, char** argv)
         }
 
 
-        if (mode_set)
+        if (flags & O_CREAT)
                 fd = open(fname, flags, mode);
         else
                 fd = open(fname, flags);