diff --git a/mk/tests-suite.mk b/mk/tests-suite.mk index 3abe6e339..b21f3688b 100644 --- a/mk/tests-suite.mk +++ b/mk/tests-suite.mk @@ -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 diff --git a/scripts/release-ready.sh b/scripts/release-ready.sh index 97bed1b6a..daac2a515 100755 --- a/scripts/release-ready.sh +++ b/scripts/release-ready.sh @@ -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" \ diff --git a/src/cells/diary_store.zi b/src/cells/diary_store.zi index a17a6038f..49e7635e3 100644 --- a/src/cells/diary_store.zi +++ b/src/cells/diary_store.zi @@ -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 diff --git a/tests/cells_behavior.zi b/tests/cells_behavior.zi index 580e0809a..ba4343b1b 100644 --- a/tests/cells_behavior.zi +++ b/tests/cells_behavior.zi @@ -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) diff --git a/tests/cells_zi_test.sh b/tests/cells_zi_test.sh index 77830d2a9..53b8db662 100755 --- a/tests/cells_zi_test.sh +++ b/tests/cells_zi_test.sh @@ -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}" \ diff --git a/tests/diary_lock_host.c b/tests/diary_lock_host.c new file mode 100644 index 000000000..8a89f15c6 --- /dev/null +++ b/tests/diary_lock_host.c @@ -0,0 +1,53 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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; +}