LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-02-2008, 02:21 AM   #16
Jurrian
Member
 
Registered: Sep 2008
Posts: 58

Original Poster
Rep: Reputation: 15

And to your later post you replied when I was writing my post,

I checked ps, but I can't find anything with the name ash in it..

Here is the output of ps:

Code:
# ps
  PID  Uid        VSZ Stat Command
    1 root       2248 S   init                
    2 root            SW< [kthreadd]
    3 root            SWN [ksoftirqd/0]
    4 root            SW< [events/0]
    5 root            SW< [khelper]
   63 root            SW< [kblockd/0]
   64 root            SW< [cqueue/0]
   66 root            SW< [mxc_spi.0]
   68 root            SW< [mxc_spi.1]
   71 root            SW< [mxc_spi.2]
   73 root            SW< [ksuspend_usbd]
   76 root            SW< [khubd]
   93 root            SW< [kmmcd]
  109 root            SW  [pdflush]
  110 root            SW  [pdflush]
  111 root            SW< [kswapd0]
  112 root            SW< [aio/0]
  741 root            SW< [mtdblockd]
  759 root            SW< [pccardd]
  806 root            SW  [mxc_ts]
  807 root            SW< [rpciod/0]
  820 root       2244 S   /sbin/syslogd 
  822 root       2240 S   /sbin/klogd 
  824 root       2248 R   /usr/sbin/telnetd 
  835 root       8792 S   Xfbdev -br -pn -mouse tslib -dpi 100 -rgba bgr -screen 640x480@90 -noreset 
  837 root       2244 S   /sbin/getty -L 115200 ttymxc0 vt100 
  838 root       2252 S   /bin/sh -sc /etc/profile 
  841 root       1624 S   /usr/sbin/simple-ftpd -f /etc/simple-ftpd.conf 
  850 root       2256 S   /bin/sh 
  864 root       2252 S   /bin/sh 
  866 root       2248 R   ps
Thanx in advance,

Jurrian
 
Old 10-02-2008, 02:26 AM   #17
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
ENV must be set upon invocation of ash if the shell is not a login shell. Since there was no output of of the line PROFILE, we can assume your shell is not a login shell. See my post #14 about how to determine this. So, setting ENV won't have any affect in non-login shell situations.

How would ENV be set upon invocation of ash? Like this:

ENV=/path/to/startup/profile ash

But you can't do this because you are logging in and don't have control of the program that starts ash. (it may be possible for you to configure that program to set the ENV environment variable before invoking ash - I don't know what program busybox uses to do this; typically this is a program such as getty or gdm calling login).
 
Old 10-02-2008, 02:33 AM   #18
Jurrian
Member
 
Registered: Sep 2008
Posts: 58

Original Poster
Rep: Reputation: 15
I tried to determine wheter ash is a interactive loginshell or not, but when I ps'ed, I can't find ash, see my #16 for the result of ps. So how could I determine wheter ash is a login shell or not?
 
Old 10-02-2008, 02:35 AM   #19
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
The ash shell is setting its process name as "sh". We see:

838 root 2252 S /bin/sh -sc /etc/profile
850 root 2256 S /bin/sh
864 root 2252 S /bin/sh

The first one says to take commands from /etc/profile, so it appears that file should be read. The other two are just shells. None of the three appear to be login shells (or they don't follow the - as the first character protocol).

Place the line

set -x

at the top if your /etc/profile and logout/in and report the output.
 
Old 10-02-2008, 02:43 AM   #20
Jurrian
Member
 
Registered: Sep 2008
Posts: 58

Original Poster
Rep: Reputation: 15
I putted set -x at the top of my /etc/profile, and replaced my ~/.profile to echo .profile, but when i logout and login there's no new result, and the shells still don't have a - before them:

838 root 2252 S /bin/sh -sc /etc/profile
841 root 1624 S /usr/sbin/simple-ftpd -f /etc/simple-ftpd.conf
872 root 2252 S /bin/sh

Perhaps I could change the way ash is started at the script that starts ash? I searched my rcS script for it but I can't find the line that starts ash there.
 
Old 10-02-2008, 02:49 AM   #21
Jurrian
Member
 
Registered: Sep 2008
Posts: 58

Original Poster
Rep: Reputation: 15
I tried to put a new line on top of my /etc/profile script, to check if it actually gets parsed, so I added echo /etc/profile, without any result when I logout/login..
 
Old 10-02-2008, 03:42 AM   #22
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
Sorry this is so challenging. What would be trivial to diagnose and solve at the keyboard becomes very difficult via forum communication. There is a lot of explanation required to help you understand the pieces of this puzzle so you can get accomplished what seems to be a simple task.

The shell is not started by your rcS script. It is started by another program. Run

ps -elfx

to see the process tree so that you can see the relationship between the processes and their children.

You have not been seeing output from your echo commands because there is no TTY associated with the shell processes that have been run. This is why they are not login shells. And later shells have been simple interactive shells only, hence all the efforts have been fruitless.

To determine the correct location for setting DISPLAY, you need to know the startup process that ultimately leads to your login and shell. The init process uses an inittab (/etc/inittab, but it doesn't have to exist in busybox) to determine which programs to launch upon startup. It will launch programs like getty and your ultimately the rcS script. Since your rcS script is a subproces of init, it cannot set environment variables for other direct children of init. The environment variable must be set in a parent. The rcS script mounts disks, sets up networking, and starts the X server. But it does not startup your getty/login session - which is being done by by init (since we don't see it in your rcS file).

What is the contents of your /etc/inittab ?

There are many variations on how environment variables are configured for user shells, and how terminal programs are started in GUI and non-GUI environments. I don't know your busybox environment, and so I don't know which variation is in use, and so can't easily give step-by-steps to solve this problem.

Last edited by Mr. C.; 10-02-2008 at 03:44 AM.
 
Old 10-02-2008, 03:52 AM   #23
Jurrian
Member
 
Registered: Sep 2008
Posts: 58

Original Poster
Rep: Reputation: 15
Ah well, I like the challenging part, but sometimes it would just be nice if a part just works

But at this way my Linux knowledge is growing, and that's nice to. And I really want to thank you for your help so far, and I know it's hard to explain things on a forum, since you don't have any clue what the knowledge of the one you are explaining to is, and small errors (ash instead of bash) are making it harder and harder, but I really appreciate your help!

Then the output of ps -elfx

# ps -elfx
ps: invalid option -- e
BusyBox v1.9.1 (2008-04-11 15:22:42 EDT) multi-call binary

Usage: ps

I guess at this part I'm missing bash, since BusyBox is a small version of bash.

Then my /etc/inittab:

# cat /etc/inittab
::sysinit:/etc/init.d/rcS
#tty2::respawn:/sbin/getty -L 38400 tty2
#tty3::respawn:/sbin/getty -L 38400 tty3
#tty4::respawn:/sbin/getty -L 38400 tty4
#tty5::respawn:/sbin/getty -L 38400 tty5
#tty6::respawn:/sbin/getty -L 38400 tty6
::respawn:/sbin/getty -L 115200 ttymxc0 vt100
::respawn:/bin/bash -sc /etc/profile
::ctrlaltdel:/sbin/reboot
::shutdown:/sbin/swapoff -a
::shutdown:/bin/umount -a -r
::restart:/sbin/init

I guess the first line starts my rcS script, and the ::respawn /bin/bash -sc /etc/profile starts bash, but I thought I was using ash?? I looked up /bin/bash with a ls -all, and found out that /bin/ash is a link to busybox, but nothing to find out about /bin/bash. The ash and bash are confusing me a little, perhaps something in there is also one of the problems why things aren't working properly?
 
Old 10-02-2008, 04:21 AM   #24
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
Ok, this is good data.

Yet another variation of ps options. No big deal.

You do have an inittab, and it shows that your tty's are started via getty (serial port) and one shell (/bin/bash) which is likely the console. But your /bin/bash is really an ash shell (as we've seen from the output).

Now your login showed:

Code:
192.168.0.253 login: root
Password:
Am I correct that this a remote login (via telnet), or is this a console login?
 
Old 10-02-2008, 04:25 AM   #25
Jurrian
Member
 
Registered: Sep 2008
Posts: 58

Original Poster
Rep: Reputation: 15
I am login in via telnet, you are right.

I use linux on an embedded system, and the embedded system doensn't have a keyboard, so I have to login remotely. If needed however I can using minicom connect my board directly, but as far as I know that wouldn't change a lot right?

Thanx in advance,

Jurrian
 
Old 10-02-2008, 04:59 AM   #26
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
This explains more of the data. I went and read the source code to verify what is going on.

Since you are telneting, telnetd is responsible for launching /bin/login, which ultimately logs you in to a shell. Login has an option (-p) to allow maintaining the environment, but telnetd does not supply this option, so you cannot set an environment varible before telnetd is started to affect telnetd's children. So, you must set your environment variable after the shell is launched, either using shell mechanisms or manually.

The source code shows that login does invoke the shell as a login shell. The ps output we're seeing is the command executed, and not the modified command name with a dash to indicate a login shell. I verified that /etc/profile is indeed read by the shell when it is a login shell, so you should be able to prove this.

Add the line
Code:
echo $$ > /tmp/mytest.$$
to the top of your /etc/profile, and then logout/in, and then run :

Code:
ls /tmp
ps
 
Old 10-02-2008, 05:07 AM   #27
Jurrian
Member
 
Registered: Sep 2008
Posts: 58

Original Poster
Rep: Reputation: 15
Allright, I'm getting more and more of it.

Output:

# ls /tmp
# ps
PID Uid VSZ Stat Command
1 root 2248 S init
2 root SW< [kthreadd]
3 root SWN [ksoftirqd/0]
4 root SW< [events/0]
5 root SW< [khelper]
63 root SW< [kblockd/0]
64 root SW< [cqueue/0]
66 root SW< [mxc_spi.0]
68 root SW< [mxc_spi.1]
71 root SW< [mxc_spi.2]
73 root SW< [ksuspend_usbd]
76 root SW< [khubd]
93 root SW< [kmmcd]
109 root SW [pdflush]
110 root SW [pdflush]
111 root SW< [kswapd0]
112 root SW< [aio/0]
741 root SW< [mtdblockd]
759 root SW< [pccardd]
806 root SW [mxc_ts]
807 root SW< [rpciod/0]
820 root 2244 S /sbin/syslogd
822 root 2240 S /sbin/klogd
824 root 2248 S /usr/sbin/telnetd
835 root 8792 S Xfbdev -br -pn -mouse tslib -dpi 100 -rgba bgr -scree
837 root 2244 S /sbin/getty -L 115200 ttymxc0 vt100
838 root 2252 S /bin/sh -sc /etc/profile
841 root 1624 S /usr/sbin/simple-ftpd -f /etc/simple-ftpd.conf
893 root 2252 S /bin/sh
895 root 2248 R ps


However I am afraid I am missing some output that should be there??
 
Old 10-02-2008, 05:44 AM   #28
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
Yup, I was expecting to see a file in /tmp. This means the source code that I read does not match what you are experiencing. And given the crippled version of some commands, it makes diagnosis difficult (can't see how /bin/sh was called for example in ARGV[0].

I verified telnetd calls login without arguments, and login invokes a login shell (it places a dash in front of the shell name, which we can't see because of the crippled ps). Regardless, we can only go by what the results tell us - /etc/profile is not being read. And if this is the case, you'll have to set the DISPLAY environment variable when starting your X commands.

You might want to consider asking your question on the busybox mailing lists - they may know something I wasn't able to see in the quick source code read.
 
Old 10-02-2008, 05:50 AM   #29
Jurrian
Member
 
Registered: Sep 2008
Posts: 58

Original Poster
Rep: Reputation: 15
well, is it a possibility that in my inittab file (see one of earlier posts) is not correct in starting bash. I vaguely remember I edited it partly last week, but I forgot to make a backup before I changed, what I usually do..

Shouldn't it start sh instead of bash?

And I start the Xserver in the rcS script. Perhaps theres a file that runs the Xserver where I can put a link to my exports?

I want to thank you for your time, I learned some new things and I feel I am closer to a solution then before you helped me.

With kind regards,

Jurrian

Last edited by Jurrian; 10-02-2008 at 05:51 AM.
 
Old 10-02-2008, 01:51 PM   #30
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
If you launch bash yourself, what shell do you actually get?

Type set to see the list of variables. Bash will set BASH_VERSION. The sh and ash shells will not; look in shell variables and environment variables for any version/shell information.

I did not see source code for bash in the busybox environment. There is ash, hush, bbsh, and msh. But your environment may have other tools.

The default login shell is "-/bin/sh" (the dash indicating a login shell should be created), and the default shell ($SHELL) is "/bin/sh". Since there is no source code for the "sh" shell, one of the above shells must be a link to one of the other shells. Shells called by another name may operate in compatibility/impersonation mode, impersonating the shell name their are called by (i.e. ash may act exactly like sh if called by the name sh).

A login user's shell is controlled by the shell parameter in /etc/passwd. Check out root's login shell.

You are missing the point about sibling processes not being able to affect their sibling's (or parent's) environment. Your X server is started in the rcS script. Any environment variable you set in that script can *only* affect those processes started by that script. Any "file that runs the Xserver" can only affect children of that file (script/program). Since telnetd is NOT started by that script, telnetd wold not magically inherit any environment variables set there. Furthermore, as I mentioned, the login program (spawned by telnetd) WIPES OUT the environment and specifically sets it to only required, safe values, unless the -p option is specified on the command line. To change this behavior, you would have to recompile telnetd. So, via telnetd, you get:

Code:
telnetd
   \ login (with wiped environment)
       \ shell
The initialization code from rcS looks like:

Code:
...
initial rcS processes
...
telnetd
   \ login (with wiped environment)
       \ shell   <--- you are here
...
Xserver
   \ xserver clients
You should be able to see that the Xserver and any clients do not affect the shell that ultimately get's created via telnetd.

Since login launches a shell (/bin/sh), you could replace /bin/sh with an executable wrapper script such as:

Code:
#!/bin/sh.orig

DISPLAY=:0
export DISPLAY

exec /bin/sh.orig
But be very careful; doing this incorrectly will render your busybox dead, since there will be no shell by the name of /bin/sh that works!

This is your only hook to setting an environment variable between login and the exec of the shell.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check in a script whether the shell is login or non login? frankie_DJ Programming 7 10-21-2015 11:09 AM
login script btaylor1988 Linux - Server 8 09-12-2007 09:22 AM
Need a login script stefaandk Linux - Newbie 4 01-05-2006 05:24 PM
login script nin881 Slackware 3 06-11-2005 03:21 AM
Login script unclejessie77 Programming 5 02-24-2005 01:30 PM


All times are GMT -5. The time now is 01:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration