Release Diary locks before native helpers exit and verify the store

This commit is contained in:
waozi committed 2026-10-20 19:46:23 -03:00
1 parent 1a30ab32b2
commit 95ad66c611
6 files changed
+74 -4

No files matched your search

+1
View File
@@ -143,6 +143,7 @@ test: android-geometry-probe-test
test: lumi-feedback-delivery-test
test: lumi-connection-test
test: diary-spelling-test diary-history-test diary-markdown-test
test: cells-test
test: device-info-test
test: dew-test
test: lists-sharing-test
+9
View File
@@ -20,6 +20,7 @@
#
# sh scripts/release-ready.sh every covered job; writes the stamp
# sh scripts/release-ready.sh TARGET... only these make targets; no stamp
# RELEASE_READY_DNS optionally supplies a resolver when rootless DNS is broken.
set -eu
root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
@@ -136,8 +137,16 @@ if [ -d "$android_sdk/ndk" ]; then
fi
status=0
dns_option=""
if [ -n "${RELEASE_READY_DNS:-}" ]; then
case "$RELEASE_READY_DNS" in
*[!0-9a-fA-F.:]*) echo "release-ready: RELEASE_READY_DNS must be an IP address" >&2; exit 2 ;;
esac
dns_option="--dns=$RELEASE_READY_DNS"
fi
# shellcheck disable=SC2086
podman run --rm --pull=never --userns=keep-id \
$dns_option \
-v "$root:/src:O" \
-v "$root/$output/build:/src/build" \
-v "$root/$output/home:/home/ubuntu" \
+5 -1
View File
@@ -45,6 +45,7 @@ diary_blob_generation: s64;
diary_preview_generation: s64;
#if !#defined(_WIN32) && !#defined(PLATFORM_WEB) {
DiaryLock :: (descriptor: s32, operation: s32) -> s32 #foreign c "flock";
DiaryDescriptorFlags :: (descriptor: s32, command: s32, flags: s32) -> s32 #foreign c "fcntl";
}
DiaryStorePrepare :: () -> bool {
@@ -74,7 +75,10 @@ DiaryStorePrepare :: () -> bool {
if !diary_lock.valid {
return false
}
if DiaryLock(diary_lock.fd, 6) != 0 {
// Downloads and file pickers exec native helpers. They must not keep
// this app's lock alive when it closes and another instance opens.
// fcntl(F_SETFD, FD_CLOEXEC) applies on every supported Unix host.
if DiaryDescriptorFlags(diary_lock.fd, 2, 1) != 0 || DiaryLock(diary_lock.fd, 6) != 0 {
unused CloseFile(diary_lock)
diary_lock = FileHandle.{}
return false
+4 -2
View File
@@ -66,6 +66,7 @@ ModuleTestCount :: (sql: string) -> s32 #foreign c;
ModuleTestSeedOld :: () -> bool #foreign c;
ModuleTestRuns :: () -> s32 #foreign c;
ModuleTestPackageBytes :: () -> bool #foreign c;
ModuleTestDiaryLockInheritance :: () -> bool #foreign c;
app: InnerBreeze;
list_id: [37]u8;
@@ -129,10 +130,10 @@ CheckRootConfiguration :: () {
AppTextFromCString(*size_text[0], 32) == "1.0 MB", 232)
Expect(!AppBundleSizeText(0, size_text[:]) && size_text[0] == cast(u8)0, 233)
// Practice pictures ship in each practice's pack; Wim Hof's pack ships
// with the app.
// with the app. Its card banner stays in Practices before installation.
shipped := AssetRead("assets/practices/default/whm.zib")
Expect(shipped.found && shipped.data.count > 8 && shipped.data[:3] == "ZIB" &&
!AssetRead("assets/practices/whm/banner-light.png").found, 106)
AssetRead("assets/practices/whm/banner-light.png").found, 106)
language := AssetRead("locales/es.txt")
Expect(language.found && language.data.count > 1000, 107)
Expect(!AssetRead("apps/publishers.json").found, 108)
@@ -233,6 +234,7 @@ CheckDiary :: () {
Expect(ModuleTestInstanceOpens() == instances, 240)
state := DiaryRun(DiaryMessage.{.action = DIARY_LOAD, .year = 2024, .month = 2, .day = 28})
Expect(state.succeeded && state.saved && !state.load_error && state.text == "", 82)
Expect(ModuleTestDiaryLockInheritance(), 491)
state.action = DIARY_EDIT
state.replacement = "A calm day 🌿\nSecond line"
state = DiaryRun(state)
+2 -1
View File
@@ -62,7 +62,8 @@ cp "$root/build/cells/habits.zib" "$root/build/cells/practices.zib" "$work/inval
-I"$root/build/packages/monocypher/src" -I"$root/build/packages/monocypher/src/optional" \
-I"$root/vendor-builds/sqlite" -I"$root/vendor-builds/linux/x86_64/inbe-liboqs/include" \
-I"$root/build/packages/raylib/src" \
"$root/tests/cells_host_test.c" "$root/tests/node_app_audio_host.c" "$work/generated"/*.c \
"$root/tests/cells_host_test.c" "$root/tests/diary_lock_host.c" \
"$root/tests/node_app_audio_host.c" "$work/generated"/*.c \
"$root/build/packages/monocypher/src/monocypher.c" \
"$root/build/packages/monocypher/src/optional/monocypher-ed25519.c" \
"$root/vendor-builds/sqlite/sqlite3.c" "$liboqs" "${ZIRAN_LIB:-$(dirname "$(dirname "$ziran")")/libziran.a}" \
+53
View File
@@ -0,0 +1,53 @@
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
extern bool diary_store_DiaryStorePrepare(void);
extern void diary_store_DiaryStoreClose(void);
bool ModuleTestDiaryLockInheritance(void)
{
assert(diary_store_DiaryStorePrepare());
int status[2];
assert(pipe(status) == 0);
assert(fcntl(status[1], F_SETFD, FD_CLOEXEC) == 0);
pid_t child = fork();
assert(child >= 0);
if(child == 0) {
close(status[0]);
/* Match download/picker helpers: exec without closing the parent's
* unrelated descriptors. EOF on status proves exec has completed. */
execl("/bin/sleep", "sleep", "30", (char *)NULL);
int error = errno;
(void)write(status[1], &error, sizeof(error));
_exit(127);
}
close(status[1]);
int error = 0;
ssize_t count;
do {
count = read(status[0], &error, sizeof(error));
} while(count < 0 && errno == EINTR);
close(status[0]);
assert(count == 0);
int result;
assert(waitpid(child, &result, WNOHANG) == 0);
/* The next app must reopen Diary even while the previous app's helper
* remains alive. The real store performs both lock acquisitions. */
diary_store_DiaryStoreClose();
bool reopened = diary_store_DiaryStorePrepare();
assert(kill(child, SIGKILL) == 0);
assert(waitpid(child, &result, 0) == child);
assert(diary_store_DiaryStorePrepare());
if(!reopened) {
fputs("Diary lock survived in an exec'd helper after the app closed\n", stderr);
}
return reopened;
}