Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 588a2cad authored by James Hawkins's avatar James Hawkins
Browse files

system/core: Cleanup direct calls to opendir by containing in a

std::unique_ptr.

Bug: 26643633
Change-Id: Ia3491fdbff086558da694ae949cf08e4c89d0307
parent d3289ac5
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -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;
}

+3 −5
Original line number Diff line number Diff line
@@ -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;
}
+3 −3
Original line number Diff line number Diff line
@@ -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.
+4 −3
Original line number Diff line number Diff line
@@ -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());
    }
}

+2 −3
Original line number Diff line number Diff line
@@ -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) {
Loading