Skip to content

Commit 01d67a0

Browse files
committed
Fix closing monitor before USB drive is connected.
1 parent 87e36d4 commit 01d67a0

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

raspi/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ add_custom_command(OUTPUT ${RASPI5_PKGS}
5050
sacnlogger_crossbuild_arm64:latest
5151
cpack -B "./packages" -G DEB
5252
VERBATIM
53-
DEPENDS ${PROJECT_NAME}
53+
DEPENDS sacnlogger_monitor ${PROJECT_NAME}
5454
USES_TERMINAL
5555
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
5656
)

raspi/custom/device/sacnlogger-pi5/device/initramfs-tools/scripts/local-bottom/fs.sh

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/sh
22
# Mount the root filesystem.
3-
# Based on https://unix.stackexchange.com/a/445141, modified for initramfs-tools and Raspberry Pi.
3+
# Based on https://unix.stackexchange.com/a/445141, added error handling and modified for initramfs-tools and
4+
# Raspberry Pi.
45

56
PREREQ=""
67
prereqs()
@@ -16,10 +17,7 @@ esac
1617
. /scripts/functions
1718
# Begin real processing below this line
1819

19-
# Debugging
20-
set -x
21-
22-
# load module
20+
# load modules
2321
modprobe overlay
2422
if [ $? -ne 0 ]; then
2523
panic "ERROR: missing overlay kernel module"
@@ -29,7 +27,7 @@ if [ $? -ne 0 ]; then
2927
panic "ERROR: missing squashfs kernel module"
3028
fi
3129

32-
log_begin_msg "Setting up tmpfs overlay..."
30+
log_begin_msg "Mounting root filesystem overlay..."
3331

3432
# create some temporary directories under the initramfs's /run
3533
# they will be our mountpoints and such, which will get moved
@@ -48,6 +46,7 @@ if [ $? -ne 0 ]; then
4846
fi
4947

5048
# mount the squashfs and then the overlay to our designated locations
49+
# The mount command available here doesn't know how to create loopback devices, so need to do it separately.
5150
losetup /dev/loop0 /run/rootfs/drive/filesystem.squashfs
5251
if [ $? -ne 0 ]; then
5352
panic "ERROR: failed to mount compressed filesystem loopback"
@@ -56,17 +55,19 @@ mount -t squashfs -o ro /dev/loop0 /run/rootfs/ro
5655
if [ $? -ne 0 ]; then
5756
panic "ERROR: failed to mount compressed filesystem directory"
5857
fi
58+
# Now we have both the real filesystem and the tmpfs writable layer, create the overlay.
5959
mount -t overlay -o lowerdir=/run/rootfs/ro,upperdir=/run/rootfs/rw,workdir=/run/rootfs/.workdir root "${rootmnt}"
6060
if [ $? -ne 0 ]; then
6161
panic "ERROR: failed to mount overlay"
6262
fi
63+
# At this point we have our overlay root at ${rootmnt}!
6364

64-
# at this point we have our overlay root at ${rootmnt}!
65-
# move the drive's filesystem mount to where RPI's firmware partition should be mounted.
65+
# Move the drive's filesystem mount to where RPI's firmware partition should be mounted.
6666
mkdir -p "${rootmnt}/boot/firmware"
6767
mount -n -o move /run/rootfs/drive "${rootmnt}/boot/firmware"
6868
if [ $? -ne 0 ]; then
6969
panic "ERROR: failed to relocate firmware partition"
7070
fi
71+
# Cleanup the scratch dir.
7172
rm -d /run/rootfs/drive
7273
log_end_msg

src/sacnlogger_monitor/main.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121

2222
#include <argparse/argparse.hpp>
2323
#include <boost/asio/io_context.hpp>
24-
#include <boost/process/v2/process.hpp>
2524
#include <boost/process/v2/environment.hpp>
25+
#include <boost/process/v2/process.hpp>
2626
#include <filesystem>
2727
#include <fmt/format.h>
2828
#include <fstream>
@@ -66,6 +66,8 @@ bool diskAvailable()
6666

6767
void requestTerm(int) { termRequested = true; }
6868

69+
void cleanup() { spdlog::shutdown(); }
70+
6971
int main(int argc, char* argv[])
7072
{
7173
// Arguments
@@ -107,6 +109,11 @@ int main(int argc, char* argv[])
107109
// Wait for disk to be available.
108110
while (!diskAvailable())
109111
{
112+
if (termRequested)
113+
{
114+
cleanup();
115+
return EXIT_SUCCESS;
116+
}
110117
std::this_thread::sleep_for(std::chrono::seconds(1));
111118
}
112119
// Add monitor log on disk.
@@ -149,7 +156,7 @@ int main(int argc, char* argv[])
149156
exe.request_exit();
150157
exe.wait();
151158
}
152-
spdlog::shutdown();
159+
cleanup();
153160

154161
return exe.exit_code();
155162
}

0 commit comments

Comments
 (0)