Skip to content

Commit 56052a1

Browse files
authored
Library part6 (#292)
* Build liblsof as shared library * Remove missing dprint.c * Add lsof_freeze * Add lsof_gather * Add lsof_destroy and lsof_free_result * Move print_proc to src * Move print_unix and print_tcptpi to src * Move endnm to lib * Move print_fflags and alloc_fflbuf to src * Move CmdLim and Ntype to context * Move FsvByf and RptTm to context * Move Foffset to context * [linux] Check selinux context even without -Z * Move Fsize to context * Expand InodeFmt_d to literal * Add weak usage shim for liblsof * Move Fsv check to cli * Fix null pointer exception * Copy string in Readlink to avoid double free * Add LTbasic2 to test liblsof * Update 00DIST for introduction of liblsof * Move printiproto and printunkaf to lib * Move FsvFlagX to lib * [freebsd] Add workaround for FreeBSD 12 bug * Implicit freeze the context for user
1 parent 2600d59 commit 56052a1

22 files changed

Lines changed: 2610 additions & 1655 deletions

File tree

00DIST

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5563,6 +5563,11 @@ Supplement Regenerated the 4.04 distribution to correct a non-
55635563

55645564
[aix] Suppress warnings properly on AIX version greater than
55655565
5.0. Closes #187.
5566+
5567+
Introduce alpha version of liblsof which allows users to use
5568+
lsof functionality via C functions instead of spawning a
5569+
subprocess and parsing the output. This version may contain BUGs
5570+
and memory leaks, and the API may change before it stablizes.
55665571

55675572
4.9?.? ????????? ??, ????
55685573

Makefile.am

Lines changed: 54 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
bin_PROGRAMS = lsof
2-
3-
# Documentation
4-
EXTRA_DIST = 00.README.FIRST 00CREDITS 00DCACHE 00DIALECTS 00DIST 00FAQ 00LSOF-L 00MANIFEST 00PORTING 00QUICKSTART 00README 00TEST 00XCONFIG
5-
# Testing
6-
EXTRA_DIST += tests/00README tests/TestDB tests/CkTestDB tests/Makefile tests/LsofTest.h check.bash
1+
# liblsof
2+
lib_LTLIBRARIES = liblsof.la
73

8-
# Dialect neutral sources
9-
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 \
10-
lib/ckkv.c lib/cvfs.c lib/dvch.c lib/fino.c lib/lsof.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
11-
lsof_SOURCES += lib/common.h include/lsof_fields.h lib/proto.h lib/hash.h src/cli.h
4+
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
5+
liblsof_la_SOURCES += lib/common.h lib/proto.h lib/hash.h
126
include_HEADERS = include/lsof.h include/lsof_fields.h
7+
8+
# Hide internal functions
9+
AM_CFLAGS = -fvisibility=hidden
10+
1311
DIALECT_ROOT = $(top_srcdir)/lib/dialects
1412
DIALECT_PATH = $(DIALECT_ROOT)/$(LSOF_DIALECT_DIR)
1513

1614
# Dialect specific sources
1715
if LINUX
18-
lsof_SOURCES += lib/dialects/linux/dfile.c \
16+
liblsof_la_SOURCES += lib/dialects/linux/dfile.c \
1917
lib/dialects/linux/dmnt.c \
2018
lib/dialects/linux/dnode.c \
2119
lib/dialects/linux/dproc.c \
@@ -27,7 +25,7 @@ lsof_SOURCES += lib/dialects/linux/dfile.c \
2725
endif
2826

2927
if DARWIN
30-
lsof_SOURCES += lib/dialects/darwin/ddev.c \
28+
liblsof_la_SOURCES += lib/dialects/darwin/ddev.c \
3129
lib/dialects/darwin/dfile.c \
3230
lib/dialects/darwin/dmnt.c \
3331
lib/dialects/darwin/dproc.c \
@@ -39,7 +37,7 @@ lsof_SOURCES += lib/dialects/darwin/ddev.c \
3937
endif
4038

4139
if FREEBSD
42-
lsof_SOURCES += lib/dialects/freebsd/dmnt.c \
40+
liblsof_la_SOURCES += lib/dialects/freebsd/dmnt.c \
4341
lib/dialects/freebsd/dnode.c \
4442
lib/dialects/freebsd/dproc.c \
4543
lib/dialects/freebsd/dsock.c \
@@ -50,7 +48,7 @@ lsof_SOURCES += lib/dialects/freebsd/dmnt.c \
5048
endif
5149

5250
if NETBSD
53-
lsof_SOURCES += lib/dialects/netbsd/dmnt.c \
51+
liblsof_la_SOURCES += lib/dialects/netbsd/dmnt.c \
5452
lib/dialects/netbsd/dnode.c \
5553
lib/dialects/netbsd/dproc.c \
5654
lib/dialects/netbsd/dsock.c \
@@ -61,7 +59,7 @@ lsof_SOURCES += lib/dialects/netbsd/dmnt.c \
6159
endif
6260

6361
if OPENBSD
64-
lsof_SOURCES += lib/dialects/openbsd/dfile.c \
62+
liblsof_la_SOURCES += lib/dialects/openbsd/dfile.c \
6563
lib/dialects/openbsd/dmnt.c \
6664
lib/dialects/openbsd/dnode.c \
6765
lib/dialects/openbsd/dproc.c \
@@ -73,7 +71,7 @@ lsof_SOURCES += lib/dialects/openbsd/dfile.c \
7371
endif
7472

7573
if SOLARIS
76-
lsof_SOURCES += lib/dialects/sun/ddev.c \
74+
liblsof_la_SOURCES += lib/dialects/sun/ddev.c \
7775
lib/dialects/sun/dfile.c \
7876
lib/dialects/sun/dmnt.c \
7977
lib/dialects/sun/dnode.c \
@@ -86,7 +84,7 @@ lsof_SOURCES += lib/dialects/sun/ddev.c \
8684
endif
8785

8886
if AIX
89-
lsof_SOURCES += lib/dialects/aix/ddev.c \
87+
liblsof_la_SOURCES += lib/dialects/aix/ddev.c \
9088
lib/dialects/aix/dfile.c \
9189
lib/dialects/aix/dmnt.c \
9290
lib/dialects/aix/dnode.c \
@@ -99,22 +97,28 @@ lsof_SOURCES += lib/dialects/aix/ddev.c \
9997
lib/dialects/aix/machine.h
10098
endif
10199

102-
lsof_CPPFLAGS = -I$(DIALECT_PATH) -Iautotools -I$(top_srcdir)/lib -I$(top_srcdir)/include
103-
lsof_CPPFLAGS += -DAUTOTOOLS
100+
# Binary
101+
bin_PROGRAMS = lsof
104102

105-
# Manpages
106-
lsof.man: Lsof.8 version 00DIALECTS
107-
soelim < Lsof.8 > $@
108-
man8_MANS = lsof.man
109-
EXTRA_DIST += Lsof.8
110-
# Fix distcheck error
111-
clean-local:
112-
rm -rf lsof.man
113-
distclean-local:
114-
rm -rf lockf_owner.h lockf.h
103+
lsof_SOURCES = src/arg.c src/main.c src/print.c src/ptti.c src/store.c src/usage.c src/util.c
104+
lsof_SOURCES += src/cli.h
105+
106+
if LINUX
107+
lsof_SOURCES += src/dialects/linux/dprint.c
108+
endif
109+
if DARWIN
110+
lsof_SOURCES += src/dialects/darwin/dprint.c
111+
endif
112+
# TODO: link to dynamic library instead after internal functions are no longer used
113+
lsof_SOURCES += $(liblsof_la_SOURCES)
114+
#lsof_LDADD = liblsof.la
115+
116+
liblsof_la_CPPFLAGS = -I$(DIALECT_PATH) -Iautotools -DAUTOTOOLS -I$(top_srcdir)/lib -I$(top_srcdir)/include
117+
lsof_CPPFLAGS = -I$(DIALECT_PATH) -Iautotools -DAUTOTOOLS -I$(top_srcdir)/lib -I$(top_srcdir)/include -I$(top_srcdir)/src
115118

116119
# Testing scripts
117120
AM_TESTS_ENVIRONMENT = export LSOF_DIALECT_DIR=$(LSOF_DIALECT_DIR); export LSOF_DIALECT=$(LSOF_DIALECT);
121+
EXTRA_DIST =
118122
# Dialect neutral
119123
DIALECT_NEUTRAL_TESTS = tests/case-00-hello.bash \
120124
tests/case-01-version.bash \
@@ -193,3 +197,24 @@ tests_LTszoff_SOURCES = tests/LTszoff.c tests/LTlib.c
193197
tests_LTszoff_CFLAGS = @LSOF_TEST_CFLAGS@ -I$(top_srcdir)/include
194198
tests_LTunix_SOURCES = tests/LTunix.c tests/LTlib.c
195199
tests_LTunix_CFLAGS = @LSOF_TEST_CFLAGS@ -I$(top_srcdir)/include
200+
201+
TESTS += tests/LTbasic2
202+
check_PROGRAMS += tests/LTbasic2
203+
tests_LTbasic2_CFLAGS = -I$(top_srcdir)/include
204+
tests_LTbasic2_LDADD = liblsof.la
205+
206+
# Documentation
207+
EXTRA_DIST += 00.README.FIRST 00CREDITS 00DCACHE 00DIALECTS 00DIST 00FAQ 00LSOF-L 00MANIFEST 00PORTING 00QUICKSTART 00README 00TEST 00XCONFIG
208+
# Testing
209+
EXTRA_DIST += tests/00README tests/TestDB tests/CkTestDB tests/Makefile tests/LsofTest.h check.bash
210+
211+
# Manpages
212+
lsof.man: Lsof.8 version 00DIALECTS
213+
soelim < Lsof.8 > $@
214+
man8_MANS = lsof.man
215+
EXTRA_DIST += Lsof.8
216+
# Fix distcheck error
217+
clean-local:
218+
rm -rf lsof.man
219+
distclean-local:
220+
rm -rf lockf_owner.h lockf.h

configure.ac

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
AC_INIT([lsof],[4.98.0])
22
AM_INIT_AUTOMAKE([subdir-objects])
3+
LT_INIT([disable-fast-install]) # avoid lt-lsof naming
34
# Locate custom m4 macros
45
AC_CONFIG_MACRO_DIR([m4])
56

@@ -247,6 +248,10 @@ CFLAGS="$CFLAGS -DLSOF_VSTR=\\\"$LSOF_TMP\\\""
247248
AC_SUBST([LSOF_DIALECT])
248249
AC_SUBST([LSOF_DIALECT_DIR])
249250

251+
# Export public function with default visibility
252+
AC_DEFINE([API_EXPORT], [__attribute__ ((visibility ("default")))],
253+
[Set visibility to default for exported API functions.])
254+
250255
# --enable-security to define HASSECURITY
251256
AC_ARG_ENABLE(security, AS_HELP_STRING([--enable-security],
252257
[allow only the root user to list all open files @<:@default=no@:>@]), [], [enable_security=no])

0 commit comments

Comments
 (0)