Only suppress the path state column when producing traditional text output. When generating html output, always include the column. When generating json or xml output, only include the path state, if it is applicable.
This should address the issues raised by Alan.
Details
Diff Detail
- Repository
- rG FreeBSD src repository
- Lint
Lint Not Applicable - Unit
Tests Not Applicable
Event Timeline
| usr.bin/sockstat/sockstat.1 | ||
|---|---|---|
| 208–209 | This seems to conflict with what your commit message says. When using text, json, or xml, it is shown if applicable, but if using html, it is shown even if empty? | |
I too am confused by the commit message. Won't the column always be shown in json and xml output, if "-s" is used?
When using json or xml there are no columns. For each row, only the elements which makes sense are there. So we have:
tuexen@interop:~ % sockstat -wi USER COMMAND PID FD PROTO LOCAL ADDRESS FOREIGN ADDRESS ID tuexen sockstat 1937 6 stream ?? -> [1931 8] ?? tuexen sockstat 1936 6 stream ?? -> [1931 7] ?? tuexen sockstat 1935 6 stream ?? -> [1931 6] ?? tuexen sockstat 1934 6 stream ?? -> [1931 4] ?? tuexen sockstat 1931 4 stream ?? -> [1934 6] ?? tuexen sockstat 1931 6 stream ?? -> [1935 6] ?? tuexen sockstat 1931 7 stream ?? -> [1936 6] ?? tuexen sockstat 1931 8 stream ?? -> [1937 6] ?? tuexen sshd-sessi 1891 6 stream ?? -> [1879 8] ?? tuexen sshd-sessi 1891 7 tcp6 2a02:c6a0:4015:11::80:22 2a02:c6a0:4015:12:9de5:b43f:c4d:36d0:58101 29 tuexen sshd-sessi 1891 9 stream (not connected) ?? ?? root sshd-sessi 1879 7 tcp6 2a02:c6a0:4015:11::80:22 2a02:c6a0:4015:12:9de5:b43f:c4d:36d0:58101 29 root sshd-sessi 1879 8 stream ?? -> [1891 6] ?? root sshd-sessi 1879 9 stream (not connected) ?? ?? root sshd 1668 6 tcp6 *:22 *:* 5 root sshd 1668 7 tcp4 *:22 *:* 6 root syslogd 1447 15 stream ?? -> [1443 16] ?? root syslogd 1446 15 stream ?? -> [1443 14] ?? root syslogd 1443 6 dgram /var/run/log <- [1149 8] ?? root syslogd 1443 8 dgram /var/run/logpriv ?? ?? root syslogd 1443 14 stream ?? -> [1446 15] ?? root syslogd 1443 16 stream ?? -> [1447 15] ?? root devd 1149 4 stream /var/run/devd.pipe ?? ?? root devd 1149 5 seqpack /var/run/devd.seqpacket.pipe ?? ?? root devd 1149 8 dgram ?? -> /var/run/log ??
So you see a column ID, which has only valid entries for TCP sockets. If you compare this with
tuexen@interop:~ % sockstat --libxo json,pretty -i
{
"__version": "1",
"sockstat": {
"socket": [
{
"user": "tuexen",
"command": "sockstat",
"pid": 1944,
"fd": 6,
"proto": "stream",
"foreign": {
"connections": [
{
"pid": 1938,
"fd": 8
}
]
}
},
{
"user": "tuexen",
"command": "sockstat",
"pid": 1943,
"fd": 6,
"proto": "stream",
"foreign": {
"connections": [
{
"pid": 1938,
"fd": 7
}
]
}
},
{
"user": "tuexen",
"command": "sockstat",
"pid": 1942,
"fd": 6,
"proto": "stream",
"foreign": {
"connections": [
{
"pid": 1938,
"fd": 6
}
]
}
},
{
"user": "tuexen",
"command": "sockstat",
"pid": 1941,
"fd": 6,
"proto": "stream",
"foreign": {
"connections": [
{
"pid": 1938,
"fd": 4
}
]
}
},
{
"user": "tuexen",
"command": "sockstat",
"pid": 1938,
"fd": 4,
"proto": "stream",
"foreign": {
"connections": [
{
"pid": 1941,
"fd": 6
}
]
}
},
{
"user": "tuexen",
"command": "sockstat",
"pid": 1938,
"fd": 6,
"proto": "stream",
"foreign": {
"connections": [
{
"pid": 1942,
"fd": 6
}
]
}
},
{
"user": "tuexen",
"command": "sockstat",
"pid": 1938,
"fd": 7,
"proto": "stream",
"foreign": {
"connections": [
{
"pid": 1943,
"fd": 6
}
]
}
},
{
"user": "tuexen",
"command": "sockstat",
"pid": 1938,
"fd": 8,
"proto": "stream",
"foreign": {
"connections": [
{
"pid": 1944,
"fd": 6
}
]
}
},
{
"user": "tuexen",
"command": "sshd-session",
"pid": 1891,
"fd": 6,
"proto": "stream",
"foreign": {
"connections": [
{
"pid": 1879,
"fd": 8
}
]
}
},
{
"user": "tuexen",
"command": "sshd-session",
"pid": 1891,
"fd": 7,
"proto": "tcp6",
"local": {
"address": "2a02:c6a0:4015:11::80",
"port": 22
},
"foreign": {
"address": "2a02:c6a0:4015:12:9de5:b43f:c4d:36d0",
"port": 58101
},
"id": "29"
},
{
"user": "tuexen",
"command": "sshd-session",
"pid": 1891,
"fd": 9,
"proto": "stream"
},
{
"user": "root",
"command": "sshd-session",
"pid": 1879,
"fd": 7,
"proto": "tcp6",
"local": {
"address": "2a02:c6a0:4015:11::80",
"port": 22
},
"foreign": {
"address": "2a02:c6a0:4015:12:9de5:b43f:c4d:36d0",
"port": 58101
},
"id": "29"
},
{
"user": "root",
"command": "sshd-session",
"pid": 1879,
"fd": 8,
"proto": "stream",
"foreign": {
"connections": [
{
"pid": 1891,
"fd": 6
}
]
}
},
{
"user": "root",
"command": "sshd-session",
"pid": 1879,
"fd": 9,
"proto": "stream"
},
{
"user": "root",
"command": "sshd",
"pid": 1668,
"fd": 6,
"proto": "tcp6",
"local": {
"address": "*",
"port": 22
},
"foreign": {
"address": "*",
"port": 0
},
"id": "5"
},
{
"user": "root",
"command": "sshd",
"pid": 1668,
"fd": 7,
"proto": "tcp4",
"local": {
"address": "*",
"port": 22
},
"foreign": {
"address": "*",
"port": 0
},
"id": "6"
},
{
"user": "root",
"command": "syslogd",
"pid": 1447,
"fd": 15,
"proto": "stream",
"foreign": {
"connections": [
{
"pid": 1443,
"fd": 16
}
]
}
},
{
"user": "root",
"command": "syslogd",
"pid": 1446,
"fd": 15,
"proto": "stream",
"foreign": {
"connections": [
{
"pid": 1443,
"fd": 14
}
]
}
},
{
"user": "root",
"command": "syslogd",
"pid": 1443,
"fd": 6,
"proto": "dgram",
"local": {
"path": "/var/run/log"
},
"foreign": {
"connections": [
{
"pid": 1149,
"fd": 8
}
]
}
},
{
"user": "root",
"command": "syslogd",
"pid": 1443,
"fd": 8,
"proto": "dgram",
"local": {
"path": "/var/run/logpriv"
}
},
{
"user": "root",
"command": "syslogd",
"pid": 1443,
"fd": 14,
"proto": "stream",
"foreign": {
"connections": [
{
"pid": 1446,
"fd": 15
}
]
}
},
{
"user": "root",
"command": "syslogd",
"pid": 1443,
"fd": 16,
"proto": "stream",
"foreign": {
"connections": [
{
"pid": 1447,
"fd": 15
}
]
}
},
{
"user": "root",
"command": "devd",
"pid": 1149,
"fd": 4,
"proto": "stream",
"local": {
"path": "/var/run/devd.pipe"
}
},
{
"user": "root",
"command": "devd",
"pid": 1149,
"fd": 5,
"proto": "seqpacket",
"local": {
"path": "/var/run/devd.seqpacket.pipe"
}
},
{
"user": "root",
"command": "devd",
"pid": 1149,
"fd": 8,
"proto": "dgram",
"foreign": {
"path": "/var/run/log"
}
}
]
}
}you see that the id field is only present, when it is not ??.
Please note that in the SUMMARY field I just wanted to clearly describe the behavior. The commit message will only be the first two sentences of the SUMMARY, since that describes the change. The last sentence was just to describe what happens anyway. My changes do not impact xml or json output.
| usr.bin/sockstat/sockstat.1 | ||
|---|---|---|
| 208–209 | If using traditional text, the path state is suppressed if it is empty (meaning all entries are ??). If the output is HTML, the column is shown no matter if it is empty. JSON and XML only show values, if there are applicable. I am not changing that. | |