Windowsからのandlinuxアプリの起動過程を追ってみる
個人的メモ。大したことは全く書いてない。時々更新すると思われる。
とりあえずその前はどうなってるのかわからないが/usr/bin/X11/startwindowsterminalsessionを追ってみる。
/usr/bin/X11/startwindowsterminalsession:
#!/bin/bash # andLinux script to start windows terminal session # wait until drive is mounted while [ ! -f /mnt/and/settings.txt ] do /bin/sleep 1 done . /etc/profile /usr/local/sbin/firstboot.sh termcommand=`cat /etc/winterm` #sux - root ${termcommand} sux - nos ${termcommand}
とりあえず一応見ておくとうちのsettings.txtはこんなかんじ↓
mem=384 root=/dev/cobd0 initrd=initrd.gz kernel=vmlinux cobd0=Drives\base.drv cobd1=Drives\swap.drv eth0=slirp eth1=tuntap,"TAP-Colinux",00:11:22:33:44:55 cofs0=C:\cygdrive cofs1=C:\docs
これが読み込まれるまで待つのにどういう意味があるのかよくわからないが、andLinuxが起動してなかった時の起動待ち?
普通に考えるとこっちじゃなくてwindowsのディレクトリの方が読み込まれているかの方を確認しそうなものだけどなあ。なんでだろ。
.はsourceコマンドの略記でファイルの読み込み。
/etc/profile:
#!/bin/bash # /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:/usr/bin/X11:/usr/games" if [ "$BASH" ]; then PS1='[\u@\h \W]\$ ' else if [ "`id -u`" -eq 0 ]; then PS1='# ' else PS1='$ ' fi fi export PATH PS1 # set DISPLAY env variable export DISPLAY=192.168.11.1:0.0 export ESPEAKER=192.168.11.1:16001 export PULSE_SERVER=192.168.11.1 umask 022 # Japanese input method export GTK_IM_MODULE=scim-bridge export QT_IM_MODULE=scim-bridge
デフォルトでは$BASHには/usr/bashが入ってた。これもどっかで設定してるんだろう。PS1はプロンプトだよね。この\uとか\Wはあとから都度置き換えて表示するんだろう。
DISPLAY、ESPEAKER、PULSE_SERVERはWindowsのXMINGと音のサーバーのアドレス?うち音が出るインストール設定にはしてないけど。
umaskは新規作成されたファイル・ディレクトリのパーミッションにマスクをかける設定。
666で作ろうとするとそこから022を引いた644がデフォルトのパーミッションになって他人が書き込みできなくなる。こうやって制御してるのね。
ref:http://x68000.q-e-d.net/~68user/unix/pickup?umask
2行あるexportはこの前追加した日本語入力設定。
初回起動時処理
/usr/local/sbin/firstboot.sh:
#!/bin/bash if [ -f /mnt/and/firstboot.txt ] ; then # move to andLinux filesystem to avoid temporal side effects... cp -f /mnt/and/firstboot.txt /tmp/firstboot.txt # convert to UNIX format, otherwise \r is remaining at the end of the parameters... dos2unix /tmp/firstboot.txt # remove possibly existing old /mnt/win mount point if [ `grep -c "/mnt/win" /etc/fstab` -ne 0 ] ; then if [ `mount | grep -c "/mnt/win"` -ne 0 ] ; then umount /mnt/win fi grep -v "/mnt/win" /etc/fstab > /tmp/fstab mv -f /etc/fstab /etc/fstab.old mv -f /tmp/fstab /etc/fstab chmod 644 /etc/fstab fi # add new /mnt/win mount point mounttype=`cat /tmp/firstboot.txt | grep mounttype | cut -d = -f 2` mkdir -p /mnt/win if [ $mounttype = "cofs" ] ; then echo "/dev/cofs0 /mnt/win cofs defaults 0 0" >> /etc/fstab mount /mnt/win elif [ $mounttype = "samba" ] ; then mountshare=`cat /tmp/firstboot.txt | grep mountshare | cut -d = -f 2` # fstab entry doesn't work because mounting is done too early (network unavailable) #echo "//windows-host/$mountshare /mnt/win smbfs credentials=/etc/smbpasswd,iocharset=iso8859-1,codepage=cp437 0 0" >> /etc/fstab sed -e "s/# __ANDLINUX_AUTOGEN_MARKER__/mount -t smbfs -o credentials=\/etc\/smbpasswd,iocharset=iso8859-1,codepage=cp437 \/\/windows-host\/$mountshare \/mnt\/win/" < /etc/rc.local > /tmp/rc.local mv -f /tmp/rc.local /etc/rc.local chmod 755 /etc/rc.local mountuser=`cat /tmp/firstboot.txt | grep mountuser | cut -d = -f 2` mountpassword=`cat /tmp/firstboot.txt | grep mountpassword | cut -d = -f 2` if [ -f /etc/smbpasswd ] ; then mv -f /etc/smbpasswd /etc/smbpasswd.old fi echo "username = $mountuser" > /etc/smbpasswd echo "password = $mountpassword" >> /etc/smbpasswd chmod 600 /etc/smbpasswd #mount /mnt/win /etc/rc.local # re-execute on first boot as already done before this script is run fi # check for and adapt launcher script launcher=`cat /tmp/firstboot.txt | grep launcher | cut -d = -f 2` if [ $launcher = "yes" ] ; then mountpath=`cat /tmp/firstboot.txt | grep mountpath | cut -d = -f 2 | sed -e 's/\\\\/\\\\\\\\\\\\\\\\/g'` sed -e "s/\$windowsPathPrefix = \".*\";/\$windowsPathPrefix = \"$mountpath\";/" < /usr/local/sbin/launcher.pl > /tmp/launcher.pl mv -f /tmp/launcher.pl /usr/local/sbin/launcher.pl chmod 755 /usr/local/sbin/launcher.pl echo "/usr/local/sbin/launcher.pl" > /etc/winterm else echo "/usr/bin/xfce4-panel" > /etc/winterm fi # remove firstboot.txt rm -f /mnt/and/firstboot.txt fi
firstboot.txtを読み込んでマウントやらの初期設定をしているようだ。txtの中身がちょっと気になるがもう消えてる。最初に走らせる前に書き換えとけばいろいろ初期設定ができるようだ。firstboot.sh自体はディスクイメージに最初から入ってたんだろうか?
で
で最後にsux(suのX版)でwintermを実行しているわけだけども、このファイル自体は
/etc/winterm:
/usr/local/sbin/launcher.pl
いたってシンプル。launcherの方の中身はというと
/usr/local/sbin/launcher.pl:
#!/usr/bin/perl use IO::Socket; $windowsPathPrefix = "C:\\"; $linuxPathPrefix = "/mnt/win/"; #$sock = new IO::Socket::INET(LocalPort => 81, Reuse => 1, Listen => 20) or die("Error creating local socket: $@\n"); $sock = new IO::Socket::INET(LocalPort => 8081, Reuse => 1, Listen => 20) or die("Error creating local socket: $@\n"); while($client = $sock->accept()) { $request = <$client>; chomp $request; if($request =~ m/^cmd=(.+)&file=(.*)$/) { $cmd = $1; $file = $2; $escapedWindowsPathPrefix = $windowsPathPrefix; $escapedWindowsPathPrefix =~ s/\\/\\\\/g; $file =~ s/$escapedWindowsPathPrefix/$linuxPathPrefix/g; $file =~ s/\\/\//g; system("$cmd $file &"); print $client "ok\n"; } else { print $client "failed: parse error\n"; } $client->close(); }
と。