Skip to content

Commit

Permalink
Fix build with musl and add Alpine buildnode to CI (#174)
Browse files Browse the repository at this point in the history
* configure: Add AC_SYS_LARGEFILE autoconf macro

This will define _FILE_OFFSET_BITS to be 64 if off_t is 64bit
and we do not need to define lfs64 functions

Signed-off-by: Khem Raj <raj.khem@gmail.com>

* Fix build for out-of-tree builds

When build tree is outside source-tree its not able to find
fanotify-dfid-name.h, add needed include paths on compiler commandline

Signed-off-by: Khem Raj <raj.khem@gmail.com>

* libinotifytools: Bridge differences between musl/glibc/kernel fnotify.h

System detects to use sys/fnotify.h and then assumes glibc's definitions
but musl has definitions of its own. perhaps portable thing would be to
use linux/fnotify.h interface directly on linux irrespective of libc

See the differences discussion here [1]

[1] https://inbox.vuxu.org/musl/20191112220151.GC27331@x230/T/#ma8700992467200c8792e0fa8508eae656b81aeba

Signed-off-by: Khem Raj <raj.khem@gmail.com>

* replace stat64/lstat64 with stat/lstat

lfs64 functions are not needed when off_t is 64-bit
Additionally this fixes build with musl which does not
export these functions without defining _LARGEFILE64_SOURCE

Signed-off-by: Khem Raj <raj.khem@gmail.com>

* Apply changes from clang-format

Signed-off-by: Khem Raj <raj.khem@gmail.com>

* Fix errors found by clang-format

Fixes
-Wno-gnu-variable-sized-type-not-at-end for musl clang-format

Signed-off-by: Khem Raj <raj.khem@gmail.com>

* ci: Enable musl in CI using alpine

Signed-off-by: Khem Raj <raj.khem@gmail.com>

* Tell clang-tidy to ignore warning about variable sized type

Signed-off-by: Eric Curtin <ecurtin@redhat.com>

* Add gcompat for code coverage tool

Signed-off-by: Eric Curtin <ecurtin@redhat.com>

* Skip sonarcloud on alpine

Signed-off-by: Eric Curtin <ecurtin@redhat.com>

Signed-off-by: Khem Raj <raj.khem@gmail.com>
Signed-off-by: Eric Curtin <ecurtin@redhat.com>
Co-authored-by: Eric Curtin <ecurtin@redhat.com>
  • Loading branch information
kraj and ericcurtin committed Dec 30, 2022
1 parent f57005c commit 8367bdd
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 34 deletions.
10 changes: 9 additions & 1 deletion build_and_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ if command -v apt; then
$pre apt install -y zip || true
elif command -v apk; then
apk add build-base alpine-sdk autoconf automake libtool bash coreutils clang \
clang-extra-tools lld linux-headers curl git zip
clang-extra-tools lld linux-headers curl git zip gcompat
fi

#!/bin/bash
Expand Down Expand Up @@ -112,6 +112,7 @@ if command -v clang-tidy > /dev/null; then
s_c_t="$s_c_t,-clang-analyzer-unix.Malloc"
s_c_t="$s_c_t,-clang-analyzer-security.insecureAPI.strcpy"
s_c_t="$s_c_t,-clang-diagnostic-incompatible-pointer-types-discards-qualifiers"
s_c_t="$s_c_t,-clang-diagnostic-gnu-variable-sized-type-not-at-end"
c_t="clang-tidy"
q="--quiet"
w="--warnings-as-errors"
Expand Down Expand Up @@ -229,6 +230,13 @@ if [ "$os" != "freebsd" ] && [ "$(uname -m)" = "x86_64" ]; then
--form description="$description" \
https://scan.coverity.com/builds?project=$project

id=$(grep ^ID= /etc/os-release | sed "s/^ID=//g")

# Don't do sonarcloud on alpine
if [ "$id" = "alpine" ]; then
exit 0
fi

# sonarcloud
export SONAR_TOKEN="0bc5d48614caa711d6b908f80c039464aff99611"
mkdir -p $HOME/.sonar
Expand Down
2 changes: 1 addition & 1 deletion build_and_test_multi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if [ -n "$container" ]; then
container_run "ubuntu:22.04"
container_run "ubuntu:20.04"
container_run "ubuntu:18.04"
# container_run "alpine:3.17"
container_run "alpine:3.17"
exit 0
fi

Expand Down
3 changes: 3 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ AC_PROG_CC
AM_INIT_AUTOMAKE
LT_INIT

# Add option for largefile support
AC_SYS_LARGEFILE

AC_PATH_PROG(DOXYGEN, doxygen, NO_DOXYGEN)

AC_ARG_ENABLE(doxygen,
Expand Down
1 change: 1 addition & 0 deletions libinotifytools/src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ SUBDIRS = inotifytools

lib_LTLIBRARIES = libinotifytools.la
libinotifytools_la_SOURCES = inotifytools.c inotifytools_p.h redblack.c redblack.h stats.c stats.h
libinotifytools_la_CFLAGS = -I$(srcdir)/inotifytools
libinotifytools_la_LDFLAGS = -version-info 4:1:4

check_PROGRAMS = test
Expand Down
21 changes: 13 additions & 8 deletions libinotifytools/src/inotifytools.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,16 @@ struct fanotify_event_fid;
#include <sys/vfs.h>
#include "inotifytools/fanotify.h"

#ifndef __GLIBC__
#define val __val
#define __kernel_fsid_t fsid_t
#endif

struct fanotify_event_fid {
struct fanotify_event_info_fid info;
struct file_handle handle;
};

#endif

/**
Expand Down Expand Up @@ -1746,14 +1752,14 @@ int inotifytools_watch_recursively_with_exclude(char const* path,

static struct dirent * ent;
char * next_file;
static struct stat64 my_stat;
static struct stat my_stat;
ent = readdir( dir );
// Watch each directory within this directory
while ( ent ) {
if ( (0 != strcmp( ent->d_name, "." )) &&
(0 != strcmp( ent->d_name, ".." )) ) {
nasprintf(&next_file,"%s%s", my_path, ent->d_name);
if ( -1 == lstat64( next_file, &my_stat ) ) {
if (-1 == lstat(next_file, &my_stat)) {
error = errno;
free( next_file );
if ( errno != EACCES ) {
Expand All @@ -1762,9 +1768,8 @@ int inotifytools_watch_recursively_with_exclude(char const* path,
closedir( dir );
return 0;
}
}
else if ( S_ISDIR( my_stat.st_mode ) &&
!S_ISLNK( my_stat.st_mode )) {
} else if (S_ISDIR(my_stat.st_mode) &&
!S_ISLNK(my_stat.st_mode)) {
free( next_file );
nasprintf(&next_file,"%s%s/", my_path, ent->d_name);
static unsigned int no_watch;
Expand Down Expand Up @@ -1802,7 +1807,7 @@ int inotifytools_watch_recursively_with_exclude(char const* path,
}
} // if !no_watch
free( next_file );
} // if isdir and not islnk
} // if isdir and not islnk
else {
free( next_file );
}
Expand Down Expand Up @@ -1836,9 +1841,9 @@ int inotifytools_error() {
* @internal
*/
static int isdir( char const * path ) {
static struct stat64 my_stat;
static struct stat my_stat;

if ( -1 == lstat64( path, &my_stat ) ) {
if (-1 == lstat(path, &my_stat)) {
if (errno == ENOENT) return 0;
fprintf(stderr, "Stat failed on %s: %s\n", path, strerror(errno));
return 0;
Expand Down
2 changes: 1 addition & 1 deletion libinotifytools/src/inotifytools/fanotify-dfid-name.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ struct fanotify_event_info_fid {
* Following is an opaque struct file_handle that can be passed as
* an argument to open_by_handle_at(2).
*/
unsigned char handle[0];
unsigned char handle[];
};

struct fanotify_response {
Expand Down
5 changes: 0 additions & 5 deletions libinotifytools/src/inotifytools/inotify-nosys.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@
#include <sys/syscall.h>
#include <unistd.h>

#ifdef __FreeBSD__
#define stat64 stat
#define lstat64 lstat
#endif

/*
* struct inotify_event - structure read from the inotify device for each event
*
Expand Down
5 changes: 0 additions & 5 deletions libinotifytools/src/inotifytools/inotifytools.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
#ifndef _inotifytools_H
#define _inotifytools_H

#ifdef __FreeBSD__
#define stat64 stat
#define lstat64 lstat
#endif

#ifdef __cplusplus
extern "C"
{
Expand Down
17 changes: 9 additions & 8 deletions src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ void print_event_descriptions() {
}

int isdir(char const *path) {
static struct stat64 my_stat;

if (-1 == lstat64(path, &my_stat)) {
if (errno == ENOENT)
return 0;
fprintf(stderr, "Stat failed on %s: %s\n", path, strerror(errno));
return 0;
}
static struct stat my_stat;

if (-1 == lstat(path, &my_stat)) {
if (errno == ENOENT)
return 0;
fprintf(stderr, "Stat failed on %s: %s\n", path,
strerror(errno));
return 0;
}

return S_ISDIR(my_stat.st_mode) && !S_ISLNK(my_stat.st_mode);
}
Expand Down
6 changes: 1 addition & 5 deletions src/common.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
#ifndef COMMON_H
#define COMMON_H

#ifdef __FreeBSD__
#define stat64 stat
#define lstat64 lstat
#ifdef ENABLE_FANOTIFY
#if defined(__FreeBSD__) && defined(ENABLE_FANOTIFY)
#error "FreeBSD does not support fanotify"
#endif
#endif

#include <stdbool.h>

Expand Down

0 comments on commit 8367bdd

Please sign in to comment.