Re: [Vserver] /etc/vserver/server/flags not working as expected (fakeinit)

From: Herbert Poetzl <herbert_at_13thfloor.at>
Date: Tue 28 Mar 2006 - 14:19:55 BST
Message-ID: <20060328131955.GB14576@MAIL.13thfloor.at>

On Tue, Mar 28, 2006 at 11:26:51AM +0200, Andreas Baetz wrote:
> When using /etc/vserver/vserver/flags, the flags are set, but the flag fakeinit dos not work as expected:
>
> host:/etc/vservers/vserver# cat flags
>
> host:/etc/vservers/vserver# vserver vserver start
> Starting system log daemon: syslogd.
> Starting kernel log daemon: klogd.
> Starting internet superserver: inetd.
> Starting deferred execution scheduler: atd.
> Starting periodic command scheduler: cron.
> host:/etc/vservers/vserver# vserver vserver enter
> mesg: /dev/pts/10: Operation not permitted
> vserver:/# cat /proc/self/vinfo
> XID: 8004
> BCaps: 0000000000000001
> CCaps: 0000000000000001
> CFlags: 0000000202020010
> CIPid: 0
> vserver:/# ps ax
> PID TTY STAT TIME COMMAND
> 1 ? S 0:00 init [2]
> 21542 ? Ss 0:00 /sbin/syslogd
> 21581 ? Ss 0:00 /usr/sbin/inetd
> 21587 ? Ss 0:00 /usr/sbin/cron
> 21600 pts/10 S 0:00 /bin/bash -login
> 21620 pts/10 R+ 0:00 ps ax
> vserver:/# logout
>
> Now, fakeinit is put into flags:
>
> host:/etc/vservers/vserver# cat flags
> fakeinit
> host:/etc/vservers/vserver# vserver vserver start
> host:/etc/vservers/vserver# Starting system log daemon: syslogd.
> Starting kernel log daemon: klogd.
> Starting internet superserver: inetd.
> Starting deferred execution scheduler: atd.
> Starting periodic command scheduler: cron.
>
> host:/etc/vservers/vserver# vserver vserver enter
> mesg: /dev/pts/10: Operation not permitted
> vserver:/# cat /proc/self/vinfo
> XID: 8004
> BCaps: 0000000000000001
> CCaps: 0000000000000001
> CFlags: 0000000002020010
> CIPid: 21945
> vserver:/# ps ax
> PID TTY STAT TIME COMMAND
> 21958 ? Ss 0:00 /sbin/syslogd
> 21997 ? Ss 0:00 /usr/sbin/inetd
> 22003 ? Ss 0:00 /usr/sbin/cron
> 22009 pts/10 R 0:00 /bin/bash -login
> 22025 pts/10 R+ 0:00 ps ax
> vserver:/# logout
>
> Now, 0x10 (fakeinit) is put into flags:
>
> host:/etc/vservers/vserver# cat flags
> 0x00000010
> host:/etc/vservers/vserver# vserver vserver start
> Starting system log daemon: syslogd.
> Starting kernel log daemon: klogd.
> Starting internet superserver: inetd.
> Starting deferred execution scheduler: atd.
> Starting periodic command scheduler: cron.
> host:/etc/vservers/vserver# vserver vserver enter
> mesg: /dev/pts/10: Operation not permitted
> vserver:/# cat /proc/self/vinfo
> XID: 8004
> BCaps: 0000000000000001
> CCaps: 0000000000000001
> CFlags: 0000000202020010
> CIPid: 0
> vserver:/# ps ax
> PID TTY STAT TIME COMMAND
> 1 ? S 0:00 init [2]
> 22335 ? Ss 0:00 /sbin/syslogd
> 22374 ? Ss 0:00 /usr/sbin/inetd
> 22380 ? Ss 0:00 /usr/sbin/cron
> 22393 pts/10 S 0:00 /bin/bash -login
> 22408 pts/10 R+ 0:00 ps ax
> vserver:/# logout
>
> There are 2 questions:
>
> 1) Why does fakeinit not work, while 0x10 does ?
> 2) Why does 0x10 not set just 0x0000000000000010, but 0x0000000202020010 ?

I guess this is a tool question actually, but I answer
it from the kernel PoV, Enrico might comment on the
tool side ...

the kernel knows the following flags:

        VXF_INFO_INIT 0x0000000010
        VXF_STATE_INIT 0x0200000000

the kernel also 'defines'

        VXF_FAKE_INIT (VXF_INFO_INIT|VXF_STATE_INIT)

the kernel uses the INFO_INIT to decide wether it should
remap the initpid to 1 (and the other way round), and the
STATE_INIT (one time flag) to set an initpid (i.e. clearing
this flag takes the current process pid as initpid)

now, the following flag combinations make sense:

        0x0000000000 init process, no remapping
        0x0000000010 init process, remapping to 1
        0x0200000000 no init process, no fakeing
        0x0200000010 no init process, init faked

which gives an excellent opportunity to advertise the new
low-level test tool (it's just a few hours old :) to send
arbitrary vserver syscall commands (vcmd [1])

here is a faked init process (blend through)

./vcmd -i 42 -qBC ctx_create .flagword=^33^4 -- ps auxww

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 1560 532 ? S Mar27 0:03 init [5]
root 3920 0.0 0.0 2576 844 pts/0 R+ 15:18 0:00 ps auxww

here is a real init process (which gets remapped)

./vcmd -i 42 -qBC ctx_create .flagword=^33^32 -- \
  ./vcmd -i -1 -qBC set_cflags .flagword=^4 .mask=^33^32^4 -- ps auxww

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 2528 700 pts/0 R 15:16 0:00 ps auxww

HTH,
Herbert

[1] http://vserver.13thfloor.at/Experimental/TOOLS/vcmd-0.01.tar.bz2

>
> Andreas
> _______________________________________________
> Vserver mailing list
> Vserver@list.linux-vserver.org
> http://list.linux-vserver.org/mailman/listinfo/vserver
_______________________________________________
Vserver mailing list
Vserver@list.linux-vserver.org
http://list.linux-vserver.org/mailman/listinfo/vserver
Received on Tue Mar 28 14:20:36 2006

[Next/Previous Months] [Main vserver Project Homepage] [Howto Subscribe/Unsubscribe] [Paul Sladen's vserver stuff]
Generated on Tue 28 Mar 2006 - 14:20:39 BST by hypermail 2.1.8