diff options
| -rw-r--r-- | .clangd | 5 | ||||
| -rw-r--r-- | .github/ISSUE_TEMPLATE/bug_report.yml | 2 | ||||
| -rw-r--r-- | .github/workflows/ci.yml | 19 | ||||
| -rw-r--r-- | CHANGELOG.md | 21 | ||||
| -rw-r--r-- | CONTRIBUTING.md | 17 | ||||
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | README.md | 21 | ||||
| -rw-r--r-- | buildenv | 56 | ||||
| -rw-r--r-- | whoson.c | 44 |
9 files changed, 156 insertions, 31 deletions
@@ -22,6 +22,11 @@ Diagnostics: - unknown_typename - incomplete_type - implicit_function_declaration + - implicit-function-declaration + - typecheck_decl_incomplete_type + - field_incomplete_or_sizeless + - no_member + - fatal_too_many_errors ClangTidy: # Use .clang-tidy; do not duplicate its checks here. FastCheckFilter: Strict diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index c32923f..597ea1a 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -30,7 +30,7 @@ body: id: version attributes: label: whoson --version - placeholder: whoson 1.0.0 + placeholder: whoson 1.1.0 validations: required: true diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0b30bfe..db6b52c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,3 +37,22 @@ jobs: # well formed. -n runs nothing. - run: make -n all - run: make -n install check list + + port: + name: zopen port + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + persist-credentials: false + # buildenv is sourced by zopen's shell, and the port's stable tarball + # must be the release this tree claims to be. + - run: sh -n buildenv + - name: buildenv matches VERSION + run: | + version=$(sed -n 's/^VERSION[[:space:]]*=[[:space:]]*//p' Makefile) + port=$(sed -n 's/^WHOSON_VERSION="\(.*\)"/\1/p' buildenv) + if [ "$version" != "$port" ]; then + echo "buildenv $port != Makefile $version" >&2 + exit 1 + fi diff --git a/CHANGELOG.md b/CHANGELOG.md index ac390e8..ef0b3df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,17 @@ # Changelog -## Unreleased +## 1.1.0 +Rewritten to read the system directly, and packaged as a zopen port. This is +the first release since 1.0.0; the entries below are the changes since then. + +- A `buildenv` makes the tree a zopen port: `zopen build` fetches the release +tarball, builds with the zopen clang, runs `make check` and installs under +`$ZOPEN_INSTALL_DIR`. The stable port and the GitHub release are the same +archive. +- The session table is sized from `ASVTMAXU` plus the number of processes, + and rows are no longer collapsed by ASID, so separate sessions that share an + address space (`_BPX_SHAREAS`) are all listed. - Rewritten without ZOAU and without a console display. Sessions are read straight out of common storage, walking CVT -> ASVT -> ASCB, which needs no APF authorization, no supervisor state and no key zero; SSH sessions come @@ -18,18 +28,21 @@ (falling back to `ASCBJBNS` when it is blank), and the logon procedure comes from the session's CSCB (`CHCLS`), not from `ASCBJBNS`. - `CPU` adds `ASSBASST` to `ASCBEJST` + `ASCBSRBT` and converts TOD units with - `>> 12`; the old rewrite multiplied by 1024, overstating CPU time by 2^22. + `>> 12`; the earlier code multiplied by 1024, overstating CPU time by 2^22. +- The ASVT walk validates each ASCB, and a fault while reading a terminated + address space skips that row instead of abending. All tables are allocated + after the scans that size them, so no fixed ceiling is left behind. - `SSH` rows come from the process tree (parent `sshd`, child not `sshd`), not from `-R`, so OpenSSH 9.8's `sshd-session` and unauthenticated preauth children are handled. Rows join to the ASCB by ASID. -- The ASVT walk sizes itself from `ASVTMAXU`, validates each ASCB, and a fault - while reading a terminated address space skips that row instead of abending. - Output follows the zopen character-set convention: files are tagged ISO8859-1 (CCSID 819) and receive ASCII; terminals, pipes and EBCDIC files are IBM-1047 with the runtime converting from ASCII (`F_CONTROL_CVT`). The same tag drives how `ps` output is read. - Requires z/OS 2.5 or later. Revises the tooling docs, CI comment and issue templates to drop ZOAU and the old console displays. +- The README lists what the table does not show: session start time, JES job + id, frames, swap state, CEA application tag and the SSH tty/remote host. ## 1.0.0 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4bc6455..784d2f6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -16,6 +16,17 @@ make install # -> ~/.local/bin/whoson Needs IBM Open XL C/C++ 2.2 (`ibm-clang`, pinned by absolute path in the `Makefile`) and z/OS 2.5 or later, the oldest target that compiler accepts. +`buildenv` is the zopen port. From a checkout or a release tree: + +```sh +zopen build # stable: the release tarball +zopen build -b DEV # the git tree on main +``` + +It builds with the compiler zopen detects, runs `make check`, and installs +`whoson` under `$ZOPEN_INSTALL_DIR`. Bump `WHOSON_VERSION` there with `VERSION` +in the `Makefile`; CI checks they agree. + GNU make and IBM's make both have to parse the Makefile: keep it to POSIX make syntax (`?=` is out), and let `make -n` stay free of side effects. @@ -40,11 +51,13 @@ syntax (`?=` is out), and let `make -n` stay free of side effects. ## Releasing -1. Bump `VERSION` in the `Makefile` and add the entry to `CHANGELOG.md`. +1. Bump `VERSION` in the `Makefile`, `WHOSON_VERSION` in `buildenv`, and add + the entry to `CHANGELOG.md`. 2. Merge, then tag `main` with `v<version>` and push the tag. 3. `.github/workflows/release.yml` refuses a tag that disagrees with `VERSION`, takes the release notes from that `CHANGELOG.md` section, and - attaches the source archive with its sha256. + attaches the source archive with its sha256. `buildenv` fetches that same + archive for the zopen stable build. There is no binary in a release: whoson only builds on z/OS, so a release ships the sources and the build instructions. @@ -34,7 +34,7 @@ PREFIX = $(HOME)/.local BINDIR = $(PREFIX)/bin # The release workflow refuses a tag that does not match this, and the binary # reports it through --version. -VERSION = 1.0.0 +VERSION = 1.1.0 CCDIR = /usr/lpp/IBM/cnw/v2r2/openxl/bin CC = $(CCDIR)/ibm-clang LISTFMT = $(CCDIR)/ibm-clang-listing-formatter @@ -53,7 +53,7 @@ units. ```sh whoson # the table -whoson --version # whoson 1.0.0 +whoson --version # whoson 1.1.0 whoson --help ``` @@ -89,6 +89,18 @@ Without the `chtag`, IBM's make reads the Makefile as one line and stops with Or from a checkout, `make install` straight away. It copies the binary to `~/.local/bin`; `PREFIX` moves it (`make PREFIX=/usr/local install`). +With [zopen][zopen-guide], from a checkout or a release tree: + +```sh +zopen build +``` + +`buildenv` in the repository root is the port: `zopen build` pulls the +release tarball (or the git tree on the DEV line), builds with the zopen +clang, runs `make check`, and installs `whoson` under `$ZOPEN_INSTALL_DIR`, +so it appears on `PATH` through the zopen configuration. No flags or +extra dependencies are needed. `zopen build -b DEV` builds `main`. + ## Build and run ```sh @@ -124,6 +136,7 @@ where `printf` and a raw `write()` each get one of the two wrong. Help and error text go through the same `emit()`. [zopen]: https://zopen.community/Guides/CommonSolutions +[zopen-guide]: https://zopen.community/Guides/Porting ## How the data is produced @@ -158,6 +171,12 @@ No display command and no subsystem interface is involved: - SSH rows need `w_getpsent()` visibility, as described under Requirements. Only pty logins have a `/etc/utmpx` record; whoson does not read it, so a session's tty and remote address are not shown. +- Not shown, because common storage does not carry them or reaching them + needs authority this program does not ask for: the session start time, the + JES job id, real frames in use, swapped-out or logon-in-progress state, the + CEA application tag, and the 3270 LU or TN3270 client address. A system + name column (for sysplex) and `otelnetd`/`orlogind` sessions are also not + handled yet. The offsets above are the ones the ASVT, ASCB, CSCB and ASSB macros on the system generate, and they were checked against a probe that read all 355 diff --git a/buildenv b/buildenv new file mode 100644 index 0000000..378fac1 --- /dev/null +++ b/buildenv @@ -0,0 +1,56 @@ +# zopen build configuration for whoson. +# +# The stable source is the release tarball, so the port builds exactly what +# the GitHub release ships. Bump WHOSON_VERSION together with Makefile's +# VERSION and the release tag; the CI job checks the first two agree. +# `zopen build -b DEV` uses the git tree instead. + +WHOSON_VERSION="1.1.0" + +export ZOPEN_PROJECT_NAME="whoson" +export ZOPEN_NAME="whoson" +export ZOPEN_BUILD_LINE="STABLE" +export ZOPEN_CATEGORIES="utilities monitoring" +export ZOPEN_STABLE_URL="https://github.com/skurtz97/whoson/releases/download/v${WHOSON_VERSION}/whoson-${WHOSON_VERSION}.tar.gz" +export ZOPEN_STABLE_DEPS="make" +export ZOPEN_DEV_URL="https://github.com/skurtz97/whoson.git" +export ZOPEN_DEV_TAG="main" +export ZOPEN_DEV_DEPS="make" +export ZOPEN_COMP="CLANG" +# whoson calls libc and POSIX only; zoslib would add a runtime dependency the +# package does not declare. +export ZOPEN_DONT_ADD_ZOSLIB_DEP="1" + +# Plain make, no configure script. +export ZOPEN_CONFIGURE="skip" + +# The Makefile pins its own compiler and flags, and zopen's injected CFLAGS +# would replace them. The port only passes the compiler zopen detected. +# These strings are eval'd at build time, when PATH and CC are set. +export ZOPEN_MAKE_MINIMAL="1" +export ZOPEN_MAKE_OPTS='CC=${CC:-clang}' +export ZOPEN_CHECK="make" +export ZOPEN_CHECK_OPTS='check CC=${CC:-clang}' +export ZOPEN_CHECK_MINIMAL="1" +export ZOPEN_INSTALL_OPTS='install CC=${CC:-clang} PREFIX=$ZOPEN_INSTALL_DIR' +export ZOPEN_INSTALL_MINIMAL="1" + +# `make check` runs the binary once: its only job is to prove the program +# starts and reads the control blocks on the build system. +zopen_check_results() +{ + chk="$1/$2_check.log" + if grep -q '^USER ' "$chk"; then + failures=0 + else + failures=1 + fi + echo "actualFailures:${failures}" + echo "totalTests:1" + echo "expectedFailures:0" +} + +zopen_get_version() +{ + echo "$WHOSON_VERSION" +} @@ -448,18 +448,20 @@ static int scan_one(unsigned idx, uint32_t entry, uint32_t entries, read_u64(ascb + (uint32_t)offsetof(struct ascb, ascbsrbt)); cscb = read_u32(ascb + (uint32_t)offsetof(struct ascb, ascbcscb)); tso = read_u32(ascb + (uint32_t)offsetof(struct ascb, ascbtsb)) != 0; - if (cscb != 0) { - uint32_t assb; + { + uint32_t assb = + read_u32(ascb + (uint32_t)offsetof(struct ascb, ascbassb)); + if (assb != 0) + tod += read_u64(assb + (uint32_t)offsetof(struct assb, assbasst)); + } + if (cscb != 0) { read_tagged_name(cscb + (uint32_t)offsetof(struct cscb, chkey), key, sizeof(key)); read_tagged_name(cscb + (uint32_t)offsetof(struct cscb, chcls), cls, sizeof(cls)); if (read_u8(cscb + (uint32_t)offsetof(struct cscb, chtrkid)) == 0x01) tso = true; - assb = read_u32(ascb + (uint32_t)offsetof(struct ascb, ascbassb)); - if (assb != 0) - tod += read_u64(assb + (uint32_t)offsetof(struct assb, assbasst)); } read_name(read_u32(ascb + (uint32_t)offsetof(struct ascb, ascbjbni)), tmp.job, sizeof(tmp.job)); @@ -984,7 +986,6 @@ static int collect(struct row *rows, size_t maxrows, const struct space *snap, unsigned maxu, const struct proc *procs, size_t nprocs, const struct pid_asid *map, size_t nmap) { size_t n = 0; - size_t ssh_start; unsigned i; size_t k; @@ -1003,15 +1004,12 @@ static int collect(struct row *rows, size_t maxrows, const struct space *snap, snap[i].logon[0] != '\0' ? snap[i].logon : "-"); n++; } - ssh_start = n; for (k = 0; k < nprocs && n < maxrows; k++) { const struct proc *parent; const struct pid_asid *pa; unsigned asid = 0; uint64_t us = 0; const char *job = "-"; - size_t r; - bool dup = false; parent = find_proc(procs, nprocs, procs[k].ppid); if (parent == NULL || !is_sshd(parent->name) || is_sshd(procs[k].name)) @@ -1023,14 +1021,6 @@ static int collect(struct row *rows, size_t maxrows, const struct space *snap, if (snap[asid - 1].job[0] != '\0') job = snap[asid - 1].job; } - if (asid != 0) { - for (r = ssh_start; r < n; r++) { - if (rows[r].asid == asid) - dup = true; - } - } - if (dup) - continue; rows[n].asid = asid; rows[n].tso = false; rows[n].us = us; @@ -1056,7 +1046,6 @@ int main(int argc, char **argv) { uint32_t entries; int nrows; int arg; - size_t bytes; size_t space_bytes; save_cvt(STDOUT_FILENO); @@ -1082,14 +1071,12 @@ int main(int argc, char **argv) { return 1; } space_bytes = (sizeof(struct space) + 15u) & ~(size_t)15u; - bytes = (size_t)maxu * (space_bytes + sizeof(struct row)); - snap = calloc(1, bytes); + snap = calloc(1, (size_t)maxu * space_bytes); if (snap == NULL) { unguard(); error_msg("whoson: out of memory for %u address spaces\n", maxu); return 1; } - rows = (struct row *)(void *)((char *)snap + (size_t)maxu * space_bytes); ascb_scan(entries, maxu, snap, &found); unguard(); if (found == 0) { @@ -1107,9 +1094,22 @@ int main(int argc, char **argv) { return 1; } qsort(map, nmap, sizeof(*map), cmp_pid_asid); - nrows = collect(rows, maxu, snap, maxu, procs, nprocs, map, nmap); + /* At most one TSO row per address space and one SSH row per process, so + * the table can hold both lists; maxu alone would drop SSH sessions on a + * system that shares address spaces (_BPX_SHAREAS). */ + rows = calloc((size_t)maxu + nprocs, sizeof(*rows)); + if (rows == NULL) { + error_msg("whoson: out of memory for the session table\n"); + free(procs); + free(map); + free(snap); + return 1; + } + nrows = collect(rows, (size_t)maxu + nprocs, snap, maxu, procs, nprocs, map, + nmap); qsort(rows, (size_t)nrows, sizeof(*rows), cmp_rows); print_rows(rows, (size_t)nrows); + free(rows); free(procs); free(map); free(snap); |
