summaryrefslogtreecommitdiffstats
path: root/otafault
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--otafault/Android.bp60
-rw-r--r--otafault/Android.mk54
-rw-r--r--otafault/config.cpp12
-rw-r--r--otafault/include/otafault/config.h (renamed from otafault/config.h)20
-rw-r--r--otafault/include/otafault/ota_io.h (renamed from otafault/ota_io.h)3
-rw-r--r--otafault/ota_io.cpp9
-rw-r--r--otafault/test.cpp5
7 files changed, 86 insertions, 77 deletions
diff --git a/otafault/Android.bp b/otafault/Android.bp
new file mode 100644
index 000000000..91a5d9a54
--- /dev/null
+++ b/otafault/Android.bp
@@ -0,0 +1,60 @@
+// Copyright (C) 2017 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+cc_library_static {
+ name: "libotafault",
+
+ srcs: [
+ "config.cpp",
+ "ota_io.cpp",
+ ],
+
+ static_libs: [
+ "libbase",
+ "liblog",
+ "libziparchive",
+ ],
+
+ export_include_dirs: [
+ "include",
+ ],
+
+ cflags: [
+ "-D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS",
+ "-Wall",
+ "-Werror",
+ "-Wthread-safety",
+ "-Wthread-safety-negative",
+ ],
+}
+
+cc_test {
+ name: "otafault_test",
+
+ srcs: ["test.cpp"],
+
+ cflags: [
+ "-Wall",
+ "-Werror",
+ ],
+
+ static_executable: true,
+
+ static_libs: [
+ "libotafault",
+ "libziparchive",
+ "libbase",
+ "liblog",
+ ],
+}
diff --git a/otafault/Android.mk b/otafault/Android.mk
deleted file mode 100644
index ec4cdb365..000000000
--- a/otafault/Android.mk
+++ /dev/null
@@ -1,54 +0,0 @@
-# Copyright 2015 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific languae governing permissions and
-# limitations under the License.
-
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-
-otafault_static_libs := \
- libziparchive \
- libz \
- libselinux \
- libbase \
- liblog
-
-LOCAL_CFLAGS := \
- -Werror \
- -Wthread-safety \
- -Wthread-safety-negative \
- -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS
-
-LOCAL_SRC_FILES := config.cpp ota_io.cpp
-LOCAL_MODULE_TAGS := eng
-LOCAL_MODULE := libotafault
-LOCAL_CLANG := true
-LOCAL_C_INCLUDES := bootable/recovery
-LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
-LOCAL_WHOLE_STATIC_LIBRARIES := $(otafault_static_libs)
-
-include $(BUILD_STATIC_LIBRARY)
-
-# otafault_test (static executable)
-# ===============================
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := config.cpp ota_io.cpp test.cpp
-LOCAL_MODULE_TAGS := tests
-LOCAL_MODULE := otafault_test
-LOCAL_STATIC_LIBRARIES := $(otafault_static_libs)
-LOCAL_CFLAGS := -Werror
-LOCAL_C_INCLUDES := bootable/recovery
-LOCAL_FORCE_STATIC_EXECUTABLE := true
-
-include $(BUILD_EXECUTABLE)
diff --git a/otafault/config.cpp b/otafault/config.cpp
index 8590833ee..3993948ff 100644
--- a/otafault/config.cpp
+++ b/otafault/config.cpp
@@ -14,17 +14,15 @@
* limitations under the License.
*/
+#include "otafault/config.h"
+
#include <map>
#include <string>
-#include <stdio.h>
-#include <unistd.h>
-
#include <android-base/stringprintf.h>
#include <ziparchive/zip_archive.h>
-#include "config.h"
-#include "ota_io.h"
+#include "otafault/ota_io.h"
#define OTAIO_MAX_FNAME_SIZE 128
@@ -69,7 +67,9 @@ std::string fault_fname(const char* io_type) {
fname.resize(OTAIO_MAX_FNAME_SIZE);
ZipString zip_type_path(type_path.c_str());
ZipEntry entry;
- int status = FindEntry(archive, zip_type_path, &entry);
+ if (FindEntry(archive, zip_type_path, &entry) != 0) {
+ return {};
+ }
ExtractToMemory(archive, &entry, reinterpret_cast<uint8_t*>(&fname[0]), OTAIO_MAX_FNAME_SIZE);
return fname;
}
diff --git a/otafault/config.h b/otafault/include/otafault/config.h
index 4adbdd121..cc4bfd2ad 100644
--- a/otafault/config.h
+++ b/otafault/include/otafault/config.h
@@ -15,13 +15,13 @@
*/
/*
- * Read configuration files in the OTA package to determine which files, if any, will trigger errors.
+ * Read configuration files in the OTA package to determine which files, if any, will trigger
+ * errors.
*
- * OTA packages can be modified to trigger errors by adding a top-level
- * directory called .libotafault, which may optionally contain up to three
- * files called READ, WRITE, and FSYNC. Each one of these optional files
- * contains the name of a single file on the device disk which will cause
- * an IO error on the first call of the appropriate I/O action to that file.
+ * OTA packages can be modified to trigger errors by adding a top-level directory called
+ * .libotafault, which may optionally contain up to three files called READ, WRITE, and FSYNC.
+ * Each one of these optional files contains the name of a single file on the device disk which
+ * will cause an IO error on the first call of the appropriate I/O action to that file.
*
* Example:
* ota.zip
@@ -29,9 +29,9 @@
* .libotafault
* WRITE
*
- * If the contents of the file WRITE were /system/build.prop, the first write
- * action to /system/build.prop would fail with EIO. Note that READ and
- * FSYNC files are absent, so these actions will not cause an error.
+ * If the contents of the file WRITE were /system/build.prop, the first write action to
+ * /system/build.prop would fail with EIO. Note that READ and FSYNC files are absent, so these
+ * actions will not cause an error.
*/
#ifndef _UPDATER_OTA_IO_CFG_H_
@@ -39,8 +39,6 @@
#include <string>
-#include <stdbool.h>
-
#include <ziparchive/zip_archive.h>
#define OTAIO_BASE_DIR ".libotafault"
diff --git a/otafault/ota_io.h b/otafault/include/otafault/ota_io.h
index 9428f1b1f..45e481a62 100644
--- a/otafault/ota_io.h
+++ b/otafault/include/otafault/ota_io.h
@@ -23,8 +23,9 @@
#ifndef _UPDATER_OTA_IO_H_
#define _UPDATER_OTA_IO_H_
+#include <stddef.h>
#include <stdio.h>
-#include <sys/stat.h>
+#include <sys/stat.h> // mode_t
#include <memory>
diff --git a/otafault/ota_io.cpp b/otafault/ota_io.cpp
index faae5275d..63ef18e26 100644
--- a/otafault/ota_io.cpp
+++ b/otafault/ota_io.cpp
@@ -14,20 +14,23 @@
* limitations under the License.
*/
-#include "ota_io.h"
+#include "otafault/ota_io.h"
#include <errno.h>
#include <fcntl.h>
+#include <stdint.h>
#include <stdio.h>
#include <sys/stat.h>
+#include <sys/types.h>
#include <unistd.h>
#include <map>
-#include <memory>
#include <mutex>
+#include <string>
#include <android-base/thread_annotations.h>
-#include "config.h"
+
+#include "otafault/config.h"
static std::mutex filename_mutex;
static std::map<intptr_t, const char*> filename_cache GUARDED_BY(filename_mutex);
diff --git a/otafault/test.cpp b/otafault/test.cpp
index 6514782bf..63e2445af 100644
--- a/otafault/test.cpp
+++ b/otafault/test.cpp
@@ -14,12 +14,13 @@
* limitations under the License.
*/
-#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
+#include <sys/stat.h>
+#include <sys/types.h>
#include <unistd.h>
-#include "ota_io.h"
+#include "otafault/ota_io.h"
int main(int /* argc */, char** /* argv */) {
int fd = open("testdata/test.file", O_RDWR);