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

Library part5 #290

Merged
merged 34 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
0a5d6a4
Move Lp, Lproc, Lf and Plf to context
jiegec May 4, 2023
1cc8e00
Add missing lsof_context_dialect declarations
jiegec May 4, 2023
ea603f6
Add missing ctx arguments
jiegec May 4, 2023
4ef7df6
Fix missing ctx on Linux
jiegec May 4, 2023
7d520d1
Allocate space for lsof_context
jiegec May 4, 2023
89b92f8
Move Pn and Fwarn to context
jiegec May 4, 2023
3534a89
Move Namech and Namechl to context
jiegec May 4, 2023
1864c33
Move SelAll, Selflags, SelProc, Selinet to context
jiegec May 4, 2023
a3ed9ba
Move DevDev to context
jiegec May 4, 2023
a54e57b
Move Tcp/Udp state table to context
jiegec May 4, 2023
3eb8d6d
Move Funix, Fnet, FnetTy and Fnfs to context
jiegec May 4, 2023
99aa818
Move Fand and Fxopt to context
jiegec May 5, 2023
ef59a09
Move Fblock, Fovhd, FeptE and Ftask to context
jiegec May 5, 2023
b72ddf0
Move Fdl, FdlTy, IgnTasks, MaxFd, MntSup and MntSupP to context
jiegec May 5, 2023
6c0d3d3
Move Nlproc, Nlink, TmLimit and Npuns to context
jiegec May 5, 2023
d4603a8
Fix MaxFd on Linux
jiegec May 5, 2023
677e2ac
Move Mypid, Myuid, Mygid, Setgid and Setuidroot to context
jiegec May 9, 2023
62c219b
Move Dstk, Sfile and Efsysl to context
jiegec May 9, 2023
4f0deb0
Move select uid/pid/pgid to context
jiegec May 9, 2023
5809b06
Move select all procs/command/network address to context
jiegec May 9, 2023
bcad86c
Move device table and selinux context select to context
jiegec May 9, 2023
eabd96b
Move device cache, name list, procfs, name cache, local mount info, h…
jiegec May 9, 2023
b0e092d
Fix darwin
jiegec May 9, 2023
6edcbe4
Set default value to FdlTy
jiegec May 9, 2023
2adce94
Fix FreeBSD
jiegec May 9, 2023
f20a708
Fix OpenBSD
jiegec May 9, 2023
5a13357
Fix Solaris
jiegec May 9, 2023
7867e16
Fix indentation and missing snpf
jiegec May 10, 2023
19181d7
Move HbyCd to context
jiegec May 10, 2023
44a2faf
Fix NetBSD
jiegec May 10, 2023
403bec1
Add lsof_error, lsof_avoid_blocking, lsof_avoid_forking and
jiegec May 12, 2023
97f51db
Add lsof_select_process
jiegec May 12, 2023
0a95d3b
Add lsof_set_output_stream
jiegec May 12, 2023
5faeada
free(NULL) is no-op
jiegec May 23, 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
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ EXTRA_DIST += tests/00README tests/TestDB tests/CkTestDB tests/Makefile tests/Ls

# 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
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
lsof_SOURCES += lib/common.h include/lsof_fields.h lib/proto.h lib/hash.h src/cli.h
include_HEADERS = include/lsof.h include/lsof_fields.h
DIALECT_ROOT = $(top_srcdir)/lib/dialects
Expand Down
97 changes: 97 additions & 0 deletions include/lsof.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@
#if !defined(LSOF_H)
# define LSOF_H 1

# include <stdio.h>

/** lsof error returns */
enum lsof_error {
LSOF_SUCCESS = 0, /**< Success */
LSOF_ERROR_INVALID_ARGUMENT, /**< Invalid argument */
LSOF_ERROR_NO_MEMORY, /**< No memory */
LSOF_ERROR_UNSUPPORTED, /**< Unsupported operation */
};

/** File access mode */
enum lsof_file_access_mode {
LSOF_FILE_ACCESS_NONE = 0, /**< None */
Expand Down Expand Up @@ -220,4 +230,91 @@ enum lsof_file_type {
LSOF_FILE_VNODE_VPORT, /**< The vnode represents a port */
};

/** API version of liblsof
* you may use this macro to check the existence of
* functions
*/
# define LSOF_API_VERSION 1

/** Get runtime API version of liblsof
*
* liblsof might not function properly if API version mismatched between compile
* time and runtime.
*
* \since API version 1
*/
int lsof_get_api_version();

/** Get library version of liblsof
*
* \return a string like "4.xx.x". The caller must not free it.
*
* \since API version 1
*/
char *lsof_get_library_version();

/** Create a new lsof context
*
* The context should be freed via `lsof_destroy()`.
*
* \since API version 1
*/
struct lsof_context *lsof_new();

/** Set output stream for warning and error messages
*
* lsof may want to print warning and error messages to the user. You can allow
* printing by setting the output stream and whether prints warning or not. You
* should also supply `program_name` so that the output starts with your program
* name.
*
* By default, the output is suppressed. You can set fp to NULL to suppress
* output.
*
* \since API version 1
*/
enum lsof_error lsof_set_output_stream(struct lsof_context *ctx, FILE *fp,
char *program_name, int warn);

/** Ask lsof to avoid using blocking functions
*
* lsof may block when calling lstat(), readlink() or stat(). Call this function
* with `avoid=1` to let lsof avoid calling these functions.
*
* \since API version 1
*/
enum lsof_error lsof_avoid_blocking(struct lsof_context *ctx, int avoid);

/** Ask lsof to avoid forking
*
* To avoid being blocked by some kernel operations, liblsof does them in forked
* child processes. Call this function to change this behavior.
*
* \since API version 1
*/
enum lsof_error lsof_avoid_forking(struct lsof_context *ctx, int avoid);

/** Ask lsof to AND the selections
*
* By default, lsof OR the selections, for example, if you call
* lsof_select_unix_socket() and lsof_select_login(), it will report unix
* sockets OR open files by the user. If lsof_logic_and() is called, it will
* report unix sockets open by the specified user.
*
* \since API version 1
*/
enum lsof_error lsof_logic_and(struct lsof_context *ctx);

/** Ask lsof to select process by command
*
* Select process executing the command that begins with the characters of
* `command`. You can specify exclusion by setting `exclude` to 1.
*
* You can call this function multiple times to add more search conditions.
*
* \since API version 1
*/
enum lsof_error lsof_select_process(struct lsof_context *ctx, char *command,
int exclude);

#endif
Loading