| View previous topic :: View next topic |
| Author |
Message |
Carlos Guru


Joined: 07 Aug 2002 Posts: 458 Location: Providence, RI
|
Posted: Fri Dec 06, 2002 1:30 pm Post subject: Bizarre su -c behavior |
|
|
When I tryPortage retrieves the package, but doesn't actually install it. Also, when I do something like I can open and edit the file fine, but I get the following error when I exit: | Code: | | E138: Can't write viminfo file $HOME/.viminfo! | None of these problems happen if I su to root then execute commands instead of using su -c, but I find it perplexing. Alas, I'm not sure where to RTFM and can't think of how to search for similar problems, so I'm posting here. I suspect that this happened after I ran etc-update at some point, but I'm not entirely sure. _________________ Man must shape his tools lest they shape him. |
|
| Back to top |
|
 |
zhenlin Veteran

Joined: 09 Nov 2002 Posts: 1361
|
Posted: Fri Dec 06, 2002 2:15 pm Post subject: |
|
|
| There are a few types of su, a binary one and one embedded in the shell. su - -c 'ls ~' should list the home dir of root, not the current user. su -c 'ls ~' should list the home dir of the current user. |
|
| Back to top |
|
 |
Carlos Guru


Joined: 07 Aug 2002 Posts: 458 Location: Providence, RI
|
Posted: Sat Dec 07, 2002 12:08 am Post subject: |
|
|
| zhenlin wrote: | | There are a few types of su, a binary one and one embedded in the shell. su - -c 'ls ~' should list the home dir of root, not the current user. su -c 'ls ~' should list the home dir of the current user. | I've tried those, but they both give the listing of /root. Also, I tried using "su - -c" instead of "su -c" with emerge and vim, but I'm still getting the same problems. _________________ Man must shape his tools lest they shape him. |
|
| Back to top |
|
 |
ebrostig Bodhisattva


Joined: 20 Jul 2002 Posts: 3152 Location: Orlando, Fl
|
Posted: Sat Dec 07, 2002 12:28 am Post subject: |
|
|
But none of the command lines you listed includes a user name.
I take it that you wanted to su to root, then run the command as root and exit back to your normal user?
Take a look at sudo, this command is normally used for this type of jobs.
Erik |
|
| Back to top |
|
 |
Carlos Guru


Joined: 07 Aug 2002 Posts: 458 Location: Providence, RI
|
Posted: Sat Dec 07, 2002 12:47 am Post subject: |
|
|
Well, su su's to root by default, and I'm sure I've seen what I'm doing recommended somewhere - otherwise I never would have started using it, considering that I can't find documentation for the -c option. In any event, it was working perfectly until recently; if things stay this way I might install sudo. _________________ Man must shape his tools lest they shape him. |
|
| Back to top |
|
 |
ebrostig Bodhisattva


Joined: 20 Jul 2002 Posts: 3152 Location: Orlando, Fl
|
Posted: Sat Dec 07, 2002 1:49 am Post subject: |
|
|
| Carlos wrote: | | Well, su su's to root by default, and I'm sure I've seen what I'm doing recommended somewhere - otherwise I never would have started using it, considering that I can't find documentation for the -c option. In any event, it was working perfectly until recently; if things stay this way I might install sudo. |
You're right about su ofcourse, my bad
Here is a way around it:
1. Create a shell script with the following entry:
#! /bin/bash
export HOME=/root
vi $*
2. Make it executable:
chmod +x filename
3. Use su like this:
su -c "./filename parameterlist"
This will avoid the message you see, why I don't know
Erik |
|
| Back to top |
|
 |
Carlos Guru


Joined: 07 Aug 2002 Posts: 458 Location: Providence, RI
|
Posted: Sat Dec 07, 2002 1:53 am Post subject: |
|
|
| ebrostig wrote: |
You're right about su ofcourse, my bad  | No problem. Thanks for the solution for the vi part; I'm still quite curious about what the trouble with emerge is, and what the underlying cause of all the trouble is, but it's only a minor inconvenience.
The search continues... _________________ Man must shape his tools lest they shape him. |
|
| Back to top |
|
 |
lx Veteran


Joined: 28 May 2002 Posts: 1012 Location: Netherlands
|
Posted: Sat Dec 07, 2002 1:53 am Post subject: |
|
|
| ebrostig wrote: |
1. Create a shell script with the following entry:
#! /bin/bash
export HOME=/root
vi $*
Erik |
Well I wanted to suggest su - -c "set" a while ago, but when I do a test on my machine it just works, HOME=/root etc well I don't have vim but anyway, still I had some problems executing files using other user besides root in startup script, I fixed this using su - -c "/bin/bash --login -c ....", but I can't remember what the problem was then, but it also got to do with some environment variable not being set.
Cya lX. _________________ "Remember there's a big difference between kneeling down and bending over.", Frank Zappa |
|
| Back to top |
|
 |
ebrostig Bodhisattva


Joined: 20 Jul 2002 Posts: 3152 Location: Orlando, Fl
|
Posted: Sat Dec 07, 2002 2:12 am Post subject: |
|
|
Ok, I took this to another level
I ran strace as my su command:
su -c "strace -ff -o /root/su.out vi /root/aaa"
Exiting resulted in the now infamous "Cannot write to $HOME/.viminfo"
When I looked at the strace output, this is what i found:
| Code: |
stat64("/root/aaa", {st_mode=S_IFREG|0644, st_size=13, ...}) = 0
write(1, "\33[43;13H5L, 13C written", 23) = 23
_llseek(4, 0, [0], SEEK_SET) = 0
write(4, "b0VIM 6.1\0\0\0\0\20\0\0\271R\361=\344k)\0S@\0\0root"..., 4096) = 4096
unlink("/root/aaa~") = 0
open("$HOME/.viminfo", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
stat64("$HOME/.viminfo", 0xbffff290) = -1 ENOENT (No such file or directory)
umask(077) = 022
open("$HOME/.viminfo", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0666) = -1 ENOENT (No such file or directory)
umask(022) = 077
write(1, "\r\r\n\33[1m\33[37m\33[41mE138: Can\'t wri"..., 63) = 63
write(1, "\33[m\r\r\n\33[32mHit ENTER or type com"..., 48) = 48
|
As you can see, it can not expand the $HOME variable, henc can not really find the correct directory. That si why the little script I gave you works since it sets the HOME variable prior to executing vi. Oh, btw, I do have a /root/viminfo
Erik |
|
| Back to top |
|
 |
kyptin Tux's lil' helper


Joined: 29 Jun 2002 Posts: 95 Location: UNC (Chapel Hill, NC, USA)
|
Posted: Sat Dec 07, 2002 5:51 am Post subject: environments |
|
|
I'm pretty sure this behavior has something to do with which environment you're in when the command executes. For instance, the su manpage says
| su manpage wrote: | | The optional argument - may be used to provide an environment similar to what the user would expect had the user logged in directly. |
So, my understanding is that - will invoke the shell specified in /etc/passwd for the user you're su-ing to, and that shell might look at .bashrc or whatever startup files it needed. I'm thinking a simple su -c without the - option simply changes the UID of the current user for that process, which could interfere with the environment somehow.
Looking into this further, at the login manpage (the su manpage directed me here)....
Seems like su with the - option basically does the same thing as login does. And according to its manpage, login is responsible for setting UID/GID, $HOME, $SHELL, $PATH, etc.
I haven't quite nailed anything down, but maybe I've managed to set somebody to sniffing in the right direction. I'd look more, but my eyelids are beginning to interfere with my vision, meaning I need to go to bed.  |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|