]> gitweb.michael.orlitzky.com - apply-default-acl.git/blobdiff - src/libadacl.c
libadacl: add error checking when we open() the filesystem root.
[apply-default-acl.git] / src / libadacl.c
index 8e36230c0c09ace1eb85868ecdecc4155cd457ec..21b8141cbbc0158a3c6cfce3e985838bed1e20ce 100644 (file)
@@ -46,6 +46,9 @@
  * @param pathname
  *   The path to the file/directory/whatever whose descriptor you want.
  *
+ * @param flags
+ *   File status flags to be passed to @c openat.
+ *
  * @return a file descriptor for @c pathname if everything goes well,
  *   and @c OPEN_ERROR if not.
  */
@@ -106,6 +109,9 @@ int safe_open_ex(int at_fd, char* pathname, int flags) {
  * @param pathname
  *   The path to the file/directory/whatever whose descriptor you want.
  *
+ * @param flags
+ *   File status flags to be passed to @c openat.
+ *
  * @return a file descriptor for @c pathname if everything goes well,
  *   and @c OPEN_ERROR if not.
  */
@@ -154,6 +160,11 @@ int safe_open(const char* pathname, int flags) {
   }
 
   int fd = open("/", flags);
+  if (fd == OPEN_ERROR) {
+    perror("safe_open (open)");
+    return OPEN_ERROR;
+  }
+
   if (strcmp(abspath, "/") == 0) {
     return fd;
   }