Re: pvclock(4)

2018-11-24 Thread Greg Steuck
I realize this report is practically useless, but better out than in
(according to Shrek).
I found this in the logs of my GCE VM running syzkaller bot. No further
details were preserved...

2018/11/24 09:53:48 ci-openbsd-main: poll:
94bf4886dbb69e9fbf0f92f975fc23f16fc5c80f
2018/11/24 09:53:48 ci-openbsd-main: building kernel...
2018/11/24 09:54:03 ci-openbsd-main: testing image...
2018/11/24 10:04:07 ci-openbsd-main: VM boot failed with: panic: pvclock0:
unstable result on stable clock

The host is running
OpenBSD 6.4-current (GENERIC.MP) #456: Tue Nov 20 08:46:59 MST 2018
dera...@amd64.openbsd.org:/usr/src/sys/arch/amd64/compile/GENERIC.MP

The VM kernel at the time was built at "zap 10 tab leading whitespace
before 'struct evp_pkey_ctx_st {'", so maybe "only attach pvclock(4) inside
a KVM guest" would've fixed it?

Thanks
Greg


diff: ftpd(8): fix for sign-compare compiler warnings

2018-11-24 Thread Jan Klemkow
Hi,

This diff fixes some -Wsign-compare compiler warnings in ftpd(8) by
using the right types for 'i' and 'len'.  One warning is left, but I
don't see that it's fixable without suppressing the warning by a cast of
len to size_t.  And casting might be controversial in this case?!

/usr/src/libexec/ftpd/ftpd.c:2781:11: warning: comparison of integers of
different signs: 'int' and
  'unsigned long' [-Wsign-compare]
if (len >= sizeof(buf) || len == -1) {
~~~ ^  ~~~

Bye,
Jan

Index: ftpd.c
===
RCS file: /cvs/src/libexec/ftpd/ftpd.c,v
retrieving revision 1.223
diff -u -p -r1.223 ftpd.c
--- ftpd.c  3 Sep 2016 15:00:48 -   1.223
+++ ftpd.c  24 Nov 2018 22:26:02 -
@@ -390,10 +390,10 @@ main(int argc, char *argv[])
endpwent();
 
if (daemon_mode) {
-   int *fds, i, fd;
+   int *fds, fd;
struct pollfd *pfds;
struct addrinfo hints, *res, *res0;
-   nfds_t n;
+   nfds_t n, i;
 
/*
 * Detach from parent.
@@ -1809,8 +1809,8 @@ statcmd(void)
ispassive++;
goto printaddr;
} else if (usedefault == 0) {
-   size_t alen;
-   int af, i;
+   size_t alen, i;
+   int af;
 
su = (union sockunion *)_dest;
 printaddr:
@@ -2545,7 +2545,8 @@ guniquefd(char *local, char **nam)
 {
static char new[PATH_MAX];
struct stat st;
-   int count, len, fd;
+   size_t len;
+   int count, fd;
char *cp;
 
cp = strrchr(local, '/');



top: allow reverse sort order

2018-11-24 Thread Klemens Nanni
Sometimes I want to see certain programs with least amount of memory,
so this diff implements `o -field' to sort in reverse order.

The logic is straight forward:

1. merge common code from argument and command loops into new setorder()
2. introduce global state `rev_order' (set in the helper)
3. move identical code to set up process objects from compare_*()
   functions into SETORDER macro using global boolean

compare_*() are used by qsort(3). To sort in reverse, the macro simply
swaps the objects used by the ORDERKEY_* macros. That is it inverts the
comparison from `p1 > p2' into `p2 > p1' respectively `p1 < p2'.

Works fine for all available fields on amd64, no behaviour change for
"normal" order.


Feedback? Objections?

Index: display.c
===
RCS file: /cvs/src/usr.bin/top/display.c,v
retrieving revision 1.57
diff -u -p -r1.57 display.c
--- display.c   17 Nov 2018 23:10:08 -  1.57
+++ display.c   24 Nov 2018 14:09:38 -
@@ -817,7 +817,8 @@ show_help(void)
"I | i- toggle the display of idle processes\n"
"k [-sig] pid - send signal `-sig' to process `pid'\n"
"n|# count- show `count' processes\n"
-   "o field  - specify sort order (size, res, cpu, time, pri, pid, 
command)\n"
+   "o [-]field   - specify sort order (size, res, cpu, time, pri, pid, 
command)\n"
+   "   (o -field sorts in reverse)\n"
"P pid- highlight process `pid' (P+ switches highlighting 
off)\n"
"p pid- display process by `pid' (p+ selects all 
processes)\n"
"q- quit\n"
Index: machine.c
===
RCS file: /cvs/src/usr.bin/top/machine.c,v
retrieving revision 1.95
diff -u -p -r1.95 machine.c
--- machine.c   17 Nov 2018 23:10:08 -  1.95
+++ machine.c   24 Nov 2018 14:47:32 -
@@ -602,6 +602,8 @@ static unsigned char sorted_state[] =
1   /* zombie*/
 };
 
+extern int rev_order;
+
 /*
  *  proc_compares - comparison functions for "qsort"
  */
@@ -631,6 +633,17 @@ static unsigned char sorted_state[] =
 #define ORDERKEY_CMD \
if ((result = strcmp(p1->p_comm, p2->p_comm)) == 0)
 
+/* remove one level of indirection and set sort order */
+#define SETORDER do { \
+   if (rev_order) { \
+   p1 = *(struct kinfo_proc **) pp2; \
+   p2 = *(struct kinfo_proc **) pp1; \
+   } else { \
+   p1 = *(struct kinfo_proc **) pp1; \
+   p2 = *(struct kinfo_proc **) pp2; \
+   } \
+   } while (0)
+
 /* compare_cpu - the comparison function for sorting by cpu percentage */
 static int
 compare_cpu(const void *v1, const void *v2)
@@ -640,9 +653,7 @@ compare_cpu(const void *v1, const void *
struct kinfo_proc *p1, *p2;
int result;
 
-   /* remove one level of indirection */
-   p1 = *(struct kinfo_proc **) pp1;
-   p2 = *(struct kinfo_proc **) pp2;
+   SETORDER;
 
ORDERKEY_PCTCPU
ORDERKEY_CPUTIME
@@ -663,9 +674,7 @@ compare_size(const void *v1, const void 
struct kinfo_proc *p1, *p2;
int result;
 
-   /* remove one level of indirection */
-   p1 = *(struct kinfo_proc **) pp1;
-   p2 = *(struct kinfo_proc **) pp2;
+   SETORDER;
 
ORDERKEY_MEM
ORDERKEY_RSSIZE
@@ -686,9 +695,7 @@ compare_res(const void *v1, const void *
struct kinfo_proc *p1, *p2;
int result;
 
-   /* remove one level of indirection */
-   p1 = *(struct kinfo_proc **) pp1;
-   p2 = *(struct kinfo_proc **) pp2;
+   SETORDER;
 
ORDERKEY_RSSIZE
ORDERKEY_MEM
@@ -709,9 +716,7 @@ compare_time(const void *v1, const void 
struct kinfo_proc *p1, *p2;
int result;
 
-   /* remove one level of indirection */
-   p1 = *(struct kinfo_proc **) pp1;
-   p2 = *(struct kinfo_proc **) pp2;
+   SETORDER;
 
ORDERKEY_CPUTIME
ORDERKEY_PCTCPU
@@ -732,9 +737,7 @@ compare_prio(const void *v1, const void 
struct kinfo_proc *p1, *p2;
int result;
 
-   /* remove one level of indirection */
-   p1 = *(struct kinfo_proc **) pp1;
-   p2 = *(struct kinfo_proc **) pp2;
+   SETORDER;
 
ORDERKEY_PRIO
ORDERKEY_PCTCPU
@@ -754,9 +757,7 @@ compare_pid(const void *v1, const void *
struct kinfo_proc *p1, *p2;
int result;
 
-   /* remove one level of indirection */
-   p1 = *(struct kinfo_proc **) pp1;
-   p2 = *(struct kinfo_proc **) pp2;
+   SETORDER;
 
ORDERKEY_PID
ORDERKEY_PCTCPU
@@ -777,9 +778,7 @@ compare_cmd(const void *v1, const void *
struct kinfo_proc *p1, *p2;
int result;
 
-   /* remove one level of indirection */
-   p1 = *(struct kinfo_proc **) pp1;
-   p2 =