Re: Problem in bin/sh stripping the * character through ${expansion%}

2009-08-06 Thread Eygene Ryabinkin
Doug, good day.

Thu, Aug 06, 2009 at 11:15:12AM -0700, Doug Barton wrote:
> I came across this problem during a recent portmaster update. When
> trying to strip off the * character using variable expansion in bin/sh
> it doesn't work. Other "special" characters do work if they are
> properly escaped.
> 
> The attached mini-script clearly shows the problem:
> 
> $ sh sh-strip-problem
> var before stripping: foo\*
> var after stripping: foo\*
> 
> var before stripping: foo\$
> var after stripping: foo\

According to the sh(1), it is not a problem.  Namely,
 - \* being unquoted at all will produce a lone '*';
 - '*' when treated as the smallest pattern, will result in a stripping
   of a zero-length string -- it is the smallest pattern in the case of
   '*' that matches anything.

In order to strip the trailing star you should use
-
var=${var%[*]}
-
This gives you the pattern of '[*]' that is properly treated as the
single star -- it's a weird way to escape the star in the patterns.

Other characters work, but only because they produce no patterns.
In principle, you can try \? that will remove any trailing character
no matter what, since it is the second character that will produce
the pattern.

> In contrast, bash does the right thing:
> 
> bash sh-strip-problem
> var before stripping: foo\*
> var after stripping: foo\
> 
> var before stripping: foo\$
> var after stripping: foo\

I will try to look at the XCU to understand what is the POSIX
way of doing the things.
-- 
Eygene
 ____   _.--.   #
 \`.|\.....-'`   `-._.-'_.-'`   #  Remember that it is hard
 /  ' ` ,   __.--'  #  to read the on-line manual
 )/' _/ \   `-_,   /#  while single-stepping the kernel.
 `-'" `"\_  ,_.-;_.-\_ ',  fsc/as   #
 _.-'_./   {_.'   ; /   #-- FreeBSD Developers handbook
{_.-``-' {_/#
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


Re: Problem in bin/sh stripping the * character through ${expansion%}

2009-08-06 Thread Johan van Selst
Johan van Selst wrote:
> When I tried it myself, I automatically typed quotes, which does work
>   var="${var%\*}"

Really should learn to read better: this in fact procudes 'foo'
rather than 'foo\' in the given example case. Again, not like bash.


Johan


pgpbI94sMye6i.pgp
Description: PGP signature


Re: Problem in bin/sh stripping the * character through ${expansion%}

2009-08-06 Thread Johan van Selst
Doug Barton wrote:
> I came across this problem during a recent portmaster update. When
> trying to strip off the * character using variable expansion in bin/sh
> it doesn't work. Other "special" characters do work if they are
> properly escaped.

Your script does
var=${var%\*}

When I tried it myself, I automatically typed quotes, which does work
var="${var%\*}"

Alternatively you could use (with or without quotes)
var="${var%[*]}"

Still, I don't see a reason why your variant shouldn't work as well..


Regards,
Johan


pgpF040hK1k5O.pgp
Description: PGP signature


Problem in bin/sh stripping the * character through ${expansion%}

2009-08-06 Thread Doug Barton
Howdy,

I came across this problem during a recent portmaster update. When
trying to strip off the * character using variable expansion in bin/sh
it doesn't work. Other "special" characters do work if they are
properly escaped.

The attached mini-script clearly shows the problem:

$ sh sh-strip-problem
var before stripping: foo\*
var after stripping: foo\*

var before stripping: foo\$
var after stripping: foo\

In contrast, bash does the right thing:

bash sh-strip-problem
var before stripping: foo\*
var after stripping: foo\

var before stripping: foo\$
var after stripping: foo\

Should I go ahead and file a PR on this?


Doug

-- 

This .signature sanitized for your protection

var='foo\*'
echo "var before stripping: $var"
var=${var%\*}
echo "var after stripping: $var"
echo ''
var='foo\$'
echo "var before stripping: $var"
var=${var%\$}
echo "var after stripping: $var"

exit 0
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"

Re: sosend() and mbuf

2009-08-06 Thread John Baldwin
On Tuesday 04 August 2009 12:57:25 pm Dag-Erling Smørgrav wrote:
> Ed Schouten  writes:
> > Maslan  writes:
> > > However, when i checked the pid & tid of the new created thread it
> > > was not the same as the parent nor as the proc0 & thread0
> > I am not sure, but sharing another process's address space doesn't have
> > to imply it shares the same pid, right?
> 
> The man page explicitly states that if no process is specified, the new
> thread is assigned to proc0, which has a valid filedesc table, valid
> creds etc., so this shouldn't be a problem.  However, he's getting a
> different PID, which shouldn't happen.  Either the man page is wrong, or
> things were different in 7.

proc0 does not have a fully valid file descriptor table.  It has a structure, 
but fd_[cjr]dir are not initialized to point at anything.  File descriptors 
are a property of userland processes, not of kernel processes.  However, 
fd_[cjr]dir need to be valid to perform any namei() lookup even if one is 
simply going to do a vn_open() on the resulting vnode (which is more 
approprate for kernel code to do, if it is to open a file at all).

-- 
John Baldwin
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"