Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
branches: [ "master" ]

jobs:
build:
linux:
strategy:
matrix:
os: [ubuntu-24.04, ubuntu-22.04]
Expand All @@ -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
13 changes: 1 addition & 12 deletions lib/dialects/darwin/dfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
*/
Expand Down
8 changes: 1 addition & 7 deletions lib/dialects/darwin/machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -338,7 +332,7 @@
* returns non-zero if it prints a name to stdout.
*/

# define HASPRIVNMCACHE print_v_path
/* #define HASPRIVNMCACHE <function name> */

/*
* HASPRIVPRIPP is defined for dialects that have a private function for
Expand Down
39 changes: 39 additions & 0 deletions lib/dialects/freebsd/dlsof.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,49 @@ int getmntinfo(struct statfs **, int);

# include <sys/domain.h>
# define pmap RPC_pmap
/* fix missing sysctl_ctx_list definition in FreeBSD 15 */
# if FREEBSDV >= 15000
# define _KERNEL
# include <sys/sysctl.h>
# undef _KERNEL
# endif
# include <rpc/rpc.h>
# include <rpc/pmap_prot.h>
# 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 <paths.h>
# include <ufs/ufs/quota.h>

Expand Down
2 changes: 1 addition & 1 deletion lib/lsof.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
23 changes: 11 additions & 12 deletions src/usage.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ? " " : "",

Expand All @@ -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)
Expand All @@ -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 ? " " : "",

Expand Down
26 changes: 24 additions & 2 deletions tests/LTbasic2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -36,6 +36,9 @@

#include "lsof.h"
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>

int main(int argc, char **argv) {
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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;
}
}
}
}
Expand All @@ -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);
}
Loading