加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

应用程序自动启动(busybox)

(2014-09-23 08:37:30)
标签:

busybox

应用程序自动启动

linux

在 Busybox init进程启动过程分析 中共存在3个用户可以介入的启动点:inittab项,inittab的sysinit目标,以及sh启动项。

1、在 inittab 中添加启动项,由 init 进程启动。
embedded linux with busybox auto-login  介绍了如下启动程序的方法:
首先建一个 startup.sh 的脚本文件:

#!/bin/sh # #Sets necessary environment variables and runs the desktop # export TSLIB_TSDEVICE=/dev/touchscreen-1wire export TSLIB_TSEVENTTYPE=INPUT export TSLIB_FBDEVICE=/dev/fb0 export TSLIB_PLUGINDIR=/usr/lib/ts/ export TSLIB_CONSOLEDEVICE=none export TSLIB_CONFFILE=/etc/ts.conf export TSLIB_CALIBFILE=/etc/pointercal export LD_LIBRARY_PATH=/usr/lib export QTDIR=/usr/lib/qt export QWS_MOUSE_PROTO=tslib:/dev/touchscreen-1wire /path/to/application -qws

Then made it executable with:


$chmod +x startup.sh

then added this line to inittab:


tty1::once:/path/to/startup.sh

测试表明,这个方法没有 用户登录,没有tty连接。用户程序虽然能够正常执行,但是似乎影响到了tty连接建立的后续语句的执行。

2、利用 inittab 中 sysinit 功能启动
执行inittab中的命令时,首先执行的是 ::sysinit:/etc/init.d/rcS 。
下面是分析文件系统中/etc/init.d/rcS的内容,这是我的rcS文件中的内容。这个文件会在inittab中使用。rcS文件如下:
#!/bin/sh 
PATH=/sbin:/bin:/usr/sbin:/usr/bin 
runlevel=S 
prevlevel=N 
umask 022 
export PATH runlevel prevlevel  //上面几句为启动环境设置必要的环境变量
#!/bin/sh
#
# rcS Call all S??* scripts in /etc/rcS.d in
# numerical/alphabetical order.
#
# Version: @(#)/etc/init.d/rcS  2.76  19-Apr-1999  miquels@cistron.nl
#
PATH=/sbin:/bin:/usr/sbin:/usr/bin
runlevel=S
prevlevel=N
umask 022
export PATH runlevel prevlevel

# Make sure proc is mounted
#
[ -d "/proc/1" ] || mount /proc

#
# Source defaults.
#
. /etc/default/rcS
#
# Trap CTRL-C &c only in this shell so we can interrupt subprocesses.
#
trap ":" INT QUIT TSTP
#
# Call all parts in order.
#
exec /etc/init.d/rc S

可以在 rc5.d 下放置 启动用户程序的脚本或者链接。一般是软链接。不过由于 petalinux sdk 是自动生成 rootfs 的,所以把脚本直接拷贝(文件名必须以Sxx开头)到了 rc5.d 下,可以运行,运行效果 与 在 inittab 中加一行的效果类似,程序(图形界面)运行完(关闭)后,没有任何shell可用。有人建议放在这里的程序应该是“可感知tty的”,在tty建立前等待,建立后挂接,实现方法待查。

3、/etc/profile文件

这个文件是sh用的,当用户获得一个shell后,sh就会根据这个文件配置用户的登陆环境。

# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))

# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

PATH="/usr/local/bin:/usr/bin:/bin"

EDITOR="/bin/vi" # needed for packages like cron

test -z "$TERM" && TERM="vt100" # Basic terminal capab. For screen etc.

if [ ! -e /etc/localtime ]; then

TZ="UTC" # Time Zone. Look at http://theory.uwinnipeg.ca/gnu/glibc/libc_303.html 

# for an explanation of how to set this to your local timezone.

export TZ

fi

if [ "$HOME" = "/home/root" ]; then

   PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin

fi

if [ "$PS1" ]; then

# works for bash and ash (no other shells known to be in use here)

   PS1='\u@\h:\w\$ '

fi

if [ -d /etc/profile.d ]; then

  for i in /etc/profile.d/* ; do

    . $i

  done

  unset i

fi

export PATH PS1 OPIEDIR QPEDIR QTDIR EDITOR TERM

umask 022

        用户登录后,会执行 /etc/profile.d 中的所有文件。将启动脚本命名为 profile.xxx,放到 /etc/profile.d目录下,用户登录后,该脚本会自动执行。如果有多个文件,执行顺序似乎取决于后缀的字母序。
        这种方法不丢失 用户、tty、shell 。



0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有