Compare commits

...

3 commits

Author SHA1 Message Date
CismonX
9de097d9ee
build: refactor configuration scripts
- Move common `AC_DEFINE()` usage to `EX_FEAT()`.
- Remove unused argument `action-if-disabled` for `EX_FEAT()`.
- Conditionally enable features by default.
2025-06-17 13:41:17 +08:00
CismonX
fb0d39dfc3
defs: remove HAVE_PIPE2 macro
This feature check is only used in `xpipe2()`.
2025-06-17 12:24:08 +08:00
CismonX
99ac2b79f8
test: misc fix and refactor 2025-06-16 18:32:36 +08:00
8 changed files with 64 additions and 97 deletions

View file

@ -40,81 +40,50 @@ AC_PROG_MAKE_SET
# -- Checks for features --
EX_FEAT([bookmarkfs-util], [no], [the BookmarkFS utility library])
EX_FEAT([bookmarkfs-util], [no], [the BookmarkFS utility library], , [1])
EX_FEAT([bookmarkctl], [no], [the bookmarkctl program])
EX_FEAT([bookmarkctl], [no], [the bookmarkctl program], , [1])
EX_FEAT([bookmarkfs-fsck], [no], [the fsck.bookmarkfs program], [
AS_VAR_SET([enable_bookmarkfs_util], [yes])
])
AS_VAR_SET([enable_bookmarkfs_util], [yes])
AS_VAR_SET([enable_interactive_fsck], [yes])
], [1])
EX_FEAT([bookmarkfs-mkfs], [no], [the mkfs.bookmarkfs program])
EX_FEAT([bookmarkfs-mkfs], [no], [the mkfs.bookmarkfs program], , [1])
EX_FEAT([bookmarkfs-mount], [no], [the mount.bookmarkfs program], [
AS_VAR_SET([enable_bookmarkfs_util], [yes])
])
], [1])
EX_FEAT([sandbox], [yes], [sandboxing], [
AC_DEFINE([BOOKMARKFS_SANDBOX], [1],
[Define to 1 if sandboxing is enabled.])
])
EX_FEAT([sandbox], [yes], [sandboxing])
AS_VAR_IF([host_os_is_linux], [yes], [
EX_FEAT([sandbox-landlock], [yes], [Landlock features for sandboxing], [
AC_DEFINE([BOOKMARKFS_SANDBOX_LANDLOCK], [1],
[Define to 1 if Landlock is enabled for sandboxing.])
])
EX_FEAT([sandbox-landlock], [yes], [Landlock features for sandboxing])
])
EX_FEAT([xxhash-inline], [no], [using xxhash as a header-only library], [
AC_DEFINE([BOOKMARKFS_XXHASH_INLINE], [1],
[Define to 1 if using xxhash as a header-only library.])
])
EX_FEAT([xxhash-inline], [no], [using xxhash as a header-only library])
EX_FEAT([bookmarkfs-debug], [no], [debugging features for BookmarkFS], [
AC_DEFINE([BOOKMARKFS_DEBUG], [1],
[Define to 1 if BookmarkFS debugging is enabled.])
])
EX_FEAT([bookmarkfs-debug], [no], [debugging features for BookmarkFS])
EX_FEAT([backend-firefox], [no], [Firefox backend], [
AS_VAR_SET([enable_bookmarkfs_util], [yes])
])
AS_VAR_SET([enable_bookmarkfs_util], [yes])
AS_VAR_SET([enable_backend_firefox_write], [yes])
], [1])
EX_FEAT([backend-firefox-write], [yes],
[write support for the Firefox backend],
[
AC_DEFINE([BOOKMARKFS_BACKEND_FIREFOX_WRITE], [1],
[Define to 1 if the Firefox backend supports writing.])
])
EX_FEAT([backend-firefox-write], , [write support for the Firefox backend])
EX_FEAT([backend-chromium], [no], [Chromium backend], [
AS_VAR_SET([enable_bookmarkfs_util], [yes])
])
AS_VAR_SET([enable_bookmarkfs_util], [yes])
AS_VAR_SET([enable_backend_chromium_write], [yes])
], [1])
EX_FEAT([backend-chromium-write], [yes],
[write support for the Chromium backend],
[
AC_DEFINE([BOOKMARKFS_BACKEND_CHROMIUM_WRITE], [1],
[Define to 1 if the Chromium backend supports writing.])
])
EX_FEAT([backend-chromium-write], , [write support for the Chromium backend])
EX_FEAT([native-watcher], [yes], [platform-specific file watcher], [
AC_DEFINE([BOOKMARKFS_NATIVE_WATCHER], [1],
[Define to 1 if platform-specific file watcher is enabled.])
])
EX_FEAT([native-watcher], [yes], [platform-specific file watcher])
EX_FEAT([interactive-fsck], [yes],
[interactive features for fsck.bookmarkfs],
[
AS_VAR_IF([enable_bookmarkfs_fsck], [no], [
AS_VAR_SET([enable_interactive_fsck], [no])
], [
AC_DEFINE([BOOKMARKFS_INTERACTIVE_FSCK], [1],
[Define to 1 if interactive fsck features are enabled.])
])
])
EX_FEAT([interactive-fsck], , [interactive features for fsck.bookmarkfs])
EX_FEAT([fsck-handler-tcl], [no], [Tcl-based fsck handler])
EX_FEAT([fsck-handler-tcl], [no], [Tcl-based fsck handler], , [1])
# -- Checks for libraries --

View file

@ -8,8 +8,8 @@ dnl This file is offered as-is, without any warranty.
dnl
dnl
dnl EX_FEAT(feature, default-value, description, [action-if-enabled],
dnl [action-if-disabled])
dnl EX_FEAT(feature, [default-value], description, [action-if-enabled],
dnl [no-ac-define])
dnl
dnl Provide an option to enable or disable a feature.
dnl
@ -19,15 +19,19 @@ AC_DEFUN([EX_FEAT], [
AC_MSG_CHECKING(m4_normalize([if $3 is enabled]))
AC_ARG_ENABLE([$1], m4_normalize([
AS_HELP_STRING([--]arg_action_[-$1], arg_action_ [$3])
]), , [
]), , m4_ifnblank([$2], [
AS_VAR_SET([enable_]feat_name_, [$2])
])
AS_VAR_IF([enable_]feat_name_, [no], [
AC_MSG_RESULT([no])
$5
], [
]))
AS_VAR_IF([enable_]feat_name_, [yes], [
AC_MSG_RESULT([yes])
$4
m4_ifblank([$5], [
AC_DEFINE(m4_if(m4_substr(feat_name_, 0, 10), [bookmarkfs], ,
[BOOKMARKFS_])[]m4_toupper(feat_name_),
[1], [Define to 1 if $3 is enabled.])
])
], [
AC_MSG_RESULT([no])
])
AS_VAR_SET([desc_]feat_name_, ["$3"])
m4_popdef([arg_action_])

View file

@ -92,10 +92,6 @@
# define UNUSED_VAR(name) name##_unused_ VARATTR_UNUSED_
#endif /* defined(HAVE_STDC_23) */
#if defined(__FreeBSD__) || (defined(__linux__) && defined(_GNU_SOURCE))
# define HAVE_PIPE2 1
#endif
#ifndef __FreeBSD__
# define O_RESOLVE_BENEATH 0
# define PROT_MAX(prot) 0

View file

@ -111,14 +111,14 @@ xpipe2 (
int pipefd[2],
int flags
) {
#ifdef HAVE_PIPE2
#if defined(__FreeBSD__) || (defined(__linux__) && defined(_GNU_SOURCE))
if (0 != pipe2(pipefd, flags)) {
log_printf("pipe2(): %s", xstrerror(errno));
return -1;
}
return 0;
#else /* !defined(HAVE_PIPE2) */
#else
if (0 != pipe(pipefd)) {
log_printf("pipe(): %s", xstrerror(errno));
return -1;
@ -147,7 +147,7 @@ xpipe2 (
close(pipefd[1]);
return -1;
#endif /* defined(HAVE_PIPE2) */
#endif
}
void *

View file

@ -42,10 +42,11 @@
struct check_item {
int id;
unsigned flags;
int ref;
};
// Forward declaration start
static int dent_check (int, struct check_item *, int const *, int, int);
static int dent_check (int, struct check_item *, int, int);
static int dent_delete (int, struct check_item *);
static int dent_new (int, struct check_item *);
static int dent_permute (int, struct check_item *, struct check_item *);
@ -55,8 +56,7 @@ static int do_check_fs_dents (int, int);
static int
dent_check (
int dirfd,
struct check_item *item,
int const *map,
struct check_item *items,
int n,
int ignore_dirty
) {
@ -81,7 +81,7 @@ dent_check (
if (id < 0 || id >= n) {
return -1;
}
struct check_item *found = item + map[id];
struct check_item *found = items + items[id].ref;
if (found->flags & (ITEM_DELETED | ITEM_MARKED)) {
return -1;
}
@ -95,14 +95,14 @@ dent_check (
found->flags |= ITEM_MARKED;
}
for (last_found = item + n; item < last_found; ++item) {
if (ignore_dirty && item->flags & ITEM_DIRTY) {
for (last_found = items + n; items < last_found; ++items) {
if (ignore_dirty && items->flags & ITEM_DIRTY) {
continue;
}
if (!(item->flags & (ITEM_DELETED | ITEM_MARKED))) {
if (!(items->flags & (ITEM_DELETED | ITEM_MARKED))) {
return -1;
}
item->flags &= ~ITEM_MARKED;
items->flags &= ~ITEM_MARKED;
}
return 0;
}
@ -176,10 +176,10 @@ dent_permute (
}
struct check_item item_tmp = *item1;
*item1 = *item2;
*item2 = item_tmp;
item1->flags |= ITEM_DIRTY;
item2->flags |= ITEM_DIRTY;
item1->id = item2->id;
item1->flags = item2->flags | ITEM_DIRTY;
item2->id = item_tmp.id;
item2->flags = item_tmp.flags | ITEM_DIRTY;
return 0;
}
@ -192,15 +192,14 @@ do_check_fs_dents (
#define ASSERT_NE(val, expr) ASSERT_EXPR_INT(expr, r_, (val) != r_, goto end;)
struct check_item *items = calloc(n, sizeof(struct check_item));
int *map = malloc(sizeof(int) * n);
if (items == NULL || map == NULL) {
if (items == NULL) {
return -1;
}
int status = -1;
for (int i = 0; i < n; ++i) {
struct check_item *item = items + i;
map[i] = item->id = i;
item->ref = item->id = i;
ASSERT_EQ(0, dent_new(dirfd, item));
}
@ -219,20 +218,19 @@ do_check_fs_dents (
continue;
}
ASSERT_EQ(0, dent_permute(dirfd, i1, i2));
map[i1->id] = i1 - items;
map[i2->id] = i2 - items;
items[i1->id].ref = i1 - items;
items[i2->id].ref = i2 - items;
#endif
}
}
ASSERT_EQ(0, dent_check(dirfd, items, map, n, 1));
ASSERT_EQ(0, dent_check(dirfd, items, n, 1));
ASSERT_EQ(0, lseek(dirfd, 0, SEEK_SET));
ASSERT_EQ(0, dent_check(dirfd, items, map, n, 0));
ASSERT_EQ(0, dent_check(dirfd, items, n, 0));
status = 0;
end:
free(items);
free(map);
return status;
}

View file

@ -122,7 +122,7 @@ do_check_fs_regrw (
#ifndef O_DIRECT
# define O_DIRECT 0
#endif
int fd = open(path, O_RDWR | O_CREAT | O_TRUNC | O_DIRECT);
int fd = open(path, O_RDWR | O_CREAT | O_TRUNC | O_DIRECT, 0600);
ASSERT_NE(-1, fd);
struct stat stat_buf;

View file

@ -68,11 +68,12 @@ do_check_fs_times (
#define ASSERT_NE(val, expr) ASSERT_EXPR_INT(expr, r_, (val) != r_, goto end;)
int status = -1;
int fd = -1;
struct timespec now;
ASSERT_EQ(0, clock_gettime(CLOCK_REALTIME, &now));
int fd = openat(dirfd, FILE1_NAME, O_WRONLY | O_CREAT | O_EXCL);
fd = openat(dirfd, FILE1_NAME, O_WRONLY | O_CREAT | O_EXCL, 0600);
ASSERT_NE(-1, fd);
struct stat stat_buf;

View file

@ -58,18 +58,17 @@ do_check_sandbox (
# error "not implemented"
#endif
#define ASSERT_BAD_SYS(expr, cleanup_action) \
ASSERT_EXPR_INT(expr, r_, (err_ = errno, r_ < 0), { \
cleanup_action \
goto end; \
}); \
ASSERT_EXPR_INT(err_, r_, r_ == ERR1 || r_ == ERR2, goto end;)
#define ASSERT_BAD_SYS(expr, cleanup_action) \
ASSERT_EXPR_INT(expr, r_, r_ < 0, { \
cleanup_action \
goto end; \
}); \
ASSERT_EXPR_INT(errno, r_, r_ == ERR1 || r_ == ERR2, goto end;)
#define ASSERT_BAD_FD(expr) ASSERT_BAD_SYS(expr, close(r_);)
#define ASSERT_EQ(val, expr) ASSERT_EXPR_INT(expr, r_, (val) == r_, goto end;)
#define ASSERT_NE(val, expr) ASSERT_EXPR_INT(expr, r_, (val) != r_, goto end;)
int err_;
int status = -1;
int fd = socket(AF_INET, SOCK_STREAM, 0);