fu-tool: put lockfile in user's cache directory if no permissions for /run

This commit is contained in:
Mario Limonciello 2022-01-07 17:28:42 -06:00 committed by Mario Limonciello
parent cf5a341a51
commit 62a64afda5

View File

@ -186,12 +186,21 @@ fu_util_lock(FuUtilPrivate *priv, GError **error)
.l_type = F_WRLCK, .l_type = F_WRLCK,
.l_whence = SEEK_SET, .l_whence = SEEK_SET,
}; };
g_autofree gchar *lockdir = NULL;
g_autofree gchar *lockfn = NULL; g_autofree gchar *lockfn = NULL;
gboolean use_user = FALSE;
#ifdef HAVE_GETUID
if (getuid() != 0 || geteuid() != 0)
use_user = TRUE;
#endif
/* open file */ /* open file */
lockdir = fu_common_get_path(FU_PATH_KIND_LOCKDIR); if (use_user) {
lockfn = g_build_filename(lockdir, "fwupdtool", NULL); lockfn = fu_util_get_user_cache_path("fwupdtool");
} else {
g_autofree gchar *lockdir = fu_common_get_path(FU_PATH_KIND_LOCKDIR);
lockfn = g_build_filename(lockdir, "fwupdtool", NULL);
}
if (!fu_common_mkdir_parent(lockfn, error)) if (!fu_common_mkdir_parent(lockfn, error))
return FALSE; return FALSE;
priv->lock_fd = g_open(lockfn, O_RDWR | O_CREAT, S_IRWXU); priv->lock_fd = g_open(lockfn, O_RDWR | O_CREAT, S_IRWXU);