[bug] Problem with cd -@ if filesystem does not support extended attributes (O_XATTR)

2013-11-06 Thread Joshuah Hurst
Chet, on Solaris the /devices filesystem does not support extended
attributes (O_XATTR), yet cd -@ returns 0 (success):

./bash -c 'cd -@ /devices 2>/dev/null; echo $?'
0
~/bin/ksh -c 'cd -@ /devices 2>/dev/null; echo $?'
1

truss shows that bash gets errno==EINVAL but then uses
chdir("/devices") instead of returning the error:
stat64("/devices", 0x08047520)  = 0
open64("/devices", O_RDONLY|O_NONBLOCK) = 3
openat64(3, ".", O_RDONLY|O_XATTR)  Err#22 EINVAL
close(3)= 0
chdir("/devices")   = 0
brk(0x0819C000) = 0

Josh

-- Forwarded message --
From: Lionel Cons 
Date: Tue, Nov 5, 2013 at 11:12 PM
Subject: Re: Bash-4.3-beta2 available for FTP
To: Chester Ramey 
Cc: Simon Toedt , bug-bash@gnu.org, Joshuah
Hurst , Cedric Blancher
, Chester Ramey 


On 5 November 2013 22:56, Chet Ramey  wrote:
>> > I'm interested in the patch if cd -@ file works like in ksh. Or
>> > whatever, just send the patch that I can test it.
>> >
>> > Thank you.
>>
>> Again. Any patch or git pull tarball which we could try?
>
> The cd -@ option is available in the `devel' branch of the git tree on
> savannah:
>
> http://git.savannah.gnu.org/cgit/bash.git/?h=devel
>
> It first appears in the bash-20131025 snapshot.

Chet, thank you

Build instructions:
git clone --branch devel git://git.savannah.gnu.org/bash.git

Apply this patch and then build as usual:
diff --git a/builtins/cd.def b/builtins/cd.def
index 498cf88..c448c5a 100644
--- a/builtins/cd.def
+++ b/builtins/cd.def
@@ -194,7 +194,7 @@ cdxattr (dir, ndirp)
 {
 #if defined (O_XATTR)
   int apfd, fd, r, e;
-  char buf[11+40+40];  /* construct new `fake' path for pwd */
+  char buff[11+40+40]; /* construct new `fake' path for pwd */

   apfd = openat (AT_FDCWD, dir, O_RDONLY|O_NONBLOCK);
   if (apfd < 0)

Lionel


-- 
Josh



Re: [bug] Problem with cd -@ if filesystem does not support extended attributes (O_XATTR)

2013-11-06 Thread Lionel Cons
On 6 November 2013 13:16, Joshuah Hurst  wrote:
> Chet, on Solaris the /devices filesystem does not support extended
> attributes (O_XATTR), yet cd -@ returns 0 (success):
>
> ./bash -c 'cd -@ /devices 2>/dev/null; echo $?'
> 0
> ~/bin/ksh -c 'cd -@ /devices 2>/dev/null; echo $?'
> 1
>
> truss shows that bash gets errno==EINVAL but then uses
> chdir("/devices") instead of returning the error:
> stat64("/devices", 0x08047520)  = 0
> open64("/devices", O_RDONLY|O_NONBLOCK) = 3
> openat64(3, ".", O_RDONLY|O_XATTR)  Err#22 EINVAL
> close(3)= 0
> chdir("/devices")   = 0
> brk(0x0819C000) = 0
>
> Josh

Thanks

The following patch should fix the bugs (build+cd -@ /devices):
===
diff --git a/builtins/cd.def b/builtins/cd.def
index 498cf88..7dd9684 100644
--- a/builtins/cd.def
+++ b/builtins/cd.def
@@ -194,7 +194,7 @@ cdxattr (dir, ndirp)
 {
 #if defined (O_XATTR)
   int apfd, fd, r, e;
-  char buf[11+40+40];  /* construct new `fake' path for pwd */
+  char buff[11+40+40]; /* construct new `fake' path for pwd */

   apfd = openat (AT_FDCWD, dir, O_RDONLY|O_NONBLOCK);
   if (apfd < 0)
@@ -630,7 +630,7 @@ change_to_directory (newdir, nolinks, xattr)
   /* We're not in physical mode (nolinks == 0), but we failed to change to
  the canonicalized directory name (TDIR).  Try what the user passed
  verbatim. If we succeed, reinitialize the_current_working_directory. */
-  if (chdir (newdir) == 0)
+  if (!xattr && (chdir (newdir) == 0))
 {
   t = resetpwd ("cd");
   if (t == 0)
===

After applying the patch I get:

./bash -c 'cd -@ /devices ; echo $?'
./bash: line 0: cd: /devices: Invalid argument
1 <--- correct
./bash -c 'cd -@ / ; ls -l'
total 2
-r--r--r--   1 root root 156 Sep 18 05:05 SUNWattr_ro
-rw-r--r--   1 root root 472 Sep 18 05:05 SUNWattr_rw

Lionel



Old idea for vi-yank-pop

2013-11-06 Thread ian
A few years ago, I had an idea for bash, which I recently remembered. I
never cared about it enough to propose it, but I figured I should share
in case it is helpful to someone else.

In vim, you can get access to multiple yanks/cuts/kills, but you can't
in bash's vi-mode. It would be a good feature to give vi-mode access to
the the stack of yanks from the default emacs mode. I figured it could
be called vi_yank_pop. This is a patch I wrote a long time ago. I don't
know if it works, and it probably mostly copies the emacs code.

Cheers,
Ian Kelling


--- ../bash-4.0/lib/readline/kill.c 2008-08-12 14:59:31.0
-0700
+++ kill.c  2009-03-12 20:58:07.0 -0700
@@ -550,6 +550,39 @@
 }
 }
 
+int
+rl_vi_yank_pop (count, key)
+ int count, key;
+{
+  int l, n;
+
+  if (((rl_last_func != rl_vi_yank_pop) && (rl_last_func != rl_vi_put))
||
+  !rl_kill_ring)
+{
+  _rl_abort_internal ();
+  return -1;
+}
+
+  l = strlen (rl_kill_ring[rl_kill_index]);
+  n = rl_point - l;
+  if (n >= 0 && STREQN (rl_line_buffer + n + 1,
rl_kill_ring[rl_kill_index], l))
+{
+  rl_delete_text (n, rl_point);
+  rl_point = n;
+  rl_kill_index--;
+  if (rl_kill_index < 0)
+   rl_kill_index = rl_kill_ring_length - 1;
+  rl_vi_put (1, 'p');
+  return 0;
+}
+  else
+{
+  _rl_abort_internal ();
+  return -1;
+}
+}
+
+
 /* Yank the COUNTh argument from the previous history line, skipping
HISTORY_SKIP lines before looking for the `previous line'. */
 static int
--- ../bash-4.0/lib/readline/funmap.c   2009-01-04 11:32:33.0
-0800
+++ funmap.c2009-03-12 18:37:18.0 -0700
@@ -139,6 +139,7 @@
   { "yank-last-arg", rl_yank_last_arg },
   { "yank-nth-arg", rl_yank_nth_arg },
   { "yank-pop", rl_yank_pop },
+  { "vi-yank-pop", rl_vi_yank_pop },
 
 #if defined (VI_MODE)
   { "vi-append-eol", rl_vi_append_eol },
--- ../bash-4.0/lib/readline/readline.h 2009-01-04 11:32:33.0
-0800
+++ readline.h  2009-03-12 18:37:18.0 -0700
@@ -167,6 +167,7 @@
 extern int rl_copy_backward_word PARAMS((int, int));
 extern int rl_yank PARAMS((int, int));
 extern int rl_yank_pop PARAMS((int, int));
+extern int rl_vi_yank_pop PARAMS((int, int));
 extern int rl_yank_nth_arg PARAMS((int, int));
 extern int rl_yank_last_arg PARAMS((int, int));
 /* Not available unless __CYGWIN__ is defined. */



Re: [bug] Problem with cd -@ if filesystem does not support extended attributes (O_XATTR)

2013-11-06 Thread Chet Ramey
On 11/6/13, 7:16 AM, Joshuah Hurst wrote:
> Chet, on Solaris the /devices filesystem does not support extended
> attributes (O_XATTR), yet cd -@ returns 0 (success):

Thanks for the report.  This will be fixed for bash-4.3.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/



Re: Testcase for cd -@ / O_XATTR

2013-11-06 Thread Chet Ramey
On 11/5/13, 5:20 PM, Lionel Cons wrote:
> Chet, below is a simple testcase for cd -@ / O_XATTR support:
> 
> ./bash -c 'set -o errexit ; touch foo ; runat foo "echo hello1
>> myxattr" ; cd -@ foo ; exec {n}<>myxattr ; cd -P .. ; cat <&$n ;
> true'
> 
> This should print 'hello1'.
> 
> Any suggestion where this test can be placed?

I'll think about it.  I generally don't like to add test cases for features
that are available on so few platforms.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/



Re: Testcase for cd -@ / O_XATTR

2013-11-06 Thread Chris Down
On 2013-11-06 22:23:41 -0500, Chet Ramey wrote:
> I'll think about it.  I generally don't like to add test cases for features
> that are available on so few platforms.

Why? Surely that is the place where such test cases would be most
valuable?


pgpkMsDg4AKUh.pgp
Description: PGP signature