diff options
author | Martin Pärtel <martin.partel@gmail.com> | 2023-11-27 23:35:41 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-27 23:35:41 +0200 |
commit | 2b5f2e24527f04f4255161965ae4099192714b73 (patch) | |
tree | b8edd8485dfcd64c68b12da4221a356acd54a0fa | |
parent | 47f4cac457c3583548c0d7dba402568a1e0871b8 (diff) | |
parent | 95936b647c0283cc6ebd2b685cc5b72889cda8bd (diff) | |
download | bindfs-2b5f2e24527f04f4255161965ae4099192714b73.tar.gz |
Merge pull request #150 from hartwork/macos-ci
Cover macOS in CI + make CI use the right compiler + fix more compile warnings
-rw-r--r-- | .github/workflows/tests.yml | 70 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/bindfs.c | 32 | ||||
-rw-r--r-- | src/permchain.c | 2 | ||||
-rw-r--r-- | src/permchain.h | 2 | ||||
-rw-r--r-- | src/rate_limiter.c | 4 | ||||
-rw-r--r-- | src/rate_limiter.h | 6 | ||||
-rw-r--r-- | src/userinfo.c | 22 | ||||
-rw-r--r-- | src/userinfo.h | 2 | ||||
-rw-r--r-- | src/usermap.c | 2 | ||||
-rw-r--r-- | src/usermap.h | 2 | ||||
-rw-r--r-- | tests/internals/test_common.c | 2 | ||||
-rw-r--r-- | tests/internals/test_common.h | 4 | ||||
-rw-r--r-- | tests/internals/test_internals.c | 12 | ||||
-rw-r--r-- | tests/internals/test_rate_limiter.c | 10 | ||||
-rw-r--r-- | tests/odirect_read.c | 2 | ||||
-rw-r--r-- | tests/odirect_write.c | 5 | ||||
-rw-r--r-- | tests/test_dir_rewind.c | 4 |
18 files changed, 123 insertions, 62 deletions
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 94ae76a..a406be0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,6 +10,10 @@ on: - cron: '0 3 * * 5' # Every Friday at 3am workflow_dispatch: +# Minimum permissions for security +permissions: + contents: read + jobs: linux: name: Build (${{ matrix.cc }} and ${{ matrix.fuse_package }} on ${{ matrix.runs-on }}) @@ -44,9 +48,23 @@ jobs: clang_repo_suffix: runs-on: ubuntu-22.04 fuse_package: libfuse3-dev + # fuse-t + - cc: gcc-13 + cxx: g++-13 + clang_major_version: null + clang_repo_suffix: null + runs-on: macos-12 + fuse_package: fuse-t + # macFUSE + - cc: clang-15 + cxx: clang++-15 + clang_major_version: 15 + clang_repo_suffix: null + runs-on: macos-12 + fuse_package: macfuse steps: - name: Add Clang/LLVM repositories - if: "${{ contains(matrix.cxx, 'clang') }}" + if: "${{ runner.os == 'Linux' && contains(matrix.cxx, 'clang') }}" run: |- set -x source /etc/os-release @@ -54,6 +72,7 @@ jobs: sudo add-apt-repository "deb http://apt.llvm.org/${UBUNTU_CODENAME}/ llvm-toolchain-${UBUNTU_CODENAME}${{ matrix.clang_repo_suffix }} main" - name: Install build dependencies + if: "${{ runner.os == 'Linux' }}" run: |- sudo apt-get update sudo apt-get install --yes --no-install-recommends \ @@ -64,12 +83,39 @@ jobs: pkg-config \ valgrind + - name: Install build dependencies + if: "${{ runner.os == 'macOS' }}" + run: |- + set -x + + if [[ ${{ matrix.fuse_package }} = macfuse ]]; then + brew install --cask macfuse + elif [[ ${{ matrix.fuse_package }} = fuse-t ]]; then + brew tap macos-fuse-t/homebrew-cask + brew install fuse-t + else + false # should never get here + fi + + brew install \ + autoconf \ + automake \ + libtool \ + pkg-config + - name: Install build dependency Clang ${{ matrix.clang_major_version }} - if: "${{ contains(matrix.cxx, 'clang') }}" + if: "${{ runner.os == 'Linux' && contains(matrix.cxx, 'clang') }}" run: |- sudo apt-get install --yes --no-install-recommends -V \ clang-${{ matrix.clang_major_version }} + - name: Add versioned aliases for Clang ${{ matrix.clang_major_version }} + if: "${{ runner.os == 'macOS' && contains(matrix.cxx, 'clang') }}" + run: |- + set -x + sudo ln -s "$(brew --prefix llvm@${{ matrix.clang_major_version }})"/bin/clang /usr/local/bin/clang-${{ matrix.clang_major_version }} + sudo ln -s "$(brew --prefix llvm@${{ matrix.clang_major_version }})"/bin/clang++ /usr/local/bin/clang++-${{ matrix.clang_major_version }} + - name: Checkout Git branch uses: actions/checkout@v4 @@ -79,6 +125,8 @@ jobs: - name: 'Configure' env: + CC: ${{ matrix.cc }} + CXX: ${{ matrix.cxx }} CFLAGS: -Werror run: |- set -x @@ -87,18 +135,30 @@ jobs: - name: 'Build' run: |- set -x - make -j$(nproc) VERBOSE=1 + make -j$(nproc || sysctl -n hw.logicalcpu) VERBOSE=1 - name: 'Test as non-root' run: |- + if [[ ${{ runner.os }} = macOS ]]; then + ignore_errors=true # while unfixed + else + ignore_errors=false + fi + set -x whoami - make check + make check || ${ignore_errors} - name: 'Test as root' run: |- + if [[ ${{ runner.os }} = macOS ]]; then + ignore_errors=true # while unfixed + else + ignore_errors=false + fi + set -x - sudo make check + sudo make check || ${ignore_errors} - name: 'Install' run: |- diff --git a/src/Makefile.am b/src/Makefile.am index da443a1..1fd6ef9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -12,7 +12,7 @@ bindfs_LDADD = ${fuse_LIBS} ${fuse3_LIBS} ${fuse_t_LIBS} ${my_LDFLAGS} man_MANS = bindfs.1 if BUILD_OS_IS_DARWIN -bindfs_BUNDLEDIR = /Library/Filesystems/bindfs.fs +bindfs_BUNDLEDIR = $(DESTDIR)/Library/Filesystems/bindfs.fs bindfs_BUNDLEBINDIR = "${bindfs_BUNDLEDIR}/Contents/Resources" install-exec-hook: diff --git a/src/bindfs.c b/src/bindfs.c index 5f52395..c21cdb5 100644 --- a/src/bindfs.c +++ b/src/bindfs.c @@ -225,7 +225,7 @@ static bool bindfs_init_failed = false; /* PROTOTYPES */ -static int is_mirroring_enabled(); +static int is_mirroring_enabled(void); /* Checks whether the uid is to be the mirrored owner of all files. */ static int is_mirrored_user(uid_t uid); @@ -257,7 +257,7 @@ static size_t round_up_buffer_size_for_direct_io(size_t size); #ifdef HAVE_FUSE_3 static void *bindfs_init(struct fuse_conn_info *conn, struct fuse_config *cfg); #else -static void *bindfs_init(); +static void *bindfs_init(struct fuse_conn_info *conn); #endif static void bindfs_destroy(void *private_data); #ifdef HAVE_FUSE_3 @@ -316,9 +316,11 @@ static int bindfs_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi); static int bindfs_write(const char *path, const char *buf, size_t size, off_t offset, struct fuse_file_info *fi); +#if defined(HAVE_FUSE_29) || defined(HAVE_FUSE_3) static int bindfs_lock(const char *path, struct fuse_file_info *fi, int cmd, struct flock *lock); static int bindfs_flock(const char *path, struct fuse_file_info *fi, int op); +#endif #ifdef HAVE_FUSE_3 static int bindfs_ioctl(const char *path, int cmd, void *arg, struct fuse_file_info *fi, unsigned int flags, @@ -343,14 +345,14 @@ static int process_option(void *data, const char *arg, int key, struct fuse_args *outargs); static int parse_mirrored_users(char* mirror); static int parse_user_map(UserMap *map, UserMap *reverse_map, char *spec); -static char *get_working_dir(); -static void maybe_stdout_stderr_to_file(); +static char *get_working_dir(void); +static void maybe_stdout_stderr_to_file(void); /* Sets up handling of SIGUSR1. */ -static void setup_signal_handling(); +static void setup_signal_handling(void); static void signal_handler(int sig); -static void atexit_func(); +static void atexit_func(void); /* Ignore some options (starting with -o) @@ -362,7 +364,7 @@ are special ones interpreted by systemd in /etc/fstab struct fuse_args filter_special_opts(struct fuse_args *args); static bool keep_option(const char* opt); -static int is_mirroring_enabled() +static int is_mirroring_enabled(void) { return settings.num_mirrored_users + settings.num_mirrored_members > 0; } @@ -707,11 +709,11 @@ static size_t round_up_buffer_size_for_direct_io(size_t size) #ifdef HAVE_FUSE_3 static void *bindfs_init(struct fuse_conn_info *conn, struct fuse_config *cfg) #else -static void *bindfs_init() +static void *bindfs_init(struct fuse_conn_info *conn) #endif { - #ifdef HAVE_FUSE_3 (void) conn; + #ifdef HAVE_FUSE_3 cfg->use_ino = 1; // Disable caches so changes in base FS are visible immediately. @@ -1454,6 +1456,7 @@ static int bindfs_write(const char *path, const char *buf, size_t size, return res; } +#if defined(HAVE_FUSE_29) || defined(HAVE_FUSE_3) /* This callback is only installed if lock forwarding is enabled. */ static int bindfs_lock(const char *path, struct fuse_file_info *fi, int cmd, struct flock *lock) @@ -1476,6 +1479,7 @@ static int bindfs_flock(const char *path, struct fuse_file_info *fi, int op) } return 0; } +#endif #ifdef HAVE_FUSE_3 static int bindfs_ioctl(const char *path, int cmd, void *arg, @@ -1674,7 +1678,7 @@ static int bindfs_listxattr(const char *path, char* list, size_t size) } curr += thislen; len += thislen; - } while (len < res); + } while (len < (size_t)res); } else { // TODO: https://github.com/osxfuse/fuse/blob/master/example/fusexmp_fh.c // had this commented out bit here o_O @@ -2304,7 +2308,7 @@ fail: return 0; } -static void maybe_stdout_stderr_to_file() +static void maybe_stdout_stderr_to_file(void) { /* TODO: make this a command line option. */ #if 0 @@ -2327,7 +2331,7 @@ static void maybe_stdout_stderr_to_file() #endif } -static char *get_working_dir() +static char *get_working_dir(void) { size_t buf_size = 4096; char* buf = malloc(buf_size); @@ -2338,7 +2342,7 @@ static char *get_working_dir() return buf; } -static void setup_signal_handling() +static void setup_signal_handling(void) { struct sigaction sa; sa.sa_handler = signal_handler; @@ -2354,7 +2358,7 @@ static void signal_handler(int sig) invalidate_user_cache(); } -static void atexit_func() +static void atexit_func(void) { free(settings.mntsrc); free(settings.mntdest); diff --git a/src/permchain.c b/src/permchain.c index d101aa1..1e6fd98 100644 --- a/src/permchain.c +++ b/src/permchain.c @@ -40,7 +40,7 @@ struct permchain { struct permchain *next; }; -struct permchain *permchain_create() +struct permchain *permchain_create(void) { struct permchain *pc = malloc(sizeof(struct permchain)); pc->mask = 0000; diff --git a/src/permchain.h b/src/permchain.h index 0f268f0..aad66f2 100644 --- a/src/permchain.h +++ b/src/permchain.h @@ -36,7 +36,7 @@ struct permchain; -struct permchain *permchain_create(); +struct permchain *permchain_create(void); /* Parses chmod arguments like 0777, a=rX, og-rwx etc. Multiple rules may be given, separated with commas or colons. diff --git a/src/rate_limiter.c b/src/rate_limiter.c index 68763c7..fff8f21 100644 --- a/src/rate_limiter.c +++ b/src/rate_limiter.c @@ -28,7 +28,7 @@ const double rate_limiter_idle_credit = -0.2; -double gettimeofday_clock() +double gettimeofday_clock(void) { struct timeval tv; gettimeofday(&tv, NULL); @@ -50,7 +50,7 @@ static void sleep_seconds(double s) nanosleep(&ts, NULL); } -void rate_limiter_init(RateLimiter *limiter, double rate, double (*clock)()) +void rate_limiter_init(RateLimiter *limiter, double rate, double (*clock)(void)) { limiter->rate = rate; limiter->clock = clock; diff --git a/src/rate_limiter.h b/src/rate_limiter.h index 95c0069..4a4ad85 100644 --- a/src/rate_limiter.h +++ b/src/rate_limiter.h @@ -30,16 +30,16 @@ extern const double rate_limiter_idle_credit; typedef struct RateLimiter { double rate; /* bytes / second */ - double (*clock)(); + double (*clock)(void); double last_modified; double accumulated_sleep_time; pthread_mutex_t mutex; } RateLimiter; -double gettimeofday_clock(); +double gettimeofday_clock(void); /* 0 on success, error number on error. */ -void rate_limiter_init(RateLimiter* limiter, double rate, double (*clock)()); +void rate_limiter_init(RateLimiter* limiter, double rate, double (*clock)(void)); /* Blocks until the rate limiter clears `size` units. */ void rate_limiter_wait(RateLimiter* limiter, size_t size); /* Updates the rate limiter like `rate_limiter_wait` but does not actually diff --git a/src/userinfo.c b/src/userinfo.c index a3ac91c..68291c1 100644 --- a/src/userinfo.c +++ b/src/userinfo.c @@ -52,13 +52,13 @@ static struct memory_block cache_memory_block = MEMORY_BLOCK_INITIALIZER; static volatile int cache_rebuild_requested = 1; -static void rebuild_cache(); +static void rebuild_cache(void); static struct uid_cache_entry *uid_cache_lookup(uid_t key); static struct gid_cache_entry *gid_cache_lookup(gid_t key); -static int rebuild_uid_cache(); -static int rebuild_gid_cache(); -static void clear_uid_cache(); -static void clear_gid_cache(); +static int rebuild_uid_cache(void); +static int rebuild_gid_cache(void); +static void clear_uid_cache(void); +static void clear_gid_cache(void); static int uid_cache_name_sortcmp(const void *key, const void *entry); static int uid_cache_name_searchcmp(const void *key, const void *entry); static int uid_cache_uid_sortcmp(const void *key, const void *entry); @@ -66,7 +66,7 @@ static int uid_cache_uid_searchcmp(const void *key, const void *entry); static int gid_cache_gid_sortcmp(const void *key, const void *entry); static int gid_cache_gid_searchcmp(const void *key, const void *entry); -static void rebuild_cache() +static void rebuild_cache(void) { free_memory_block(&cache_memory_block); init_memory_block(&cache_memory_block, 1024); @@ -98,7 +98,7 @@ static struct gid_cache_entry *gid_cache_lookup(gid_t key) ); } -static int rebuild_uid_cache() +static int rebuild_uid_cache(void) { /* We're holding the lock, so we have mutual exclusion on getpwent and getgrent too. */ struct passwd *pw; @@ -144,7 +144,7 @@ error: return 0; } -static int rebuild_gid_cache() +static int rebuild_gid_cache(void) { /* We're holding the lock, so we have mutual exclusion on getpwent and getgrent too. */ struct group *gr; @@ -205,12 +205,12 @@ error: return 0; } -static void clear_uid_cache() +static void clear_uid_cache(void) { uid_cache_size = 0; } -static void clear_gid_cache() +static void clear_gid_cache(void) { gid_cache_size = 0; } @@ -361,7 +361,7 @@ done: return ret; } -void invalidate_user_cache() +void invalidate_user_cache(void) { cache_rebuild_requested = 1; } diff --git a/src/userinfo.h b/src/userinfo.h index 4c0ca55..6886284 100644 --- a/src/userinfo.h +++ b/src/userinfo.h @@ -35,6 +35,6 @@ int user_uid(const char *username, uid_t *ret); int group_gid(const char *groupname, gid_t *ret); int user_belongs_to_group(uid_t uid, gid_t gid); -void invalidate_user_cache(); /* safe to call from signal handler */ +void invalidate_user_cache(void); /* safe to call from signal handler */ #endif diff --git a/src/usermap.c b/src/usermap.c index eb7b61c..456bc74 100644 --- a/src/usermap.c +++ b/src/usermap.c @@ -14,7 +14,7 @@ struct UserMap { int group_size; }; -UserMap *usermap_create() +UserMap *usermap_create(void) { UserMap* map = (UserMap*)malloc(sizeof(UserMap)); map->user_from = NULL; diff --git a/src/usermap.h b/src/usermap.h index 9c1387e..db2a9c3 100644 --- a/src/usermap.h +++ b/src/usermap.h @@ -37,7 +37,7 @@ typedef enum UsermapStatus { usermap_status_duplicate_key = 1 } UsermapStatus; -UserMap *usermap_create(); +UserMap *usermap_create(void); void usermap_destroy(UserMap *map); UsermapStatus usermap_add_uid(UserMap *map, uid_t from, uid_t to); diff --git a/tests/internals/test_common.c b/tests/internals/test_common.c index 6c10292..449c64a 100644 --- a/tests/internals/test_common.c +++ b/tests/internals/test_common.c @@ -3,7 +3,7 @@ int failures = 0; -int run_suite(void (*suite)()) { +int run_suite(void (*suite)(void)) { suite(); return (failures > 0) ? 1 : 0; } diff --git a/tests/internals/test_common.h b/tests/internals/test_common.h index 1688add..055fc38 100644 --- a/tests/internals/test_common.h +++ b/tests/internals/test_common.h @@ -10,8 +10,8 @@ extern int failures; #define TEST_ASSERT(expr) do { if (!(expr)) { printf("Assertion failed: %s:%d: `%s'\n", __FILE__, __LINE__, #expr); ++failures; } } while (0); #define NEAR(a, b, eps) (fabs((a) - (b)) < (eps)) -int run_suite(void (*suite)()); +int run_suite(void (*suite)(void)); -#define TEST_MAIN(suite) int main() { return run_suite(suite); } +#define TEST_MAIN(suite) int main(void) { return run_suite(suite); } #endif diff --git a/tests/internals/test_internals.c b/tests/internals/test_internals.c index 53f9872..23fa192 100644 --- a/tests/internals/test_internals.c +++ b/tests/internals/test_internals.c @@ -6,7 +6,7 @@ #include <string.h> #include <stdlib.h> -static void arena_suite() +static void arena_suite(void) { const int iterations = 1000; struct arena arena; @@ -55,7 +55,7 @@ static void test_path_starts_with(const char* path, const char* prefix, bool exp } } -static void my_dirname_suite() +static void my_dirname_suite(void) { char buf[256]; @@ -90,7 +90,7 @@ static void my_dirname_suite() test_my_dirname(buf, ".."); } -static void path_starts_with_suite() +static void path_starts_with_suite(void) { test_path_starts_with("/a/b/c", "/a/b", true); test_path_starts_with("/a/b/c", "/a/b/", true); @@ -144,7 +144,7 @@ static void path_starts_with_suite() test_path_starts_with("/a/b/c", "/", true); } -static void sprintf_new_suite() { +static void sprintf_new_suite(void) { char *result; result = sprintf_new("Hello %d %s", 123, "World"); @@ -214,7 +214,7 @@ static void filter_o_opts_test(const char **init, const char **expected) { free(joined_input); } -static void filter_o_opts_suite() { +static void filter_o_opts_suite(void) { { const char *in[] = {"-obad1", NULL}; const char *exp[] = {NULL}; @@ -299,7 +299,7 @@ static void filter_o_opts_suite() { } } -static void test_internal_suite() { +static void test_internal_suite(void) { arena_suite(); my_dirname_suite(); path_starts_with_suite(); diff --git a/tests/internals/test_rate_limiter.c b/tests/internals/test_rate_limiter.c index 09b219e..25e26fb 100644 --- a/tests/internals/test_rate_limiter.c +++ b/tests/internals/test_rate_limiter.c @@ -6,12 +6,12 @@ static const double epsilon = 0.000000000001; static volatile double time_now = 123123.0; -double test_clock() +double test_clock(void) { return time_now; } -void computes_correct_sleep_times() +void computes_correct_sleep_times(void) { time_now = 123123.0; RateLimiter limiter; @@ -29,7 +29,7 @@ void computes_correct_sleep_times() rate_limiter_destroy(&limiter); } -void works_after_being_idle() +void works_after_being_idle(void) { time_now = 123123.0; RateLimiter limiter; @@ -45,7 +45,7 @@ void works_after_being_idle() rate_limiter_destroy(&limiter); } -void sleeps_correct_amount() +void sleeps_correct_amount(void) { RateLimiter limiter; rate_limiter_init(&limiter, 10, &gettimeofday_clock); @@ -58,7 +58,7 @@ void sleeps_correct_amount() rate_limiter_destroy(&limiter); } -void rate_limiter_suite() +void rate_limiter_suite(void) { computes_correct_sleep_times(); works_after_being_idle(); diff --git a/tests/odirect_read.c b/tests/odirect_read.c index 8fc746b..42d5b79 100644 --- a/tests/odirect_read.c +++ b/tests/odirect_read.c @@ -51,7 +51,7 @@ int main(int argc, char** argv) { #include <stdio.h> -int main() { +int main(void) { fprintf(stderr, "Not supported on this platform.\n"); return 1; } diff --git a/tests/odirect_write.c b/tests/odirect_write.c index bc9040f..11dde43 100644 --- a/tests/odirect_write.c +++ b/tests/odirect_write.c @@ -32,7 +32,6 @@ int main(int argc, char** argv) { return 1; } - size_t total_size = 0; while (1) { if (feof(stdin)) { break; @@ -48,8 +47,6 @@ int main(int argc, char** argv) { continue; } - total_size += amt_read; - ssize_t res = write(fd, buf, buf_size); if (res == -1) { perror("failed to write"); @@ -70,7 +67,7 @@ int main(int argc, char** argv) { #include <stdio.h> -int main() { +int main(void) { fprintf(stderr, "Not supported on this platform.\n"); return 1; } diff --git a/tests/test_dir_rewind.c b/tests/test_dir_rewind.c index 6ae0497..d2d9d2a 100644 --- a/tests/test_dir_rewind.c +++ b/tests/test_dir_rewind.c @@ -17,7 +17,7 @@ #define BUF_SIZE 4096 -int main() +int main(void) { int fd = open(".", O_RDONLY | O_DIRECTORY); if (fd == -1) { @@ -72,7 +72,7 @@ int main() #include <stdio.h> -int main() +int main(void) { printf("This test currently only compiles on Linux/amd64.\n"); printf("Skipping by just returning successfully.\n"); |