Debian Codegraph @

debian/patches/w_no_crash_short

raw symbols SCIP
1 Description: ps: Don't crash when using short option
2 ps would crash with the -si or -sf options with systemd enabled.
3 The issue was the utmp wasn't filled in, the long option checked, the
4 short option did not.
5 .
6 Refactored the showinfo() function so instead of a branch with duplicate
7 prints for the items in both long and short we just branch on the items
8 for long output.
9 .
10 Also, made the function prototypes not dependendent on systemd enabled,
11 it was too messy that way and passing a char* NULL is not really going
12 to hurt anything
13 Author: Craig Small <[email protected]>
14 Origin: upstream, https://gitlab.com/procps-ng/procps/-/commit/79042e07fab9956135a21b1df7a69d1fbde7ef79
15 Bug: https://gitlab.com/procps-ng/procps/-/issues/301
16 Applied-Upstream: 4.0.5
17 Reviewed-by: Craig Small <[email protected]>
18 Last-Update: 2025-04-13
19 ---
20 This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
21 --- a/src/w.c
22 +++ b/src/w.c
23 @@ -207,9 +207,7 @@
24
25 /* This routine prints either the hostname or the IP address of the remote */
26 static void print_from(
27 -#if (defined(WITH_SYSTEMD) || defined(WITH_ELOGIND)) && defined(HAVE_SD_SESSION_GET_LEADER)
28 const char *session,
29 -#endif
30 const utmp_t *restrict const u, const int ip_addresses, const int fromlen) {
31 #if (defined(WITH_SYSTEMD) || defined(WITH_ELOGIND)) && defined(HAVE_SD_SESSION_GET_LEADER)
32 if (session) {
33 @@ -508,11 +506,10 @@
34 #undef PIDS_GETSTR
35 }
36
37 +
38 static void showinfo(
39 -#if (defined(WITH_SYSTEMD) || defined(WITH_ELOGIND)) && defined(HAVE_SD_SESSION_GET_LEADER)
40 const char *session, const char *name,
41 -#endif
42 - utmp_t * u, int formtype, int maxcmd, int from,
43 + utmp_t * u, const int longform, int maxcmd, int from,
44 const int userlen, const int fromlen, const int ip_addresses,
45 const int pids)
46 {
47 @@ -575,25 +572,20 @@
48 /* force NUL term for printf */
49 uname[UT_NAMESIZE] = '\0';
50
51 - if (formtype) {
52 - printf("%-*.*s%-9.8s", userlen + 1, userlen, uname, tty + 5);
53 + printf("%-*.*s%-9.8s", userlen + 1, userlen, uname, tty + 5);
54 + if (from)
55 + print_from(session, NULL, ip_addresses, fromlen);
56 +
57 + /* login time */
58 + if (longform) {
59 #if (defined(WITH_SYSTEMD) || defined(WITH_ELOGIND)) && defined(HAVE_SD_SESSION_GET_LEADER)
60 if (session) {
61 uint64_t ltime;
62
63 - if (from)
64 - print_from(session, NULL, ip_addresses, fromlen);
65 -
66 sd_session_get_start_time(session, &ltime);
67 print_logintime(ltime/((uint64_t) 1000000ULL), stdout);
68 } else {
69 #endif
70 - if (from)
71 - print_from(
72 -#if (defined(WITH_SYSTEMD) || defined(WITH_ELOGIND)) && defined(HAVE_SD_SESSION_GET_LEADER)
73 - NULL,
74 -#endif
75 - u, ip_addresses, fromlen);
76
77 #ifdef HAVE_UTMPX_H
78 print_logintime(u->ut_tv.tv_sec, stdout);
79 @@ -603,11 +595,16 @@
80 #if (defined(WITH_SYSTEMD) || defined(WITH_ELOGIND)) && defined(HAVE_SD_SESSION_GET_LEADER)
81 }
82 #endif
83 - if (u && *u->ut_line == ':')
84 - /* idle unknown for xdm logins */
85 - printf(" ?xdm? ");
86 - else
87 - print_time_ival7(idletime(tty), 0, stdout);
88 + }
89 + /* idle */
90 + if (u && *u->ut_line == ':')
91 + /* idle unknown for xdm logins */
92 + printf(" ?xdm? ");
93 + else
94 + print_time_ival7(idletime(tty), 0, stdout);
95 +
96 + /* jpcpu/pcpu */
97 + if (longform) {
98 print_time_ival7(jcpu / hertz, (jcpu % hertz) * (100. / hertz),
99 stdout);
100 if (pcpu > 0)
101 @@ -616,20 +613,8 @@
102 stdout);
103 else
104 printf(" ? ");
105 - } else {
106 - printf("%-*.*s%-9.8s", userlen + 1, userlen, uname, tty + 5);
107 - if (from)
108 - print_from(
109 -#if (defined(WITH_SYSTEMD) || defined(WITH_ELOGIND)) && defined(HAVE_SD_SESSION_GET_LEADER)
110 - NULL,
111 -#endif
112 - u, ip_addresses, fromlen);
113 - if (u && *u->ut_line == ':')
114 - /* idle unknown for xdm logins */
115 - printf(" ?xdm? ");
116 - else
117 - print_time_ival7(idletime(tty), 0, stdout);
118 }
119 + /* what */
120 if (pids) {
121 pid_t ut_pid = -1;
122 if (u)
123 @@ -798,9 +783,9 @@
124 * headers. Try to keep alignment intact. */
125 printf(_("%-*s TTY "), userlen, _("USER"));
126 if (from)
127 - printf("%-*s", fromlen - 1, _("FROM"));
128 + printf("%-*s", fromlen, _("FROM"));
129 if (longform)
130 - printf(_(" LOGIN@ IDLE JCPU PCPU WHAT\n"));
131 + printf(_(" LOGIN@ IDLE JCPU PCPU WHAT\n"));
132 else
133 printf(_(" IDLE WHAT\n"));
134 }
135 @@ -857,9 +842,7 @@
136 continue;
137 if (!strncmp(u->ut_user, user, UT_NAMESIZE))
138 showinfo(
139 -#if (defined(WITH_SYSTEMD) || defined(WITH_ELOGIND)) && defined(HAVE_SD_SESSION_GET_LEADER)
140 NULL, NULL,
141 -#endif
142 u, longform, maxcmd, from, userlen,
143 fromlen, ip_addresses, pids);
144 }
145 @@ -876,9 +859,7 @@
146 continue;
147 if (*u->ut_user)
148 showinfo(
149 -#if (defined(WITH_SYSTEMD) || defined(WITH_ELOGIND)) && defined(HAVE_SD_SESSION_GET_LEADER)
150 NULL, NULL,
151 -#endif
152 u, longform, maxcmd, from, userlen,
153 fromlen, ip_addresses, pids);
154 }