v4.0.0-rc3 - add is_process_root

This commit is contained in:
Liam Waldron 2024-10-08 13:36:28 -04:00
parent f00cdff880
commit 619e4bc346
2 changed files with 46 additions and 0 deletions

View File

@ -34,4 +34,20 @@
void runtime_exists(); void runtime_exists();
/*
* is_process_root
*
* DESCRIPTION: is_process_root checks if the process is running with root privileges.
* PARAMETERS:
* None.
* RETURN VALUES:
* 0 on root, 1 on non-root
* CAVEATS:
* None.
* EXAMPLE:
* is_process_root();
*/
int is_process_root();
#endif #endif

View File

@ -51,6 +51,7 @@ const char *runtime_files[] = {
* *
* DESCRIPTION: Output a stylized info message. * DESCRIPTION: Output a stylized info message.
* PARAMETERS: char MSG[] * PARAMETERS: char MSG[]
* DEFINED IN: glacier_log.h
* *
*/ */
@ -70,6 +71,7 @@ infolog(char MSG[])
* *
* DESCRIPTION: Output a stylized warning message. * DESCRIPTION: Output a stylized warning message.
* Parameters: char MSG[] * Parameters: char MSG[]
* DEFINED IN: glacier_log.h
* *
*/ */
@ -89,6 +91,7 @@ warnlog(char MSG[])
* *
* DESCRIPTION: Output a stylized error message. * DESCRIPTION: Output a stylized error message.
* PARAMETERS: char MSG[] * PARAMETERS: char MSG[]
* DEFINED IN: glacier_log.h
* *
*/ */
@ -108,6 +111,7 @@ errlog(char MSG[])
* *
* DESCRIPTION: Output a stylized success message. * DESCRIPTION: Output a stylized success message.
* PARAMETERS: char MSG[] * PARAMETERS: char MSG[]
* DEFINED IN: glacier_log.h
* *
*/ */
@ -130,6 +134,7 @@ successlog(char MSG[])
* *
* DESCRIPTION: Check if necesary runtime files exist. * DESCRIPTION: Check if necesary runtime files exist.
* PARAMETERS: None. * PARAMETERS: None.
* DEFINED IN: glacier_runtime.h
* *
*/ */
@ -148,11 +153,30 @@ runtime_exists()
return 1; return 1;
} }
/*
* is_process_root
*
* DESCRIPTION: Check if process is running as root.
* PARAMETERS: None.
* DEFINED IN: glacier_runtime.h
*
*/
int
is_process_root()
{
if (getuid() != 0) {
errlog("Failed to open package index: permission denied. Are you root?");
exit(1);
}
}
/* /*
* init_config * init_config
* *
* DESCRIPTION: Initialize libconfig. * DESCRIPTION: Initialize libconfig.
* PARAMETERS: None. * PARAMETERS: None.
* DEFINED IN: glacier_config.h
* *
*/ */
@ -177,6 +201,7 @@ init_config()
* *
* DESCRIPTION: Kill libconfig. * DESCRIPTION: Kill libconfig.
* PARAMETERS: None. * PARAMETERS: None.
* DEFINED IN: glacier_config.h
* *
*/ */
@ -193,6 +218,7 @@ die_config()
* *
* DESCRIPTION: Loads all settings from the Glacier config file. * DESCRIPTION: Loads all settings from the Glacier config file.
* PARAMETERS: None. * PARAMETERS: None.
* DEFINED IN: glacier_config.h
* *
*/ */
@ -222,6 +248,7 @@ load_all_from_config()
* *
* DESCRIPTION: Load a specified setting from the Glacier config file. * DESCRIPTION: Load a specified setting from the Glacier config file.
* PARAMETERS: char SETTING[] * PARAMETERS: char SETTING[]
* DEFINED IN: glacier_config.h
* *
*/ */
@ -234,6 +261,7 @@ load_setting_from_config(char SETTING[])
* *
* DESCRIPTION: Creates a new Glacier workspace in /tmp. * DESCRIPTION: Creates a new Glacier workspace in /tmp.
* PARAMETERS: None. * PARAMETERS: None.
* DEFINED IN: glacier_pkgops.h
* *
*/ */
@ -257,6 +285,7 @@ mkworkspace()
* *
* DESCRIPTION: Copies a package archive from the localdb to the workspace, and unpacks it. * DESCRIPTION: Copies a package archive from the localdb to the workspace, and unpacks it.
* PARAMETERS: char PACKAGE[] * PARAMETERS: char PACKAGE[]
* DEFINED IN: glacier_pkgops.h
* *
*/ */
@ -340,6 +369,7 @@ TEST_chdir(char dir[])
* *
* DESCRIPTION: Runs a make task in current working directory * DESCRIPTION: Runs a make task in current working directory
* PARAMETERS: char TASK[] * PARAMETERS: char TASK[]
* DEFINED IN: glacier_pkgops.h
* *
*/ */