OSDN Git Service

installd: remove spammy warning for non-existent profile dirs.
authorNarayan Kamath <narayan@google.com>
Mon, 2 May 2016 08:47:49 +0000 (09:47 +0100)
committerNarayan Kamath <narayan@google.com>
Tue, 3 May 2016 09:07:41 +0000 (10:07 +0100)
Also gets rid of a lstat call which seems unnecessary. We can
directly open the directory and fail if the open fails.

bug: 28510519
Change-Id: Iaf2b7e69d51e2670e62cbe2807874c9b0dd471e5

cmds/installd/commands.cpp

index 60118a8..90ef277 100644 (file)
@@ -1022,16 +1022,15 @@ static void close_all_fds(const std::vector<fd_t>& fds, const char* description)
 }
 
 static fd_t open_profile_dir(const std::string& profile_dir) {
-    struct stat buffer;
-    if (TEMP_FAILURE_RETRY(lstat(profile_dir.c_str(), &buffer)) == -1) {
-        PLOG(ERROR) << "Failed to lstat profile_dir: " << profile_dir;
-        return -1;
-    }
-
     fd_t profile_dir_fd = TEMP_FAILURE_RETRY(open(profile_dir.c_str(),
             O_PATH | O_CLOEXEC | O_DIRECTORY | O_NOFOLLOW));
     if (profile_dir_fd < 0) {
-        PLOG(ERROR) << "Failed to open profile_dir: " << profile_dir;
+        // In a multi-user environment, these directories can be created at
+        // different points and it's possible we'll attempt to open a profile
+        // dir before it exists.
+        if (errno != ENOENT) {
+            PLOG(ERROR) << "Failed to open profile_dir: " << profile_dir;
+        }
     }
     return profile_dir_fd;
 }