summaryrefslogtreecommitdiff
path: root/sysutils/tload/patches/patch-aa
blob: 1f595ed497d1528a1de1a09c42fd7fa6b0150973 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
$NetBSD: patch-aa,v 1.3 2003/09/23 08:47:18 wiz Exp $

--- tload.c.orig	Tue Sep  2 18:02:19 1997
+++ tload.c
@@ -34,6 +34,25 @@
 extern int optind;
 extern char *optarg;
 
+#ifndef linux
+void
+display_version(void)
+{
+	printf("procps 2.0.6, pkgsrc port\n");
+}
+
+
+int
+loadavg(double *l0, double *l1, double *l2)
+{
+	double l[3];
+	getloadavg(l, 3);
+	*l0 = l[0];
+	*l1 = l[1];
+	*l2 = l[2];
+}
+#endif
+
 void alrm(int n)
 {
     signal(SIGALRM, alrm);
@@ -74,6 +93,11 @@
     double av[3];
     static double max_scale, scale_fact;
     char *scale_arg = NULL;
+    static char hostname[256];
+    static char date[256];
+    time_t datet;
+    static char headl[256], headr[256];
+    int lenl, lenr;
 
     while ((opt = getopt(argc, argv, "s:d:V")) != -1)
 	switch (opt) {
@@ -94,6 +118,11 @@
 
     setsize(0);
 
+    if (gethostname(hostname, sizeof(hostname)) < 0) {
+	    perror(argv[optind]);
+	    exit(1);
+    }
+
     if (scale_arg)
       max_scale = atof(scale_arg);
     else
@@ -144,8 +173,13 @@
 	    for(row = nrows-2; row >= 0; --row)
 		*(screen + row * ncols + col) = ' ';
 	}
-	i = sprintf(screen, " %.2f, %.2f, %.2f",
-		av[0], av[1], av[2]);
+	datet = time(NULL);
+	strftime(date, sizeof(date), "%c", localtime(&datet));
+	lenr = sprintf(headr, "%s %s", hostname, date); 
+	lenl = sprintf(headl, " %.2f, %.2f, %.2f",
+		    av[0], av[1], av[2]);
+	i = sprintf(screen, "%s %*.s %s", headl,
+		    ncols - lenl - lenr - 2, "", headr);
 	if (i>0)
 	    screen[i] = ' ';