summaryrefslogtreecommitdiff
path: root/cmds/installd/utils.cpp
diff options
context:
space:
mode:
author Andreas Gampe <agampe@google.com> 2015-11-11 20:43:16 -0800
committer Andreas Gampe <agampe@google.com> 2015-12-08 09:24:43 -0800
commit02d0de56c75347a0cb8d5a8565dc8c4ee7616057 (patch)
tree4d501c54e987de4f6c124b2069e0d744cff4bf10 /cmds/installd/utils.cpp
parent9dc117c415d0df0a3acd900709d05deabe975704 (diff)
Installd: Refactor in preparation for OTA
Refactor installd code so reuse with a few key plugin functions is possible. Do a bit of code cleanup. Bug: 25612095 Change-Id: I544604f0a391583a4c07887a8234343a3a255942
Diffstat (limited to 'cmds/installd/utils.cpp')
-rw-r--r--cmds/installd/utils.cpp58
1 files changed, 55 insertions, 3 deletions
diff --git a/cmds/installd/utils.cpp b/cmds/installd/utils.cpp
index 750a136f60..92a956531a 100644
--- a/cmds/installd/utils.cpp
+++ b/cmds/installd/utils.cpp
@@ -14,15 +14,38 @@
** limitations under the License.
*/
-#include "installd.h"
+#include "utils.h"
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+
+#if defined(__APPLE__)
+#include <sys/mount.h>
+#else
+#include <sys/statfs.h>
+#endif
-#include <android-base/stringprintf.h>
#include <android-base/logging.h>
+#include <android-base/stringprintf.h>
+#include <cutils/fs.h>
+#include <cutils/log.h>
+#include <private/android_filesystem_config.h>
+
+#include "globals.h" // extern variables.
+#ifndef LOG_TAG
+#define LOG_TAG "installd"
+#endif
#define CACHE_NOISY(x) //x
using android::base::StringPrintf;
+namespace android {
+namespace installd {
+
/**
* Check that given string is valid filename, and that it attempts no
* parent or child directory traversal.
@@ -184,7 +207,7 @@ int create_user_config_path(char path[PATH_MAX], userid_t userid) {
int create_move_path(char path[PKG_PATH_MAX],
const char* pkgname,
const char* leaf,
- userid_t userid __unused)
+ userid_t userid ATTRIBUTE_UNUSED)
{
if ((android_data_dir.len + strlen(PRIMARY_USER_PREFIX) + strlen(pkgname) + strlen(leaf) + 1)
>= PKG_PATH_MAX) {
@@ -1170,3 +1193,32 @@ int ensure_config_user_dirs(userid_t userid) {
return 0;
}
+
+int wait_child(pid_t pid)
+{
+ int status;
+ pid_t got_pid;
+
+ while (1) {
+ got_pid = waitpid(pid, &status, 0);
+ if (got_pid == -1 && errno == EINTR) {
+ printf("waitpid interrupted, retrying\n");
+ } else {
+ break;
+ }
+ }
+ if (got_pid != pid) {
+ ALOGW("waitpid failed: wanted %d, got %d: %s\n",
+ (int) pid, (int) got_pid, strerror(errno));
+ return 1;
+ }
+
+ if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
+ return 0;
+ } else {
+ return status; /* always nonzero */
+ }
+}
+
+} // namespace installd
+} // namespace android