summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSean Kurtz <seankurtz75@gmail.com>2026-11-24 19:47:52 -0600
committerSean Kurtz <seankurtz75@gmail.com>2026-11-24 19:47:52 -0600
commit35629feea51aa60de182c7d56c3e2b7342d2fdb9 (patch)
tree2a0bfe34f1f8bb74c6b75d47d87bc8dcaf292b61
parente770f9ca9ef8e9b44f9f34752a397f059f58eaae (diff)
downloadwhoson-35629feea51aa60de182c7d56c3e2b7342d2fdb9.tar.gz
whoson: convert the opercmd display only when it is EBCDIC
A login shell has _TAG_REDIR_OUT=txt (/etc/profile:114), and with it in the environment opercmd returns the DISPLAY OMVS and DISPLAY TS output already in ASCII. run_display converted it to ASCII a second time, which mixed the two character sets, so both parsers found no rows and an interactive session printed the header and nothing else. Detect the character set of the response instead of assuming it: EBCDIC console text breaks lines with 0x15 and contains no '\n'. Verified on cbt against ZOAU 1.4: interactive zash (full table), the same with _TAG_REDIR_OUT=txt and stdout redirected, and the non-interactive path, which never had the tags.
-rw-r--r--whoson.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/whoson.c b/whoson.c
index 76340ad..1cc8ae7 100644
--- a/whoson.c
+++ b/whoson.c
@@ -16,9 +16,11 @@
* double quotes, "D TS,A". Unquoted, the D is taken for an option letter and
* the call fails with opercmd's usage text (rc 2). The program is built in
* ASCII character mode and passes the command in that mode; opercmd returns
- * the display itself in EBCDIC, so run_display converts each response. The
- * table leaves with write(2): CEE turns stdio output into EBCDIC on a
- * terminal, and sshd forwards that pty to the client untouched.
+ * the display in EBCDIC, or already in ASCII when _TAG_REDIR_OUT is txt, which
+ * every login shell here gets from /etc/profile. run_display converts only the
+ * response that needs converting. The table leaves with write(2): CEE turns
+ * stdio output into EBCDIC on a terminal, and sshd forwards that pty to the
+ * client untouched.
*
* A TSO/E session reports its own CPU time (CT), elapsed time (ET), job id
* (WUID/SCL/P) and region (RGP), so those columns need no second source. An
@@ -428,10 +430,19 @@ static int compare_rows(const void *a, const void *b)
return strcmp(x->asid, y->asid);
}
+/* Convert EBCDIC text to ASCII in place, leaving ASCII text alone: with
+ * _TAG_REDIR_OUT=txt in the environment opercmd answers in ASCII already.
+ * EBCDIC console text breaks lines with 0x15 and contains no '\n'. */
+static void to_ascii(char *buf, size_t len)
+{
+ if (memchr(buf, '\n', len) == NULL)
+ __e2a_l(buf, len);
+}
+
/* Run one display; returns 0 and a NUL-terminated copy of stdout, or -1.
* ASCII (the build's character mode), and quoted so that the whole command is
- * one argv element. The display that comes back is EBCDIC, so it is converted
- * to ASCII here before the parser sees it. */
+ * one argv element. The display is converted to ASCII here before the parser
+ * sees it. */
static int run_display(zoautil_vector4_t *vector, const char *args,
zoautil_options_t options, char **out)
{
@@ -455,8 +466,8 @@ static int run_display(zoautil_vector4_t *vector, const char *args,
response->stderr_len > 0) {
char text[MSG_LEN];
- __e2a_l(response->stderr_response,
- (size_t)response->stderr_len);
+ to_ascii(response->stderr_response,
+ (size_t)response->stderr_len);
snprintf(text, sizeof(text), "%.*s\n",
response->stderr_len,
response->stderr_response);
@@ -478,8 +489,8 @@ static int run_display(zoautil_vector4_t *vector, const char *args,
return -1;
}
memcpy(*out, response->stdout_response, (size_t)response->stdout_len);
- /* The display is EBCDIC; this program is ASCII. */
- __e2a_l(*out, (size_t)response->stdout_len);
+ /* This program is ASCII whatever the display came back as. */
+ to_ascii(*out, (size_t)response->stdout_len);
(*out)[response->stdout_len] = '\0';
free_response(response);
return 0;