admin: Use locking for most sysroot commands
The previous commit introduced locking for `ostree admin deploy`, but we do expect people to possibly accidentally do e.g. `ostree admin upgrade` concurrently. Using consistent locking in the admin commands will help rpm-ostree. Closes: https://github.com/GNOME/ostree/pull/110
This commit is contained in:
parent
06818ceddc
commit
c10bc00249
|
|
@ -79,9 +79,6 @@ ot_admin_builtin_deploy (int argc, char **argv, GCancellable *cancellable, GErro
|
||||||
|
|
||||||
refspec = argv[1];
|
refspec = argv[1];
|
||||||
|
|
||||||
if (!ot_admin_sysroot_lock (sysroot, error))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
if (!ostree_sysroot_load (sysroot, cancellable, error))
|
if (!ostree_sysroot_load (sysroot, cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
|
@ -175,8 +172,6 @@ ot_admin_builtin_deploy (int argc, char **argv, GCancellable *cancellable, GErro
|
||||||
|
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
out:
|
out:
|
||||||
if (sysroot)
|
|
||||||
ostree_sysroot_unlock (sysroot);
|
|
||||||
if (origin)
|
if (origin)
|
||||||
g_key_file_unref (origin);
|
g_key_file_unref (origin);
|
||||||
if (context)
|
if (context)
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ ot_admin_builtin_diff (int argc, char **argv, GCancellable *cancellable, GError
|
||||||
g_option_context_add_main_entries (context, options, NULL);
|
g_option_context_add_main_entries (context, options, NULL);
|
||||||
|
|
||||||
if (!ostree_admin_option_context_parse (context, options, &argc, &argv,
|
if (!ostree_admin_option_context_parse (context, options, &argc, &argv,
|
||||||
OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER,
|
OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER | OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED,
|
||||||
&sysroot, cancellable, error))
|
&sysroot, cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ ot_admin_builtin_init_fs (int argc, char **argv, GCancellable *cancellable, GErr
|
||||||
context = g_option_context_new ("PATH - Initialize a root filesystem");
|
context = g_option_context_new ("PATH - Initialize a root filesystem");
|
||||||
|
|
||||||
if (!ostree_admin_option_context_parse (context, options, &argc, &argv,
|
if (!ostree_admin_option_context_parse (context, options, &argc, &argv,
|
||||||
OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER,
|
OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER | OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED,
|
||||||
&sysroot, cancellable, error))
|
&sysroot, cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -116,7 +116,7 @@ ot_admin_builtin_instutil (int argc, char **argv, GCancellable *cancellable, GEr
|
||||||
|
|
||||||
/* This will not return for some options (e.g. --version). */
|
/* This will not return for some options (e.g. --version). */
|
||||||
if (ostree_admin_option_context_parse (context, NULL, &argc, &argv,
|
if (ostree_admin_option_context_parse (context, NULL, &argc, &argv,
|
||||||
OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER,
|
OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER | OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED,
|
||||||
NULL, cancellable, error))
|
NULL, cancellable, error))
|
||||||
{
|
{
|
||||||
if (subcommand_name == NULL)
|
if (subcommand_name == NULL)
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ ot_admin_builtin_os_init (int argc, char **argv, GCancellable *cancellable, GErr
|
||||||
context = g_option_context_new ("OSNAME - Initialize empty state for given operating system");
|
context = g_option_context_new ("OSNAME - Initialize empty state for given operating system");
|
||||||
|
|
||||||
if (!ostree_admin_option_context_parse (context, options, &argc, &argv,
|
if (!ostree_admin_option_context_parse (context, options, &argc, &argv,
|
||||||
OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER,
|
OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER | OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED,
|
||||||
&sysroot, cancellable, error))
|
&sysroot, cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "ostree.h"
|
#include "ostree.h"
|
||||||
|
#include "ot-admin-functions.h"
|
||||||
#include "ot-main.h"
|
#include "ot-main.h"
|
||||||
#include "otutil.h"
|
#include "otutil.h"
|
||||||
|
|
||||||
|
|
@ -362,6 +363,13 @@ ostree_admin_option_context_parse (GOptionContext *context,
|
||||||
exit (EXIT_SUCCESS);
|
exit (EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((flags & OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED) == 0)
|
||||||
|
{
|
||||||
|
/* Released when sysroot is finalized, or on process exit */
|
||||||
|
if (!ot_admin_sysroot_lock (sysroot, error))
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
gs_transfer_out_value (out_sysroot, &sysroot);
|
gs_transfer_out_value (out_sysroot, &sysroot);
|
||||||
|
|
||||||
success = TRUE;
|
success = TRUE;
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,8 @@ typedef enum {
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
OSTREE_ADMIN_BUILTIN_FLAG_NONE = 0,
|
OSTREE_ADMIN_BUILTIN_FLAG_NONE = 0,
|
||||||
OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER = 1 << 0
|
OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER = 1 << 0,
|
||||||
|
OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED = 1 << 1
|
||||||
} OstreeAdminBuiltinFlags;
|
} OstreeAdminBuiltinFlags;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue