Re: [Patch] man cdce(4) added ZTE MF831 LTE USB Modem

2017-12-09 Thread Jason McIntyre
On Sun, Dec 10, 2017 at 12:42:32AM +0100, Christoph R. Murauer wrote:
> Hello !
> 

morning.

fixed, thanks.
jmc

> 
> Index: cdce.4
> ===
> RCS file: /cvs/src/share/man/man4/cdce.4,v
> retrieving revision 1.23
> diff -u -p -r1.23 cdce.4
> --- cdce.4  13 Nov 2016 08:22:47 -  1.23
> +++ cdce.4  9 Dec 2017 23:19:16 -
> @@ -68,6 +68,8 @@ Sony Ericsson F3705g
>  .It
>  Yota LU156
>  .It
> +ZTE MF831 LTE USB Modem
> +.It
>  Zyxel P-971M
>  .El
>  .Pp
> 
> The ZTE MF831 is a Cat 4 LTE USB modem stick with microSD card slot.
> It provides a web interface and handles SMS.
> 
> Tested / used on amd64 -current #261 Dec 8 and macppc #122 Dec 6. The
> output below is from the amd64 machine.
> 
> thinkpad-w541$ tail -n 20 /var/log/messages
> Dec  9 23:41:06 thinkpad-w541 apmd: battery status: high. external
> power status: connected. estimated battery life 100%
> Dec  9 23:41:27 thinkpad-w541 reorder_kernel: kernel relinking done
> Dec 10 00:00:01 thinkpad-w541 syslogd[74133]: restart
> Dec 10 00:08:00 thinkpad-w541 /bsd: umass0 at uhub0 port 3
> configuration 1 interface 0 "ZTE,Incorporated ZTE Wireless Ethernet
> Adapter" rev 2.00/52.45 addr 8
> Dec 10 00:08:00 thinkpad-w541 /bsd: umass0: using SCSI over Bulk-Only
> Dec 10 00:08:00 thinkpad-w541 /bsd: scsibus4 at umass0: 2 targets,
> initiator 0
> Dec 10 00:08:01 thinkpad-w541 /bsd: cd1 at scsibus4 targ 1 lun 0:
>  SCSI2 5/cdrom removable
> Dec 10 00:08:02 thinkpad-w541 /bsd: sd2 at scsibus4 targ 1 lun 1:
>  SCSI2 0/direct removable
> Dec 10 00:08:15 thinkpad-w541 /bsd: cd1 detached
> Dec 10 00:08:15 thinkpad-w541 /bsd: sd2 detached
> Dec 10 00:08:15 thinkpad-w541 /bsd: scsibus4 detached
> Dec 10 00:08:15 thinkpad-w541 /bsd: umass0 detached
> Dec 10 00:08:16 thinkpad-w541 /bsd: cdce0 at uhub0 port 3
> configuration 1 interface 0 "ZTE,Incorporated ZTE Wireless Ethernet
> Adapter" rev 2.00/52.45 addr 8
> Dec 10 00:08:16 thinkpad-w541 /bsd: cdce0: address 36:4b:50:b7:ef:da
> Dec 10 00:08:16 thinkpad-w541 /bsd: umass0 at uhub0 port 3
> configuration 1 interface 2 "ZTE,Incorporated ZTE Wireless Ethernet
> Adapter" rev 2.00/52.45 addr 8
> Dec 10 00:08:16 thinkpad-w541 /bsd: umass0: using SCSI over Bulk-Only
> Dec 10 00:08:16 thinkpad-w541 /bsd: scsibus4 at umass0: 2 targets,
> initiator 0
> Dec 10 00:08:17 thinkpad-w541 /bsd: cd1 at scsibus4 targ 1 lun 0:
>  SCSI2 5/cdrom removable
> Dec 10 00:08:18 thinkpad-w541 /bsd: sd2 at scsibus4 targ 1 lun 1:
>  SCSI2 0/direct removable
> Dec 10 00:08:18 thinkpad-w541 /bsd: sd2: 29724MB, 512 bytes/sector,
> 60874752 sectors
> 
> thinkpad-w541$ ifconfig cdce0
> cdce0: flags=8802 mtu 1500
> lladdr 36:4b:50:b7:ef:da
> index 7 priority 0 llprio 3
> thinkpad-w541$ ifconfig cdce0
> # after using dhclient
> cdce0: flags=8843 mtu 1500
> lladdr 36:4b:50:b7:ef:da
> index 7 priority 0 llprio 3
> groups: egress
> inet 192.168.0.153 netmask 0xff00 broadcast 192.168.0.255
> 
> thinkpad-w541$ usbdevs
> addr 1: xHCI root hub, Intel
>  addr 8: ZTE Wireless Ethernet Adapter, ZTE,Incorporated
>  addr 2: EMV Smartcard Reader, Generic
>  addr 3: VFS5011 Fingerprint Reader, Validity Sensors
>  addr 4: Sierra Wireless EM7345 4G LTE, Sierra Wireless Inc.
>  addr 5: product 0x07dc, Intel
>  addr 6: Integrated Camera, SunplusIT INC.
>  addr 7: product 0x5010, vendor 0x0765
> addr 1: EHCI root hub, Intel
>  addr 2: Rate Matching Hub, Intel
> addr 1: EHCI root hub, Intel
>  addr 2: Rate Matching Hub, Intel
> 
> Regards,
> 
> Christoph
> 
> 



rpc: use monotime for timeouts

2017-12-09 Thread Scott Cheloha
Hi,

These timeouts in sunrpc need to be based on the monotonic
clock to avoid a race with adjtime(2), settimeofday(2), etc.

There are obvious possible improvements here and elsewhere
in sunrpc.  Here especially the time-related variable names
could be made more descriptive, the various BSD time macros
could be more effectively employed, and ppoll(2) can (now) be
leveraged to ignore EINTR and simplify those loops.  But that
all belongs in a separate diff.

Likewise, there are dead timevals elsewhere in RPC
that I can remove in a separate diff.

Then again, this is ancient upstream code.  Does cleanup here
put too much burden on the project?  Like, I imagine that the
sort of cleanup I'm seeing here could make merging changes
from elsewhere painful.

I have also included here my sys/time.h diff from like two
seconds ago, which enables the use of TIMEVAL_TO_TIMESPEC
in the body of the if statement in clnt_udp.c.  Its use makes
the diff simpler.

This is probably not adequately tested, though it compiles
and I'm not seeing any issues in my (small) NFS setup.

Thoughts and feedback?

--
Scott Cheloha

Index: lib/libc/rpc/clnt_tcp.c
===
RCS file: /cvs/src/lib/libc/rpc/clnt_tcp.c,v
retrieving revision 1.29
diff -u -p -r1.29 clnt_tcp.c
--- lib/libc/rpc/clnt_tcp.c 1 Nov 2015 03:45:29 -   1.29
+++ lib/libc/rpc/clnt_tcp.c 10 Dec 2017 06:08:55 -
@@ -385,25 +385,26 @@ static int
 readtcp(struct ct_data *ct, caddr_t buf, int len)
 {
struct pollfd pfd[1];
-   struct timeval start, after, duration, tmp;
-   int delta, r, save_errno;
+   struct timespec start, after, duration, tmp, delta, wait;
+   int r, save_errno;
 
if (len == 0)
return (0);
 
pfd[0].fd = ct->ct_sock;
pfd[0].events = POLLIN;
-   delta = ct->ct_wait.tv_sec * 1000 + ct->ct_wait.tv_usec / 1000;
-   gettimeofday(, NULL);
+   TIMEVAL_TO_TIMESPEC(>ct_wait, );
+   delta = wait;
+   clock_gettime(CLOCK_MONOTONIC, );
for (;;) {
-   r = poll(pfd, 1, delta);
+   r = ppoll(pfd, 1, , NULL);
save_errno = errno;
 
-   gettimeofday(, NULL);
-   timersub(, , );
-   timersub(>ct_wait, , );
-   delta = tmp.tv_sec * 1000 + tmp.tv_usec / 1000;
-   if (delta <= 0)
+   clock_gettime(CLOCK_MONOTONIC, );
+   timespecsub(, , );
+   timespecsub(, , );
+   delta = tmp;
+   if (delta.tv_sec < 0 || !timespecisset())
r = 0;
 
switch (r) {
Index: lib/libc/rpc/clnt_udp.c
===
RCS file: /cvs/src/lib/libc/rpc/clnt_udp.c,v
retrieving revision 1.32
diff -u -p -r1.32 clnt_udp.c
--- lib/libc/rpc/clnt_udp.c 1 Nov 2015 03:45:29 -   1.32
+++ lib/libc/rpc/clnt_udp.c 10 Dec 2017 06:08:55 -
@@ -216,19 +216,20 @@ clntudp_call(CLIENT *cl,  /* client handl
struct sockaddr_in from;
struct rpc_msg reply_msg;
XDR reply_xdrs;
-   struct timeval time_waited, start, after, tmp1, tmp2;
+   struct timespec time_waited, start, after, tmp1, tmp2, wait;
bool_t ok;
int nrefreshes = 2; /* number of times to refresh cred */
-   struct timeval timeout;
+   struct timespec timeout;
 
if (cu->cu_total.tv_usec == -1)
-   timeout = utimeout; /* use supplied timeout */
+   TIMEVAL_TO_TIMESPEC(, ); /* use supplied 
timeout */
else
-   timeout = cu->cu_total; /* use default timeout */
+   TIMEVAL_TO_TIMESPEC(>cu_total, ); /* use default 
timeout */
 
pfd[0].fd = cu->cu_sock;
pfd[0].events = POLLIN;
-   timerclear(_waited);
+   timespecclear(_waited);
+   TIMEVAL_TO_TIMESPEC(>cu_wait, );
 call_again:
xdrs = &(cu->cu_outxdrs);
xdrs->x_op = XDR_ENCODE;
@@ -254,7 +255,7 @@ send_again:
/*
 * Hack to provide rpc-based message passing
 */
-   if (!timerisset())
+   if (!timespecisset())
return (cu->cu_error.re_status = RPC_TIMEDOUT);
 
/*
@@ -266,14 +267,13 @@ send_again:
reply_msg.acpted_rply.ar_results.where = resultsp;
reply_msg.acpted_rply.ar_results.proc = xresults;
 
-   gettimeofday(, NULL);
+   clock_gettime(CLOCK_MONOTONIC, );
for (;;) {
-   switch (poll(pfd, 1,
-   cu->cu_wait.tv_sec * 1000 + cu->cu_wait.tv_usec / 1000)) {
+   switch (ppoll(pfd, 1, , NULL)) {
case 0:
-   timeradd(_waited, >cu_wait, );
+   timespecadd(_waited, , );
time_waited = tmp1;
-   if (timercmp(_waited, , <))
+   if (timespeccmp(_waited, , <))

TIMEVAL_TO_TIMESPEC, etc: use do-loop for compound macros

2017-12-09 Thread Scott Cheloha
Hi,

Per style(9), macros with compound statements are easier used in
an if statement when do-loop wrapped.

--
Scott Cheloha

P.S. Is it just me or does the argument ordering for
TIMESPEC_TO_TIMEVAL seem backwards?

Index: sys/sys/time.h
===
RCS file: /cvs/src/sys/sys/time.h,v
retrieving revision 1.36
diff -u -p -r1.36 time.h
--- sys/sys/time.h  12 Sep 2016 19:41:20 -  1.36
+++ sys/sys/time.h  10 Dec 2017 04:35:28 -
@@ -60,14 +60,14 @@ struct timespec {
 };
 #endif
 
-#defineTIMEVAL_TO_TIMESPEC(tv, ts) {   
\
+#defineTIMEVAL_TO_TIMESPEC(tv, ts) do {
\
(ts)->tv_sec = (tv)->tv_sec;\
(ts)->tv_nsec = (tv)->tv_usec * 1000;   \
-}
-#defineTIMESPEC_TO_TIMEVAL(tv, ts) {   
\
+} while (0)
+#defineTIMESPEC_TO_TIMEVAL(tv, ts) do {
\
(tv)->tv_sec = (ts)->tv_sec;\
(tv)->tv_usec = (ts)->tv_nsec / 1000;   \
-}
+} while (0)
 
 struct timezone {
int tz_minuteswest; /* minutes west of Greenwich */



grdc: simplify via clock_gettime

2017-12-09 Thread Scott Cheloha
Hi,

This program can be simplified if we keep everything in a timespec and
use clock_gettime(2)'s CLOCK_REALTIME clock instead of gettimeofday(2).

The "now" timespec could be moved into main(), but I think that change
belongs alongside other general refactoring/tidying in a separate diff.

--
Scott Cheloha

Index: games/grdc/grdc.c
===
RCS file: /cvs/src/games/grdc/grdc.c,v
retrieving revision 1.27
diff -u -p -r1.27 grdc.c
--- games/grdc/grdc.c   13 Jul 2017 02:57:52 -  1.27
+++ games/grdc/grdc.c   10 Dec 2017 02:10:05 -
@@ -18,6 +18,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #define XLENGTH 58
@@ -61,8 +62,7 @@ main(int argc, char *argv[])
int i, j, s, k;
int scrol;
int n = 0;
-   struct timeval nowtv, endtv;
-   struct timespec delay;
+   struct timespec delay, end;
const char *errstr;
long scroldelay = 5000;
int xbase;
@@ -119,10 +119,9 @@ main(int argc, char *argv[])
curs_set(0);
sigwinched = 1; /* force initial sizing */
 
-   gettimeofday(, NULL);
-   TIMEVAL_TO_TIMESPEC(, );
+   clock_gettime(CLOCK_REALTIME, );
if (n)
-   endtv.tv_sec = nowtv.tv_sec + n - 1;
+   end.tv_sec = now.tv_sec + n - 1;
do {
if (sigwinched) {
sigwinched = 0;
@@ -205,8 +204,7 @@ main(int argc, char *argv[])
}
}
if (scrol && k <= 4) {
-   gettimeofday(, NULL);
-   TIMEVAL_TO_TIMESPEC(, );
+   clock_gettime(CLOCK_REALTIME, );
delay.tv_sec = 0;
delay.tv_nsec = 10 - now.tv_nsec
- (4-k) * scroldelay;
@@ -217,8 +215,7 @@ main(int argc, char *argv[])
}
move(6, 0);
refresh();
-   gettimeofday(, NULL);
-   TIMEVAL_TO_TIMESPEC(, );
+   clock_gettime(CLOCK_REALTIME, );
delay.tv_sec = 0;
delay.tv_nsec = (10 - now.tv_nsec);
/* want scrolling to END on the second */
@@ -234,7 +231,7 @@ main(int argc, char *argv[])
endwin();
errx(1, "terminated by signal %d", sigtermed);
}
-   } while (n == 0 || nowtv.tv_sec < endtv.tv_sec);
+   } while (n == 0 || now.tv_sec < end.tv_sec);
standend();
clear();
refresh();



Re: Include hostname in shell prompts by default

2017-12-09 Thread lists
Sat, 09 Dec 2017 12:33:30 -0700 "Theo de Raadt" 
> > Sat, 09 Dec 2017 12:02:07 -0700 "Theo de Raadt"   
> > > > With all the respect and understanding what you're saying is true, yet
> > > > I have the time to change my prompt, and it would still affect me.
> > > 
> > > If you have changed it, it is irrelevant what the value was before
> > > the change.  You detail no impact.  You appeal is 100% emotion.  
> > 
> > Hi Theo,
> > 
> > Anyone use Emacs tramp mode?  If it works after this change, I'm happy.
> > If not, I'd have to go and plea there, or plea here to have a tunable..
> > Over time tramp mode will pick it up, just as it picked up bash prompt.
> > Please don't let me get in the way of this change, objection retracted.  
> 
> OH COME ON
> 
> If you are noting the problem, then you probably use the software!
> 
> The diff is *trivial* to apply, and you could have tested that case
> before you replied, then provided definitive FACTUAL INFORMATION to
> the conversation instead of moaning and groaning all emo.
> 
> As I've told a few other people, this diff seperates the boys from the
> men.  The boys are the ones with 1 machine, maybe 2 with seperate
> keyboards.  The men are the ones with 50 machine or maybe even more,
> who are struggling with the time commitment to keep infrastructure on
> the leading tip, and therefore this totally minimal default prompt
> setting may be a substantial step at reducing error.
> 
> But maybe this boys vs men comparison also regards other
> conversational strategies, you ever think of that??
> 
> It is sub-conversations like this which cause many developers to not
> send their diffs to tech and move them forward more privately.  This
> forum has too many people who think their voice is equal when their
> discourse is sub-equal.  A big part of the project is a meritocratic
> which requires participants aim to keep the conversation about the
> TECHNICAL IMPACT rather than only 'gut reaction'.  Therefore many of
> you are not equal, because you don't attempt to be equal in discourse.
> You are 2 for 2 of saying essentially "maybe but maybe not" and taking
> no effort to elevate to FACTS.  Looking at my cat on the couch I see a
> clear look of "maybe but maybe not".  I think we can expect better on
> this list.

Hi Theo,

You'll find the boys cheering in the "+1" shell / modal editors section,
and also in the "-1" configuration management / cargo scripting section.

Please allow me to know (rarely say) what could affect "my" use case for
previous experience w/ Emacs tramp, not blaming this for withheld diffs.
After tests (debug), confirmed it WORKS without issues in this use case.

Trying this in use actually seems meaningful, and useful out of the box.
Now I have to invent another reason to keep setting PS1 on all machines:

PS1='\a=== \D{%a %b %d [%H:%M]} \u@\h:\w (\l) j\j e$? h\! ===\n\$ '

=== Sun Dec 10 [01:10] ant@sun:~ (tty00) j0 e0 h1 ===
$ 

I am not playing along the script, raised some concern here, that's all.
I'll run with this without any more fuss, just as if I didn't notice it.
As previously said, I'd retracted my objection already, confirmed again.

Kind regards,
Anton Lazarov



[Patch] man cdce(4) added ZTE MF831 LTE USB Modem

2017-12-09 Thread Christoph R. Murauer
Hello !


Index: cdce.4
===
RCS file: /cvs/src/share/man/man4/cdce.4,v
retrieving revision 1.23
diff -u -p -r1.23 cdce.4
--- cdce.4  13 Nov 2016 08:22:47 -  1.23
+++ cdce.4  9 Dec 2017 23:19:16 -
@@ -68,6 +68,8 @@ Sony Ericsson F3705g
 .It
 Yota LU156
 .It
+ZTE MF831 LTE USB Modem
+.It
 Zyxel P-971M
 .El
 .Pp

The ZTE MF831 is a Cat 4 LTE USB modem stick with microSD card slot.
It provides a web interface and handles SMS.

Tested / used on amd64 -current #261 Dec 8 and macppc #122 Dec 6. The
output below is from the amd64 machine.

thinkpad-w541$ tail -n 20 /var/log/messages
Dec  9 23:41:06 thinkpad-w541 apmd: battery status: high. external
power status: connected. estimated battery life 100%
Dec  9 23:41:27 thinkpad-w541 reorder_kernel: kernel relinking done
Dec 10 00:00:01 thinkpad-w541 syslogd[74133]: restart
Dec 10 00:08:00 thinkpad-w541 /bsd: umass0 at uhub0 port 3
configuration 1 interface 0 "ZTE,Incorporated ZTE Wireless Ethernet
Adapter" rev 2.00/52.45 addr 8
Dec 10 00:08:00 thinkpad-w541 /bsd: umass0: using SCSI over Bulk-Only
Dec 10 00:08:00 thinkpad-w541 /bsd: scsibus4 at umass0: 2 targets,
initiator 0
Dec 10 00:08:01 thinkpad-w541 /bsd: cd1 at scsibus4 targ 1 lun 0:
 SCSI2 5/cdrom removable
Dec 10 00:08:02 thinkpad-w541 /bsd: sd2 at scsibus4 targ 1 lun 1:
 SCSI2 0/direct removable
Dec 10 00:08:15 thinkpad-w541 /bsd: cd1 detached
Dec 10 00:08:15 thinkpad-w541 /bsd: sd2 detached
Dec 10 00:08:15 thinkpad-w541 /bsd: scsibus4 detached
Dec 10 00:08:15 thinkpad-w541 /bsd: umass0 detached
Dec 10 00:08:16 thinkpad-w541 /bsd: cdce0 at uhub0 port 3
configuration 1 interface 0 "ZTE,Incorporated ZTE Wireless Ethernet
Adapter" rev 2.00/52.45 addr 8
Dec 10 00:08:16 thinkpad-w541 /bsd: cdce0: address 36:4b:50:b7:ef:da
Dec 10 00:08:16 thinkpad-w541 /bsd: umass0 at uhub0 port 3
configuration 1 interface 2 "ZTE,Incorporated ZTE Wireless Ethernet
Adapter" rev 2.00/52.45 addr 8
Dec 10 00:08:16 thinkpad-w541 /bsd: umass0: using SCSI over Bulk-Only
Dec 10 00:08:16 thinkpad-w541 /bsd: scsibus4 at umass0: 2 targets,
initiator 0
Dec 10 00:08:17 thinkpad-w541 /bsd: cd1 at scsibus4 targ 1 lun 0:
 SCSI2 5/cdrom removable
Dec 10 00:08:18 thinkpad-w541 /bsd: sd2 at scsibus4 targ 1 lun 1:
 SCSI2 0/direct removable
Dec 10 00:08:18 thinkpad-w541 /bsd: sd2: 29724MB, 512 bytes/sector,
60874752 sectors

thinkpad-w541$ ifconfig cdce0
cdce0: flags=8802 mtu 1500
lladdr 36:4b:50:b7:ef:da
index 7 priority 0 llprio 3
thinkpad-w541$ ifconfig cdce0
# after using dhclient
cdce0: flags=8843 mtu 1500
lladdr 36:4b:50:b7:ef:da
index 7 priority 0 llprio 3
groups: egress
inet 192.168.0.153 netmask 0xff00 broadcast 192.168.0.255

thinkpad-w541$ usbdevs
addr 1: xHCI root hub, Intel
 addr 8: ZTE Wireless Ethernet Adapter, ZTE,Incorporated
 addr 2: EMV Smartcard Reader, Generic
 addr 3: VFS5011 Fingerprint Reader, Validity Sensors
 addr 4: Sierra Wireless EM7345 4G LTE, Sierra Wireless Inc.
 addr 5: product 0x07dc, Intel
 addr 6: Integrated Camera, SunplusIT INC.
 addr 7: product 0x5010, vendor 0x0765
addr 1: EHCI root hub, Intel
 addr 2: Rate Matching Hub, Intel
addr 1: EHCI root hub, Intel
 addr 2: Rate Matching Hub, Intel

Regards,

Christoph




Re: Include hostname in shell prompts by default

2017-12-09 Thread Theo de Raadt
> But we should probably keep the POSIX default for sh.  POSIX doesn't
> cover csh, so we're free to do what we want here too.
> 
> So my proposal is to make the change, but stick with the current
> default for ksh-invoked-as-sh.

Seriously, can anyone find one reason other than "dusty papers"?




Re: Include hostname in shell prompts by default

2017-12-09 Thread Mark Kettenis
> From: "Theo de Raadt" 
> Date: Sat, 09 Dec 2017 11:38:44 -0700
> 
> > this just feels like a needless deviation.
> 
> all i can say is:
> 
> bash-4.4$ 

Which is perfectly fine for bash since it isn't the POSIX shell when
invoked as bash.  For the same reason we can do what we want for ksh.
But we should probably keep the POSIX default for sh.  POSIX doesn't
cover csh, so we're free to do what we want here too.

So my proposal is to make the change, but stick with the current
default for ksh-invoked-as-sh.




Re: Include hostname in shell prompts by default

2017-12-09 Thread Brian Callahan


On 12/9/2017 1:28 PM, Bryan Steele wrote:
> On Sat, Dec 09, 2017 at 06:44:44PM +0100, Theo Buehler wrote:
>> This was discussed in a smaller circle and has been in snaps for two
>> days, but I'd like to show this to a wider audience.
>>
>> Theo asked me to make sure that all our shells print a prompt including
>> the hostname by default. The reasoning is roughly as follows:
>>
>> With tmux, ssh and vmd, we tend to open shells on many different hosts
>> simultaneously and the default prompts '$ ' and '# ' for {,k}sh as well
>> as  '% ' and '# ' for csh become dangerous: it's very easy to issue a
>> command on the wrong host.
>>
>> This can easily be avoided by displaying the hostname in the prompt.
>> Everything beyond "hostname{$,#,%} " is going to be a matter of taste,
>> so we left it at that. If you use an FQDN, only the first part (the
>> output of 'hostname -s') will be printed.
>>
>> Since not everybody makes use of the config files in /etc/skel or runs
>> only login shells, it is not really possible to handle this with config
>> files. Thus, we decided to hardcode it in the shells. We are aware that
>> POSIX says that PS1 defaults to '$ ' or '# ' for sh(1).
>>
>> The simplest case is ksh: rely on the already existing shell escapes.
>> For sh we can easily fall back to these (the diff to ksh/lex.c).  For
>> csh, I decided to implement the "%m" prompt escape which is standard in
>> c-type shells, so I don't expect this to cause surprises.
>>
>> In single user mode and the early installer, gethostname() returns the
>> empty string, so the familiar prompts will be displayed there.
> I think we should go ahead with this for the reasons mentioned, the
> default configuration should make things easier for the people using it,
> which means developers doing release builds, spinning up vms, etc.
>
> People can go on and on about standards compliance, but if it means
> someone is less likely to reboot the wrong machine, or worse, then
> POSIX be damned.
>
> ok brynet@

I'm with brynet@ and the others on this. Was a nice surprise when I
installed a new snap last night, already proved itself to be useful.

ok bcallah@, fwiw

>> Index: bin/csh/const.c
>> ===
>> RCS file: /var/cvs/src/bin/csh/const.c,v
>> retrieving revision 1.8
>> diff -u -p -r1.8 const.c
>> --- bin/csh/const.c  26 Oct 2015 16:27:04 -  1.8
>> +++ bin/csh/const.c  8 Dec 2017 12:15:26 -
>> @@ -114,6 +114,8 @@ Char STRprintexitvalue[] = { 'p', 'r', '
>>  'a', 'l', 'u', 'e', '\0' };
>>  Char STRprompt[]= { 'p', 'r', 'o', 'm', 'p', 't', '\0' };
>>  Char STRprompt2[]   = { 'p', 'r', 'o', 'm', 'p', 't', '2', '\0' };
>> +Char STRpromptroot[]= { '%', 'm', '#', ' ', '\0' };
>> +Char STRpromptuser[]= { '%', 'm', '%', ' ', '\0' };
>>  Char STRpushdsilent[]   = { 'p', 'u', 's', 'h', 'd', 's', 'i', 'l', 
>> 'e', 'n',
>>  't', '\0' };
>>  Char STRret[]   = { '\n', '\0' };
>> @@ -138,8 +140,6 @@ Char STRspor2sp[]= { ' ', '|', '|', ' '
>>  Char STRsporsp[]= { ' ', '|', ' ', '\0' };
>>  Char STRstar[]  = { '*', '\0' };
>>  Char STRstatus[]= { 's', 't', 'a', 't', 'u', 's', '\0' };
>> -Char STRsymcent[]   = { '%', ' ', '\0' };
>> -Char STRsymhash[]   = { '#', ' ', '\0' };
>>  Char STRterm[]  = { 't', 'e', 'r', 'm', '\0' };
>>  Char STRthen[]  = { 't', 'h', 'e', 'n', '\0' };
>>  Char STRtilde[] = { '~', '\0' };
>> Index: bin/csh/csh.c
>> ===
>> RCS file: /var/cvs/src/bin/csh/csh.c,v
>> retrieving revision 1.41
>> diff -u -p -r1.41 csh.c
>> --- bin/csh/csh.c30 Aug 2017 06:42:21 -  1.41
>> +++ bin/csh/csh.c8 Dec 2017 12:16:00 -
>> @@ -401,7 +401,7 @@ main(int argc, char *argv[])
>>   * Set up the prompt.
>>   */
>>  if (prompt) {
>> -set(STRprompt, Strsave(uid == 0 ? STRsymhash : STRsymcent));
>> +set(STRprompt, Strsave(uid == 0 ? STRpromptroot : STRpromptuser));
>>  /* that's a meta-questionmark */
>>  set(STRprompt2, Strsave(STRmquestion));
>>  }
>> @@ -1283,7 +1283,16 @@ printprompt(void)
>>  for (cp = value(STRprompt); *cp; cp++)
>>  if (*cp == HIST)
>>  (void) fprintf(cshout, "%d", eventno + 1);
>> -else {
>> +else if (*cp == '%' && *(cp + 1) == 'm') {
>> +char hostname[HOST_NAME_MAX + 1];
>> +char *p;
>> +
>> +gethostname(hostname, sizeof hostname);
>> +if ((p = strchr(hostname, '.')) != NULL)
>> +*p = '\0';
>> +fprintf(cshout, "%s", hostname);
>> +cp++;
>> +} else {
>>  if (*cp == '\\' && cp[1] == HIST)
>>  cp++;
>>  (void) vis_fputc(*cp | QUOTE, cshout);
>> Index: bin/ksh/lex.c
>> ===
>> 

Re: Include hostname in shell prompts by default

2017-12-09 Thread x9p
On Sat, December 9, 2017 3:44 pm, Theo Buehler wrote:
> This was discussed in a smaller circle and has been in snaps for two
> days, but I'd like to show this to a wider audience.
>
> Theo asked me to make sure that all our shells print a prompt including
> the hostname by default. The reasoning is roughly as follows:
>
> With tmux, ssh and vmd, we tend to open shells on many different hosts
> simultaneously and the default prompts '$ ' and '# ' for {,k}sh as well
> as  '% ' and '# ' for csh become dangerous: it's very easy to issue a
> command on the wrong host.
>

+1 for this. some of my tmux panes + PS1 are already customized to avoid
such mistakes. but once issued "reboot" just before leaving office - sadly
it was an SSH to the BGP router, not my machine.

cheers.

x9p



Re: Include hostname in shell prompts by default

2017-12-09 Thread Theo de Raadt
> Sat, 09 Dec 2017 12:02:07 -0700 "Theo de Raadt" 
> > > With all the respect and understanding what you're saying is true, yet
> > > I have the time to change my prompt, and it would still affect me.  
> > 
> > If you have changed it, it is irrelevant what the value was before
> > the change.  You detail no impact.  You appeal is 100% emotion.
> 
> Hi Theo,
> 
> Anyone use Emacs tramp mode?  If it works after this change, I'm happy.
> If not, I'd have to go and plea there, or plea here to have a tunable..
> Over time tramp mode will pick it up, just as it picked up bash prompt.
> Please don't let me get in the way of this change, objection retracted.

OH COME ON

If you are noting the problem, then you probably use the software!

The diff is *trivial* to apply, and you could have tested that case
before you replied, then provided definitive FACTUAL INFORMATION to
the conversation instead of moaning and groaning all emo.

As I've told a few other people, this diff seperates the boys from the
men.  The boys are the ones with 1 machine, maybe 2 with seperate
keyboards.  The men are the ones with 50 machine or maybe even more,
who are struggling with the time commitment to keep infrastructure on
the leading tip, and therefore this totally minimal default prompt
setting may be a substantial step at reducing error.

But maybe this boys vs men comparison also regards other
conversational strategies, you ever think of that??

It is sub-conversations like this which cause many developers to not
send their diffs to tech and move them forward more privately.  This
forum has too many people who think their voice is equal when their
discourse is sub-equal.  A big part of the project is a meritocratic
which requires participants aim to keep the conversation about the
TECHNICAL IMPACT rather than only 'gut reaction'.  Therefore many of
you are not equal, because you don't attempt to be equal in discourse.
You are 2 for 2 of saying essentially "maybe but maybe not" and taking
no effort to elevate to FACTS.  Looking at my cat on the couch I see a
clear look of "maybe but maybe not".  I think we can expect better on
this list.



Re: Include hostname in shell prompts by default

2017-12-09 Thread Ian Darwin

On 2017-12-09 1:10 PM, Theo de Raadt wrote:

the default prompt works exactly because it doesn;t try to second guess
what the user wants, or what is or isn;t good for them. the mechanism
for changing the prompt is trivial.

i don;t think it makes sense to change the shells in this way.

Having seen bug reports with data from the wrong machine multiple
times in the last year, especially related to Mike's new work in vmm,
I'm sorry I have to disagree.  Some developers have even rebooted
the wrong machines.

Is there anyone who hasn't?


Not everyone has time to configure their development machines
as you suggest.
If it truly can't be fixed in /etc/profile and/or /etc/ksh.kshrc, then 
it should be fixed it in the code.


This change has *no impact* on the people who already take the time
to change their prompt.  It improves the lives of those who don't have
time to do so.


Yup.



Re: Include hostname in shell prompts by default

2017-12-09 Thread Job Snijders
On Sat, Dec 09, 2017 at 06:44:44PM +0100, Theo Buehler wrote:
> Theo asked me to make sure that all our shells print a prompt
> including the hostname by default.

Thank you. This is a significant improvement.

I keep finding myself updating /etc/profile everywhere to ensure I don't
lose my bearings on where I am.

Kind regards,

Job



Re: Include hostname in shell prompts by default

2017-12-09 Thread lists
Sat, 09 Dec 2017 12:02:07 -0700 "Theo de Raadt" 
> > With all the respect and understanding what you're saying is true, yet
> > I have the time to change my prompt, and it would still affect me.  
> 
> If you have changed it, it is irrelevant what the value was before
> the change.  You detail no impact.  You appeal is 100% emotion.

Hi Theo,

Anyone use Emacs tramp mode?  If it works after this change, I'm happy.
If not, I'd have to go and plea there, or plea here to have a tunable..
Over time tramp mode will pick it up, just as it picked up bash prompt.
Please don't let me get in the way of this change, objection retracted.

Kind regards,
Anton Lazarov



Re: Include hostname in shell prompts by default

2017-12-09 Thread Base Pr1me
As a server admin, I adore the idea. I've yelled profanity too many times
rebooting the wrong machine in haste. Would be wonderful in a large tmux
session.

On Dec 9, 2017 11:57,  wrote:

Sat, 09 Dec 2017 11:10:03 -0700 "Theo de Raadt" 
> > the default prompt works exactly because it doesn;t try to second guess
> > what the user wants, or what is or isn;t good for them. the mechanism
> > for changing the prompt is trivial.
> >
> > i don;t think it makes sense to change the shells in this way.
>
> Having seen bug reports with data from the wrong machine multiple
> times in the last year, especially related to Mike's new work in vmm,
> I'm sorry I have to disagree.  Some developers have even rebooted
> the wrong machines.
>
> Not everyone has time to configure their development machines
> as you suggest.
>
> This change has *no impact* on the people who already take the time
> to change their prompt.  It improves the lives of those who don't have
> time to do so.
>

Hi Theo, Theo, Jason and everyone,

With all the respect and understanding what you're saying is true, yet
I have the time to change my prompt, and it would still affect me.  By
not being able to use remote log-ins and remote file edits by software
that depends on both interactive and non interactive shell behaviours.
Please, kindly provide a snippet in skel (profile) to revert this too.

Kind regards,
Anton Lazarov


Re: Include hostname in shell prompts by default

2017-12-09 Thread Theo de Raadt
> With all the respect and understanding what you're saying is true, yet
> I have the time to change my prompt, and it would still affect me.

If you have changed it, it is irrelevant what the value was before
the change.  You detail no impact.  You appeal is 100% emotion.



Re: Include hostname in shell prompts by default

2017-12-09 Thread lists
Sat, 09 Dec 2017 11:10:03 -0700 "Theo de Raadt" 
> > the default prompt works exactly because it doesn;t try to second guess
> > what the user wants, or what is or isn;t good for them. the mechanism
> > for changing the prompt is trivial.
> > 
> > i don;t think it makes sense to change the shells in this way.  
> 
> Having seen bug reports with data from the wrong machine multiple
> times in the last year, especially related to Mike's new work in vmm,
> I'm sorry I have to disagree.  Some developers have even rebooted
> the wrong machines.
> 
> Not everyone has time to configure their development machines
> as you suggest.
> 
> This change has *no impact* on the people who already take the time
> to change their prompt.  It improves the lives of those who don't have
> time to do so.
> 

Hi Theo, Theo, Jason and everyone,

With all the respect and understanding what you're saying is true, yet
I have the time to change my prompt, and it would still affect me.  By
not being able to use remote log-ins and remote file edits by software
that depends on both interactive and non interactive shell behaviours.
Please, kindly provide a snippet in skel (profile) to revert this too.

Kind regards,
Anton Lazarov



Re: Include hostname in shell prompts by default

2017-12-09 Thread Marc Espie
On Sat, Dec 09, 2017 at 06:33:32PM +, Jason McIntyre wrote:
> On Sat, Dec 09, 2017 at 11:10:03AM -0700, Theo de Raadt wrote:
> > > the default prompt works exactly because it doesn;t try to second guess
> > > what the user wants, or what is or isn;t good for them. the mechanism
> > > for changing the prompt is trivial.
> > > 
> > > i don;t think it makes sense to change the shells in this way.
> > 
> > Having seen bug reports with data from the wrong machine multiple
> > times in the last year, especially related to Mike's new work in vmm,
> > I'm sorry I have to disagree.  Some developers have even rebooted
> > the wrong machines.
> > 
> > Not everyone has time to configure their development machines
> > as you suggest.
> > 
> > This change has *no impact* on the people who already take the time
> > to change their prompt.  It improves the lives of those who don't have
> > time to do so.
> 
> evening.
> 
> people have plenty time to change their prompt.
> 
> having the hostname in your prompt will not prevent you from rebooting
> the wrong machine (i have found).
> 
> this just feels like a needless deviation.

Not always, not under every circumstance.

Do a chroot, forget to change your prompt back -> boom, where are you.

Run vmm, forget to change your prompt.

Run lots of vm. Run lots of chroot.

Or, hey, find time to write scripts that will write environment that will
set your prompt in a nice complex fringe case.

For me, this is progress. Even if it deviates (slightly) from POSIX.



Re: Include hostname in shell prompts by default

2017-12-09 Thread Theo de Raadt
> this just feels like a needless deviation.

all i can say is:

bash-4.4$ 




Re: Include hostname in shell prompts by default

2017-12-09 Thread Jason McIntyre
On Sat, Dec 09, 2017 at 11:10:03AM -0700, Theo de Raadt wrote:
> > the default prompt works exactly because it doesn;t try to second guess
> > what the user wants, or what is or isn;t good for them. the mechanism
> > for changing the prompt is trivial.
> > 
> > i don;t think it makes sense to change the shells in this way.
> 
> Having seen bug reports with data from the wrong machine multiple
> times in the last year, especially related to Mike's new work in vmm,
> I'm sorry I have to disagree.  Some developers have even rebooted
> the wrong machines.
> 
> Not everyone has time to configure their development machines
> as you suggest.
> 
> This change has *no impact* on the people who already take the time
> to change their prompt.  It improves the lives of those who don't have
> time to do so.

evening.

people have plenty time to change their prompt.

having the hostname in your prompt will not prevent you from rebooting
the wrong machine (i have found).

this just feels like a needless deviation.

jmc



Re: Include hostname in shell prompts by default

2017-12-09 Thread Bryan Steele
On Sat, Dec 09, 2017 at 06:44:44PM +0100, Theo Buehler wrote:
> This was discussed in a smaller circle and has been in snaps for two
> days, but I'd like to show this to a wider audience.
> 
> Theo asked me to make sure that all our shells print a prompt including
> the hostname by default. The reasoning is roughly as follows:
> 
> With tmux, ssh and vmd, we tend to open shells on many different hosts
> simultaneously and the default prompts '$ ' and '# ' for {,k}sh as well
> as  '% ' and '# ' for csh become dangerous: it's very easy to issue a
> command on the wrong host.
> 
> This can easily be avoided by displaying the hostname in the prompt.
> Everything beyond "hostname{$,#,%} " is going to be a matter of taste,
> so we left it at that. If you use an FQDN, only the first part (the
> output of 'hostname -s') will be printed.
> 
> Since not everybody makes use of the config files in /etc/skel or runs
> only login shells, it is not really possible to handle this with config
> files. Thus, we decided to hardcode it in the shells. We are aware that
> POSIX says that PS1 defaults to '$ ' or '# ' for sh(1).
> 
> The simplest case is ksh: rely on the already existing shell escapes.
> For sh we can easily fall back to these (the diff to ksh/lex.c).  For
> csh, I decided to implement the "%m" prompt escape which is standard in
> c-type shells, so I don't expect this to cause surprises.
> 
> In single user mode and the early installer, gethostname() returns the
> empty string, so the familiar prompts will be displayed there.

I think we should go ahead with this for the reasons mentioned, the
default configuration should make things easier for the people using it,
which means developers doing release builds, spinning up vms, etc.

People can go on and on about standards compliance, but if it means
someone is less likely to reboot the wrong machine, or worse, then
POSIX be damned.

ok brynet@

> Index: bin/csh/const.c
> ===
> RCS file: /var/cvs/src/bin/csh/const.c,v
> retrieving revision 1.8
> diff -u -p -r1.8 const.c
> --- bin/csh/const.c   26 Oct 2015 16:27:04 -  1.8
> +++ bin/csh/const.c   8 Dec 2017 12:15:26 -
> @@ -114,6 +114,8 @@ Char STRprintexitvalue[] = { 'p', 'r', '
>   'a', 'l', 'u', 'e', '\0' };
>  Char STRprompt[] = { 'p', 'r', 'o', 'm', 'p', 't', '\0' };
>  Char STRprompt2[]= { 'p', 'r', 'o', 'm', 'p', 't', '2', '\0' };
> +Char STRpromptroot[] = { '%', 'm', '#', ' ', '\0' };
> +Char STRpromptuser[] = { '%', 'm', '%', ' ', '\0' };
>  Char STRpushdsilent[]= { 'p', 'u', 's', 'h', 'd', 's', 'i', 'l', 
> 'e', 'n',
>   't', '\0' };
>  Char STRret[]= { '\n', '\0' };
> @@ -138,8 +140,6 @@ Char STRspor2sp[] = { ' ', '|', '|', ' '
>  Char STRsporsp[] = { ' ', '|', ' ', '\0' };
>  Char STRstar[]   = { '*', '\0' };
>  Char STRstatus[] = { 's', 't', 'a', 't', 'u', 's', '\0' };
> -Char STRsymcent[]= { '%', ' ', '\0' };
> -Char STRsymhash[]= { '#', ' ', '\0' };
>  Char STRterm[]   = { 't', 'e', 'r', 'm', '\0' };
>  Char STRthen[]   = { 't', 'h', 'e', 'n', '\0' };
>  Char STRtilde[]  = { '~', '\0' };
> Index: bin/csh/csh.c
> ===
> RCS file: /var/cvs/src/bin/csh/csh.c,v
> retrieving revision 1.41
> diff -u -p -r1.41 csh.c
> --- bin/csh/csh.c 30 Aug 2017 06:42:21 -  1.41
> +++ bin/csh/csh.c 8 Dec 2017 12:16:00 -
> @@ -401,7 +401,7 @@ main(int argc, char *argv[])
>   * Set up the prompt.
>   */
>  if (prompt) {
> - set(STRprompt, Strsave(uid == 0 ? STRsymhash : STRsymcent));
> + set(STRprompt, Strsave(uid == 0 ? STRpromptroot : STRpromptuser));
>   /* that's a meta-questionmark */
>   set(STRprompt2, Strsave(STRmquestion));
>  }
> @@ -1283,7 +1283,16 @@ printprompt(void)
>   for (cp = value(STRprompt); *cp; cp++)
>   if (*cp == HIST)
>   (void) fprintf(cshout, "%d", eventno + 1);
> - else {
> + else if (*cp == '%' && *(cp + 1) == 'm') {
> + char hostname[HOST_NAME_MAX + 1];
> + char *p;
> +
> + gethostname(hostname, sizeof hostname);
> + if ((p = strchr(hostname, '.')) != NULL)
> + *p = '\0';
> + fprintf(cshout, "%s", hostname);
> + cp++;
> + } else {
>   if (*cp == '\\' && cp[1] == HIST)
>   cp++;
>   (void) vis_fputc(*cp | QUOTE, cshout);
> Index: bin/ksh/lex.c
> ===
> RCS file: /var/cvs/src/bin/ksh/lex.c,v
> retrieving revision 1.72
> diff -u -p -r1.72 lex.c
> --- bin/ksh/lex.c 7 Dec 2017 01:54:33 -   1.72
> +++ bin/ksh/lex.c 8 Dec 2017 11:02:10 -
> @@ -1246,7 +1246,8 @@ dopprompt(const char *sp, int ntruncate,
>  

Re: Include hostname in shell prompts by default

2017-12-09 Thread Theo de Raadt
> the default prompt works exactly because it doesn;t try to second guess
> what the user wants, or what is or isn;t good for them. the mechanism
> for changing the prompt is trivial.
> 
> i don;t think it makes sense to change the shells in this way.

Having seen bug reports with data from the wrong machine multiple
times in the last year, especially related to Mike's new work in vmm,
I'm sorry I have to disagree.  Some developers have even rebooted
the wrong machines.

Not everyone has time to configure their development machines
as you suggest.

This change has *no impact* on the people who already take the time
to change their prompt.  It improves the lives of those who don't have
time to do so.



Re: Include hostname in shell prompts by default

2017-12-09 Thread Jason McIntyre
On Sat, Dec 09, 2017 at 06:44:44PM +0100, Theo Buehler wrote:
> This was discussed in a smaller circle and has been in snaps for two
> days, but I'd like to show this to a wider audience.
> 
> Theo asked me to make sure that all our shells print a prompt including
> the hostname by default. The reasoning is roughly as follows:
> 
> With tmux, ssh and vmd, we tend to open shells on many different hosts
> simultaneously and the default prompts '$ ' and '# ' for {,k}sh as well
> as  '% ' and '# ' for csh become dangerous: it's very easy to issue a
> command on the wrong host.
> 
> This can easily be avoided by displaying the hostname in the prompt.
> Everything beyond "hostname{$,#,%} " is going to be a matter of taste,
> so we left it at that. If you use an FQDN, only the first part (the
> output of 'hostname -s') will be printed.
> 
> Since not everybody makes use of the config files in /etc/skel or runs
> only login shells, it is not really possible to handle this with config
> files. Thus, we decided to hardcode it in the shells. We are aware that
> POSIX says that PS1 defaults to '$ ' or '# ' for sh(1).
> 
> The simplest case is ksh: rely on the already existing shell escapes.
> For sh we can easily fall back to these (the diff to ksh/lex.c).  For
> csh, I decided to implement the "%m" prompt escape which is standard in
> c-type shells, so I don't expect this to cause surprises.
> 
> In single user mode and the early installer, gethostname() returns the
> empty string, so the familiar prompts will be displayed there.
> 

hi.

the default prompt works exactly because it doesn;t try to second guess
what the user wants, or what is or isn;t good for them. the mechanism
for changing the prompt is trivial.

i don;t think it makes sense to change the shells in this way.

jmc

> Index: bin/csh/const.c
> ===
> RCS file: /var/cvs/src/bin/csh/const.c,v
> retrieving revision 1.8
> diff -u -p -r1.8 const.c
> --- bin/csh/const.c   26 Oct 2015 16:27:04 -  1.8
> +++ bin/csh/const.c   8 Dec 2017 12:15:26 -
> @@ -114,6 +114,8 @@ Char STRprintexitvalue[] = { 'p', 'r', '
>   'a', 'l', 'u', 'e', '\0' };
>  Char STRprompt[] = { 'p', 'r', 'o', 'm', 'p', 't', '\0' };
>  Char STRprompt2[]= { 'p', 'r', 'o', 'm', 'p', 't', '2', '\0' };
> +Char STRpromptroot[] = { '%', 'm', '#', ' ', '\0' };
> +Char STRpromptuser[] = { '%', 'm', '%', ' ', '\0' };
>  Char STRpushdsilent[]= { 'p', 'u', 's', 'h', 'd', 's', 'i', 'l', 
> 'e', 'n',
>   't', '\0' };
>  Char STRret[]= { '\n', '\0' };
> @@ -138,8 +140,6 @@ Char STRspor2sp[] = { ' ', '|', '|', ' '
>  Char STRsporsp[] = { ' ', '|', ' ', '\0' };
>  Char STRstar[]   = { '*', '\0' };
>  Char STRstatus[] = { 's', 't', 'a', 't', 'u', 's', '\0' };
> -Char STRsymcent[]= { '%', ' ', '\0' };
> -Char STRsymhash[]= { '#', ' ', '\0' };
>  Char STRterm[]   = { 't', 'e', 'r', 'm', '\0' };
>  Char STRthen[]   = { 't', 'h', 'e', 'n', '\0' };
>  Char STRtilde[]  = { '~', '\0' };
> Index: bin/csh/csh.c
> ===
> RCS file: /var/cvs/src/bin/csh/csh.c,v
> retrieving revision 1.41
> diff -u -p -r1.41 csh.c
> --- bin/csh/csh.c 30 Aug 2017 06:42:21 -  1.41
> +++ bin/csh/csh.c 8 Dec 2017 12:16:00 -
> @@ -401,7 +401,7 @@ main(int argc, char *argv[])
>   * Set up the prompt.
>   */
>  if (prompt) {
> - set(STRprompt, Strsave(uid == 0 ? STRsymhash : STRsymcent));
> + set(STRprompt, Strsave(uid == 0 ? STRpromptroot : STRpromptuser));
>   /* that's a meta-questionmark */
>   set(STRprompt2, Strsave(STRmquestion));
>  }
> @@ -1283,7 +1283,16 @@ printprompt(void)
>   for (cp = value(STRprompt); *cp; cp++)
>   if (*cp == HIST)
>   (void) fprintf(cshout, "%d", eventno + 1);
> - else {
> + else if (*cp == '%' && *(cp + 1) == 'm') {
> + char hostname[HOST_NAME_MAX + 1];
> + char *p;
> +
> + gethostname(hostname, sizeof hostname);
> + if ((p = strchr(hostname, '.')) != NULL)
> + *p = '\0';
> + fprintf(cshout, "%s", hostname);
> + cp++;
> + } else {
>   if (*cp == '\\' && cp[1] == HIST)
>   cp++;
>   (void) vis_fputc(*cp | QUOTE, cshout);
> Index: bin/ksh/lex.c
> ===
> RCS file: /var/cvs/src/bin/ksh/lex.c,v
> retrieving revision 1.72
> diff -u -p -r1.72 lex.c
> --- bin/ksh/lex.c 7 Dec 2017 01:54:33 -   1.72
> +++ bin/ksh/lex.c 8 Dec 2017 11:02:10 -
> @@ -1246,7 +1246,8 @@ dopprompt(const char *sp, int ntruncate,
>   cp++;
>   if (!*cp)
>   break;
> - if 

Re: Include hostname in shell prompts by default

2017-12-09 Thread lists
Sat, 9 Dec 2017 18:44:44 +0100 Theo Buehler 
> This was discussed in a smaller circle and has been in snaps for two
> days, but I'd like to show this to a wider audience.
> 
> Theo asked me to make sure that all our shells print a prompt including
> the hostname by default. The reasoning is roughly as follows:
> 
> With tmux, ssh and vmd, we tend to open shells on many different hosts
> simultaneously and the default prompts '$ ' and '# ' for {,k}sh as well
> as  '% ' and '# ' for csh become dangerous: it's very easy to issue a
> command on the wrong host.
> 
> This can easily be avoided by displaying the hostname in the prompt.
> Everything beyond "hostname{$,#,%} " is going to be a matter of taste,
> so we left it at that. If you use an FQDN, only the first part (the
> output of 'hostname -s') will be printed.
> 
> Since not everybody makes use of the config files in /etc/skel or runs
> only login shells, it is not really possible to handle this with config
> files. Thus, we decided to hardcode it in the shells. We are aware that
> POSIX says that PS1 defaults to '$ ' or '# ' for sh(1).
> 
> The simplest case is ksh: rely on the already existing shell escapes.
> For sh we can easily fall back to these (the diff to ksh/lex.c).  For
> csh, I decided to implement the "%m" prompt escape which is standard in
> c-type shells, so I don't expect this to cause surprises.

Hi,

I feel the need for this, and have always customised my PS1 everywhere.
Please, also test this to make sure Emacs tramp mode does not get to be
a show stopper, for it expects the prompt to be a certain simple form..
Maybe POSIX / something else, I'd be really really disappointed if they
refused to adjust around (any) non-standard implementations on our end.

Kind regards,
Anton Lazarov

> In single user mode and the early installer, gethostname() returns the
> empty string, so the familiar prompts will be displayed there.
> 
> Index: bin/csh/const.c
> ===
> RCS file: /var/cvs/src/bin/csh/const.c,v
> retrieving revision 1.8
> diff -u -p -r1.8 const.c
> --- bin/csh/const.c   26 Oct 2015 16:27:04 -  1.8
> +++ bin/csh/const.c   8 Dec 2017 12:15:26 -
> @@ -114,6 +114,8 @@ Char STRprintexitvalue[] = { 'p', 'r', '
>   'a', 'l', 'u', 'e', '\0' };
>  Char STRprompt[] = { 'p', 'r', 'o', 'm', 'p', 't', '\0' };
>  Char STRprompt2[]= { 'p', 'r', 'o', 'm', 'p', 't', '2', '\0' };
> +Char STRpromptroot[] = { '%', 'm', '#', ' ', '\0' };
> +Char STRpromptuser[] = { '%', 'm', '%', ' ', '\0' };
>  Char STRpushdsilent[]= { 'p', 'u', 's', 'h', 'd', 's', 'i', 'l', 
> 'e', 'n',
>   't', '\0' };
>  Char STRret[]= { '\n', '\0' };
> @@ -138,8 +140,6 @@ Char STRspor2sp[] = { ' ', '|', '|', ' '
>  Char STRsporsp[] = { ' ', '|', ' ', '\0' };
>  Char STRstar[]   = { '*', '\0' };
>  Char STRstatus[] = { 's', 't', 'a', 't', 'u', 's', '\0' };
> -Char STRsymcent[]= { '%', ' ', '\0' };
> -Char STRsymhash[]= { '#', ' ', '\0' };
>  Char STRterm[]   = { 't', 'e', 'r', 'm', '\0' };
>  Char STRthen[]   = { 't', 'h', 'e', 'n', '\0' };
>  Char STRtilde[]  = { '~', '\0' };
> Index: bin/csh/csh.c
> ===
> RCS file: /var/cvs/src/bin/csh/csh.c,v
> retrieving revision 1.41
> diff -u -p -r1.41 csh.c
> --- bin/csh/csh.c 30 Aug 2017 06:42:21 -  1.41
> +++ bin/csh/csh.c 8 Dec 2017 12:16:00 -
> @@ -401,7 +401,7 @@ main(int argc, char *argv[])
>   * Set up the prompt.
>   */
>  if (prompt) {
> - set(STRprompt, Strsave(uid == 0 ? STRsymhash : STRsymcent));
> + set(STRprompt, Strsave(uid == 0 ? STRpromptroot : STRpromptuser));
>   /* that's a meta-questionmark */
>   set(STRprompt2, Strsave(STRmquestion));
>  }
> @@ -1283,7 +1283,16 @@ printprompt(void)
>   for (cp = value(STRprompt); *cp; cp++)
>   if (*cp == HIST)
>   (void) fprintf(cshout, "%d", eventno + 1);
> - else {
> + else if (*cp == '%' && *(cp + 1) == 'm') {
> + char hostname[HOST_NAME_MAX + 1];
> + char *p;
> +
> + gethostname(hostname, sizeof hostname);
> + if ((p = strchr(hostname, '.')) != NULL)
> + *p = '\0';
> + fprintf(cshout, "%s", hostname);
> + cp++;
> + } else {
>   if (*cp == '\\' && cp[1] == HIST)
>   cp++;
>   (void) vis_fputc(*cp | QUOTE, cshout);
> Index: bin/ksh/lex.c
> ===
> RCS file: /var/cvs/src/bin/ksh/lex.c,v
> retrieving revision 1.72
> diff -u -p -r1.72 lex.c
> --- bin/ksh/lex.c 7 Dec 2017 01:54:33 -   1.72
> +++ bin/ksh/lex.c 8 Dec 2017 11:02:10 -
> @@ -1246,7 +1246,8 @@ dopprompt(const char *sp, int 

Include hostname in shell prompts by default

2017-12-09 Thread Theo Buehler
This was discussed in a smaller circle and has been in snaps for two
days, but I'd like to show this to a wider audience.

Theo asked me to make sure that all our shells print a prompt including
the hostname by default. The reasoning is roughly as follows:

With tmux, ssh and vmd, we tend to open shells on many different hosts
simultaneously and the default prompts '$ ' and '# ' for {,k}sh as well
as  '% ' and '# ' for csh become dangerous: it's very easy to issue a
command on the wrong host.

This can easily be avoided by displaying the hostname in the prompt.
Everything beyond "hostname{$,#,%} " is going to be a matter of taste,
so we left it at that. If you use an FQDN, only the first part (the
output of 'hostname -s') will be printed.

Since not everybody makes use of the config files in /etc/skel or runs
only login shells, it is not really possible to handle this with config
files. Thus, we decided to hardcode it in the shells. We are aware that
POSIX says that PS1 defaults to '$ ' or '# ' for sh(1).

The simplest case is ksh: rely on the already existing shell escapes.
For sh we can easily fall back to these (the diff to ksh/lex.c).  For
csh, I decided to implement the "%m" prompt escape which is standard in
c-type shells, so I don't expect this to cause surprises.

In single user mode and the early installer, gethostname() returns the
empty string, so the familiar prompts will be displayed there.

Index: bin/csh/const.c
===
RCS file: /var/cvs/src/bin/csh/const.c,v
retrieving revision 1.8
diff -u -p -r1.8 const.c
--- bin/csh/const.c 26 Oct 2015 16:27:04 -  1.8
+++ bin/csh/const.c 8 Dec 2017 12:15:26 -
@@ -114,6 +114,8 @@ Char STRprintexitvalue[] = { 'p', 'r', '
'a', 'l', 'u', 'e', '\0' };
 Char STRprompt[]   = { 'p', 'r', 'o', 'm', 'p', 't', '\0' };
 Char STRprompt2[]  = { 'p', 'r', 'o', 'm', 'p', 't', '2', '\0' };
+Char STRpromptroot[]   = { '%', 'm', '#', ' ', '\0' };
+Char STRpromptuser[]   = { '%', 'm', '%', ' ', '\0' };
 Char STRpushdsilent[]  = { 'p', 'u', 's', 'h', 'd', 's', 'i', 'l', 'e', 'n',
't', '\0' };
 Char STRret[]  = { '\n', '\0' };
@@ -138,8 +140,6 @@ Char STRspor2sp[]   = { ' ', '|', '|', ' '
 Char STRsporsp[]   = { ' ', '|', ' ', '\0' };
 Char STRstar[] = { '*', '\0' };
 Char STRstatus[]   = { 's', 't', 'a', 't', 'u', 's', '\0' };
-Char STRsymcent[]  = { '%', ' ', '\0' };
-Char STRsymhash[]  = { '#', ' ', '\0' };
 Char STRterm[] = { 't', 'e', 'r', 'm', '\0' };
 Char STRthen[] = { 't', 'h', 'e', 'n', '\0' };
 Char STRtilde[]= { '~', '\0' };
Index: bin/csh/csh.c
===
RCS file: /var/cvs/src/bin/csh/csh.c,v
retrieving revision 1.41
diff -u -p -r1.41 csh.c
--- bin/csh/csh.c   30 Aug 2017 06:42:21 -  1.41
+++ bin/csh/csh.c   8 Dec 2017 12:16:00 -
@@ -401,7 +401,7 @@ main(int argc, char *argv[])
  * Set up the prompt.
  */
 if (prompt) {
-   set(STRprompt, Strsave(uid == 0 ? STRsymhash : STRsymcent));
+   set(STRprompt, Strsave(uid == 0 ? STRpromptroot : STRpromptuser));
/* that's a meta-questionmark */
set(STRprompt2, Strsave(STRmquestion));
 }
@@ -1283,7 +1283,16 @@ printprompt(void)
for (cp = value(STRprompt); *cp; cp++)
if (*cp == HIST)
(void) fprintf(cshout, "%d", eventno + 1);
-   else {
+   else if (*cp == '%' && *(cp + 1) == 'm') {
+   char hostname[HOST_NAME_MAX + 1];
+   char *p;
+
+   gethostname(hostname, sizeof hostname);
+   if ((p = strchr(hostname, '.')) != NULL)
+   *p = '\0';
+   fprintf(cshout, "%s", hostname);
+   cp++;
+   } else {
if (*cp == '\\' && cp[1] == HIST)
cp++;
(void) vis_fputc(*cp | QUOTE, cshout);
Index: bin/ksh/lex.c
===
RCS file: /var/cvs/src/bin/ksh/lex.c,v
retrieving revision 1.72
diff -u -p -r1.72 lex.c
--- bin/ksh/lex.c   7 Dec 2017 01:54:33 -   1.72
+++ bin/ksh/lex.c   8 Dec 2017 11:02:10 -
@@ -1246,7 +1246,8 @@ dopprompt(const char *sp, int ntruncate,
cp++;
if (!*cp)
break;
-   if (Flag(FSH))
+   /* Expand \h and \$ for both, sh(1) and ksh(1) */
+   if (Flag(FSH) && !(*cp == 'h' || *cp == 'p'))
snprintf(strbuf, sizeof strbuf, "\\%c", *cp);
else switch (*cp) {
case 'a':   /* '\' 'a' bell */
Index: bin/ksh/main.c
===
RCS file: /var/cvs/src/bin/ksh/main.c,v

Re: grep(1) -m support

2017-12-09 Thread Paul Irofti
On Fri, Dec 08, 2017 at 03:23:02PM -0700, Theo de Raadt wrote:
> > Here is a new diff that supports 0 and negative m values.
> 
> I am very unsure about negative values.
> 
> In posix you have
> 
>-m-1
> and
>-m -1
> 
> And you'll observe the latter doesn't work like you think it should.

Here is a version without negative values, but with m0 support.


Index: grep.1
===
RCS file: /cvs/src/usr.bin/grep/grep.1,v
retrieving revision 1.43
diff -u -p -u -p -r1.43 grep.1
--- grep.1  13 Jan 2015 04:45:34 -  1.43
+++ grep.1  9 Dec 2017 17:29:08 -
@@ -44,6 +44,7 @@
 .Op Fl C Ns Op Ar num
 .Op Fl e Ar pattern
 .Op Fl f Ar file
+.Op Fl m Ar num
 .Op Fl -binary-files Ns = Ns Ar value
 .Op Fl -context Ns Op = Ns Ar num
 .Op Fl -line-buffered
@@ -216,6 +217,10 @@ Pathnames are listed once per file searc
 If the standard input is searched, the string
 .Dq (standard input)
 is written.
+.It Fl m Ar num
+Stop after
+.Ar num
+matches.
 .It Fl n
 Each output line is preceded by its relative line number in the file,
 starting at line 1.
@@ -354,7 +359,7 @@ utility is compliant with the
 specification.
 .Pp
 The flags
-.Op Fl AaBbCGHhILoRUVwZ
+.Op Fl AaBbCGHhILmoRUVwZ
 are extensions to that specification, and the behaviour of the
 .Fl f
 flag when used with an empty pattern file is left undefined.
Index: grep.c
===
RCS file: /cvs/src/usr.bin/grep/grep.c,v
retrieving revision 1.55
diff -u -p -u -p -r1.55 grep.c
--- grep.c  28 Nov 2015 01:17:12 -  1.55
+++ grep.c  9 Dec 2017 17:29:08 -
@@ -71,6 +71,9 @@ intcflag; /* -c: only show a count of
 int hflag; /* -h: don't print filename headers */
 int iflag; /* -i: ignore case */
 int lflag; /* -l: only show names of files with matches */
+int mflag; /* -m x: stop reading the files after x matches */
+long long mcount;  /* count for -m */
+long long mlimit;  /* requested value for -m */
 int nflag; /* -n: show line numbers in front of matching lines */
 int oflag; /* -o: print each match */
 int qflag; /* -q: quiet mode (don't output anything) */
@@ -111,15 +114,16 @@ usage(void)
 #else
"usage: %s [-abcEFGHhIiLlnoqRsUVvwxZ] [-A num] [-B num] [-C[num]]\n"
 #endif
-   "\t[-e pattern] [-f file] [--binary-files=value] 
[--context[=num]]\n"
-   "\t[--line-buffered] [pattern] [file ...]\n", __progname);
+   "\t[-e pattern] [-f file] [-m num] [--binary-files=value]\n"
+   "\t[--context[=num]] [--line-buffered] [pattern] [file ...]\n",
+   __progname);
exit(2);
 }
 
 #ifdef NOZ
-static const char optstr[] = "0123456789A:B:CEFGHILRUVabce:f:hilnoqrsuvwxy";
+static const char optstr[] = "0123456789A:B:CEFGHILRUVabce:f:hilm:noqrsuvwxy";
 #else
-static const char optstr[] = "0123456789A:B:CEFGHILRUVZabce:f:hilnoqrsuvwxy";
+static const char optstr[] = "0123456789A:B:CEFGHILRUVZabce:f:hilm:noqrsuvwxy";
 #endif
 
 static const struct option long_options[] =
@@ -147,6 +151,7 @@ static const struct option long_options[
{"ignore-case", no_argument,NULL, 'i'},
{"files-without-match", no_argument,NULL, 'L'},
{"files-with-matches",  no_argument,NULL, 'l'},
+   {"max-count",   required_argument,  NULL, 'm'},
{"line-number", no_argument,NULL, 'n'},
{"quiet",   no_argument,NULL, 'q'},
{"silent",  no_argument,NULL, 'q'},
@@ -375,6 +380,13 @@ main(int argc, char *argv[])
case 'l':
Lflag = 0;
lflag = qflag = 1;
+   break;
+   case 'm':
+   mflag = 1;
+   mlimit = mcount = strtonum(optarg, 0, LLONG_MAX,
+  );
+   if (errstr != NULL)
+   errx(2, "number of matches %s", errstr);
break;
case 'n':
nflag = 1;
Index: grep.h
===
RCS file: /cvs/src/usr.bin/grep/grep.h,v
retrieving revision 1.24
diff -u -p -u -p -r1.24 grep.h
--- grep.h  14 Dec 2015 20:02:07 -  1.24
+++ grep.h  9 Dec 2017 17:29:08 -
@@ -66,14 +66,17 @@ extern int   cflags, eflags;
 /* Command line flags */
 extern int  Aflag, Bflag, Eflag, Fflag, Hflag, Lflag,
 Rflag, Zflag,
-bflag, cflag, hflag, iflag, lflag, nflag, oflag, qflag, sflag,
-vflag, wflag, xflag;
+bflag, cflag, hflag, iflag, lflag, mflag, nflag, oflag, qflag,
+sflag, vflag, wflag, xflag;
 extern int  binbehave;
 
 extern int  first, matchall, 

Re: sshd(8) logging of client disconnect from ClientAliveInterval

2017-12-09 Thread Lars Nooden
On Wed, 18 Oct 2017, Darren Tucker wrote:
> I meant reusing the existing function rather than cloning it.  It's
> currently static so it needs to be exported but IMO that's better than
> duplicating the code.
> 
> Index: packet.c
> ===
> RCS file: /cvs/src/usr.bin/ssh/packet.c,v
> retrieving revision 1.265
> diff -u -p -r1.265 packet.c
> --- packet.c  13 Oct 2017 21:13:54 -  1.265
> +++ packet.c  17 Oct 2017 22:49:08 -
> @@ -1773,8 +1773,8 @@ ssh_packet_send_debug(struct ssh *ssh, c
>   fatal("%s: %s", __func__, ssh_err(r));
>  }
>  
> -static void
> -fmt_connection_id(struct ssh *ssh, char *s, size_t l)
> +void
> +sshpkt_fmt_connection_id(struct ssh *ssh, char *s, size_t l)
>  {
>   snprintf(s, l, "%.200s%s%s port %d",
>   ssh->log_preamble ? ssh->log_preamble : "",
> @@ -1790,7 +1790,7 @@ sshpkt_fatal(struct ssh *ssh, const char
>  {
>   char remote_id[512];
>  
> - fmt_connection_id(ssh, remote_id, sizeof(remote_id));
> + sshpkt_fmt_connection_id(ssh, remote_id, sizeof(remote_id));
>  
>   switch (r) {
>   case SSH_ERR_CONN_CLOSED:
> @@ -1852,7 +1852,7 @@ ssh_packet_disconnect(struct ssh *ssh, c
>* Format the message.  Note that the caller must make sure the
>* message is of limited size.
>*/
> - fmt_connection_id(ssh, remote_id, sizeof(remote_id));
> + sshpkt_fmt_connection_id(ssh, remote_id, sizeof(remote_id));
>   va_start(args, fmt);
>   vsnprintf(buf, sizeof(buf), fmt, args);
>   va_end(args);
> Index: packet.h
> ===
> RCS file: /cvs/src/usr.bin/ssh/packet.h,v
> retrieving revision 1.82
> diff -u -p -r1.82 packet.h
> --- packet.h  12 Sep 2017 06:32:07 -  1.82
> +++ packet.h  17 Oct 2017 22:49:08 -
> @@ -186,6 +186,7 @@ int   sshpkt_get_cstring(struct ssh *ssh, 
>  int  sshpkt_get_ec(struct ssh *ssh, EC_POINT *v, const EC_GROUP *g);
>  int  sshpkt_get_bignum2(struct ssh *ssh, BIGNUM *v);
>  int  sshpkt_get_end(struct ssh *ssh);
> +void sshpkt_fmt_connection_id(struct ssh *ssh, char *s, size_t l);
>  const u_char *sshpkt_ptr(struct ssh *, size_t *lenp);
>  
>  /* OLD API */
> Index: serverloop.c
> ===
> RCS file: /cvs/src/usr.bin/ssh/serverloop.c,v
> retrieving revision 1.198
> diff -u -p -r1.198 serverloop.c
> --- serverloop.c  12 Sep 2017 06:35:32 -  1.198
> +++ serverloop.c  17 Oct 2017 22:49:08 -
> @@ -162,10 +162,12 @@ static void
>  client_alive_check(struct ssh *ssh)
>  {
>   int channel_id;
> + char remote_id[512];
>  
>   /* timeout, check to see how many we have had */
>   if (packet_inc_alive_timeouts() > options.client_alive_count_max) {
> - logit("Timeout, client not responding.");
> + sshpkt_fmt_connection_id(ssh, remote_id, sizeof(remote_id));
> + logit("Timeout, client not responding from %s", remote_id);
>   cleanup_exit(255);
>   }
>  
> 

Yes, thanks.  That provides the log information I am looking for when a 
client times out.  

/Lars



new variable in bsd.regress.mk

2017-12-09 Thread Sergey Bronnikov
Hi,

some regression tests depends on 3rd party modules and now some tests contains
duplicate code which check precense of dependencies and install them in case of
abcense. Perhaps it would be better to care about dependencies in the
bsd.regress.mk and specify dependencies in special variable in tests.
This patch intoduce PKG_REQUIRED var and adopt tests where it is required.

diff --git a/regress/sys/fileops/Makefile.inc b/regress/sys/fileops/Makefile.inc
index d6d2c05781e..b327a383c8f 100644
--- a/regress/sys/fileops/Makefile.inc
+++ b/regress/sys/fileops/Makefile.inc
@@ -1,7 +1,6 @@
 # $OpenBSD: Makefile.inc,v 1.3 2017/08/15 17:16:39 sf Exp $
 
-PERL_REQUIRE != perl -e 'eval { require File::Slurp } or print $$@'
-
+PKG_REQUIRED=  p5-File-Slurp
 TESTS1=create read mmap
 TESTS2=many_files_root many_files_subdir file_write
 TESTS= ${TESTS1} ${TESTS2}
@@ -48,16 +47,9 @@ run-regress-${t}: stamp-setup ${.OBJDIR}/../fileops
 
 .for t in ${TESTS2}
 REGRESS_TARGETS+=  run-regress-${t}
-.if ! empty(PERL_REQUIRE)
-run-regress-${t}:
-   @echo "${PERL_REQUIRE}"
-   @echo "Install the p5-File-Slurp package to run the fileops ${t} 
subtest"
-   @echo SKIPPED
-.else
 run-regress-${t}: stamp-setup
@echo '\n $@ '
perl ${.CURDIR}/../fileops2.pl ${t} ${FILEOPS_MNT}
-.endif
 .endfor
 
 REGRESS_TARGETS+=  run-regress-cleanup
diff --git a/regress/sys/net/Makefile b/regress/sys/net/Makefile
index d56a7cc9189..653060732ec 100644
--- a/regress/sys/net/Makefile
+++ b/regress/sys/net/Makefile
@@ -1,5 +1,7 @@
 #  $OpenBSD: Makefile,v 1.13 2017/11/17 10:29:16 bluhm Exp $
 
+PKG_REQUIRED += scapy py-libdnet
+
 SUBDIR +=  etherip loop
 SUBDIR +=  pf_divert pf_forward pf_fragment pf_print pf_state pf_table
 SUBDIR +=  rdomains rtable vxlan
diff --git a/regress/sys/net/pf_divert/Makefile 
b/regress/sys/net/pf_divert/Makefile
index 2c5f538ed8d..aaad41af726 100644
--- a/regress/sys/net/pf_divert/Makefile
+++ b/regress/sys/net/pf_divert/Makefile
@@ -3,20 +3,8 @@
 # The following ports must be installed for the regression tests:
 # p5-IO-Socket-INET6   object interface for AF_INET and AF_INET6 domain sockets
 # p5-Socket6   Perl defines relating to AF_INET6 sockets
-#
-# Check wether all required perl packages are installed.  If some
-# are missing print a warning and skip the tests, but do not fail.
-
-PERL_REQUIRE !=perl -Mstrict -Mwarnings -e ' \
-eval { require IO::Socket::INET6 } or print $@; \
-eval { require Socket6 } or print $@; \
-'
-.if ! empty(PERL_REQUIRE)
-regress:
-   @echo "${PERL_REQUIRE}"
-   @echo install these perl packages for additional tests
-   @echo SKIPPED
-.endif
+
+PKG_REQUIRED +=p5-IO-Socket-INET6 p5-Socket6
 
 # Fill out these variables as you have to test divert with the pf
 # kernel running on a remote machine.  You have to specify a local
diff --git a/regress/sys/net/pflow/Makefile b/regress/sys/net/pflow/Makefile
index 122fe9b13e9..d6acd95d7ea 100644
--- a/regress/sys/net/pflow/Makefile
+++ b/regress/sys/net/pflow/Makefile
@@ -27,6 +27,7 @@
 # Destroy it in the end.
 
 REGRESS_TARGETS=template_v10 flow_10_4 flow_10_6 ifconfig
+PKG_REQUIRED   += p5-Net-Flow
 
 PROG=   gen_traffic
 LDADD=  -levent
diff --git a/regress/sys/netinet/arp/Makefile b/regress/sys/netinet/arp/Makefile
index 7081e928b99..8578c2b6614 100644
--- a/regress/sys/netinet/arp/Makefile
+++ b/regress/sys/netinet/arp/Makefile
@@ -6,17 +6,7 @@
 # py-libdnet  python interface to libdnet
 # scapy   powerful interactive packet manipulation in python
 
-.if ! (make(clean) || make(cleandir) || make(obj))
-# Check wether all required python packages are installed.  If some
-# are missing print a warning and skip the tests, but do not fail.
-PYTHON_IMPORT != python2.7 -c 'from scapy.all import *' 2>&1 || true
-.endif
-.if ! empty(PYTHON_IMPORT)
-regress:
-   @echo '${PYTHON_IMPORT}'
-   @echo install python and the scapy module for additional tests
-   @echo SKIPPED
-.endif
+PKG_REQUIRED += python-2.7 scapy py-libdnet
 
 # This test needs a manual setup of two machines
 # Set up machines: LOCAL REMOTE
diff --git a/regress/sys/netinet/frag/Makefile 
b/regress/sys/netinet/frag/Makefile
index 195634b5d07..381cc6950dc 100644
--- a/regress/sys/netinet/frag/Makefile
+++ b/regress/sys/netinet/frag/Makefile
@@ -6,20 +6,7 @@
 # py-libdnet  python interface to libdnet
 # scapy   powerful interactive packet manipulation in python
 
-.if ! (make(clean) || make(cleandir) || make(obj))
-# Check wether all required python packages are installed.  If some
-# are missing print a warning and skip the tests, but do not fail.
-PYTHON_IMPORT !!= python2.7 -c 'from scapy.all import *' 2>&1 || true
-.endif
-
-.if ! empty(PYTHON_IMPORT)
-.BEGIN:
-   @true
-regress:
-   @echo '${PYTHON_IMPORT}'
-   @echo Install python and the scapy module for additional tests.
-   

openbsd code coverage

2017-12-09 Thread Sergey Bronnikov
Hi,

I'm working on measuring OpenBSD code coverage.
The process still has drawbacks,
but some results are already available.

https://ligurio.github.io/openbsd-tests/6.2/coverage.html

Sergey



Re: nc: random failure with TLS: no protocols available / libtls patch

2017-12-09 Thread Sebastien Marie
On Sat, Dec 09, 2017 at 09:23:13AM +0100, Sebastien Marie wrote:
> 
> but I am unsure with nc(1) works sometimes...
> 

replying to myself...

because inside nc(1), it uses an uninitialized stack value in such cases...

   150  main(int argc, char *argv[])
   151  {
...
   164  uint32_t protocols;
...
   499  if (tls_config_parse_protocols(, 
tls_protocols) == -1)
   500  errx(1, "invalid TLS protocols `%s'", 
tls_protocols);
   501  if (tls_config_set_protocols(tls_cfg, protocols) == -1)
   502  errx(1, "%s", tls_config_error(tls_cfg));

with current code in libtls, tls_config_parse_protocols() returns
something that it isn't -1, so protocols is still uninitialized and
tls_config_set_protocols() just use the uninitialized value...

-- 
Sebastien Marie



nc: random failure with TLS: no protocols available / libtls patch

2017-12-09 Thread Sebastien Marie
Hi,

With latest snapshot on amd64 (OpenBSD 6.2-current (GENERIC.MP) #263: Fri Dec  
8 18:19:04 MST 2017), I have random failure with nc when using TLS.


$ date ; nc -vvc www.free.fr 443
Sat Dec  9 09:05:34 CET 2017
Connection to www.free.fr 443 port [tcp/https] succeeded!
nc: tls handshake failed (handshake failed: error:140020BF:SSL 
routines:CONNECT_CW_CLNT_HELLO:no protocols available)

$ date ; nc -vvc www.free.fr 443
Sat Dec  9 09:05:35 CET 2017
Connection to www.free.fr 443 port [tcp/https] succeeded!
TLS handshake negotiated TLSv1.2/ECDHE-RSA-AES128-GCM-SHA256 with host 
www.free.fr
Peer name: www.free.fr
Subject: /CN=*.free.fr
Issuer: /C=US/O=GeoTrust Inc./CN=RapidSSL SHA256 CA
Valid From: Thu Jul 27 02:00:00 2017
Valid Until: Thu Aug  8 01:59:59 2019
Cert Hash: 
SHA256:9f32a1e1feee258fe14d103af98a017f208cd4795d88c681130919031e5d817d
OCSP URL: http://gp.symcd.com
^C

If I pass additional "-T protocols=default", it seems to connect
reliably. 

I dig a bit inside nc code source without finding any problem. But in
tls_config_parse_protocols(), it could be one.

tls_config_parse_protocols() should return 0 or -1 and put the result
inside *protocols parameter.

man page:
 The tls_config_parse_protocols() utility function parses a protocol
 string and returns the corresponding value via the protocols argument.

If the protostr is NULL, it currently returns TLS_PROTOCOLS_DEFAULT
instead of put it inside *protocols.


but I am unsure with nc(1) works sometimes...

by recompiling and installing the patched libtls (and recompiling nc),
it seems to problem is corrected.

thanks.
-- 
Sebastien Marie


Index: tls_config.c
===
RCS file: /cvs/src/lib/libtls/tls_config.c,v
retrieving revision 1.44
diff -u -p -r1.44 tls_config.c
--- tls_config.c25 Sep 2017 18:07:03 -  1.44
+++ tls_config.c9 Dec 2017 08:17:02 -
@@ -311,8 +311,10 @@ tls_config_parse_protocols(uint32_t *pro
char *s, *p, *q;
int negate;
 
-   if (protostr == NULL)
-   return TLS_PROTOCOLS_DEFAULT;
+   if (protostr == NULL) {
+   *protocols = TLS_PROTOCOLS_DEFAULT;
+   return (0);
+   }
 
if ((s = strdup(protostr)) == NULL)
return (-1);