// This can happen in a unit testing environment; at some point what we want to do here
// is move all of the zipl logic to a systemd unit instead that's keyed of
// ostree-finalize-staged.service.
- if (getuid () != 0)
+ if (!ot_util_process_privileged ())
return TRUE;
// If we're in a booted deployment, we don't need to spawn a container.
self->reserved_blocks = reserved_bytes / self->txn.blocksize;
/* Use the appropriate free block count if we're unprivileged */
- guint64 bfree = (getuid () != 0 ? stvfsbuf.f_bavail : stvfsbuf.f_bfree);
+ guint64 bfree = (ot_util_process_privileged () ? stvfsbuf.f_bfree : stvfsbuf.f_bavail);
if (bfree > self->reserved_blocks)
self->txn.max_blocks = bfree - self->reserved_blocks;
else
return FALSE;
/* Do nothing if we're not privileged */
- if (getuid () != 0)
+ if (!ot_util_process_privileged ())
return TRUE;
/* We also assume operating on non-booted roots won't have a readonly sysroot */
ot_transfer_out_value (out_components, &ret_components);
return TRUE;
}
+
+/* Check if current process is privileged */
+gboolean
+ot_util_process_privileged (void)
+{
+ return geteuid() == 0;
+}
gboolean ot_util_path_split_validate (const char *path, GPtrArray **out_components, GError **error);
+gboolean ot_util_process_privileged (void);
+
G_END_DECLS
*out_ns = FALSE;
/* If we're not root, then we almost certainly can't be remounting anything */
- if (getuid () != 0)
+ if (!ot_util_process_privileged ())
return TRUE;
/* If the system isn't booted via libostree, also nothing to do */
/* Only require root if we're manipulating a booted sysroot. (Mostly
* useful for the test suite)
*/
- if (booted && getuid () != 0)
+ if (booted && !ot_util_process_privileged ())
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED,
"You must be root to perform this command");