Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

systat(1) hostname

1 view
Skip to first unread message

Otto Moerbeek

unread,
Oct 12, 2016, 9:20:33 AM10/12/16
to te...@openbsd.org

Hi,

simple diff to show the hostname on the second line. OK?

BTW, batch mode doesn't function here as expected. Need to look into that,

-Otto

Index: main.c
===================================================================
RCS file: /cvs/src/usr.bin/systat/main.c,v
retrieving revision 1.64
diff -u -p -r1.64 main.c
--- main.c 2 Jan 2016 15:02:05 -0000 1.64
+++ main.c 8 Oct 2016 13:34:07 -0000
@@ -124,8 +124,10 @@ print_header(void)

if (rawmode)
printf("\n\n%s\n", header);
- else
+ else {
mvprintw(0, 0, "%s", header);
+ mvprintw(1, 1, "%s", hostname);
+ }

return (1);
}

Alexander Bluhm

unread,
Oct 12, 2016, 4:52:39 PM10/12/16
to Otto Moerbeek, te...@openbsd.org
On Wed, Oct 12, 2016 at 03:20:00PM +0200, Otto Moerbeek wrote:
> simple diff to show the hostname on the second line. OK?

OK bluhm@

Theo de Raadt

unread,
Oct 12, 2016, 11:52:52 PM10/12/16
to Alexander Bluhm, Otto Moerbeek, te...@openbsd.org
> On Wed, Oct 12, 2016 at 03:20:00PM +0200, Otto Moerbeek wrote:
> > simple diff to show the hostname on the second line. OK?
>
> OK bluhm@
>
> >
> > BTW, batch mode doesn't function here as expected. Need to look into that,

I hoped this would look more like top(1) so I did it a different way.
This does not work quite right for long hostnames, but then.. neither
does top.

Shrug.

Index: main.c
===================================================================
RCS file: /cvs/src/usr.bin/systat/main.c,v
retrieving revision 1.64
diff -u -p -u -r1.64 main.c
--- main.c 2 Jan 2016 15:02:05 -0000 1.64
+++ main.c 13 Oct 2016 03:50:16 -0000
@@ -67,7 +67,7 @@ int ut, hz, stathz;
char hostname[HOST_NAME_MAX+1];
WINDOW *wnd;
int CMDLINE;
-char timebuf[26];
+char hostbuf[26];
char uloadbuf[TIMEPOS];


@@ -101,14 +101,21 @@ print_header(void)
tb_start();

if (!paused) {
+ char *ctim;
+
getloadavg(avenrun, sizeof(avenrun) / sizeof(avenrun[0]));

snprintf(uloadbuf, sizeof(uloadbuf),
"%5d users Load %.2f %.2f %.2f",
ucount(), avenrun[0], avenrun[1], avenrun[2]);

+ gethostname(hostbuf, sizeof hostbuf);
+ strlcat(hostbuf, " ", sizeof hostbuf);
+
time(&now);
- strlcpy(timebuf, ctime(&now), sizeof(timebuf));
+ ctim = ctime(&now);
+ ctim[11+8] = '\0';
+ strlcat(hostbuf, ctim + 11, sizeof(hostbuf));
}

if (num_disp && (start > 1 || end != num_disp))
@@ -120,7 +127,7 @@ print_header(void)
"%s %s", uloadbuf,
paused ? "PAUSED" : "");

- snprintf(header, sizeof(header), "%-55s%s", tmpbuf, timebuf);
+ snprintf(header, sizeof(header), "%-55s%s", tmpbuf, hostbuf);

Ted Unangst

unread,
Oct 13, 2016, 12:16:04 AM10/13/16
to Theo de Raadt, Alexander Bluhm, Otto Moerbeek, te...@openbsd.org
Theo de Raadt wrote:
> > On Wed, Oct 12, 2016 at 03:20:00PM +0200, Otto Moerbeek wrote:
> > > simple diff to show the hostname on the second line. OK?
> >
> > OK bluhm@
> >
> > >
> > > BTW, batch mode doesn't function here as expected. Need to look into that,
>
> I hoped this would look more like top(1) so I did it a different way.
> This does not work quite right for long hostnames, but then.. neither
> does top.

this truncates hostname to always display time.


Index: main.c
===================================================================
RCS file: /cvs/src/usr.bin/systat/main.c,v
retrieving revision 1.64
diff -u -p -r1.64 main.c
--- main.c 2 Jan 2016 15:02:05 -0000 1.64
+++ main.c 13 Oct 2016 04:13:45 -0000
@@ -67,6 +67,7 @@ int ut, hz, stathz;
char hostname[HOST_NAME_MAX+1];
WINDOW *wnd;
int CMDLINE;
+char hostbuf[26];
char timebuf[26];
char uloadbuf[TIMEPOS];

@@ -101,14 +102,20 @@ print_header(void)
tb_start();

if (!paused) {
+ char *ctim;
+
getloadavg(avenrun, sizeof(avenrun) / sizeof(avenrun[0]));

snprintf(uloadbuf, sizeof(uloadbuf),
"%5d users Load %.2f %.2f %.2f",
ucount(), avenrun[0], avenrun[1], avenrun[2]);

+ gethostname(hostbuf, sizeof hostbuf);
+
time(&now);
- strlcpy(timebuf, ctime(&now), sizeof(timebuf));
+ ctim = ctime(&now);
+ ctim[11+8] = '\0';
+ strlcpy(timebuf, ctim + 11, sizeof(timebuf));
}

if (num_disp && (start > 1 || end != num_disp))
@@ -120,7 +127,7 @@ print_header(void)
"%s %s", uloadbuf,
paused ? "PAUSED" : "");

- snprintf(header, sizeof(header), "%-55s%s", tmpbuf, timebuf);
+ snprintf(header, sizeof(header), "%-45s%s %s", tmpbuf, hostbuf, timebuf);

Otto Moerbeek

unread,
Oct 13, 2016, 2:01:57 AM10/13/16
to Ted Unangst, Theo de Raadt, Alexander Bluhm, te...@openbsd.org
On Thu, Oct 13, 2016 at 12:15:34AM -0400, Ted Unangst wrote:

> Theo de Raadt wrote:
> > > On Wed, Oct 12, 2016 at 03:20:00PM +0200, Otto Moerbeek wrote:
> > > > simple diff to show the hostname on the second line. OK?
> > >
> > > OK bluhm@
> > >
> > > >
> > > > BTW, batch mode doesn't function here as expected. Need to look into that,
> >
> > I hoped this would look more like top(1) so I did it a different way.
> > This does not work quite right for long hostnames, but then.. neither
> > does top.
>
> this truncates hostname to always display time.

If the line grows (because of multiple pages and/or PAUSED mode), the
line wraps now.... Also, we have hostname already available in a
buffer.

-Otto

Index: main.c
===================================================================
RCS file: /cvs/src/usr.bin/systat/main.c,v
retrieving revision 1.64
diff -u -p -r1.64 main.c
--- main.c 2 Jan 2016 15:02:05 -0000 1.64
+++ main.c 13 Oct 2016 05:59:32 -0000
@@ -101,6 +101,8 @@ print_header(void)
tb_start();

if (!paused) {
+ char *ctim;
+
getloadavg(avenrun, sizeof(avenrun) / sizeof(avenrun[0]));

snprintf(uloadbuf, sizeof(uloadbuf),
@@ -108,7 +110,9 @@ print_header(void)
ucount(), avenrun[0], avenrun[1], avenrun[2]);

time(&now);
- strlcpy(timebuf, ctime(&now), sizeof(timebuf));
+ ctim = ctime(&now);
+ ctim[11+8] = '\0';
+ strlcpy(timebuf, ctim + 11, sizeof(timebuf));
}

if (num_disp && (start > 1 || end != num_disp))
@@ -120,7 +124,8 @@ print_header(void)
"%s %s", uloadbuf,
paused ? "PAUSED" : "");

- snprintf(header, sizeof(header), "%-55s%s", tmpbuf, timebuf);
+ snprintf(header, sizeof(header), "%-44s %.15s %s", tmpbuf, hostname,
+ timebuf);

Otto Moerbeek

unread,
Oct 13, 2016, 2:21:26 AM10/13/16
to Ted Unangst, Theo de Raadt, Alexander Bluhm, te...@openbsd.org
On Thu, Oct 13, 2016 at 08:01:22AM +0200, Otto Moerbeek wrote:

> On Thu, Oct 13, 2016 at 12:15:34AM -0400, Ted Unangst wrote:
>
> > Theo de Raadt wrote:
> > > > On Wed, Oct 12, 2016 at 03:20:00PM +0200, Otto Moerbeek wrote:
> > > > > simple diff to show the hostname on the second line. OK?
> > > >
> > > > OK bluhm@
> > > >
> > > > >
> > > > > BTW, batch mode doesn't function here as expected. Need to look into that,
> > >
> > > I hoped this would look more like top(1) so I did it a different way.
> > > This does not work quite right for long hostnames, but then.. neither
> > > does top.
> >
> > this truncates hostname to always display time.
>
> If the line grows (because of multiple pages and/or PAUSED mode), the
> line wraps now.... Also, we have hostname already available in a
> buffer.
>
> -Otto
>

new diff against current:

Index: main.c
===================================================================
RCS file: /cvs/src/usr.bin/systat/main.c,v
retrieving revision 1.65
diff -u -p -r1.65 main.c
--- main.c 13 Oct 2016 05:46:20 -0000 1.65
+++ main.c 13 Oct 2016 06:20:30 -0000
@@ -67,7 +67,6 @@ int ut, hz, stathz;
char hostname[HOST_NAME_MAX+1];
WINDOW *wnd;
int CMDLINE;
-char hostbuf[26];
char timebuf[26];
char uloadbuf[TIMEPOS];

@@ -110,8 +109,6 @@ print_header(void)
"%5d users Load %.2f %.2f %.2f",
ucount(), avenrun[0], avenrun[1], avenrun[2]);

- gethostname(hostbuf, sizeof hostbuf);
-
time(&now);
ctim = ctime(&now);
ctim[11+8] = '\0';
@@ -127,7 +124,8 @@ print_header(void)
"%s %s", uloadbuf,
paused ? "PAUSED" : "");

- snprintf(header, sizeof(header), "%-45s%25.25s %s", tmpbuf, hostbuf, timebuf);
+ snprintf(header, sizeof(header), "%-44s %15.15s %s", tmpbuf, hostname,

Otto Moerbeek

unread,
Oct 13, 2016, 5:08:07 AM10/13/16
to Ted Unangst, Theo de Raadt, Alexander Bluhm, te...@openbsd.org
On Thu, Oct 13, 2016 at 08:20:52AM +0200, Otto Moerbeek wrote:

> On Thu, Oct 13, 2016 at 08:01:22AM +0200, Otto Moerbeek wrote:
>
> > On Thu, Oct 13, 2016 at 12:15:34AM -0400, Ted Unangst wrote:
> >
> > > Theo de Raadt wrote:
> > > > > On Wed, Oct 12, 2016 at 03:20:00PM +0200, Otto Moerbeek wrote:
> > > > > > simple diff to show the hostname on the second line. OK?
> > > > >
> > > > > OK bluhm@
> > > > >
> > > > > >
> > > > > > BTW, batch mode doesn't function here as expected. Need to look into that,
> > > >
> > > > I hoped this would look more like top(1) so I did it a different way.
> > > > This does not work quite right for long hostnames, but then.. neither
> > > > does top.
> > >
> > > this truncates hostname to always display time.
> >
> > If the line grows (because of multiple pages and/or PAUSED mode), the
> > line wraps now.... Also, we have hostname already available in a
> > buffer.
> >
> > -Otto
> >
>

And squeeze the users/Load info a bit.

-Otto

Index: main.c
===================================================================
RCS file: /cvs/src/usr.bin/systat/main.c,v
retrieving revision 1.65
diff -u -p -r1.65 main.c
--- main.c 13 Oct 2016 05:46:20 -0000 1.65
+++ main.c 13 Oct 2016 09:05:40 -0000
@@ -52,7 +52,7 @@
#include "engine.h"
#include "systat.h"

-#define TIMEPOS 55
+#define TIMEPOS (80 - 8 - 20 - 1)

double dellave;

@@ -67,7 +67,6 @@ int ut, hz, stathz;
char hostname[HOST_NAME_MAX+1];
WINDOW *wnd;
int CMDLINE;
-char hostbuf[26];
char timebuf[26];
char uloadbuf[TIMEPOS];

@@ -107,11 +106,9 @@ print_header(void)
getloadavg(avenrun, sizeof(avenrun) / sizeof(avenrun[0]));

snprintf(uloadbuf, sizeof(uloadbuf),
- "%5d users Load %.2f %.2f %.2f",
+ "%4d users Load %.2f %.2f %.2f",
ucount(), avenrun[0], avenrun[1], avenrun[2]);

- gethostname(hostbuf, sizeof hostbuf);
-
time(&now);
ctim = ctime(&now);
ctim[11+8] = '\0';
@@ -127,7 +124,8 @@ print_header(void)
"%s %s", uloadbuf,
paused ? "PAUSED" : "");

- snprintf(header, sizeof(header), "%-45s%25.25s %s", tmpbuf, hostbuf, timebuf);
+ snprintf(header, sizeof(header), "%-*s %19.19s %s", TIMEPOS - 1,
+ tmpbuf, hostname, timebuf);

Ted Unangst

unread,
Oct 13, 2016, 7:13:49 AM10/13/16
to Otto Moerbeek, Theo de Raadt, Alexander Bluhm, te...@openbsd.org
Otto Moerbeek wrote:
> On Thu, Oct 13, 2016 at 08:20:52AM +0200, Otto Moerbeek wrote:
>
> > On Thu, Oct 13, 2016 at 08:01:22AM +0200, Otto Moerbeek wrote:
> >
> > > On Thu, Oct 13, 2016 at 12:15:34AM -0400, Ted Unangst wrote:
> > >
> > > > Theo de Raadt wrote:
> > > > > > On Wed, Oct 12, 2016 at 03:20:00PM +0200, Otto Moerbeek wrote:
> > > > > > > simple diff to show the hostname on the second line. OK?
> > > > > >
> > > > > > OK bluhm@
> > > > > >
> > > > > > >
> > > > > > > BTW, batch mode doesn't function here as expected. Need to look into that,
> > > > >
> > > > > I hoped this would look more like top(1) so I did it a different way.
> > > > > This does not work quite right for long hostnames, but then.. neither
> > > > > does top.
> > > >
> > > > this truncates hostname to always display time.
> > >
> > > If the line grows (because of multiple pages and/or PAUSED mode), the
> > > line wraps now.... Also, we have hostname already available in a
> > > buffer.
> > >
> > > -Otto
> > >
> >
>
> And squeeze the users/Load info a bit.

that looks good
0 new messages