Skip to content

Commit e2da74c

Browse files
committed
sun: support old procfs psinfo layout
1 parent acf7511 commit e2da74c

1 file changed

Lines changed: 28 additions & 9 deletions

File tree

‎lib/dialects/sun/dproc.c‎

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ static int nm2id(char *nm, int *id) {
4646
#define PSINFO_EUID 28
4747
#define PSINFO_FNAME 136
4848

49+
/* Old (non-structured) prpsinfo_t used by some illumos/Solaris systems. */
50+
#define PSINFO_OLD_SIZE 328
51+
#define PSINFO_OLD_PID 16
52+
#define PSINFO_OLD_PPID 20
53+
#define PSINFO_OLD_PGID 24
54+
#define PSINFO_OLD_UID 8
55+
#define PSINFO_OLD_EUID 288
56+
#define PSINFO_OLD_FNAME 120
57+
4958
/*
5059
* /proc/<pid>/fdinfo/nn is a variable-length prfdinfo_t followed by
5160
* self-describing pr_misc entries. The layout is from Solaris/illumos
@@ -372,14 +381,17 @@ static void process_fdinfo(struct lsof_context *ctx, int pid, int fd,
372381
link_lfile(ctx);
373382
}
374383

375-
static int read_psinfo(const char *p, unsigned char *ps) {
384+
static int read_psinfo(const char *p, unsigned char *ps, int *len) {
376385
int fd, n;
377386

378387
if ((fd = open(p, O_RDONLY)) < 0)
379388
return (1);
380389
n = (int)read(fd, ps, PSINFO_SIZE);
381390
(void)close(fd);
382-
return (n == PSINFO_SIZE) ? 0 : 1;
391+
*len = n;
392+
if (n >= PSINFO_SIZE)
393+
return (0);
394+
return (n == PSINFO_OLD_SIZE) ? 0 : 1;
383395
}
384396

385397
static void enter_path(struct lsof_context *ctx, enum lsof_fd_type fdt,
@@ -501,18 +513,25 @@ void gather_proc_info(struct lsof_context *ctx) {
501513
if (nm2id(dp->d_name, &pid))
502514
continue;
503515
(void)snpf(pspath, sizeof(pspath), "%s/%d/psinfo", PROC_BASE, pid);
504-
if (read_psinfo(pspath, ps))
516+
int pslen;
517+
if (read_psinfo(pspath, ps, &pslen))
505518
continue;
506519
{
520+
int pidoff = (pslen == PSINFO_OLD_SIZE) ? PSINFO_OLD_PID : PSINFO_PID;
521+
int ppidoff = (pslen == PSINFO_OLD_SIZE) ? PSINFO_OLD_PPID : PSINFO_PPID;
522+
int pgidoff = (pslen == PSINFO_OLD_SIZE) ? PSINFO_OLD_PGID : PSINFO_PGID;
523+
int uidoff = (pslen == PSINFO_OLD_SIZE) ? PSINFO_OLD_UID : PSINFO_UID;
524+
int euidoff = (pslen == PSINFO_OLD_SIZE) ? PSINFO_OLD_EUID : PSINFO_EUID;
525+
int fnameoff = (pslen == PSINFO_OLD_SIZE) ? PSINFO_OLD_FNAME : PSINFO_FNAME;
507526
pid_t ps_pid, ps_ppid, ps_pgid;
508527
uid_t ps_uid, ps_euid;
509528

510-
memcpy(&ps_pid, &ps[PSINFO_PID], sizeof(ps_pid));
511-
memcpy(&ps_ppid, &ps[PSINFO_PPID], sizeof(ps_ppid));
512-
memcpy(&ps_pgid, &ps[PSINFO_PGID], sizeof(ps_pgid));
513-
memcpy(&ps_uid, &ps[PSINFO_UID], sizeof(ps_uid));
514-
memcpy(&ps_euid, &ps[PSINFO_EUID], sizeof(ps_euid));
515-
(void)memcpy(cmd, &ps[PSINFO_FNAME], sizeof(cmd) - 1);
529+
memcpy(&ps_pid, &ps[pidoff], sizeof(ps_pid));
530+
memcpy(&ps_ppid, &ps[ppidoff], sizeof(ps_ppid));
531+
memcpy(&ps_pgid, &ps[pgidoff], sizeof(ps_pgid));
532+
memcpy(&ps_uid, &ps[uidoff], sizeof(ps_uid));
533+
memcpy(&ps_euid, &ps[euidoff], sizeof(ps_euid));
534+
(void)memcpy(cmd, &ps[fnameoff], sizeof(cmd) - 1);
516535
cmd[sizeof(cmd) - 1] = '\0';
517536
if (ps_pid != pid)
518537
continue;

0 commit comments

Comments
 (0)