:: Re: [DNG] Custom OS initiator. In n…
トップ ページ
このメッセージを削除
このメッセージに返信
著者: Irrwahn
日付:  
To: dng
題目: Re: [DNG] Custom OS initiator. In need of some hints...
On Tue, 14 Jun 2016 08:54:12 +0200, Edward Bartolo wrote:
> Hi,
>
> I downloaded and compiled Felker's minimal init but found it didn't
> work. Examining the code it seems that the website had been
> vandalised.


Assuming you are referring to the code quoted below:
No, it's the correct version, and I see no reason for
it "not working". However, you did not specify at all
what you mean by "didn't work". (Modulo the compiler
should have issued a warning about a missing prototype
for the wait function, for which there is a trivial
fix: #include <sys/wait.h>)

> According to my logic the endless loops should be at the
> end


Why?

> rather than at the middle of the code.


And that's exactly where it should be, namely in the body
of the "if (fork())" conditional statement, which constitutes
the entire code for the parent process to run once fork()
has returned.

> Furthermore, the code seems
> to first block signals then it enables them back afterwards
> contradicting the text.


The signals stay blocked in the parent process, i.e.
the for loop conditional on the fork(), see above.
The signals get unblocked for the child process, i.e.
everything *below* said if-block. I fail to see in what
way the code contradicts the text, or vice versa.

> I am quoting the website:
> http://ewontfix.com/14/
>
> The C code for Felker's minimal init is:
> -------------------------------------------------------------
> #define _XOPEN_SOURCE 700
> #include <signal.h>
> #include <unistd.h>
>
> int main()
> {
>     sigset_t set;
>     int status;

>
>     if (getpid() != 1) return 1;

>
>     sigfillset(&set);
>     sigprocmask(SIG_BLOCK, &set, 0);

>
>     if (fork()) for (;;) wait(&status);

>
>     sigprocmask(SIG_UNBLOCK, &set, 0);

>
>     setsid();
>     setpgid(0, 0);
>     return execve("/etc/rc", (char *[]){ "rc", 0 }, (char *[]){ 0 });
> }



Edward, with all due respect, and I'm trying hard to not
appear rude or offensive, just trying to be helpful here:
I'm afraid you are in dire need of some introductory lessons
in C programming in general, and C programming for *NIXes
in particular. For the former I highly recommend K&R2 [1]
as a primer; for the latter I'm not sure what a contemporary
canonical book recommendation would be, but there are a lot
of resources (of varying quality, beware!) out there. Maybe
other readers of DNG have good suggestions to make.

[1] The C Programming Language, 2nd Edition, by Kernighan and Ritchie

HTH, Regards
Urban