ps: possibility to display seat for a process
Library systemd-login offers possibility to display name of seat for a session on multi-seat systems. This patch adds output option "sd_seat" which will show name of seat or "-", when name of seat can not be determined, but "seat0" should always exist. 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
38e8087d55
commit
7b50c2e918
21
ps/output.c
21
ps/output.c
@ -1258,6 +1258,26 @@ fail:
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int pr_sd_seat(char *restrict const outbuf, const proc_t *restrict const pp){
|
||||
int r;
|
||||
size_t len;
|
||||
char *session;
|
||||
char *seat;
|
||||
r = sd_pid_get_session(pp->tgid, &session);
|
||||
if(r<0) goto fail;
|
||||
r = sd_session_get_seat(session, &seat);
|
||||
free(session);
|
||||
if(r<0) goto fail;
|
||||
len = snprintf(outbuf, COLWID, "%s", seat);
|
||||
free(seat);
|
||||
return len;
|
||||
|
||||
fail:
|
||||
outbuf[0] = '-';
|
||||
outbuf[1] = '\0';
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif
|
||||
/****************** FLASK & seLinux security stuff **********************/
|
||||
// move the bulk of this to libproc sometime
|
||||
@ -1588,6 +1608,7 @@ static const format_struct format_array[] = {
|
||||
#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_seat", "SEAT", pr_sd_seat, 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_uunit", "UUNIT", pr_sd_uunit, sr_nop, 31, 0, LNX, ET|LEFT},
|
||||
|
Loading…
Reference in New Issue
Block a user