diff options
author | James Hawkins <jhawkins@google.com> | 2016-02-19 11:10:30 -0800 |
---|---|---|
committer | James Hawkins <jhawkins@google.com> | 2016-02-19 11:10:30 -0800 |
commit | 22b6f7a559e02f44442a1f5079d790884971d7f2 (patch) | |
tree | e81614a7a604616a0fff892f26b1f316664cec26 | |
parent | fb516c2e635677cf7f7ad8c0eee27329b245cc54 (diff) | |
parent | 0f5d443d0ccc3d3d95604b241cdd23117363f849 (diff) | |
download | core-22b6f7a559e02f44442a1f5079d790884971d7f2.tar.gz core-22b6f7a559e02f44442a1f5079d790884971d7f2.tar.bz2 core-22b6f7a559e02f44442a1f5079d790884971d7f2.zip |
resolve merge conflicts of 0f5d443d0c to nyc-dev-plus-aosp
Change-Id: I850bda0808ae17ade5bc0e667211a599d284d6e3
-rw-r--r-- | debuggerd/getevent.cpp | 7 | ||||
-rw-r--r-- | fastboot/usb_linux.cpp | 8 | ||||
-rw-r--r-- | healthd/BatteryMonitor.cpp | 6 | ||||
-rw-r--r-- | init/devices.cpp | 7 | ||||
-rw-r--r-- | libbacktrace/backtrace_test.cpp | 5 | ||||
-rw-r--r-- | libprocessgroup/processgroup.cpp | 11 | ||||
-rw-r--r-- | libutils/ProcessCallStack.cpp | 8 | ||||
-rw-r--r-- | logcat/tests/logcat_test.cpp | 8 |
8 files changed, 27 insertions, 33 deletions
diff --git a/debuggerd/getevent.cpp b/debuggerd/getevent.cpp index 751c4fb61..e5acd1744 100644 --- a/debuggerd/getevent.cpp +++ b/debuggerd/getevent.cpp @@ -26,6 +26,7 @@ #include <sys/poll.h> #include <linux/input.h> #include <errno.h> +#include <memory> #include <cutils/log.h> static struct pollfd* ufds; @@ -143,22 +144,20 @@ static int read_notify(const char* dirname, int nfd) { static int scan_dir(const char* dirname) { char devname[PATH_MAX]; char* filename; - DIR* dir; struct dirent* de; - dir = opendir(dirname); + std::unique_ptr<DIR, decltype(&closedir)> dir(opendir(dirname), closedir); if (dir == NULL) return -1; strcpy(devname, dirname); filename = devname + strlen(devname); *filename++ = '/'; - while ((de = readdir(dir))) { + while ((de = readdir(dir.get()))) { if ((de->d_name[0] == '.' && de->d_name[1] == '\0') || (de->d_name[1] == '.' && de->d_name[2] == '\0')) continue; strcpy(filename, de->d_name); open_device(devname); } - closedir(dir); return 0; } diff --git a/fastboot/usb_linux.cpp b/fastboot/usb_linux.cpp index 02ffcd978..d4824fb2a 100644 --- a/fastboot/usb_linux.cpp +++ b/fastboot/usb_linux.cpp @@ -145,7 +145,7 @@ static int filter_usb_device(char* sysfs_name, int in, out; unsigned i; unsigned e; - + if (check(ptr, len, USB_DT_DEVICE, USB_DT_DEVICE_SIZE)) return -1; dev = (struct usb_device_descriptor *)ptr; @@ -333,15 +333,14 @@ static std::unique_ptr<usb_handle> find_usb_device(const char* base, ifc_match_f char desc[1024]; int n, in, out, ifc; - DIR *busdir; struct dirent *de; int fd; int writable; - busdir = opendir(base); + std::unique_ptr<DIR, decltype(&closedir)> busdir(opendir(base), closedir); if (busdir == 0) return 0; - while ((de = readdir(busdir)) && (usb == nullptr)) { + while ((de = readdir(busdir.get())) && (usb == nullptr)) { if (badname(de->d_name)) continue; if (!convert_to_devfs_name(de->d_name, devname, sizeof(devname))) { @@ -377,7 +376,6 @@ static std::unique_ptr<usb_handle> find_usb_device(const char* base, ifc_match_f } } } - closedir(busdir); return usb; } diff --git a/healthd/BatteryMonitor.cpp b/healthd/BatteryMonitor.cpp index 8590a115c..fd4f4b858 100644 --- a/healthd/BatteryMonitor.cpp +++ b/healthd/BatteryMonitor.cpp @@ -26,6 +26,7 @@ #include <stdlib.h> #include <sys/types.h> #include <unistd.h> +#include <memory> #include <batteryservice/BatteryService.h> #include <cutils/klog.h> @@ -456,13 +457,13 @@ void BatteryMonitor::init(struct healthd_config *hc) { char pval[PROPERTY_VALUE_MAX]; mHealthdConfig = hc; - DIR* dir = opendir(POWER_SUPPLY_SYSFS_PATH); + std::unique_ptr<DIR, decltype(&closedir)> dir(opendir(POWER_SUPPLY_SYSFS_PATH), closedir); if (dir == NULL) { KLOG_ERROR(LOG_TAG, "Could not open %s\n", POWER_SUPPLY_SYSFS_PATH); } else { struct dirent* entry; - while ((entry = readdir(dir))) { + while ((entry = readdir(dir.get()))) { const char* name = entry->d_name; if (!strcmp(name, ".") || !strcmp(name, "..")) @@ -600,7 +601,6 @@ void BatteryMonitor::init(struct healthd_config *hc) { break; } } - closedir(dir); } // This indicates that there is no charger driver registered. diff --git a/init/devices.cpp b/init/devices.cpp index 39cd70656..557a6acd5 100644 --- a/init/devices.cpp +++ b/init/devices.cpp @@ -31,6 +31,8 @@ #include <sys/un.h> #include <linux/netlink.h> +#include <memory> + #include <selinux/selinux.h> #include <selinux/label.h> #include <selinux/android.h> @@ -957,10 +959,9 @@ static void do_coldboot(DIR *d) static void coldboot(const char *path) { - DIR *d = opendir(path); + std::unique_ptr<DIR, decltype(&closedir)> d(opendir(path), closedir); if(d) { - do_coldboot(d); - closedir(d); + do_coldboot(d.get()); } } diff --git a/libbacktrace/backtrace_test.cpp b/libbacktrace/backtrace_test.cpp index 7d829fe74..b975db955 100644 --- a/libbacktrace/backtrace_test.cpp +++ b/libbacktrace/backtrace_test.cpp @@ -404,17 +404,16 @@ void GetThreads(pid_t pid, std::vector<pid_t>* threads) { char task_path[128]; snprintf(task_path, sizeof(task_path), "/proc/%d/task", pid); - DIR* tasks_dir = opendir(task_path); + std::unique_ptr<DIR, decltype(&closedir)> tasks_dir(opendir(task_path), closedir); ASSERT_TRUE(tasks_dir != nullptr); struct dirent* entry; - while ((entry = readdir(tasks_dir)) != nullptr) { + while ((entry = readdir(tasks_dir.get())) != nullptr) { char* end; pid_t tid = strtoul(entry->d_name, &end, 10); if (*end == '\0') { threads->push_back(tid); } } - closedir(tasks_dir); } TEST(libbacktrace, ptrace_threads) { diff --git a/libprocessgroup/processgroup.cpp b/libprocessgroup/processgroup.cpp index 5ab957d86..ba97f32f7 100644 --- a/libprocessgroup/processgroup.cpp +++ b/libprocessgroup/processgroup.cpp @@ -29,6 +29,7 @@ #include <string.h> #include <sys/stat.h> #include <sys/types.h> +#include <memory> #include <log/log.h> #include <private/android_filesystem_config.h> @@ -194,11 +195,11 @@ static int removeProcessGroup(uid_t uid, int pid) static void removeUidProcessGroups(const char *uid_path) { - DIR *uid = opendir(uid_path); + std::unique_ptr<DIR, decltype(&closedir)> uid(opendir(uid_path), closedir); if (uid != NULL) { struct dirent cur; struct dirent *dir; - while ((readdir_r(uid, &cur, &dir) == 0) && dir) { + while ((readdir_r(uid.get(), &cur, &dir) == 0) && dir) { char path[PROCESSGROUP_MAX_PATH_LEN]; if (dir->d_type != DT_DIR) { @@ -213,7 +214,6 @@ static void removeUidProcessGroups(const char *uid_path) SLOGV("removing %s\n", path); rmdir(path); } - closedir(uid); } } @@ -221,13 +221,13 @@ void removeAllProcessGroups() { SLOGV("removeAllProcessGroups()"); const char *cgroup_root_path = getCgroupRootPath(); - DIR *root = opendir(cgroup_root_path); + std::unique_ptr<DIR, decltype(&closedir)> root(opendir(cgroup_root_path), closedir); if (root == NULL) { SLOGE("failed to open %s: %s", cgroup_root_path, strerror(errno)); } else { struct dirent cur; struct dirent *dir; - while ((readdir_r(root, &cur, &dir) == 0) && dir) { + while ((readdir_r(root.get(), &cur, &dir) == 0) && dir) { char path[PROCESSGROUP_MAX_PATH_LEN]; if (dir->d_type != DT_DIR) { @@ -242,7 +242,6 @@ void removeAllProcessGroups() SLOGV("removing %s\n", path); rmdir(path); } - closedir(root); } } diff --git a/libutils/ProcessCallStack.cpp b/libutils/ProcessCallStack.cpp index cdb586d98..4e87a9875 100644 --- a/libutils/ProcessCallStack.cpp +++ b/libutils/ProcessCallStack.cpp @@ -21,6 +21,7 @@ #include <errno.h> #include <stdio.h> #include <string.h> +#include <memory> #include <utils/Log.h> #include <utils/Errors.h> @@ -130,11 +131,10 @@ void ProcessCallStack::clear() { } void ProcessCallStack::update() { - DIR *dp; struct dirent *ep; struct dirent entry; - dp = opendir(PATH_SELF_TASK); + std::unique_ptr<DIR, decltype(&closedir)> dp(opendir(PATH_SELF_TASK), closedir); if (dp == NULL) { ALOGE("%s: Failed to update the process's call stacks: %s", __FUNCTION__, strerror(errno)); @@ -159,7 +159,7 @@ void ProcessCallStack::update() { * - Read every file in directory => get every tid */ int code; - while ((code = readdir_r(dp, &entry, &ep)) == 0 && ep != NULL) { + while ((code = readdir_r(dp.get(), &entry, &ep)) == 0 && ep != NULL) { pid_t tid = -1; sscanf(ep->d_name, "%d", &tid); @@ -198,8 +198,6 @@ void ProcessCallStack::update() { ALOGE("%s: Failed to readdir from %s: %s", __FUNCTION__, PATH_SELF_TASK, strerror(code)); } - - closedir(dp); } void ProcessCallStack::log(const char* logtag, android_LogPriority priority, diff --git a/logcat/tests/logcat_test.cpp b/logcat/tests/logcat_test.cpp index 4f517bb18..8459bd3d0 100644 --- a/logcat/tests/logcat_test.cpp +++ b/logcat/tests/logcat_test.cpp @@ -21,6 +21,7 @@ #include <stdlib.h> #include <string.h> #include <sys/types.h> +#include <memory> #include <gtest/gtest.h> #include <log/log.h> @@ -734,8 +735,8 @@ TEST(logcat, logrotate_continue) { EXPECT_FALSE(system(command)); return; } - DIR *dir; - EXPECT_TRUE(NULL != (dir = opendir(tmp_out_dir))); + std::unique_ptr<DIR, decltype(&closedir)> dir(opendir(tmp_out_dir), closedir); + EXPECT_NE(nullptr, dir); if (!dir) { snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir); EXPECT_FALSE(system(command)); @@ -743,7 +744,7 @@ TEST(logcat, logrotate_continue) { } struct dirent *entry; unsigned count = 0; - while ((entry = readdir(dir))) { + while ((entry = readdir(dir.get()))) { if (strncmp(entry->d_name, log_filename, sizeof(log_filename) - 1)) { continue; } @@ -766,7 +767,6 @@ TEST(logcat, logrotate_continue) { free(line); unlink(command); } - closedir(dir); if (count > 1) { char *brk = strpbrk(second_last_line, "\r\n"); if (!brk) { |