busybox-1.20.2 第一个运用程序init学习记录

1、init\init.c

init_main()

	/* Check if we are supposed to be in single user mode */
	if (argv[1]
	 && (strcmp(argv[1], "single") == 0 || strcmp(argv[1], "-s") == 0 || LONE_CHAR(argv[1], '1'))
	) {
		/* ??? shouldn't we set RUNLEVEL="b" here? */
		/* Start a shell on console */
		new_init_action(RESPAWN, bb_default_login_shell, "");
	} else {
		/* Not in single user mode - see what inittab says */

		/* NOTE that if CONFIG_FEATURE_USE_INITTAB is NOT defined,
		 * then parse_inittab() simply adds in some default
		 * actions(i.e., INIT_SCRIPT and a pair
		 * of "askfirst" shells */
		parse_inittab();
	}

此段按照韦老师的视频会先执行parse_inittab()函数

2、parse_inittab()

parser_t *parser = config_open2("/etc/inittab", fopen_for_read);//打开配置文件

3、examples\inittab

用于启动不同的运用程序

inittab格式:

 Format for each entry: <id>:<runlevels>:<action>:<process>

id => /dev/id,用作终端:标准输入、标准输出、标准错误;

runlevels :忽略

action:执行时机

process:应用程序或脚本

4、new_init_action()函数

通过如下程序解析:

new_init_action(ASKFIRST, bb_default_login_shell, VC_2);

通过参数查找可就上程序替代变更为如下函数:

static void new_init_action(uint8_t action_type, const char *command, const char *cons)

new_init_action(ASKFIRST, "-/bin/sh", "/dev/tty2");

通过new_init_action函数的参数对比前面inittab格式,可以看到

action_type对应action:执行时机

const char *command对应process:应用程序或脚本

const char *cons 对应id => /dev/id 终端

new_init_action函数功能

①创建一个init_action结构,填充;

②把这个结构放入init_action_list链表;

    这个链表大概有如下内容:

    

   可以通过代码反推出

		/* No inittab file - set up some default behavior */
		/* Reboot on Ctrl-Alt-Del */
		new_init_action(CTRLALTDEL, "reboot", "");
		/* Umount all filesystems on halt/reboot */
		new_init_action(SHUTDOWN, "umount -a -r", "");
		/* Swapoff on halt/reboot */
		if (ENABLE_SWAPONOFF)
			new_init_action(SHUTDOWN, "swapoff -a", "");
		/* Prepare to restart init when a QUIT is received */
		new_init_action(RESTART, "init", "");
		/* Askfirst shell on tty1-4 */
		new_init_action(ASKFIRST, bb_default_login_shell, "");
//TODO: VC_1 instead of ""? "" is console -> ctty problems -> angry users
		new_init_action(ASKFIRST, bb_default_login_shell, VC_2);
		new_init_action(ASKFIRST, bb_default_login_shell, VC_3);
		new_init_action(ASKFIRST, bb_default_login_shell, VC_4);
		/* sysinit */
		new_init_action(SYSINIT, INIT_SCRIPT, "");

5、执行进程

run_actions(SYSINIT);
run_actions(WAIT);
run_actions(ONCE);
run_actions(RESPAWN | ASKFIRST);

最开始执行的是"SYSINIT"类的进程,具体执行可参考run_actions()函数,每类进程运行都有一定的区别。

6、总结

最小的根文件系统包括:

①/dev/console     /dev/null

②/sbin/init

③/etc/inittab

④配置文件制定的运用程序

⑤C库

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Busybox for Android v1.20.2 Stable built by Linus Yang [Aug 12, 2012 Update] - Update to 1.20.2 stable [Features] - Tested on Android 2.1, 2.3, 4.0 and 4.1. Should be capable with all Android devices (Use at your own risk) - ELF armv5te binary (statically linked) - More suitable for Android than the prebuilt ARM binaries from busybox.net - IPv6 support, using own DNS resolver, correct user name display and more improvements for Android [Install] wget http://yangapp.googlecode.com/files/busybox-1.20.2 mv busybox-1.20.2 busybox chmod 755 busybox ./busybox --install [INSTALL_DIR] You can build by yourself from my github's project: (forked from tias/android-busybox-ndk) https://github.com/linusyang/android-busybox-ndk [Information] BusyBox v1.20.2-linusyang (2012-08-12 21:41:27 CST) multi-call binary. Copyright (C) 1998-2011 Erik Andersen, Rob Landley, Denys Vlasenko and others. Licensed under GPLv2. See source distribution for full notice. Usage: busybox [function] [arguments]... or: busybox --list[-full] or: busybox --install [-s] [DIR] or: function [arguments]... BusyBox is a multi-call binary that combines many common Unix utilities into a single executable. Most people will create a link to busybox for each function they wish to use and BusyBox will act like whatever it was invoked as. Currently defined functions: [, [[, acpid, adjtimex, ar, arp, arping, ash, awk, base64, basename, bbconfig, beep, blkid, blockdev, bootchartd, brctl, bunzip2, bzcat, bzip2, cal, cat, catv, chat, chattr, chgrp, chmod, chown, chpst, chroot, chrt, chvt, cksum, clear, cmp, comm, cp, cpio, crond, crontab, cttyhack, cut, date, dc, dd, deallocvt, depmod, devmem, df, dhcprelay, diff, dirname, dmesg, dnsd, dnsdomainname, dos2unix, dpkg, dpkg-deb, du, dumpkmap, dumpleases, echo, ed, egrep, env, envdir, envuidgid, ether-wake, expand, expr, fakeidentd, false, fbset, fbsplash, fdflush, fdformat, fdisk, fgconsole, fgrep, find, findfs, flash_lock, flash_unlock, flashcp, flock, fold, free, freeramdisk, fsck, fsck.minix, fsync, ftpd, ftpget, ftpput, fuser, getopt, grep, groups, gunzip, gzip, halt, hd, hdparm, head, hexdump, hostname, httpd, hush, hwclock, id, ifconfig, ifdown, ifup, inetd, init, inotifyd, insmod, install, ionice, iostat, ip, ipaddr, ipcalc, ipcrm, ipcs, iplink, iproute, iprule, iptunnel, kbd_mode, kill, killall, killall5, klogd, less, linuxrc, ln, loadkmap, logread, losetup, lpd, lpq, lpr, ls, lsattr, lsmod, lsof, lspci, lsusb, lzcat, lzma, lzop, lzopcat, makedevs, makemime, man, md5sum, mdev, mesg, microcom, mkdir, mkdosfs, mke2fs, mkfifo, mkfs.ext2, mkfs.minix, mkfs.reiser, mkfs.vfat, mknod, mkswap, mktemp, modinfo, modprobe, more, mount, mountpoint, mpstat, mv, nameif, nanddump, nandwrite, nbd-client, nc, netstat, nice, nmeter, nohup, nslookup, od, openvt, patch, pgrep, pidof, ping, ping6, pipe_progress, pivot_root, pkill, pmap, popmaildir, poweroff, powertop, printenv, printf, ps, pscan, pstree, pwd, pwdx, raidautorun, rdate, rdev, readlink, readprofile, realpath, reboot, reformime, renice, reset, resize, rev, rm, rmdir, rmmod, route, rpm, rpm2cpio, rtcwake, run-parts, runsv, runsvdir, rx, script, scriptreplay, sed, sendmail, seq, setconsole, setkeycodes, setlogcons, setserial, setsid, setuidgid, sh, sha1sum, sha256sum, sha512sum, showkey, slattach, sleep, smemcap, softlimit, sort, split, start-stop-daemon, stat, strings, stty, sum, sv, svlogd, swapoff, swapon, switch_root, sync, sysctl, syslogd, tac, tail, tar, tcpsvd, tee, telnet, telnetd, test, tftp, tftpd, time, timeout, top, touch, tr, traceroute, traceroute6, true, tty, ttysize, tunctl, tune2fs, ubiattach, ubidetach, ubimkvol, ubirmvol, ubirsvol, ubiupdatevol, udhcpc, udhcpd, udpsvd, umount, uname, uncompress, unexpand, uniq, unix2dos, unlzma, unlzop, unxz, unzip, uptime, usleep, uudecode, uuencode, vconfig, vi, volname, watch, watchdog, wc, wget, which, whoami, whois, xargs, xz, xzcat, yes, zcat, zcip
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值