aboutsummaryrefslogtreecommitdiff
path: root/bbot/agent.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'bbot/agent.cxx')
-rw-r--r--bbot/agent.cxx89
1 files changed, 57 insertions, 32 deletions
diff --git a/bbot/agent.cxx b/bbot/agent.cxx
index 76c3a86..e608af2 100644
--- a/bbot/agent.cxx
+++ b/bbot/agent.cxx
@@ -2,6 +2,8 @@
// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
// license : MIT; see accompanying LICENSE file
+#include <bbot/agent>
+
#include <limits.h> // PATH_MAX
#include <signal.h> // signal()
#include <unistd.h> // sleep(), realink()
@@ -15,12 +17,22 @@
#include <bbot/types>
#include <bbot/utility>
-
#include <bbot/diagnostics>
-#include <bbot/agent-options>
+#include <bbot/machine>
#include <bbot/bootstrap-manifest>
+namespace bbot
+{
+ agent_options ops;
+
+ const string bs_prot ("1"); // Bootstrap protocol version.
+
+ string tc_name; // Toolchain name.
+ string tc_num; // Toolchain number.
+ string tc_id; // Toolchain id.
+}
+
using namespace std;
using namespace butl;
using namespace bbot;
@@ -34,9 +46,9 @@ inline void
btrfs (tracer& t, A&&... a)
{
if (verb >= 3)
- run (t, fdnull (), 2, 2, "btrfs", forward<A> (a)...);
+ run_io (t, fdnull (), 2, 2, "btrfs", forward<A> (a)...);
else
- run (t, fdnull (), fdnull (), 2, "btrfs", forward<A> (a)...);
+ run_io (t, fdnull (), fdnull (), 2, "btrfs", forward<A> (a)...);
}
template <typename... A>
@@ -44,20 +56,14 @@ inline butl::process_exit::code_type
btrfs_exit (tracer& t, A&&... a)
{
return verb >= 3
- ? run_exit (t, fdnull (), 2, 2, "btrfs", forward<A> (a)...)
- : run_exit (t, fdnull (), fdnull (), 2, "btrfs", forward<A> (a)...);
+ ? run_io_exit (t, fdnull (), 2, 2, "btrfs", forward<A> (a)...)
+ : run_io_exit (t, fdnull (), fdnull (), 2, "btrfs", forward<A> (a)...);
}
-agent_options ops;
-
-const string bs_prot ("1"); // Bootstrap protocol version.
-
-string tc_name; // Toolchain name.
-string tc_num; // Toolchain number.
-string tc_id; // Toolchain id.
-
static bootstrapped_machine_manifest
-bootstrap_machine (const dir_path& md, const machine_manifest& mm)
+bootstrap_machine (const dir_path& md,
+ const machine_manifest& mm,
+ optional<bootstrapped_machine_manifest> obmm)
{
bootstrapped_machine_manifest r {
mm,
@@ -72,21 +78,40 @@ bootstrap_machine (const dir_path& md, const machine_manifest& mm)
}
};
- if (!ops.fake_bootstrap ())
+ if (ops.fake_bootstrap ())
{
+ r.machine.mac = "de:ad:be:ef:de:ad";
+ }
+ else
+ {
+ unique_ptr<machine> m (
+ start_machine (md,
+ mm,
+ obmm ? obmm->machine.mac : nullopt));
+
+ r.machine.mac = m->mac;
+
+ sleep (10);
+
+ if (!m->shutdown ())
+ {
+ error << "forcing machine " << md << " down";
+ m->forcedown ();
+ throw failed ();
+ }
}
serialize_manifest (r, md / "manifest", "bootstrapped machine");
return r;
}
-static machine_manifests
+static machine_header_manifests
enumerate_machines (const dir_path& rd)
try
{
tracer trace ("enumerate_machines");
- machine_manifests r;
+ machine_header_manifests r;
// The first level are machine volumes.
//
@@ -244,26 +269,25 @@ try
(r = cmp ("libbutl", LIBBUTL_VERSION)) != 0 ? r : 0;
};
+ optional<bootstrapped_machine_manifest> obmm;
if (te)
{
- auto bmm (
- parse_manifest<bootstrapped_machine_manifest> (
- tp / "manifest",
- "bootstrapped machine"));
+ obmm = parse_manifest<bootstrapped_machine_manifest> (
+ tp / "manifest", "bootstrapped machine");
- if (bmm.machine.id != mm.id)
+ if (obmm->machine.id != mm.id)
{
l2 ([&]{trace << "re-bootstrapping " << tp << ": new machine";});
te = false;
}
- if (bmm.toolchain.id != tc_id)
+ if (obmm->toolchain.id != tc_id)
{
l2 ([&]{trace << "re-bootstrapping " << tp << ": new toolchain";});
te = false;
}
- if (int i = compare_bbot (bmm.bootstrap))
+ if (int i = compare_bbot (obmm->bootstrap))
{
if (i < 0)
{
@@ -290,7 +314,8 @@ try
// bootstrap the new machine. Then atomically rename it to
// <name>-<toolchain>.
//
- bootstrapped_machine_manifest bmm (bootstrap_machine (xp, mm));
+ bootstrapped_machine_manifest bmm (
+ bootstrap_machine (xp, mm, move (obmm)));
try
{
@@ -318,10 +343,10 @@ try
// Add the machine to the list.
//
- // In order not to forget to clear new fields, we are instead going
- // to create a new instance with just the required fields.
- //
- r.push_back (machine_manifest (mm.id, mm.name, mm.summary));
+ r.push_back (
+ machine_header_manifest (move (mm.id),
+ move (mm.name),
+ move (mm.summary)));
break;
}
@@ -453,11 +478,11 @@ try
//
for (unsigned int s; (s = 60); sleep (s))
{
- machine_manifests mms (enumerate_machines (ops.machines ()));
+ machine_header_manifests mms (enumerate_machines (ops.machines ()));
if (ops.dump_machines ())
{
- for (const machine_manifest& mm: mms)
+ for (const machine_header_manifest& mm: mms)
serialize_manifest (mm, cout, "stdout", "machine manifest");
return 0;