Revert "resourced: Use glob for file path matching in set_epp"

This reverts commit 176f2ed7b27681344d0f66d4ca94cdab55889618.

Reason for revert: glob calling statx violates the seccomp policy.

Original change's description:
> resourced: Use glob for file path matching in set_epp
>
> And fix a clippy needless-borrow warning in set_rtc_audio_active.
>
> BUG=b:169836840
> TEST=cargo test
>
> Cq-Depend: chromium:3153239
> Change-Id: Ia902688c2914bdaae1b433bf61f30651cbad78cd
> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/3152881
> Reviewed-by: Joel Fernandes <joelaf@google.com>
> Tested-by: Joel Fernandes <joelaf@google.com>
> Commit-Queue: Kuo-Hsin Yang <vovoy@chromium.org>

Bug: b:202218976
Change-Id: Ib818f0ee8adf52228ac5e1e53e8f4be1db32a292
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/3218420
Tested-by: Kuo-Hsin Yang <vovoy@chromium.org>
Auto-Submit: Kuo-Hsin Yang <vovoy@chromium.org>
Reviewed-by: Shah Hossain <shahadath@google.com>
Commit-Queue: Kuo-Hsin Yang <vovoy@chromium.org>
(cherry picked from commit b7ed0ed288d39556e6141108005d048b913afed7)
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/3286606
Reviewed-by: Kuo-Hsin Yang <vovoy@chromium.org>
Reviewed-by: Joel Fernandes <joelaf@google.com>
diff --git a/resourced/Cargo.toml b/resourced/Cargo.toml
index 5d27786..82fd0dd 100644
--- a/resourced/Cargo.toml
+++ b/resourced/Cargo.toml
@@ -10,7 +10,6 @@
 anyhow = "1.0"
 dbus = "0.9"
 dbus-tree = "0.9"
-glob = "0.3"
 libc = "0.2"
 once_cell = "1.7"
 tempfile = "3.0.2"
diff --git a/resourced/src/common.rs b/resourced/src/common.rs
index 6c36db8..5223a87 100644
--- a/resourced/src/common.rs
+++ b/resourced/src/common.rs
@@ -9,7 +9,6 @@
 use std::sync::Mutex;
 
 use anyhow::{bail, Context, Result};
-use glob::glob;
 use once_cell::sync::Lazy;
 
 // Extract the parsing function for unittest.
@@ -91,11 +90,18 @@
 // On !X86_FEATURE_HWP_EPP Intel devices, an integer write to the sysfs node
 // will fail with -EINVAL.
 pub fn set_epp(root_path: &str, value: &str) -> Result<()> {
-    let pattern = root_path.to_owned()
-        + "/sys/devices/system/cpu/cpufreq/policy*/energy_performance_preference";
+    let entries = std::fs::read_dir(root_path.to_string() + "/sys/devices/system/cpu/cpufreq/")?;
 
-    for entry in glob(&pattern)? {
-        std::fs::write(&entry?, value).context("Failed to set EPP sysfs value!")?;
+    for entry in entries {
+        let entry_str = entry.map(|e| e.path())?.display().to_string();
+
+        if entry_str.contains("policy") {
+            let file_path = entry_str + "/energy_performance_preference";
+            match std::fs::write(&file_path, value) {
+                Ok(_) => (),
+                Err(_) => bail!("Failed to set EPP sysfs value!"),
+            }
+        }
     }
 
     Ok(())
diff --git a/resourced/src/test.rs b/resourced/src/test.rs
index 1492e12..e107111 100644
--- a/resourced/src/test.rs
+++ b/resourced/src/test.rs
@@ -207,17 +207,12 @@
     tpb1.push("sys/devices/system/cpu/cpufreq/policy1/");
     std::fs::create_dir_all(&tpb1).unwrap();
 
-    tpb0.push("energy_performance_preference");
-    tpb1.push("energy_performance_preference");
-
-    // Create energy_performance_preference files.
-    std::fs::write(&tpb0, "balance_performance").unwrap();
-    std::fs::write(&tpb1, "balance_performance").unwrap();
-
     // Set the EPP
     set_epp(dir.path().to_str().unwrap(), "179").unwrap();
 
     // Verify that files were written
+    tpb0.push("energy_performance_preference");
+    tpb1.push("energy_performance_preference");
     assert_eq!(std::fs::read_to_string(&tpb0).unwrap(), "179".to_string());
     assert_eq!(std::fs::read_to_string(&tpb1).unwrap(), "179".to_string());
 }