:: Re: [DNG] Mini init script written …
トップ ページ
このメッセージを削除
このメッセージに返信
著者: Edward Bartolo
日付:  
To: Adam Borowski
CC: dng
題目: Re: [DNG] Mini init script written in Perl boots.
Hi,

Initially I started with C and still believe it is the best language
as it avoids having to link to external .so libraries and gcc
compiles efficient code. However, I was shown that there was interest
by some who wanted a script. Therefore, I produced a minimal
rudimentary Perl script that may be extended by anyone interested in
using it.


[ Lars Noodén wrote ]
<<
I see that on devuan jessie what I have
is ps showing 22 processes with a PPID of 1. So, when you say that this
perl script is minimal, do you mean that it would contain other fork
actions if it is to more closely emulate package sysvinit-core's
/sbin/init ?
>>


PID 1 should fork only once to run the first script that loads the
operating system. Once execution enters the infinite loop there is no
way of it jumping to somewhere else. Therefore, only one child is
forked. This child should terminate on as soon as the OS loading
script terminates. On my system it behaves that way. Forking children
indefinitely in absolutely NOT minimal and is highly undesired
considering this should be minimal.

I think it is a mistake to expect a few lines of code written in
whatever language to outperform other init projects written in several
thousand lines of code that are well debugged and mature. The place
for these little scripts, as I see it, is for educational purposes and
to power small computers like the Raspberry Pi, and maybe, to power
the computer of enthusiast adolescent computer geeks who want to
understand what goes on inside their operating system. Mind you, this
is not a deep look inside what happens when an operating system boots,
but it is better than having nothing, or worse of being presented
with mystery where logic should prevail.

Edward

On 17/06/2016, Adam Borowski <kilobyte@???> wrote:
> On Thu, Jun 16, 2016 at 10:47:42PM +0200, Irrwahn wrote:
>> For the record: Should I ever find myself sitting at a
>> machine running a Perl interpreter for PID1, I'd either
>> immediately kill myself or drink the SystemD Kool-Aid
>> by the gallon. (The net effect not being that different.)
> On Thu, Jun 16, 2016 at 02:14:48PM -1000, Joel Roth wrote:
>> I did a test with Memory::Usage, that reports the
>> interpreter's virtual memory size as 22MB. Seems cheap
>> to me.
>
> Yeah, we need to use an efficient language!
>
> .globl _start
> .data
> nopid1:    .ascii "No pid 1, no fun.\n"
> command: .ascii "/sbin/osloader.sh"
> norc: .ascii "Starting /sbin/osloader.sh failed!\n"
> .text
> _start:
>     mov    $39, %rax    # getpid
>     syscall
>     cmp    $1, %rax
>     je    pid1
>     mov    $1, %rax    # write
>     mov    $1, %rdi
>     mov    $nopid1, %rsi
>     mov    $18, %rdx
>     syscall
>     mov    $60, %rax    # _exit
>     mov    $1, %rdi
>     syscall
> pid1:
>     mov    $57, %rax    # fork
>     syscall
>     cmp    $0, %rax
>     jne    child
> parent:
>     mov    $61, %rax    # wait4
>     mov    $-1, %rdi
>     xor    %rsi, %rsi
>     xor    %rdx, %rdx
>     syscall
>     jmp    parent
> child:
>     mov    $59, %rax    # execve
>     mov    $command, %rdi
>     xor    %rsi, %rsi
>     xor    %rdx, %rdx
>     syscall
>     mov    $1, %rax    # write
>     mov    $1, %rdi
>     mov    $norc, %rsi
>     mov    $36, %rdx
>     syscall
>     mov    $60, %rax    # _exit
>     mov    $1, %rdi
>     syscall

>
> Hmmm... I think I'd go with Perl after all.
>
> Meow!
> --
> An imaginary friend squared is a real enemy.
> _______________________________________________
> Dng mailing list
> Dng@???
> https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/dng
>