From 8420df62eb99654230f3f95fa23dccc11ea45dee Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Tue, 25 May 2021 19:11:56 +0200 Subject: Solaris: Implement CWD column --- solaris/ProcessField.h | 2 +- solaris/SolarisProcess.c | 1 + solaris/SolarisProcessList.c | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) (limited to 'solaris') diff --git a/solaris/ProcessField.h b/solaris/ProcessField.h index 6af48772..727c641f 100644 --- a/solaris/ProcessField.h +++ b/solaris/ProcessField.h @@ -17,7 +17,7 @@ in the source distribution for its full text. CONTID = 105, \ LWPID = 106, \ \ - DUMMY_BUMP_FIELD = PROC_EXE, \ + DUMMY_BUMP_FIELD = CWD, \ // End of list diff --git a/solaris/SolarisProcess.c b/solaris/SolarisProcess.c index 713bc137..57071ab0 100644 --- a/solaris/SolarisProcess.c +++ b/solaris/SolarisProcess.c @@ -49,6 +49,7 @@ const ProcessFieldData Process_fields[LAST_PROCESSFIELD] = { [TGID] = { .name = "TGID", .title = "TGID", .description = "Thread group ID (i.e. process ID)", .flags = 0, .pidColumn = true, }, [PROC_COMM] = { .name = "COMM", .title = "COMM ", .description = "comm string of the process", .flags = 0, }, [PROC_EXE] = { .name = "EXE", .title = "EXE ", .description = "Basename of exe of the process", .flags = 0, }, + [CWD] = { .name = "CWD", .title = "CWD ", .description = "The current working directory of the process", .flags = PROCESS_FLAG_CWD, }, [ZONEID] = { .name = "ZONEID", .title = "ZONEID", .description = "Zone ID", .flags = 0, .pidColumn = true, }, [ZONE] = { .name = "ZONE", .title = "ZONE ", .description = "Zone name", .flags = 0, }, [PROJID] = { .name = "PROJID", .title = "PRJID", .description = "Project ID", .flags = 0, .pidColumn = true, }, diff --git a/solaris/SolarisProcessList.c b/solaris/SolarisProcessList.c index 15f2f41f..a496f9f5 100644 --- a/solaris/SolarisProcessList.c +++ b/solaris/SolarisProcessList.c @@ -309,6 +309,19 @@ static void SolarisProcessList_updateExe(pid_t pid, Process* proc) { Process_updateExe(proc, target); } +static void SolarisProcessList_updateCwd(pid_t pid, Process* proc) { + char path[32]; + xSnprintf(path, sizeof(path), "/proc/%d/cwd", pid); + + char target[PATH_MAX]; + ssize_t ret = readlink(path, target, sizeof(target) - 1); + if (ret <= 0) + return; + + target[ret] = '\0'; + free_and_xStrdup(&proc->procCwd, target); +} + /* NOTE: the following is a callback function of type proc_walk_f * and MUST conform to the appropriate definition in order * to work. See libproc(3LIB) on a Solaris or Illumos @@ -377,8 +390,13 @@ static int SolarisProcessList_walkproc(psinfo_t* _psinfo, lwpsinfo_t* _lwpsinfo, sproc->zname = SolarisProcessList_readZoneName(spl->kd, sproc); proc->user = UsersTable_getRef(pl->usersTable, proc->st_uid); SolarisProcessList_updateExe(_psinfo->pr_pid, proc); + Process_updateComm(proc, _psinfo->pr_fname); Process_updateCmdline(proc, _psinfo->pr_psargs, 0, 0); + + if (proc->settings->flags & PROCESS_FLAG_CWD) { + SolarisProcessList_updateCwd(_psinfo->pr_pid, proc); + } } // End common code pass 1 -- cgit v1.2.3