summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorRina Fujino <18257209+rina23q@users.noreply.github.com>2021-06-09 15:32:00 +0200
committerGitHub <noreply@github.com>2021-06-09 15:32:00 +0200
commit4790d6ddc52f4fb78d6519c9ff0f9ebe1b84b323 (patch)
tree0691585309066a7124d4db3142db26f13d5f810d /common
parent9eedd9166d8ee9b2cfdf91cdfdae463088487d4e (diff)
[CIT-402] Fix the condition to look at the default system location in tedge_mapper (#279)
* [CIT-402] Fix the condition to look at the default system location when tedge_mapper is running as the tedge-mapper user - Add UserManager::running_as(desired_user) - Add the same fix to collectd_mapper Signed-off-by: Rina Fujino <18257209+rina23q@users.noreply.github.com>
Diffstat (limited to 'common')
-rw-r--r--common/tedge_users/src/unix.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/common/tedge_users/src/unix.rs b/common/tedge_users/src/unix.rs
index 6ac81194..aef224cf 100644
--- a/common/tedge_users/src/unix.rs
+++ b/common/tedge_users/src/unix.rs
@@ -59,6 +59,22 @@ impl UserManager {
users::get_current_uid() == 0
}
+ /// Check if the process has been launched using a desired user or not.
+ ///
+ /// # Example
+ ///
+ /// ```
+ /// # use tedge_users::UserManager;
+ /// let path = if UserManager::running_as("tedge-mapper") {
+ /// "/etc/tedge/tedge.toml"
+ /// } else {
+ /// ".tedge/tedge.toml"
+ /// };
+ /// ```
+ pub fn running_as(desired_user: &str) -> bool {
+ users::get_current_username() == Some(desired_user.into())
+ }
+
/// Switch the effective user of the running process.
///
/// This method returns a guard. As long as the guard is owned by the caller,