Re: expr(1) diff 2 of 3, make it able to accept c-style radix prefixes in integers

2011-01-15 Thread Janjaap van Velthooven
On Fri, Jan 14, 2011 at 10:39:53PM -0800, Philip Guenther wrote:

 [snip relevant discussion to sidetrack a bit.]

 So, what's the answer for someone wanting to do base conversion?  If
 they use sh/ksh, then the answer is $((...)):
 
 $ echo $((0x20))
 32
 $
 
 csh shmucks^Wusers can use bc or dc for arbitrary base conversion:
 
 % printf 'ibase=16\n%s\n' 20 | bc
 32

when you are going to use printf anyways, what is wrong with something like
$ printf '%o\n' 0x20
40
$ printf '%d\n' 033
27
$

 [end of sidetrack]

 Philip Guenther

Janjaap van Velthooven
--  
   / __/ /_/ __/ /_  __/ __/ /___  / 
  / /_  __/___/_/_  /___  / / __/ /___  / /  janj...@stack.nl
 /___/_/_/_/_/_/_/___/_/_/



Re: Workaround for data corruption issue with ALI M5229 IDE chip used with Sun Blade 100/Netra X1.

2011-01-15 Thread Mark Kettenis
 Date: Fri, 14 Jan 2011 18:56:07 +0100
 From: Alexander Schrijver alexander.schrij...@gmail.com
 
  The big question of course is whether it will survive a make build
  with the change that removes the restriction of only using Ultra-DMA
  up to mode 2, but without the fixes in pciide.c.
  
  Beware, that might actually eat your filesystem.
  
 
 I'm doing this right now. I'm running a make build as we speak. I'm not sure
 when it should fuck up the filesystem.

Me neither, that's what makes this diff so difficult to test properly.

 diff i used:

That's the right diff to use for this test.

Thanks Alexander!



Re: Make expr(1) 64-bit capable and radix-aware

2011-01-15 Thread Benny Lofgren

On 2011-01-15 07.43, Otto Moerbeek wrote:

On Fri, Jan 14, 2011 at 08:22:25PM -0700, Theo de Raadt wrote:

+ Makes it 64-bit capable on 64-bit architectures by changing relevant
int:s to long:s.

I think this is a problem.
I would expect a unix utility of this importance to work exactly the
same on all our platforms.


Additionally, i very much prefer to have as little as possible
differecnes between expr(1) and the ksh builtin.


Ehum, running the risk of looking like a complete fool I've got to ask, 
is there actually a ksh builtin version of expr?


I did actually double check that prior to digging into this, with 
whence expr, and now after reading your comment I've skimmed the man 
page for ksh as well without finding any reference to a builtin expr. 
What am I missing?


Thanks for the input!


/Benny

--
internetlabbet.se / work:   +46 8 551 124 80  / Words must
Benny LC6fgren/  mobile: +46 70 718 11 90 /   be weighed,
/   fax:+46 8 551 124 89/not counted.
   /email:  benny -at- internetlabbet.se



Re: expr(1) diff 2 of 3, make it able to accept c-style radix prefixes in integers

2011-01-15 Thread Benny Lofgren

On 2011-01-15 08.29, Philip Guenther wrote:

On Fri, Jan 14, 2011 at 10:39 PM, Philip Guentherguent...@gmail.com  wrote:

On Fri, Jan 14, 2011 at 8:11 PM, Benny Lofgrenbl-li...@lofgren.biz  wrote:

+ Makes it able to use C-style radix prefixes to integers in order to do
calculations in octal and hexadecimal.

...

Unfortunately, this would make expr violate POSIX.


I should note that this would be legal behavior if a non-POSIX option
was used.  For example, it would be legal to behave like this if any
of your proposed -c, -o, -x, or -X options were used.


I've noted the POSIX objections in your previous mail, and yes, that 
would invalidate my addition.


I could theoretically add a '-d' option to the suite above, to a) force 
my behaviour and b) (redundantly) specify decimal output.


But I'm still somewhat concerned about the introduction of switches to 
expr (where there are none at all today) actually breaking working shell 
scripts so I suppose those additions are better left out altogether.


(Maybe I'm overly cautious, but I'm thinking along the lines of:

ARGS='-c'
expr ${ARGS} : '-[coXx]' # Check for valid options

Although I don't know if this would be a use case actually encountered 
in the wild.)


And, as noted elsewhere, there ARE other ways of doing base conversions, 
but that isn't the only use I would see for this. I think it would 
actually be convenient to be able to do hexadecimal calculations in a 
shell script (although it would admittedly not be very portable...).


Oh well, I won't argue this too much, just thought I would toss in the 
idea. However, the 64-bit stuff is an actual concern I've had, so that 
one I'll defend harder. :-)


Thanks for the input.


/Benny

--
internetlabbet.se / work:   +46 8 551 124 80  / Words must
Benny Lvfgren/  mobile: +46 70 718 11 90 /   be weighed,
/   fax:+46 8 551 124 89/not counted.
   /email:  benny -at- internetlabbet.se



Re: expr(1) diff 1 of 3, make it 64-bit capable

2011-01-15 Thread Benny Lofgren
On 2011-01-15 07.05, Philip Guenther wrote:
 If you're going to email diffs, you MUST turn off 'format=flowed', as
 Thunderbird munged the whitespace on your diffs enough to make them
 break with patch -l.  Thunderbird has an option for that; find it
 and use it.

Check.

for (i=0; i100; i++)
fputs(Will do homework better.\t, blackboard);

 ...
 -is_integer(struct val *vp, int *r)
 +is_integer(struct val *vp, int64_t *r)
  {
char   *s;
 -   int neg;
 -   int i;
 +   int64_t neg;
 +   int64_t i;
 
 You make 'neg' int64_t why?

Because I'm obviously sloppy. :-)  I read the code badly, thinking neg
would be set to -1 if negative, and then the result multiplied by it. In
reality of course, it is just a flag and the result, if negative, is
multiplied by the constant -1. I'll revert it to an int.

 ...
 @@ -509,7 +509,7 @@
}

if (vp-type == integer)
 -   printf(%d\n, vp-u.i);
 +   printf(%ld\n, vp-u.i);
 
 My crystal ball says you use amd64 platform and not i386, as the above
 works on LP64 and fails on ILP32LL64.  The format string should be
 %lld\n.

You are right of course. I missed to update that when I changed the diff
from long to int64_t at Teds recommendation, and I also failed to test
it afterwards on an i386 platform (which are the only two I have access
to at the moment).

  Related: try this with your version:
 
 expr 42949673000 : '.*'
 
 Your diff will have that return 2, when the correct answer is 11: the
 format string in the asprintf() call in to_string() needs to be
 updated:
 
 -   if (asprintf(tmp, %d, vp-u.i) == -1)
 +   if (asprintf(tmp, %lld, vp-u.i) == -1)

Check. Missed that one too. I knew there was a downside to reading code
when you're really too tired...

Thanks for the input.


/Benny

88888 (cut)
Index: expr.c
===
RCS file: /cvs/src/bin/expr/expr.c,v
retrieving revision 1.17
diff -u -r1.17 expr.c
--- expr.c  21 Jun 2006 18:28:24 -  1.17
+++ expr.c  15 Jan 2011 12:26:57 -
@@ -14,11 +14,11 @@
 #include regex.h
 #include err.h

-struct val *make_int(int);
+struct val *make_int(int64_t);
 struct val *make_str(char *);
 voidfree_value(struct val *);
-int is_integer(struct val *, int *);
-int to_integer(struct val *);
+int is_integer(struct val *, int64_t *);
+int64_t to_integer(struct val *);
 voidto_string(struct val *);
 int is_zero_or_null(struct val *);
 voidnexttoken(int);
@@ -44,7 +44,7 @@

union {
char   *s;
-   int i;
+   int64_t i;
} u;
 };

@@ -53,7 +53,7 @@
 char **av;

 struct val *
-make_int(int i)
+make_int(int64_t i)
 {
struct val *vp;

@@ -92,11 +92,11 @@

 /* determine if vp is an integer; if so, return it's value in *r */
 int
-is_integer(struct val *vp, int *r)
+is_integer(struct val *vp, int64_t *r)
 {
char   *s;
int neg;
-   int i;
+   int64_t i;

if (vp-type == integer) {
*r = vp-u.i;
@@ -133,10 +133,10 @@


 /* coerce to vp to an integer */
-int
+int64_t
 to_integer(struct val *vp)
 {
-   int r;
+   int64_t r;

if (vp-type == integer)
return 1;
@@ -161,7 +161,7 @@
if (vp-type == string)
return;

-   if (asprintf(tmp, %d, vp-u.i) == -1)
+   if (asprintf(tmp, %lld, vp-u.i) == -1)
err(3, NULL);

vp-type = string;
@@ -375,7 +375,7 @@
 {
struct val *l, *r;
enum token  op;
-   int v = 0, li, ri;
+   int64_t v = 0, li, ri;

l = eval3();
while ((op = token) == EQ || op == NE || op == LT || op == GT ||
@@ -509,7 +509,7 @@
}

if (vp-type == integer)
-   printf(%d\n, vp-u.i);
+   printf(%lld\n, vp-u.i);
else
printf(%s\n, vp-u.s);
88888 (cut)

-- 
internetlabbet.se / work:   +46 8 551 124 80  / Words must
Benny Lvfgren/  mobile: +46 70 718 11 90 /   be weighed,
/   fax:+46 8 551 124 89/not counted.
   /email:  benny -at- internetlabbet.se



systat.1 - Interfaces correction

2011-01-15 Thread Mark Lumsden
The number of IPKTS and OPKTS in systat(1) is calculated by taking away the new 
total packets from the old total packets and dividing the result by the delay 
between refreshes (naptime). This calculation is performed in the macro UPDATE 
in if.c

I think the current description is inaccurate.

ok?

-mark


Index: systat.1
===
RCS file: /cvs/src/usr.bin/systat/systat.1,v
retrieving revision 1.88
diff -u -p -r1.88 systat.1
--- systat.113 Jan 2011 17:44:54 -  1.88
+++ systat.115 Jan 2011 13:46:36 -
@@ -501,8 +501,9 @@ The rest of the column breaks down the t
 by device basis.
 Only devices that have interrupted at least once since boot time are shown.
 .Pp
-Below the Interrupts display is a summary of
-total number of input packets and output packets for all interfaces.
+Below the Interrupts display are
+the average number of input and output packets per second 
+for all interfaces over the last refresh interval.
 .Pp
 Below the SWAPPING display and slightly to the left of the Interrupts
 display is a list of virtual memory statistics.



Re: bioctl should retry passphrase

2011-01-15 Thread Alexander Hall
On 01/15/11 03:06, Ted Unangst wrote:
 On Thu, 13 Jan 2011, Ted Unangst wrote:
 
 If I type the wrong password into bioctl at boot, disks don't exist, 
 filesystems don't get mounted, and generally lots of things go wrong.  All 
 I need is a second chance to remind me to type the right password.
 
 After some feedback, here's a revised edition.  Keep prompting until the 
 user gets it right.  If you want out, ^C, ^D, or just plain enter will 
 quit.
 
 This also tweaks the password length check to abort on empty passwords.  
 (readpassphrase 'succeeds' after hitting ^D.)
 
 Index: bioctl.c
 ===
 RCS file: /home/tedu/cvs/src/sbin/bioctl/bioctl.c,v
 retrieving revision 1.98
 diff -u -r1.98 bioctl.c
 --- bioctl.c  1 Dec 2010 19:40:18 -   1.98
 +++ bioctl.c  15 Jan 2011 02:04:14 -
 @@ -738,6 +738,7 @@
   if (level == 'C'  no_dev != min_disks)
   errx(1, not exactly one partition);
  
 +again:
   memset(create, 0, sizeof(create));
   create.bc_cookie = bl.bl_cookie;
   create.bc_level = level;
 @@ -802,8 +803,10 @@
   memset(kdfinfo, 0, sizeof(kdfinfo));
   memset(create, 0, sizeof(create));
   if (rv == -1) {
 - if (errno == EPERM)
 - errx(1, Incorrect passphrase);
 + if (errno == EPERM) {
 + warnx(Incorrect passphrase. Try again.);
 + goto again;
 + }
   err(1, BIOCCREATERAID);
   }

I haven't looked very close but should not the handling differ between
the key_disk vs passphrase cases? I bet there would be a way to make it
loop... :-)

/Alexander


  
 @@ -1065,18 +1068,17 @@
  
   if (fgets(passphrase, sizeof(passphrase), f) == NULL)
   err(1, can't read passphrase file);
 - pl = strlen(passphrase);
 - if (pl  0  passphrase[pl - 1] == '\n')
 - passphrase[pl - 1] = '\0';
 - else
 - errx(1, invalid passphrase length);
 -
   fclose(f);
   } else {
   if (readpassphrase(prompt, passphrase, sizeof(passphrase),
   rpp_flag) == NULL)
   errx(1, unable to read passphrase);
   }
 + pl = strlen(passphrase);
 + if (pl  0  passphrase[pl - 1] == '\n')
 + passphrase[--pl] = '\0';
 + if (pl == 0)
 + errx(1, invalid passphrase length);
  
   if (verify) {
   /* request user to re-type it */



Re: bioctl should retry passphrase

2011-01-15 Thread Ted Unangst
On Sat, Jan 15, 2011 at 11:49 AM, Alexander Hall ha...@openbsd.org wrote:
 I haven't looked very close but should not the handling differ between
 the key_disk vs passphrase cases? I bet there would be a way to make it
 loop... :-)

I think you are right.  I'll fix that.



Re: Make expr(1) 64-bit capable and radix-aware

2011-01-15 Thread Otto Moerbeek
On Sat, Jan 15, 2011 at 01:00:04PM +0100, Benny Lofgren wrote:

 On 2011-01-15 07.43, Otto Moerbeek wrote:
 On Fri, Jan 14, 2011 at 08:22:25PM -0700, Theo de Raadt wrote:
 + Makes it 64-bit capable on 64-bit architectures by changing relevant
 int:s to long:s.
 I think this is a problem.
 I would expect a unix utility of this importance to work exactly the
 same on all our platforms.
 
 Additionally, i very much prefer to have as little as possible
 differecnes between expr(1) and the ksh builtin.
 
 Ehum, running the risk of looking like a complete fool I've got to
 ask, is there actually a ksh builtin version of expr?
 
 I did actually double check that prior to digging into this, with
 whence expr, and now after reading your comment I've skimmed the
 man page for ksh as well without finding any reference to a builtin
 expr. What am I missing?

You are right, I was confused.

-Otto

 
 Thanks for the input!
 
 
 /Benny
 
 -- 
 internetlabbet.se / work:   +46 8 551 124 80  / Words must
 Benny L??fgren/  mobile: +46 70 718 11 90 /   be weighed,
 /   fax:+46 8 551 124 89/not counted.
/email:  benny -at- internetlabbet.se



Re: Make expr(1) 64-bit capable and radix-aware

2011-01-15 Thread Ted Unangst
On Sat, Jan 15, 2011 at 3:30 PM, Otto Moerbeek o...@drijf.net wrote:
 Additionally, i very much prefer to have as little as possible
 differecnes between expr(1) and the ksh builtin.

 Ehum, running the risk of looking like a complete fool I've got to
 ask, is there actually a ksh builtin version of expr?

 I did actually double check that prior to digging into this, with
 whence expr, and now after reading your comment I've skimmed the
 man page for ksh as well without finding any reference to a builtin
 expr. What am I missing?

 You are right, I was confused.

although making $(()) handle 64-bit may also be a nice addition.



Re: Make expr(1) 64-bit capable and radix-aware

2011-01-15 Thread Matthias Kilian
On Sat, Jan 15, 2011 at 03:35:43PM -0500, Ted Unangst wrote:
 On Sat, Jan 15, 2011 at 3:30 PM, Otto Moerbeek o...@drijf.net wrote:
  Ehum, running the risk of looking like a complete fool I've got to
  ask, is there actually a ksh builtin version of expr?
 
  I did actually double check that prior to digging into this, with
  whence expr, and now after reading your comment I've skimmed the
  man page for ksh as well without finding any reference to a builtin
  expr. What am I missing?
 
  You are right, I was confused.

x=$(expr $a + $b)

should give the same result as

x=$((a + b))

So it's perfectly ok to demand expr(1) and ksh(1) compatibility.

 although making $(()) handle 64-bit may also be a nice addition.

I've an old diff (from december 2008) around, but IIRC i wasn't
happy with it, because it could break existing shell scripts
(MAILCHECK and TMOUT come into mind).

Ciao,
Kili



Re: Workaround for data corruption issue with ALI M5229 IDE chip used with Sun Blade 100/Netra X1.

2011-01-15 Thread Alexander Schrijver
On Sat, Jan 15, 2011 at 12:17:54PM +0100, Mark Kettenis wrote:
  Date: Fri, 14 Jan 2011 18:56:07 +0100
  From: Alexander Schrijver alexander.schrij...@gmail.com
  
   The big question of course is whether it will survive a make build
   with the change that removes the restriction of only using Ultra-DMA
   up to mode 2, but without the fixes in pciide.c.
   
   Beware, that might actually eat your filesystem.
   
  
  I'm doing this right now. I'm running a make build as we speak. I'm not sure
  when it should fuck up the filesystem.
 
 Me neither, that's what makes this diff so difficult to test properly.

So, make build failed with the following message. I'm not sure what is to blame
here.

I forgot to upgrade packages to the latest -current. AFAIK the build process
isn't dependend on external packages, but i'm not entirely sure if it could
accidentally use an externel package.

Looking at the commit logs nothing happened in /gnu/ in the last week so it
probably isn't the tree.

The boot filesystem checks went fine. Nothing new in dmesg either.

i'll run it again tomorrow with a decently upgraded system and a fresh 
/usr/src/.

I don't know anything about the perl build system so i can't really investigate
that. cvs diff says none of the files have changed in the perl directory.

The message with some stuff removed:

Running Makefile.PL in cpan/Encode

[ ... stuff removed ... ]

cp Encode/_PM.e2x ../../lib/Encode/_PM.e2x
cp lib/Encode/CJKConstants.pm ../../lib/Encode/CJKConstants.pm
make: don't know how to make ExtUtils/xsubpp. Stop in 
/usr/obj/gnu/usr.bin/perl/cpan/Encode.
Unsuccessful make(cpan/Encode): code=512 at make_ext.pl line 449.
*** Error code 25

Stop in /usr/src/gnu/usr.bin/perl/obj (line 695 of makefile).
*** Error code 1

Stop in /usr/src/gnu/usr.bin/perl (line 81 of 
/usr/src/gnu/usr.bin/perl/Makefile.bsd-wrapper).
*** Error code 1

Stop in /usr/src/gnu/usr.bin (line 48 of /usr/share/mk/bsd.subdir.mk).
*** Error code 1

Stop in /usr/src/gnu (line 48 of /usr/share/mk/bsd.subdir.mk).
*** Error code 1

Stop in /usr/src (line 48 of /usr/share/mk/bsd.subdir.mk).
*** Error code 1

Stop in /usr/src (line 74 of Makefile).

complete message:

=== gnu/usr.bin/perl
cd /usr/src/gnu/usr.bin/perl/obj  exec /bin/sh cflags.SH
Extracting cflags (with variable substitutions)
cd /usr/src/gnu/usr.bin/perl/obj  exec /bin/sh makeaperl.SH
Extracting makeaperl (with variable substitutions)
cd /usr/src/gnu/usr.bin/perl/obj  exec /bin/sh myconfig.SH
Extracting myconfig (with variable substitutions)
cd /usr/src/gnu/usr.bin/perl/obj  exec /bin/sh Policy_sh.SH
Extracting Policy.sh (with variable substitutions)
cd /usr/src/gnu/usr.bin/perl/obj/pod  exec /bin/sh Makefile.SH
Extracting pod/Makefile (with variable substitutions)
cd /usr/src/gnu/usr.bin/perl/obj/x2p  exec /bin/sh cflags.SH
Extracting x2p/cflags (with variable substitutions)
cc -O2 -pipe -g -fno-strict-aliasing -fno-delete-null-pointer-checks   
-DPERL_CORE -DPERL_RANDOM_DEVICE=/dev/arandom -I. -c 
/usr/src/gnu/usr.bin/perl/gv.c -o gv.o
cc -O2 -pipe -g -fno-strict-aliasing -fno-delete-null-pointer-checks   
-DPERL_CORE -DPERL_RANDOM_DEVICE=/dev/arandom -I. -c 
/usr/src/gnu/usr.bin/perl/toke.c -o toke.o
cc -O2 -pipe -g -fno-strict-aliasing -fno-delete-null-pointer-checks   
-DPERL_CORE -DPERL_RANDOM_DEVICE=/dev/arandom -I. -c perly.c -o perly.o
cc -O2 -pipe -g -fno-strict-aliasing -fno-delete-null-pointer-checks   
-DPERL_CORE -DPERL_RANDOM_DEVICE=/dev/arandom -I. -c 
/usr/src/gnu/usr.bin/perl/pad.c -o pad.o
cc -O2 -pipe -g -fno-strict-aliasing -fno-delete-null-pointer-checks   
-DPERL_CORE -DPERL_RANDOM_DEVICE=/dev/arandom -I. -c 
/usr/src/gnu/usr.bin/perl/regcomp.c -o regcomp.o
cc -O2 -pipe -g -fno-strict-aliasing -fno-delete-null-pointer-checks   
-DPERL_CORE -DPERL_RANDOM_DEVICE=/dev/arandom -I. -c 
/usr/src/gnu/usr.bin/perl/dump.c -o dump.o
cc -O2 -pipe -g -fno-strict-aliasing -fno-delete-null-pointer-checks   
-DPERL_CORE -DPERL_RANDOM_DEVICE=/dev/arandom -I. -c 
/usr/src/gnu/usr.bin/perl/util.c -o util.o
cc -O2 -pipe -g -fno-strict-aliasing -fno-delete-null-pointer-checks   
-DPERL_CORE -DPERL_RANDOM_DEVICE=/dev/arandom -I. -c 
/usr/src/gnu/usr.bin/perl/mg.c -o mg.o
cc -O2 -pipe -g -fno-strict-aliasing -fno-delete-null-pointer-checks   
-DPERL_CORE -DPERL_RANDOM_DEVICE=/dev/arandom -I. -c 
/usr/src/gnu/usr.bin/perl/reentr.c -o reentr.o
cc -O2 -pipe -g -fno-strict-aliasing -fno-delete-null-pointer-checks   
-DPERL_CORE -DPERL_RANDOM_DEVICE=/dev/arandom -I. -c 
/usr/src/gnu/usr.bin/perl/mro.c -o mro.o
cc -O2 -pipe -g -fno-strict-aliasing -fno-delete-null-pointer-checks   
-DPERL_CORE -DPERL_RANDOM_DEVICE=/dev/arandom -I. -c 
/usr/src/gnu/usr.bin/perl/hv.c -o hv.o
cc -O2 -pipe -g -fno-strict-aliasing -fno-delete-null-pointer-checks   
-DPERL_CORE -DPERL_RANDOM_DEVICE=/dev/arandom -I. -c 
/usr/src/gnu/usr.bin/perl/av.c -o av.o
cc -O2 -pipe -g -fno-strict-aliasing -fno-delete-null-pointer-checks   
-DPERL_CORE -DPERL_RANDOM_DEVICE=/dev/arandom -I. -c