diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d8792e10..fee31f14 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,7 +6,7 @@ on: branches: [ "master" ] jobs: - build: + linux: strategy: matrix: os: [ubuntu-24.04, ubuntu-22.04] @@ -25,3 +25,35 @@ jobs: run: make check - name: make distcheck run: make distcheck + + macos: + runs-on: macos-latest + steps: + - uses: actions/checkout@v3 + - name: install dependencies + run: brew install pkg-config libtool autoconf automake groff + - name: configure + run: LSOF_INCLUDE=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include ./Configure -n darwin + - name: make + run: make -j 2 + - name: test + run: bash ./check.bash darwin + - name: autotools build + run: | + git clean -fdx . + autoreconf -vif + ./configure + make + DESTDIR=$PWD/prefix make install + make check + - name: dist build and test + run: | + make dist + mkdir temp + cd temp + tar xvf ../lsof-*.tar.gz + cd lsof-* + ./configure + make + DESTDIR=$PWD/prefix make install + make check diff --git a/lib/dialects/darwin/dfile.c b/lib/dialects/darwin/dfile.c index 486128f3..4a0d0b89 100644 --- a/lib/dialects/darwin/dfile.c +++ b/lib/dialects/darwin/dfile.c @@ -153,7 +153,7 @@ void enter_vnode_info( */ vip->vip_path[sizeof(vip->vip_path) - 1] = '\0'; if (vip->vip_path[0] != '\0') { - Lf->V_path = mkstrcpy(vip->vip_path, (MALLOC_S *)NULL); + enter_nm(ctx, vip->vip_path); } /* * Save node number. @@ -241,17 +241,6 @@ void err2nm(struct lsof_context *ctx, /* context */ enter_nm(ctx, Namech); } -/* - * print_v_path() -- print vnode's path - */ -int print_v_path(struct lsof_context *ctx, struct lfile *lf) { - if (lf->V_path) { - safestrprt(lf->V_path, stdout, 0); - return (1); - } - return (0); -} - /* * process_atalk() -- process an Apple Talk file */ diff --git a/lib/dialects/darwin/machine.h b/lib/dialects/darwin/machine.h index 39442e05..a67280fd 100644 --- a/lib/dialects/darwin/machine.h +++ b/lib/dialects/darwin/machine.h @@ -218,18 +218,12 @@ */ # define HASLFILEADD \ - char *V_path; \ mach_port_t fileport; \ uint32_t guardflags; # define CLRLFILEADD(lf) \ - if (lf->V_path) { \ - (void)free((FREE_P *)lf->V_path); \ - lf->V_path = (char *)NULL; \ - } \ lf->fileport = MACH_PORT_NULL; \ lf->guardflags = 0; # define SETLFILEADD \ - Lf->V_path = (char *)NULL; \ Lf->fileport = MACH_PORT_NULL; \ Lf->guardflags = 0; @@ -338,7 +332,7 @@ * returns non-zero if it prints a name to stdout. */ -# define HASPRIVNMCACHE print_v_path +/* #define HASPRIVNMCACHE */ /* * HASPRIVPRIPP is defined for dialects that have a private function for diff --git a/lib/dialects/freebsd/dlsof.h b/lib/dialects/freebsd/dlsof.h index 7dafc525..b7067702 100644 --- a/lib/dialects/freebsd/dlsof.h +++ b/lib/dialects/freebsd/dlsof.h @@ -168,10 +168,49 @@ int getmntinfo(struct statfs **, int); # include # define pmap RPC_pmap +/* fix missing sysctl_ctx_list definition in FreeBSD 15 */ +# if FREEBSDV >= 15000 +# define _KERNEL +# include +# undef _KERNEL +# endif # include # include # undef pmap +# if FREEBSDV >= 15000 +/* The kernel headers dropped user space libc header compat in commit 3a0cdb2, + * undo it. The following code is copied and modified from + * /usr/src/include/rpc/clnt.h. */ +typedef struct __rpc_client_user { + AUTH *cl_auth; /* authenticator */ + struct clnt_ops_user { + /* call remote procedure */ + enum clnt_stat (*cl_call)(struct __rpc_client *, rpcproc_t, xdrproc_t, + void *, xdrproc_t, void *, struct timeval); + /* abort a call */ + void (*cl_abort)(struct __rpc_client *); + /* get specific error code */ + void (*cl_geterr)(struct __rpc_client *, struct rpc_err *); + /* frees results */ + bool_t (*cl_freeres)(struct __rpc_client *, xdrproc_t, void *); + /* destroy this structure */ + void (*cl_destroy)(struct __rpc_client *); + /* the ioctl() of rpc */ + bool_t (*cl_control)(struct __rpc_client *, u_int, void *); + } *cl_ops; + void *cl_private; /* private stuff */ + char *cl_netid; /* network token */ + char *cl_tp; /* device name */ +} CLIENT_USER; +# define CLIENT CLIENT_USER +# undef clnt_call +# define clnt_call(rh, proc, xargs, argsp, xres, resp, secs) \ + ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs)) +extern CLIENT *clnt_create(const char *, const rpcprog_t, const rpcvers_t, + const char *); +# endif + # include # include diff --git a/lib/lsof.c b/lib/lsof.c index 0892c4d8..af4b04fd 100644 --- a/lib/lsof.c +++ b/lib/lsof.c @@ -107,7 +107,7 @@ enum lsof_error lsof_avoid_blocking(struct lsof_context *ctx, int avoid) { return LSOF_ERROR_INVALID_ARGUMENT; } Fblock = avoid; - return LSOF_EXIT_SUCCESS; + return LSOF_SUCCESS; } API_EXPORT diff --git a/src/main.c b/src/main.c index 5d91a6eb..0c2e98a0 100644 --- a/src/main.c +++ b/src/main.c @@ -1301,7 +1301,7 @@ int main(int argc, char *argv[]) { else slp = (struct lproc **)realloc((MALLOC_P *)slp, len); if (!slp) { - (void)fprintf(stderr, "%s: no space for %d sort pointers\n", + (void)fprintf(stderr, "%s: no space for %zu sort pointers\n", Pn, Nlproc); Error(ctx); } diff --git a/src/usage.c b/src/usage.c index 546b3aeb..89b0e52a 100644 --- a/src/usage.c +++ b/src/usage.c @@ -221,9 +221,9 @@ static void report_HASDCACHE(struct lsof_context *ctx, /* context */ * report_HASKERNIDCK() -- report HASKERNIDCK state */ -static void report_HASKERNIDCK(pfx, verb) char *pfx; /* prefix (NULL if none) */ -char *verb; /* verb (NULL if none) */ -{ +static void report_HASKERNIDCK(char *pfx, /* prefix (NULL if none) */ + char *verb /* verb (NULL if none) */ +) { (void)fprintf(stderr, "%sernel ID check %s%s%s.\n", pfx ? pfx : "", verb ? verb : "", verb ? " " : "", @@ -240,10 +240,10 @@ char *verb; /* verb (NULL if none) */ * report_SECURITY() -- report *SECURITY states */ -static void report_SECURITY(pfx, punct) char *pfx; /* prefix (NULL if none) */ -char *punct; /* short foem punctuation - * (NULL if none) */ -{ +static void report_SECURITY(char *pfx, /* prefix (NULL if none) */ + char *punct /* short foem punctuation + * (NULL if none) */ +) { fprintf(stderr, "%s%s can list all files%s", pfx ? pfx : "", #if defined(HASSECURITY) @@ -264,11 +264,10 @@ char *punct; /* short foem punctuation * report_WARNDEVACCESS() -- report WEARNDEVACCESS state */ -static void report_WARNDEVACCESS(pfx, verb, - punct) char *pfx; /* prefix (NULL if none) */ -char *verb; /* verb (NULL if none) */ -char *punct; /* punctuation */ -{ +static void report_WARNDEVACCESS(char *pfx, /* prefix (NULL if none) */ + char *verb, /* verb (NULL if none) */ + char *punct /* punctuation */ +) { (void)fprintf(stderr, "%s/dev warnings %s%s%s%s", pfx ? pfx : "", verb ? verb : "", verb ? " " : "", diff --git a/tests/LTbasic2.c b/tests/LTbasic2.c index 4ad9024d..94c05e62 100644 --- a/tests/LTbasic2.c +++ b/tests/LTbasic2.c @@ -2,7 +2,7 @@ * LTbasic2.c -- Lsof Test basic tests 2 * * The basic tests measure the finding by liblsof of its own open CWD, open - * executable (when possible). + * executable (when possible) and opened regular file. * * V. Abell * Purdue University @@ -36,6 +36,9 @@ #include "lsof.h" #include +#include +#include +#include #include int main(int argc, char **argv) { @@ -47,8 +50,11 @@ int main(int argc, char **argv) { char buffer[128]; int exec_found = 0; /* executable found in result */ int cwd_found = 0; /* cwd found in result */ + int fd_found = 0; /* opened fd found in result */ struct stat exec_stat; struct stat cwd_stat; + int fd = -1; + int tmpfile_created = 0; if (stat(argv[0], &exec_stat)) { fprintf(stderr, "Cannot stat %s, skipping executable check\n", argv[0]); exec_found = 1; @@ -57,6 +63,11 @@ int main(int argc, char **argv) { fprintf(stderr, "Cannot stat '.', skipping cwd check\n"); cwd_found = 1; } + if ((fd = open("LTbasic2-tmp", O_CREAT, 0644)) < 0) { + fprintf(stderr, "Cannot create 'LTbasic2-tmp' in current directory, " + "skipping fd check\n"); + fd_found = 1; + } ctx = lsof_new(); lsof_select_process(ctx, "LTbasic2", 0); @@ -82,6 +93,12 @@ int main(int argc, char **argv) { f->dev == cwd_stat.st_dev && f->inode == cwd_stat.st_ino) { cwd_found = 1; } + } else if (f->fd_type == LSOF_FD_NUMERIC) { + /* check if fd matches */ + if (f->fd_num == fd && f->name && + strstr(f->name, "LTbasic2-tmp")) { + fd_found = 1; + } } } } @@ -95,5 +112,10 @@ int main(int argc, char **argv) { if (!cwd_found) { fprintf(stderr, "ERROR!!! current working directory wasn't found.\n"); } - return !(exec_found && cwd_found); + if (!fd_found) { + fprintf(stderr, "ERROR!!! opened regular file wasn't found.\n"); + } + /* cleanup created temporary file */ + unlink("LTbasic2-tmp"); + return !(exec_found && cwd_found && fd_found); } \ No newline at end of file