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

Expose functionality as a re-usable library - Part 2 #284

Merged
merged 28 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c4ca78b
Add lsof_context arguments
jiegec Mar 29, 2023
4cb08a1
Fix darwin
jiegec Apr 2, 2023
6c985ec
Fix Linux
jiegec Apr 2, 2023
e388954
Fix FreeBSD
jiegec Apr 2, 2023
0fd0550
Fix FreeBSD 14
jiegec Apr 2, 2023
4849935
Fix NetBSD
jiegec Apr 3, 2023
637b92e
Fix OpenBSD
jiegec Apr 3, 2023
9341256
Add ctx argument to kread
jiegec Apr 3, 2023
081922d
Merge remote-tracking branch 'origin/master' into library-part2
jiegec Apr 3, 2023
73c113d
Merge remote-tracking branch 'origin/master' into library-part2
jiegec Apr 3, 2023
34837cf
Modernize legacy parameter list
jiegec Apr 3, 2023
725c96a
Merge remote-tracking branch 'origin/master' into library-part2
jiegec Apr 8, 2023
07bb1c8
Add comments for context argument
jiegec Apr 8, 2023
a9bd277
Add cli.h for distcheck
jiegec Apr 8, 2023
97bcd5c
Remove _PROTOTYPE, assuming we have std c compiler
jiegec Apr 8, 2023
f16d0e5
Add missing ctx arguments
jiegec Apr 8, 2023
d1f15fe
Fix Solaris
jiegec Apr 8, 2023
18357a3
Fix NetBSD
jiegec Apr 9, 2023
47aaf11
Add comments for context argument
jiegec Apr 9, 2023
148d6c0
Add missing ctx arguments
jiegec Apr 9, 2023
b0c19be
Add missing ctx arguments to src
jiegec Apr 9, 2023
1eaa6d1
Fix FreeBSD
jiegec Apr 9, 2023
cab583f
Merge remote-tracking branch 'origin/master' into library-part2
jiegec Apr 9, 2023
cef461b
Fix AIX
jiegec Apr 9, 2023
89e8583
Add missing ctx arguments
jiegec Apr 9, 2023
1c0987f
Merge remote-tracking branch 'origin/master' into library-part2
jiegec Apr 9, 2023
11db81f
Merge remote-tracking branch 'origin/master' into library-part2
jiegec Apr 11, 2023
0701330
Modernize K&R paramter declaration
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
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,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
lsof_SOURCES += lib/common.h include/lsof_fields.h lib/proto.h lib/hash.h
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
DIALECT_PATH = $(DIALECT_ROOT)/$(LSOF_DIALECT_DIR)
Expand Down
12 changes: 6 additions & 6 deletions lib/ckkv.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@
* ckkv() - check kernel version
*/

void ckkv(d, er, ev, ea) char *d; /* dialect */
char *er; /* expected revision; NULL, no test */
char *ev; /* expected version; NULL, no test */
char *ea; /* expected architecture; NULL, no
* test */
void ckkv(struct lsof_context *ctx, /* context */
char *d, /* dialect */
char *er, /* expected revision; NULL, no test */
char *ev, /* expected version; NULL, no test */
char *ea) /* expected architecture; NULL, no test */
{

# if defined(HASKERNIDCK)
Expand All @@ -56,7 +56,7 @@ char *ea; /* expected architecture; NULL, no
*/
if (uname(&u) < 0) {
(void)fprintf(stderr, "%s: uname error: %s\n", Pn, strerror(errno));
Error();
Error(ctx);
}
if (er && strcmp(er, u.release)) {
(void)fprintf(stderr,
Expand Down
3 changes: 3 additions & 0 deletions lib/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,9 @@ typedef struct znhash {
extern znhash_t **ZoneArg;
# endif /* defined(HASZONES) */

struct lsof_context {
};

# include "proto.h"
# include "dproto.h"

Expand Down
7 changes: 4 additions & 3 deletions lib/cvfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@
* completevfs() - complete local vfs structure
*/

void completevfs(vfs, dev) struct l_vfs *vfs; /* local vfs structure pointer */
dev_t *dev; /* device */
void completevfs(struct lsof_context *ctx,
jiegec marked this conversation as resolved.
Show resolved Hide resolved
struct l_vfs *vfs, /* local vfs structure pointer */
dev_t *dev) /* device */
{
struct mounts *mp;
/*
Expand All @@ -61,7 +62,7 @@ dev_t *dev; /* device */
/*
* Search for a match on device number.
*/
for (mp = readmnt(); mp; mp = mp->next) {
for (mp = readmnt(ctx); mp; mp = mp->next) {
if (mp->dev == *dev) {

# if defined(CVFS_DEVSAVE)
Expand Down
2 changes: 1 addition & 1 deletion lib/dialects/aix/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ CFLAGS= ${CDEFS} ${INCL} ${DEBUG}

GRP=

HDR= lsof.h lsof_fields.h dlsof.h machine.h proto.h dproto.h
HDR= common.h lsof_fields.h dlsof.h machine.h proto.h dproto.h

SRC= ddev.c dfile.c dmnt.c dnode.c dnode1.c dnode2.c dproc.c dsock.c \
dstore.c arg.c main.c misc.c node.c print.c proc.c store.c usage.c \
Expand Down
57 changes: 26 additions & 31 deletions lib/dialects/aix/ddev.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ void clr_sect() {
* getchan() - get channel from file path name
*/

int getchan(p)
char *p; /* file path name */
int getchan(char *p) /* file path name */
{
int ch;
char *s;
Expand All @@ -101,11 +100,10 @@ char *p; /* file path name */
* printdevname() - print device name
*/

int printdevname(dev, rdev, f, nty)
dev_t *dev; /* device */
dev_t *rdev; /* raw device */
int f; /* 1 = follow with '\n' */
int nty; /* node type: N_BLK or N_CHR */
int printdevname(dev_t *dev, /* device */
jiegec marked this conversation as resolved.
Show resolved Hide resolved
dev_t *rdev, /* raw device */
int f, /* 1 = follow with '\n' */
int nty) /* node type: N_BLK or N_CHR */
{
struct l_dev *dp;
/*
Expand Down Expand Up @@ -136,7 +134,7 @@ int nty; /* node type: N_BLK or N_CHR */
if (!(cp = (char *)malloc((MALLOC_S)(len + 1)))) {
(void)fprintf(stderr, "%s: no nma space for: (%s %s)\n", Pn, ttl,
dp->name);
Error();
Error(ctx);
}
(void)snpf(cp, len + 1, "(%s %s)", ttl, dp->name);
(void)add_nma(cp, len);
Expand All @@ -150,7 +148,7 @@ int nty; /* node type: N_BLK or N_CHR */
* readdev() - read device names, modes and types
*/

void readdev(skip) int skip; /* skip device cache read if 1 */
void readdev(int skip) /* skip device cache read if 1 */
jiegec marked this conversation as resolved.
Show resolved Hide resolved
{

#if defined(HASDCACHE)
Expand Down Expand Up @@ -229,7 +227,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 */
mkstrcat(Dstk[Dstkx], -1, "/", 1, (char *)NULL, -1, &pl))) {
(void)fprintf(stderr, "%s: no space for: ", Pn);
safestrprt(Dstk[Dstkx], stderr, 1);
Error();
Error(ctx);
}
(void)free((FREE_P *)Dstk[Dstkx]);
Dstk[Dstkx] = (char *)NULL;
Expand All @@ -251,7 +249,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 */
(void)fprintf(stderr, "%s: no space for: ", Pn);
safestrprt(path, stderr, 0);
safestrprt(dp->d_name, stderr, 1);
Error();
Error(ctx);
}

#if defined(USE_STAT)
Expand Down Expand Up @@ -300,15 +298,15 @@ void readdev(skip) int skip; /* skip device cache read if 1 */
if (!Devtp) {
(void)fprintf(
stderr, "%s: no space for character device\n", Pn);
Error();
Error(ctx);
}
}
Devtp[i].rdev = sb.st_rdev;
Devtp[i].inode = (INODETYPE)sb.st_ino;
if (!(Devtp[i].name = mkstrcpy(fp, (MALLOC_S *)NULL))) {
(void)fprintf(stderr, "%s: no space for: ", Pn);
safestrprt(fp, stderr, 1);
Error();
Error(ctx);
}
Devtp[i].v = 0;
i++;
Expand All @@ -323,13 +321,13 @@ void readdev(skip) int skip; /* skip device cache read if 1 */
(void)fprintf(stderr,
"%s: no space for clone device: ", Pn);
safestrprt(fp, stderr, 1);
Error();
Error(ctx);
}
if (!(c->cd.name = mkstrcpy(fp, (MALLOC_S)NULL))) {
(void)fprintf(stderr,
"%s: no space for clone name: ", Pn);
safestrprt(fp, stderr, 1);
Error();
Error(ctx);
}
c->cd.inode = (INODETYPE)sb.st_ino;
c->cd.rdev = sb.st_rdev;
Expand Down Expand Up @@ -360,7 +358,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 */
if (!BDevtp) {
(void)fprintf(stderr, "%s: no space for block device\n",
Pn);
Error();
Error(ctx);
}
}
BDevtp[j].rdev = sb.st_rdev;
Expand Down Expand Up @@ -403,7 +401,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 */
(MALLOC_S)(sizeof(struct l_dev *) * BNdev)))) {
(void)fprintf(stderr,
"%s: no space for block device sort pointers\n", Pn);
Error();
Error(ctx);
}
for (j = 0; j < BNdev; j++) {
BSdev[j] = &BDevtp[j];
Expand All @@ -428,7 +426,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 */
(void)fprintf(stderr,
"%s: no space for character device sort pointers\n",
Pn);
Error();
Error(ctx);
}
for (i = 0; i < Ndev; i++) {
Sdev[i] = &Devtp[i];
Expand All @@ -438,7 +436,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 */
Ndev = rmdupdev(&Sdev, Ndev, "char");
} else {
(void)fprintf(stderr, "%s: no character devices found\n", Pn);
Error();
Error(ctx);
}

#if defined(HASDCACHE)
Expand Down Expand Up @@ -471,10 +469,9 @@ void rereaddev() {
* rmdupdev() - remove duplicate (major/minor/inode) devices
*/

static int rmdupdev(dp, n, nm)
struct l_dev ***dp; /* device table pointers address */
int n; /* number of pointers */
char *nm; /* device table name for error message */
static int rmdupdev(struct l_dev ***dp, /* device table pointers address */
jiegec marked this conversation as resolved.
Show resolved Hide resolved
int n, /* number of pointers */
char *nm) /* device table name for error message */
{

#if AIXV >= 4140
Expand Down Expand Up @@ -519,7 +516,7 @@ char *nm; /* device table name for error message */
if (!(*dp = (struct l_dev **)realloc(
(MALLOC_P *)*dp, (MALLOC_S)(j * sizeof(struct l_dev *))))) {
(void)fprintf(stderr, "%s: can't realloc %s device pointers\n", Pn, nm);
Error();
Error(ctx);
}
return (j);
}
Expand All @@ -529,8 +526,7 @@ char *nm; /* device table name for error message */
* rw_clone_sect() - read/write the device cache file clone section
*/

int rw_clone_sect(m)
int m; /* mode: 1 = read; 2 = write */
int rw_clone_sect(int m) /* mode: 1 = read; 2 = write */
jiegec marked this conversation as resolved.
Show resolved Hide resolved
{
char buf[MAXPATHLEN * 2], *cp;
struct clone *c;
Expand Down Expand Up @@ -578,7 +574,7 @@ int m; /* mode: 1 = read; 2 = write */
if (!(c = (struct clone *)calloc(1, sizeof(struct clone)))) {
(void)fprintf(stderr, "%s: no space for cached clone: ", Pn);
safestrprt(buf, stderr, 1);
Error();
Error(ctx);
}
/*
* Enter the clone device number.
Expand Down Expand Up @@ -616,7 +612,7 @@ int m; /* mode: 1 = read; 2 = write */
(void)fprintf(stderr,
"%s: no space for cached clone path: ", Pn);
safestrprt(buf, stderr, 1);
Error();
Error(ctx);
}
c->cd.v = 0;
c->next = Clone;
Expand Down Expand Up @@ -650,7 +646,7 @@ int m; /* mode: 1 = read; 2 = write */
* A shouldn't-happen case: mode neither 1 nor 2.
*/
(void)fprintf(stderr, "%s: internal rw_clone_sect error: %d\n", Pn, m);
Error();
Error(ctx);
}
#endif /* defined(HASDCACHE) && AIXV>=4140 */

Expand All @@ -661,8 +657,7 @@ int m; /* mode: 1 = read; 2 = write */
* Note: rereads entire device table when an entry can't be verified.
*/

int vfy_dev(dp)
struct l_dev *dp; /* device table pointer */
int vfy_dev(struct l_dev *dp) /* device table pointer */
{
struct stat sb;

Expand Down
Loading