File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 43
43
#include <audit.h>
44
44
#include <logging.h>
45
45
#include <expand.h>
46
+ #include <file_lib.h> /* FileLock */
47
+ #include <known_dirs.h> /* GetStateDir() */
46
48
47
49
static const char * const POLICY_ERROR_BUNDLE_NAME_RESERVED =
48
50
"Use of a reserved container name as a bundle name \"%s\"" ;
@@ -100,6 +102,29 @@ const char *NamespaceDefault(void)
100
102
101
103
/*************************************************************************/
102
104
105
+ #define MASTERFILES_STAGE_LOCK_FNAME "masterfiles-stage.lock"
106
+
107
+ bool GetMasterfilesStageLock (FileLock * lock , bool exclusive , bool wait )
108
+ {
109
+ assert (lock != NULL );
110
+ char path [PATH_MAX ];
111
+ NDEBUG_UNUSED size_t ret = StringCopy (GetStateDir (), path , sizeof (path ));
112
+ assert (ret < sizeof (path ));
113
+ NDEBUG_UNUSED char * path_ret = JoinPaths (path , sizeof (path ), MASTERFILES_STAGE_LOCK_FNAME );
114
+ assert (path_ret != NULL );
115
+
116
+ if (exclusive )
117
+ {
118
+ return (ExclusiveFileLockPath (lock , path , wait ) == 0 );
119
+ }
120
+ else
121
+ {
122
+ return (SharedFileLockPath (lock , path , wait ) == 0 );
123
+ }
124
+ }
125
+
126
+ /*************************************************************************/
127
+
103
128
Policy * PolicyNew (void )
104
129
{
105
130
Policy * policy = xcalloc (1 , sizeof (Policy ));
Original file line number Diff line number Diff line change 31
31
#include <sequence.h>
32
32
#include <json.h>
33
33
#include <set.h>
34
+ #include <file_lib.h> /* FileLock */
34
35
35
36
typedef enum
36
37
{
@@ -141,6 +142,18 @@ struct Constraint_
141
142
SourceOffset offset ;
142
143
};
143
144
145
+ /**
146
+ * Get lock for masterfiles stage (update)
147
+ * @param lock file lock to initialize (not-%NULL)
148
+ * @param exclusive %true to get exclusive lock (for write access),
149
+ * %false for a shared lock (read access)
150
+ * @param wait whether to wait for the lock (blocks) or give up immediately
151
+ * @return whether the lock was successfully obtained or not
152
+ * @note Unlock the lock with ExclusiveFileUnlock() or SharedFileUnlock()
153
+ * when done.
154
+ */
155
+ bool GetMasterfilesStageLock (FileLock * lock , bool exclusive , bool wait );
156
+
144
157
const char * NamespaceDefault (void );
145
158
146
159
Policy * PolicyNew (void );
You can’t perform that action at this time.
0 commit comments