mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-09 03:38:09 +02:00
Add helper functions to find + remember EUID / EGID, avoid many syscalls
This commit is contained in:
parent
2593ae2522
commit
3783494dfe
2 changed files with 40 additions and 0 deletions
|
|
@ -218,6 +218,42 @@ nm_main_utils_ensure_root()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uid_t nm_uid;
|
||||||
|
/**
|
||||||
|
* nm_main_utils_get_nm_uid:
|
||||||
|
*
|
||||||
|
* Checks what EUID NetworkManager is running as.
|
||||||
|
* Saves the EUID so it can be reused without making many syscalls.
|
||||||
|
*/
|
||||||
|
uid_t
|
||||||
|
nm_main_utils_get_nm_uid(void)
|
||||||
|
{
|
||||||
|
static uint8_t nm_uid_flag = 0;
|
||||||
|
if (!nm_uid_flag) {
|
||||||
|
nm_uid = geteuid();
|
||||||
|
nm_uid_flag = 1;
|
||||||
|
}
|
||||||
|
return nm_uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
gid_t nm_gid;
|
||||||
|
/**
|
||||||
|
* nm_main_utils_get_nm_gid:
|
||||||
|
*
|
||||||
|
* Checks what EGID NetworkManager is running as.
|
||||||
|
* Saves the EGID so it can be reused without making many syscalls.
|
||||||
|
*/
|
||||||
|
gid_t
|
||||||
|
nm_main_utils_get_nm_gid(void)
|
||||||
|
{
|
||||||
|
static uint8_t nm_gid_flag = 0;
|
||||||
|
if (!nm_gid_flag) {
|
||||||
|
nm_gid = getegid();
|
||||||
|
nm_gid_flag = 1;
|
||||||
|
}
|
||||||
|
return nm_gid;
|
||||||
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
nm_main_utils_early_setup(const char *progname,
|
nm_main_utils_early_setup(const char *progname,
|
||||||
int *argc,
|
int *argc,
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,10 @@
|
||||||
|
|
||||||
void nm_main_utils_ensure_root(void);
|
void nm_main_utils_ensure_root(void);
|
||||||
|
|
||||||
|
uid_t nm_main_utils_get_nm_uid(void);
|
||||||
|
|
||||||
|
gid_t nm_main_utils_get_nm_gid(void);
|
||||||
|
|
||||||
void nm_main_utils_setup_signals(GMainLoop *main_loop);
|
void nm_main_utils_setup_signals(GMainLoop *main_loop);
|
||||||
|
|
||||||
void nm_main_utils_ensure_statedir(void);
|
void nm_main_utils_ensure_statedir(void);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue