Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Expose functionality as a re-usable library #279

Closed
wants to merge 136 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
136 commits
Select commit Hold shift + click to select a range
d926c52
Re-arrange directory structure, build liblsof [ci skip]
jiegec Jan 24, 2023
a5d648d
Rewrite Readlink to get rid of static variables
jiegec Jan 28, 2023
0f35073
Fix memory leaks [ci skip]
jiegec Jan 28, 2023
7e0adb3
Fix VPATH building [ci skip]
jiegec Jan 28, 2023
498cf56
Fix compilation of legacy build system
jiegec Jan 28, 2023
ade1348
Ignore proc permission denied error as before [ci skip]
jiegec Jan 28, 2023
f94931e
Fix legacy build system on darwin
jiegec Jan 28, 2023
043140c
[linux] Fix building with selinux
jiegec Jan 28, 2023
4a31116
Install libtool in ci
jiegec Jan 28, 2023
e81c685
Move CntxArg to lib
jiegec Jan 28, 2023
9a5a943
Rename ctx->stderr to ctx->err for musl
jiegec Jan 28, 2023
72aa26a
Disable libtool fast install for deterministic executable name in tes…
jiegec Jan 28, 2023
98fd76b
Fix format strings
jiegec Jan 28, 2023
455e700
Fix compilation on FreeBSD
jiegec Jan 28, 2023
66a8d8e
Add more fd type names
jiegec Jan 28, 2023
b12a72c
Use enum lsof_file_access_mode in lfile
jiegec Jan 28, 2023
edf1564
Remove unused LSOF_FD_TTY
jiegec Jan 28, 2023
ec8197d
Move print_access to lib and fix missing calls
jiegec Jan 28, 2023
b5d1a4c
Add tests for -c option
jiegec Jan 29, 2023
a2882be
Fix FreeBSD legacy build system
jiegec Jan 29, 2023
29b1ec5
Fix mktemp argument for busybox on alpine linux
jiegec Jan 29, 2023
5765e3e
Fix building on NetBSD
jiegec Jan 29, 2023
96805cb
Fix OpenBSD support
jiegec Jan 29, 2023
abd3279
Move local mount info to ctx
jiegec Jan 29, 2023
3d2c5d8
Improve kqueue/pipe display and add tcp window for OpenBSD
jiegec Jan 29, 2023
ec2b86b
Fix regression, always check is_file_named
jiegec Jan 29, 2023
9f9716c
Add ctty support for OpenBSD
jiegec Jan 29, 2023
329949b
Convert Lf->lock to enum lsof_lock_mode
jiegec Jan 29, 2023
5bce640
Merge remote-tracking branch 'origin/master' into library
jiegec Jan 29, 2023
c2d3cc7
[freebsd] Fix ci by moving cflags to Makefile
jiegec Jan 29, 2023
6d09618
[freebsd] Fix ci by installing libtool
jiegec Jan 29, 2023
9dffc17
Add list of lsof_file_type from manpage and fix typos
jiegec Jan 29, 2023
0e0a8ba
Use enum lsof_file_type in lfile
jiegec Jan 30, 2023
ca2f696
Fix extra paren
jiegec Jan 30, 2023
5afc411
[freebsd] Fix compilation on FreeBSD 14
jiegec Jan 30, 2023
14905a0
[freebsd] Workaround FreeBSD 12 __start_set_pcpu issue
jiegec Jan 30, 2023
e982597
Only export public API functions and link statically in binary
jiegec Feb 2, 2023
1c25f25
Merge remote-tracking branch 'origin/master' into library
jiegec Feb 3, 2023
dba22b2
Bring back Error() call with conditionaly exit
jiegec Feb 3, 2023
f0c3b4c
Use ctx->error and Error(ctx) in linux dialect
jiegec Feb 3, 2023
5e81765
Use ctx->error and Error(ctx) in darwin dialect and liblsof
jiegec Feb 3, 2023
bfdeea3
[darwin] Fix typo
jiegec Feb 3, 2023
0085821
Use ctx->error in darwin and openbsd
jiegec Feb 3, 2023
65c780e
[darwin] Fix typo
jiegec Feb 3, 2023
cdc5e22
Fill more fields in lsof_file
jiegec Feb 3, 2023
d153533
Add more network protocols
jiegec Feb 3, 2023
32a6f20
Replace inp_ty with inode_def
jiegec Feb 3, 2023
27b2b4d
Use enum lsof_protocol for Lf->iproto
jiegec Feb 4, 2023
7842f8c
Add ip protos from FreeBSD
jiegec Feb 4, 2023
db24adc
Add more lsof_protocol definitions
jiegec Feb 4, 2023
75bf2ef
[darwin] Add SEP to lsof_protocol, remove DIVERT
jiegec Feb 4, 2023
ccfd07f
Pass unknown protocol number to user
jiegec Feb 4, 2023
95aede0
Add LTszoff2 rewrite
jiegec Feb 4, 2023
009ab15
Merge _valid fields to one flag field
jiegec Feb 4, 2023
e5dee8b
Add rdev to struct lsof_file
jiegec Feb 4, 2023
7f58beb
Fix pid signedness
jiegec Feb 4, 2023
affd2ac
Simplify main by moving endpoint info to linux
jiegec Feb 4, 2023
67b41d3
Remove unused HASPRINTOFF
jiegec Feb 4, 2023
87d59f9
Move static variables to ctxd
jiegec Feb 5, 2023
f31bbe0
Fix memory leak
jiegec Feb 5, 2023
76cb043
Fix double free
jiegec Feb 5, 2023
1ad7156
Fix memory leak on FreeBSD
jiegec Feb 5, 2023
d2befd9
Fix memory leak on NetBSD
jiegec Feb 5, 2023
9614fdc
Move sfile hash buckets to context
jiegec Feb 5, 2023
89c2b08
Simplify FreeBSD code by moving global to local
jiegec Feb 5, 2023
dd9faae
Fix missing cases in print_file_type
jiegec Feb 5, 2023
81cb433
Filter out unselected processes
jiegec Feb 6, 2023
ed84a4e
Filter out unselected files
jiegec Feb 7, 2023
87093c3
Fix memory leaks reported by clang-analyzer
jiegec Feb 7, 2023
b764aaa
Fix double free error in last commit
jiegec Feb 7, 2023
a54d249
Revert typo changes and improve code style
jiegec Feb 7, 2023
a1301c9
[freebsd] FreeBSD does not provide bash at /bin/bash
jiegec Feb 7, 2023
1f0ad8d
[netbsd] Fix compilation of dnode1.c
jiegec Feb 7, 2023
a46a863
[solaris] Initial support for library, tested on OpenIndiana
jiegec Feb 8, 2023
1267d11
[solaris] Fix compilation on Solaris 11.4.42.111.0
jiegec Feb 8, 2023
8301d98
Fix makefile to handle node.c folder change
jiegec Feb 8, 2023
c7775b6
[solaris] Fix compilation for legacy build system
jiegec Feb 8, 2023
60e4209
[darwin] Fix print_v_path params
jiegec Feb 8, 2023
4acbfc2
Expose network address to struct lsof_file
jiegec Feb 8, 2023
6047869
Merge remote-tracking branch 'origin/master' into library
jiegec Feb 8, 2023
89ee4dc
[darwin] Fix missing change in merge commit
jiegec Feb 8, 2023
9b2e4ec
Move header order to fix compilation on solaris
jiegec Feb 8, 2023
7d3929e
[linux] Fix regression by include order
jiegec Feb 8, 2023
b41afbe
Remove empty src/misc.c
jiegec Feb 8, 2023
0a0a811
Fix sin_port endianness
jiegec Feb 8, 2023
764b319
Merge branch 'master' into library
jiegec Feb 10, 2023
a7f1a42
Add lsof-netstat as an example of liblsof
jiegec Feb 10, 2023
86d0970
Expose TCP/TPI state and queue length to user
jiegec Feb 10, 2023
27c3724
Add mising include for struct sockaddr_in6
jiegec Feb 10, 2023
6c8e3cb
Print zero when queue length is unknown
jiegec Feb 10, 2023
73bf503
Rewrite LTunix test to use liblsof
jiegec Feb 10, 2023
33cdf97
Fix missing header
jiegec Feb 10, 2023
92745b1
Fix return value of new tests when failed
jiegec Feb 10, 2023
e729a14
Fix memory leak
jiegec Feb 11, 2023
f01cc7c
Move ZoneArg handling to liblsof
jiegec Feb 12, 2023
ea446fb
Remove snpf.c, only use system snprintf
jiegec Feb 12, 2023
51d48e2
Move CntxArg to liblsof
jiegec Feb 13, 2023
5d1baef
Migrate gethostbyname to getaddrinfo
jiegec Feb 13, 2023
d6e6885
Move enter_nwad to liblsof
jiegec Feb 13, 2023
81a0be1
Use AF_UNSPEC/AF_INET/AF_INET6 instead of 0/4/6 for FnetTy
jiegec Feb 13, 2023
bda756d
Fix uninitialized variable and address family
jiegec Feb 13, 2023
e90ad6c
Move SELNA to liblsof
jiegec Feb 13, 2023
ed94be5
Move ck_file_arg to lib/lsof.c
jiegec Feb 17, 2023
c4893aa
Add API to select files by path
jiegec Feb 17, 2023
16f9b18
Remove unused code
jiegec Feb 17, 2023
a46d783
Move Efsysl mount point check to liblsof
jiegec Feb 17, 2023
a37f204
Move CmdLim to lsof cli
jiegec Feb 17, 2023
1bbcaae
Move externs to cli
jiegec Feb 17, 2023
89aa811
Add LTshm2 test
jiegec Feb 18, 2023
3eb188f
Align freebsd posix shm display
jiegec Feb 18, 2023
0c3e6dc
[linux] Fix linking librt
jiegec Feb 18, 2023
ef155b1
Check for null pointer
jiegec Feb 18, 2023
2f98fcf
[netbsd] Link librt for shm
jiegec Feb 18, 2023
145205b
Move DevDev init to liblsof
jiegec Feb 18, 2023
6679e18
Add selection result reporting
jiegec Feb 18, 2023
6053079
Move DevDev init to lsof_new
jiegec Feb 18, 2023
8080379
Fix memory leaks in ck_file_arg
jiegec Feb 18, 2023
be71de0
Do not free TcpSt when provided by bsd
jiegec Feb 18, 2023
025fa34
Merge remote-tracking branch 'origin/master' into library
jiegec Mar 9, 2023
4c45c52
Use ctx->err instead of stderr
jiegec Mar 11, 2023
b765d49
Expose zone and context
jiegec Mar 11, 2023
217dc05
Merge remote-tracking branch 'origin/master' into library
jiegec Mar 28, 2023
6d06bf7
Merge remote-tracking branch 'origin/master' into library
jiegec Mar 28, 2023
55f3166
Merge remote-tracking branch 'origin/master' into library
jiegec Apr 2, 2023
9ecbe30
Fix merge commit
jiegec Apr 2, 2023
c2d57c0
Merge remote-tracking branch 'origin/master' into library
jiegec Apr 3, 2023
803a913
Merge branch 'master' into library
jiegec Apr 12, 2023
4585734
Merge recent changes from master
jiegec Apr 12, 2023
fa0a7b9
Merge recent changes from master: aix
jiegec Apr 12, 2023
d082446
Remove _PROTOTYPE
jiegec Apr 12, 2023
1ed4683
Fix last commit on Linux
jiegec Apr 12, 2023
5b01c02
Merge remote-tracking branch 'origin/master' into library
jiegec Apr 12, 2023
603d895
Fix testing on Linux
jiegec Apr 12, 2023
297d4bb
Fix FreeBSD
jiegec Apr 12, 2023
b7d4597
Fix NetBSD
jiegec Apr 12, 2023
78ab302
Sync recent changes
jiegec Apr 12, 2023
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
5 changes: 0 additions & 5 deletions 00PORTING
Original file line number Diff line number Diff line change
Expand Up @@ -1066,11 +1066,6 @@ possibilities
pointer to the file, and returns non-zero
if it prints a cached name to stdout.

HASPRIVPRIPP is defined for dialects that have a private
function for printing the IP protocol name.
When this is not defined, the function to
do that defaults to printiproto().

HASPROCFS defines the name (if any) of the process file
system -- e.g., /proc.

Expand Down
104 changes: 75 additions & 29 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
bin_PROGRAMS = lsof

# Documentation
EXTRA_DIST = 00.README.FIRST 00CREDITS 00DCACHE 00DIALECTS 00DIST 00FAQ 00LSOF-L 00MANIFEST 00PORTING 00QUICKSTART 00README 00TEST 00XCONFIG
# Testing
EXTRA_DIST += tests/00README tests/TestDB tests/CkTestDB tests/Makefile tests/LsofTest.h check.bash
# liblsof
lib_LTLIBRARIES = liblsof.la

# Dialect neutral sources
lsof_SOURCES = src/arg.c src/main.c lib/node.c src/print.c src/ptti.c src/store.c src/usage.c src/util.c \
lib/ckkv.c lib/cvfs.c lib/dvch.c lib/fino.c lib/isfn.c lib/lkud.c lib/misc.c lib/pdvn.c lib/prfp.c lib/print.c lib/proc.c lib/ptti.c lib/rdev.c lib/rnmt.c lib/rmnt.c lib/rnam.c lib/rnch.c lib/rnmh.c
lsof_SOURCES += lib/common.h include/lsof_fields.h lib/proto.h lib/hash.h src/cli.h
liblsof_la_SOURCES = lib/ckkv.c lib/cvfs.c lib/dvch.c lib/fino.c lib/isfn.c lib/lkud.c lib/lsof.c lib/misc.c lib/node.c lib/pdvn.c lib/prfp.c lib/print.c lib/proc.c lib/ptti.c lib/rdev.c lib/rnmt.c lib/rmnt.c lib/rnam.c lib/rnch.c lib/rnmh.c
liblsof_la_SOURCES += lib/common.h lib/proto.h lib/hash.h
include_HEADERS = include/lsof.h include/lsof_fields.h

# Hide internal functions
AM_CFLAGS = -fvisibility=hidden

DIALECT_ROOT = $(top_srcdir)/lib/dialects
DIALECT_PATH = $(DIALECT_ROOT)/$(LSOF_DIALECT_DIR)

# Dialect specific sources
if LINUX
lsof_SOURCES += lib/dialects/linux/dfile.c \
liblsof_la_SOURCES += lib/dialects/linux/dfile.c \
lib/dialects/linux/dmnt.c \
lib/dialects/linux/dnode.c \
lib/dialects/linux/dproc.c \
Expand All @@ -27,7 +26,7 @@ lsof_SOURCES += lib/dialects/linux/dfile.c \
endif

if DARWIN
lsof_SOURCES += lib/dialects/darwin/ddev.c \
liblsof_la_SOURCES += lib/dialects/darwin/ddev.c \
lib/dialects/darwin/dfile.c \
lib/dialects/darwin/dmnt.c \
lib/dialects/darwin/dproc.c \
Expand All @@ -39,7 +38,7 @@ lsof_SOURCES += lib/dialects/darwin/ddev.c \
endif

if FREEBSD
lsof_SOURCES += lib/dialects/freebsd/dmnt.c \
liblsof_la_SOURCES += lib/dialects/freebsd/dmnt.c \
lib/dialects/freebsd/dnode.c \
lib/dialects/freebsd/dproc.c \
lib/dialects/freebsd/dsock.c \
Expand All @@ -50,7 +49,7 @@ lsof_SOURCES += lib/dialects/freebsd/dmnt.c \
endif

if NETBSD
lsof_SOURCES += lib/dialects/netbsd/dmnt.c \
liblsof_la_SOURCES += lib/dialects/netbsd/dmnt.c \
lib/dialects/netbsd/dnode.c \
lib/dialects/netbsd/dproc.c \
lib/dialects/netbsd/dsock.c \
Expand All @@ -61,7 +60,7 @@ lsof_SOURCES += lib/dialects/netbsd/dmnt.c \
endif

if OPENBSD
lsof_SOURCES += lib/dialects/openbsd/dfile.c \
liblsof_la_SOURCES += lib/dialects/openbsd/dfile.c \
lib/dialects/openbsd/dmnt.c \
lib/dialects/openbsd/dnode.c \
lib/dialects/openbsd/dproc.c \
Expand All @@ -73,7 +72,7 @@ lsof_SOURCES += lib/dialects/openbsd/dfile.c \
endif

if SOLARIS
lsof_SOURCES += lib/dialects/sun/ddev.c \
liblsof_la_SOURCES += lib/dialects/sun/ddev.c \
lib/dialects/sun/dfile.c \
lib/dialects/sun/dmnt.c \
lib/dialects/sun/dnode.c \
Expand All @@ -86,7 +85,7 @@ lsof_SOURCES += lib/dialects/sun/ddev.c \
endif

if AIX
lsof_SOURCES += lib/dialects/aix/ddev.c \
liblsof_la_SOURCES += lib/dialects/aix/ddev.c \
lib/dialects/aix/dfile.c \
lib/dialects/aix/dmnt.c \
lib/dialects/aix/dnode.c \
Expand All @@ -99,22 +98,35 @@ lsof_SOURCES += lib/dialects/aix/ddev.c \
lib/dialects/aix/machine.h
endif

lsof_CPPFLAGS = -I$(DIALECT_PATH) -Iautotools -I$(top_srcdir)/lib -I$(top_srcdir)/include
lsof_CPPFLAGS += -DAUTOTOOLS
# Binary
bin_PROGRAMS = lsof lsof-netstat

lsof_SOURCES = src/arg.c src/main.c src/print.c src/ptti.c src/store.c src/usage.c src/util.c
lsof_SOURCES += src/cli.h

if LINUX
lsof_SOURCES += src/dialects/linux/dprint.c
endif
if DARWIN
lsof_SOURCES += src/dialects/darwin/dprint.c
endif
if SOLARIS
lsof_SOURCES += src/dialects/sun/dprint.c
endif
# TODO: link to dynamic library instead after internal functions are no longer used
lsof_SOURCES += $(liblsof_la_SOURCES)
#lsof_LDADD = liblsof.la
lsof_netstat_SOURCES = src/netstat.c
lsof_netstat_LDADD = liblsof.la

liblsof_la_CPPFLAGS = -I$(DIALECT_PATH) -Iautotools -DAUTOTOOLS -I$(top_srcdir)/lib -I$(top_srcdir)/include
lsof_CPPFLAGS = -I$(DIALECT_PATH) -Iautotools -DAUTOTOOLS -I$(top_srcdir)/lib -I$(top_srcdir)/include -I$(top_srcdir)/src
lsof_netstat_CPPFLAGS = -I$(DIALECT_PATH) -Iautotools -DAUTOTOOLS -I$(top_srcdir)/lib -I$(top_srcdir)/include -I$(top_srcdir)/src

# Manpages
lsof.man: Lsof.8 version 00DIALECTS
soelim < Lsof.8 > $@
man8_MANS = lsof.man
EXTRA_DIST += Lsof.8
# Fix distcheck error
clean-local:
rm -rf lsof.man
distclean-local:
rm -rf lockf_owner.h lockf.h

# Testing scripts
AM_TESTS_ENVIRONMENT = export LSOF_DIALECT_DIR=$(LSOF_DIALECT_DIR); export LSOF_DIALECT=$(LSOF_DIALECT);
EXTRA_DIST =
# Dialect neutral
DIALECT_NEUTRAL_TESTS = tests/case-00-hello.bash \
tests/case-01-version.bash \
Expand All @@ -124,7 +136,8 @@ DIALECT_NEUTRAL_TESTS = tests/case-00-hello.bash \
tests/case-20-offset-field.bash \
tests/case-20-repeat-count.bash \
tests/case-21-exit-Q-status.bash \
tests/case-22-empty-process-name.bash
tests/case-22-empty-process-name.bash \
tests/case-23-c-option.bash
TESTS = $(DIALECT_NEUTRAL_TESTS)
EXTRA_DIST += $(DIALECT_NEUTRAL_TESTS) \
tests/case-13-classic.bash \
Expand Down Expand Up @@ -193,3 +206,36 @@ tests_LTszoff_SOURCES = tests/LTszoff.c tests/LTlib.c
tests_LTszoff_CFLAGS = @LSOF_TEST_CFLAGS@ -I$(top_srcdir)/include
tests_LTunix_SOURCES = tests/LTunix.c tests/LTlib.c
tests_LTunix_CFLAGS = @LSOF_TEST_CFLAGS@ -I$(top_srcdir)/include

TESTS += tests/LTbasic2 tests/LTszoff2 tests/LTunix2 tests/LTshm2
check_PROGRAMS += tests/LTbasic2 tests/LTszoff2 tests/LTunix2 tests/LTshm2
tests_LTbasic2_CFLAGS = -I$(top_srcdir)/include
tests_LTbasic2_LDADD = liblsof.la
tests_LTszoff2_CFLAGS = -I$(top_srcdir)/include
tests_LTszoff2_LDADD = liblsof.la
tests_LTunix2_CFLAGS = -I$(top_srcdir)/include
tests_LTunix2_LDADD = liblsof.la
tests_LTshm2_CFLAGS = -I$(top_srcdir)/include
tests_LTshm2_LDADD = liblsof.la
if LINUX
tests_LTshm2_LDADD += -lrt
endif
if NETBSD
tests_LTshm2_LDADD += -lrt
endif

# Documentation
EXTRA_DIST += 00.README.FIRST 00CREDITS 00DCACHE 00DIALECTS 00DIST 00FAQ 00LSOF-L 00MANIFEST 00PORTING 00QUICKSTART 00README 00TEST 00XCONFIG
# Testing
EXTRA_DIST += tests/00README tests/TestDB tests/CkTestDB tests/Makefile tests/LsofTest.h check.bash

# Manpages
lsof.man: Lsof.8 version 00DIALECTS
soelim < Lsof.8 > $@
man8_MANS = lsof.man
EXTRA_DIST += Lsof.8
# Fix distcheck error
clean-local:
rm -rf lsof.man
distclean-local:
rm -rf lockf_owner.h lockf.h
5 changes: 5 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
AC_INIT([lsof],[4.98.0])
AM_INIT_AUTOMAKE([subdir-objects])
LT_INIT([disable-fast-install]) # avoid lt-lsof naming
# Locate custom m4 macros
AC_CONFIG_MACRO_DIR([m4])

Expand Down Expand Up @@ -247,6 +248,10 @@ CFLAGS="$CFLAGS -DLSOF_VSTR=\\\"$LSOF_TMP\\\""
AC_SUBST([LSOF_DIALECT])
AC_SUBST([LSOF_DIALECT_DIR])

# Export public function with default visibility
AC_DEFINE([API_EXPORT], [__attribute__ ((visibility ("default")))],
[Set visibility to default for exported API functions.])

# --enable-security to define HASSECURITY
AC_ARG_ENABLE(security, AS_HELP_STRING([--enable-security],
[allow only the root user to list all open files @<:@default=no@:>@]), [], [enable_security=no])
Expand Down
Loading