ps: possibility to display machine name for a process
Library systemd-login offers possibility to display the name of the VM or container which process belongs to. This patch adds output option "sd_machine" which will show machine name or "-" when the name can not be determined. To maintain compatibility with non-systemd systems, procps must be configured with --with-systemd option to enable this option.
This commit is contained in:
parent
785776c10d
commit
4c1536d5f1
@ -269,8 +269,8 @@ AC_ARG_WITH([systemd],
|
|||||||
[], [with_systemd=no])
|
[], [with_systemd=no])
|
||||||
|
|
||||||
if test "x$with_systemd" != xno; then
|
if test "x$with_systemd" != xno; then
|
||||||
PKG_CHECK_MODULES([SYSTEMD], [libsystemd-login], [], [
|
PKG_CHECK_MODULES([SYSTEMD], [libsystemd-login >= 202], [], [
|
||||||
AC_CHECK_LIB(systemd-login, sd_pid_get_unit, [have_systemd=yes], [have_systemd=no])
|
AC_CHECK_LIB(systemd-login, sd_pid_get_machine_name, [have_systemd=yes], [have_systemd=no])
|
||||||
if test "x$have_systemd" = xno; then
|
if test "x$have_systemd" = xno; then
|
||||||
AC_MSG_ERROR([systemd support missing/incomplete])
|
AC_MSG_ERROR([systemd support missing/incomplete])
|
||||||
fi
|
fi
|
||||||
|
16
ps/output.c
16
ps/output.c
@ -1224,7 +1224,22 @@ fail:
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int pr_sd_machine(char *restrict const outbuf, const proc_t *restrict const pp){
|
||||||
|
int r;
|
||||||
|
size_t len;
|
||||||
|
char *machine;
|
||||||
|
|
||||||
|
r = sd_pid_get_machine_name(pp->tgid, &machine);
|
||||||
|
if(r<0) goto fail;
|
||||||
|
len = snprintf(outbuf, COLWID, "%s", machine);
|
||||||
|
free(machine);
|
||||||
|
return len;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
outbuf[0] = '-';
|
||||||
|
outbuf[1] = '\0';
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
/****************** FLASK & seLinux security stuff **********************/
|
/****************** FLASK & seLinux security stuff **********************/
|
||||||
// move the bulk of this to libproc sometime
|
// move the bulk of this to libproc sometime
|
||||||
@ -1553,6 +1568,7 @@ static const format_struct format_array[] = {
|
|||||||
{"scnt", "SCNT", pr_nop, sr_nop, 4, 0, DEC, AN|RIGHT}, /* man page misspelling of scount? */
|
{"scnt", "SCNT", pr_nop, sr_nop, 4, 0, DEC, AN|RIGHT}, /* man page misspelling of scount? */
|
||||||
{"scount", "SC", pr_nop, sr_nop, 4, 0, AIX, AN|RIGHT}, /* scnt==scount, DEC claims both */
|
{"scount", "SC", pr_nop, sr_nop, 4, 0, AIX, AN|RIGHT}, /* scnt==scount, DEC claims both */
|
||||||
#ifdef WITH_SYSTEMD
|
#ifdef WITH_SYSTEMD
|
||||||
|
{"sd_machine","MACHINE", pr_sd_machine, sr_nop, 31, 0, LNX, ET|LEFT},
|
||||||
{"sd_ouid", "OWNER", pr_sd_ouid, sr_nop, 5, 0, LNX, ET|LEFT},
|
{"sd_ouid", "OWNER", pr_sd_ouid, sr_nop, 5, 0, LNX, ET|LEFT},
|
||||||
{"sd_session","SESSION", pr_sd_session, sr_nop, 11, 0, LNX, ET|LEFT},
|
{"sd_session","SESSION", pr_sd_session, sr_nop, 11, 0, LNX, ET|LEFT},
|
||||||
{"sd_unit", "UNIT", pr_sd_unit, sr_nop, 31, 0, LNX, ET|LEFT},
|
{"sd_unit", "UNIT", pr_sd_unit, sr_nop, 31, 0, LNX, ET|LEFT},
|
||||||
|
4
ps/ps.1
4
ps/ps.1
@ -1489,6 +1489,10 @@ SCHED_FIFO, SCHED_RR, SCHED_BATCH, SCHED_ISO, and SCHED_IDLE are respectively
|
|||||||
displayed as 0, 1, 2, 3, 4, and 5.
|
displayed as 0, 1, 2, 3, 4, and 5.
|
||||||
T}
|
T}
|
||||||
|
|
||||||
|
sd_machine MACHINE T{
|
||||||
|
displays machine name for processes assigned to VM or container.
|
||||||
|
T}
|
||||||
|
|
||||||
sd_ouid OWNER T{
|
sd_ouid OWNER T{
|
||||||
displays the Unix user identifier of the owner of the session of a process.
|
displays the Unix user identifier of the owner of the session of a process.
|
||||||
T}
|
T}
|
||||||
|
Loading…
Reference in New Issue
Block a user