Skip to content

Commit 1ec63c5

Browse files
authored
Merge pull request #348 from lsof-org/liblsof-fix-missing-name
Fix missing regular file name in liblsof
2 parents 074737f + 68f8777 commit 1ec63c5

8 files changed

Lines changed: 111 additions & 36 deletions

File tree

.github/workflows/build.yml

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
branches: [ "master" ]
77

88
jobs:
9-
build:
9+
linux:
1010
strategy:
1111
matrix:
1212
os: [ubuntu-24.04, ubuntu-22.04]
@@ -25,3 +25,35 @@ jobs:
2525
run: make check
2626
- name: make distcheck
2727
run: make distcheck
28+
29+
macos:
30+
runs-on: macos-latest
31+
steps:
32+
- uses: actions/checkout@v3
33+
- name: install dependencies
34+
run: brew install pkg-config libtool autoconf automake groff
35+
- name: configure
36+
run: LSOF_INCLUDE=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include ./Configure -n darwin
37+
- name: make
38+
run: make -j 2
39+
- name: test
40+
run: bash ./check.bash darwin
41+
- name: autotools build
42+
run: |
43+
git clean -fdx .
44+
autoreconf -vif
45+
./configure
46+
make
47+
DESTDIR=$PWD/prefix make install
48+
make check
49+
- name: dist build and test
50+
run: |
51+
make dist
52+
mkdir temp
53+
cd temp
54+
tar xvf ../lsof-*.tar.gz
55+
cd lsof-*
56+
./configure
57+
make
58+
DESTDIR=$PWD/prefix make install
59+
make check

lib/dialects/darwin/dfile.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ void enter_vnode_info(
153153
*/
154154
vip->vip_path[sizeof(vip->vip_path) - 1] = '\0';
155155
if (vip->vip_path[0] != '\0') {
156-
Lf->V_path = mkstrcpy(vip->vip_path, (MALLOC_S *)NULL);
156+
enter_nm(ctx, vip->vip_path);
157157
}
158158
/*
159159
* Save node number.
@@ -241,17 +241,6 @@ void err2nm(struct lsof_context *ctx, /* context */
241241
enter_nm(ctx, Namech);
242242
}
243243

244-
/*
245-
* print_v_path() -- print vnode's path
246-
*/
247-
int print_v_path(struct lsof_context *ctx, struct lfile *lf) {
248-
if (lf->V_path) {
249-
safestrprt(lf->V_path, stdout, 0);
250-
return (1);
251-
}
252-
return (0);
253-
}
254-
255244
/*
256245
* process_atalk() -- process an Apple Talk file
257246
*/

lib/dialects/darwin/machine.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,18 +218,12 @@
218218
*/
219219

220220
# define HASLFILEADD \
221-
char *V_path; \
222221
mach_port_t fileport; \
223222
uint32_t guardflags;
224223
# define CLRLFILEADD(lf) \
225-
if (lf->V_path) { \
226-
(void)free((FREE_P *)lf->V_path); \
227-
lf->V_path = (char *)NULL; \
228-
} \
229224
lf->fileport = MACH_PORT_NULL; \
230225
lf->guardflags = 0;
231226
# define SETLFILEADD \
232-
Lf->V_path = (char *)NULL; \
233227
Lf->fileport = MACH_PORT_NULL; \
234228
Lf->guardflags = 0;
235229

@@ -338,7 +332,7 @@
338332
* returns non-zero if it prints a name to stdout.
339333
*/
340334

341-
# define HASPRIVNMCACHE print_v_path
335+
/* #define HASPRIVNMCACHE <function name> */
342336

343337
/*
344338
* HASPRIVPRIPP is defined for dialects that have a private function for

lib/dialects/freebsd/dlsof.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,49 @@ int getmntinfo(struct statfs **, int);
168168

169169
# include <sys/domain.h>
170170
# define pmap RPC_pmap
171+
/* fix missing sysctl_ctx_list definition in FreeBSD 15 */
172+
# if FREEBSDV >= 15000
173+
# define _KERNEL
174+
# include <sys/sysctl.h>
175+
# undef _KERNEL
176+
# endif
171177
# include <rpc/rpc.h>
172178
# include <rpc/pmap_prot.h>
173179
# undef pmap
174180

181+
# if FREEBSDV >= 15000
182+
/* The kernel headers dropped user space libc header compat in commit 3a0cdb2,
183+
* undo it. The following code is copied and modified from
184+
* /usr/src/include/rpc/clnt.h. */
185+
typedef struct __rpc_client_user {
186+
AUTH *cl_auth; /* authenticator */
187+
struct clnt_ops_user {
188+
/* call remote procedure */
189+
enum clnt_stat (*cl_call)(struct __rpc_client *, rpcproc_t, xdrproc_t,
190+
void *, xdrproc_t, void *, struct timeval);
191+
/* abort a call */
192+
void (*cl_abort)(struct __rpc_client *);
193+
/* get specific error code */
194+
void (*cl_geterr)(struct __rpc_client *, struct rpc_err *);
195+
/* frees results */
196+
bool_t (*cl_freeres)(struct __rpc_client *, xdrproc_t, void *);
197+
/* destroy this structure */
198+
void (*cl_destroy)(struct __rpc_client *);
199+
/* the ioctl() of rpc */
200+
bool_t (*cl_control)(struct __rpc_client *, u_int, void *);
201+
} *cl_ops;
202+
void *cl_private; /* private stuff */
203+
char *cl_netid; /* network token */
204+
char *cl_tp; /* device name */
205+
} CLIENT_USER;
206+
# define CLIENT CLIENT_USER
207+
# undef clnt_call
208+
# define clnt_call(rh, proc, xargs, argsp, xres, resp, secs) \
209+
((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs))
210+
extern CLIENT *clnt_create(const char *, const rpcprog_t, const rpcvers_t,
211+
const char *);
212+
# endif
213+
175214
# include <paths.h>
176215
# include <ufs/ufs/quota.h>
177216

lib/lsof.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ enum lsof_error lsof_avoid_blocking(struct lsof_context *ctx, int avoid) {
107107
return LSOF_ERROR_INVALID_ARGUMENT;
108108
}
109109
Fblock = avoid;
110-
return LSOF_EXIT_SUCCESS;
110+
return LSOF_SUCCESS;
111111
}
112112

113113
API_EXPORT

src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1301,7 +1301,7 @@ int main(int argc, char *argv[]) {
13011301
else
13021302
slp = (struct lproc **)realloc((MALLOC_P *)slp, len);
13031303
if (!slp) {
1304-
(void)fprintf(stderr, "%s: no space for %d sort pointers\n",
1304+
(void)fprintf(stderr, "%s: no space for %zu sort pointers\n",
13051305
Pn, Nlproc);
13061306
Error(ctx);
13071307
}

src/usage.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,9 @@ static void report_HASDCACHE(struct lsof_context *ctx, /* context */
221221
* report_HASKERNIDCK() -- report HASKERNIDCK state
222222
*/
223223

224-
static void report_HASKERNIDCK(pfx, verb) char *pfx; /* prefix (NULL if none) */
225-
char *verb; /* verb (NULL if none) */
226-
{
224+
static void report_HASKERNIDCK(char *pfx, /* prefix (NULL if none) */
225+
char *verb /* verb (NULL if none) */
226+
) {
227227
(void)fprintf(stderr, "%sernel ID check %s%s%s.\n", pfx ? pfx : "",
228228
verb ? verb : "", verb ? " " : "",
229229

@@ -240,10 +240,10 @@ char *verb; /* verb (NULL if none) */
240240
* report_SECURITY() -- report *SECURITY states
241241
*/
242242

243-
static void report_SECURITY(pfx, punct) char *pfx; /* prefix (NULL if none) */
244-
char *punct; /* short foem punctuation
245-
* (NULL if none) */
246-
{
243+
static void report_SECURITY(char *pfx, /* prefix (NULL if none) */
244+
char *punct /* short foem punctuation
245+
* (NULL if none) */
246+
) {
247247
fprintf(stderr, "%s%s can list all files%s", pfx ? pfx : "",
248248

249249
#if defined(HASSECURITY)
@@ -264,11 +264,10 @@ char *punct; /* short foem punctuation
264264
* report_WARNDEVACCESS() -- report WEARNDEVACCESS state
265265
*/
266266

267-
static void report_WARNDEVACCESS(pfx, verb,
268-
punct) char *pfx; /* prefix (NULL if none) */
269-
char *verb; /* verb (NULL if none) */
270-
char *punct; /* punctuation */
271-
{
267+
static void report_WARNDEVACCESS(char *pfx, /* prefix (NULL if none) */
268+
char *verb, /* verb (NULL if none) */
269+
char *punct /* punctuation */
270+
) {
272271
(void)fprintf(stderr, "%s/dev warnings %s%s%s%s", pfx ? pfx : "",
273272
verb ? verb : "", verb ? " " : "",
274273

tests/LTbasic2.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* LTbasic2.c -- Lsof Test basic tests 2
33
*
44
* The basic tests measure the finding by liblsof of its own open CWD, open
5-
* executable (when possible).
5+
* executable (when possible) and opened regular file.
66
*
77
* V. Abell
88
* Purdue University
@@ -36,6 +36,9 @@
3636

3737
#include "lsof.h"
3838
#include <stdio.h>
39+
#include <fcntl.h>
40+
#include <string.h>
41+
#include <unistd.h>
3942
#include <sys/stat.h>
4043

4144
int main(int argc, char **argv) {
@@ -47,8 +50,11 @@ int main(int argc, char **argv) {
4750
char buffer[128];
4851
int exec_found = 0; /* executable found in result */
4952
int cwd_found = 0; /* cwd found in result */
53+
int fd_found = 0; /* opened fd found in result */
5054
struct stat exec_stat;
5155
struct stat cwd_stat;
56+
int fd = -1;
57+
int tmpfile_created = 0;
5258
if (stat(argv[0], &exec_stat)) {
5359
fprintf(stderr, "Cannot stat %s, skipping executable check\n", argv[0]);
5460
exec_found = 1;
@@ -57,6 +63,11 @@ int main(int argc, char **argv) {
5763
fprintf(stderr, "Cannot stat '.', skipping cwd check\n");
5864
cwd_found = 1;
5965
}
66+
if ((fd = open("LTbasic2-tmp", O_CREAT, 0644)) < 0) {
67+
fprintf(stderr, "Cannot create 'LTbasic2-tmp' in current directory, "
68+
"skipping fd check\n");
69+
fd_found = 1;
70+
}
6071

6172
ctx = lsof_new();
6273
lsof_select_process(ctx, "LTbasic2", 0);
@@ -82,6 +93,12 @@ int main(int argc, char **argv) {
8293
f->dev == cwd_stat.st_dev && f->inode == cwd_stat.st_ino) {
8394
cwd_found = 1;
8495
}
96+
} else if (f->fd_type == LSOF_FD_NUMERIC) {
97+
/* check if fd matches */
98+
if (f->fd_num == fd && f->name &&
99+
strstr(f->name, "LTbasic2-tmp")) {
100+
fd_found = 1;
101+
}
85102
}
86103
}
87104
}
@@ -95,5 +112,10 @@ int main(int argc, char **argv) {
95112
if (!cwd_found) {
96113
fprintf(stderr, "ERROR!!! current working directory wasn't found.\n");
97114
}
98-
return !(exec_found && cwd_found);
115+
if (!fd_found) {
116+
fprintf(stderr, "ERROR!!! opened regular file wasn't found.\n");
117+
}
118+
/* cleanup created temporary file */
119+
unlink("LTbasic2-tmp");
120+
return !(exec_found && cwd_found && fd_found);
99121
}

0 commit comments

Comments
 (0)