aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2023-05-11 09:30:46 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2023-05-11 09:30:46 +0200
commita3463829567defda8aefa8425e79ff4d270617ba (patch)
treec949c0ceda008b13655475f281d028c7bf0bbb3d
parent24980c2ae899707ed98b33971381502265fe0269 (diff)
Use fake lock for fake machine locking
-rw-r--r--bbot/agent/agent.cxx46
1 files changed, 26 insertions, 20 deletions
diff --git a/bbot/agent/agent.cxx b/bbot/agent/agent.cxx
index 24e3f81..8f54346 100644
--- a/bbot/agent/agent.cxx
+++ b/bbot/agent/agent.cxx
@@ -505,10 +505,13 @@ public:
{
fl_ = false; // We have tried.
- try_rmfile (fp_, ignore_errors);
+ if (fd_ != nullfd)
+ {
+ try_rmfile (fp_, ignore_errors);
- if (flock (fd_.get (), LOCK_UN) != 0 && !ignore_errors)
- throw_generic_error (errno);
+ if (flock (fd_.get (), LOCK_UN) != 0 && !ignore_errors)
+ throw_generic_error (errno);
+ }
}
}
@@ -522,23 +525,26 @@ public:
{
assert (tl.locked () && fl_);
- pid_t pid (getpid ());
+ if (fd_ != nullfd)
+ {
+ pid_t pid (getpid ());
- string l (to_string (pid));
+ string l (to_string (pid));
- if (prio)
- {
- l += ' ';
- l += to_string (*prio);
- }
+ if (prio)
+ {
+ l += ' ';
+ l += to_string (*prio);
+ }
- auto n (fdwrite (fd_.get (), l.c_str (), l.size ()));
+ auto n (fdwrite (fd_.get (), l.c_str (), l.size ()));
- if (n == -1)
- throw_generic_ios_failure (errno);
+ if (n == -1)
+ throw_generic_ios_failure (errno);
- if (static_cast<size_t> (n) != l.size ())
- throw_generic_ios_failure (EFBIG);
+ if (static_cast<size_t> (n) != l.size ())
+ throw_generic_ios_failure (EFBIG);
+ }
}
~machine_lock ()
@@ -555,6 +561,8 @@ public:
// Implementation details.
//
public:
+ // If fd is nullfd, treat it as a fake lock (used for fake machines).
+ //
machine_lock (path&& fp, auto_fd&& fd)
: fp_ (move (fp)), fd_ (move (fd)), fl_ (true) {}
@@ -719,7 +727,7 @@ try
r.push_back (
bootstrapped_machine {
dir_path (ops.machines ()) /= mh.name, // For diagnostics.
- machine_lock (),
+ machine_lock (path (), nullfd), // Fake lock.
bootstrapped_machine_manifest {
machine_manifest {
move (mh.id),
@@ -1771,7 +1779,7 @@ try
{
// @@ For now skip machines locked by other processes.
//
- if (ops.fake_machine_specified () || m.lock.locked ())
+ if (m.lock.locked ())
tq.machines.emplace_back (m.manifest.machine.id,
m.manifest.machine.name,
m.manifest.machine.summary);
@@ -1942,9 +1950,7 @@ try
{
if (mh.name == m.manifest.machine.name)
{
- if (!ops.fake_machine_specified ())
- m.lock.write (tl, 1234 /* prio */);
-
+ m.lock.write (tl, 1234 /* prio */);
pm = &m;
}
else