You are not logged in.

#1 2011-12-10 22:35:25

unformatt
Member
Registered: 2011-03-02
Posts: 24

hook not being executed before sysinit

Hi,
I'm trying a hook before sysinit but it's not working. I created a file called 'custom_hook' in /etc/rc.d/functions.d like this one:

test_hook() {
    /bin/echo 'it works' > /opt/testing
}

add_hook sysinit_start test_hook

But it does not execute because file 'testing' is not being created.

Is there anything else to consider?

Thanks in advance!
Matt.

Offline

#2 2011-12-10 23:09:30

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: hook not being executed before sysinit

Two things:

1) You're pretty much guaranteed that /  is mounted read-only when sysinit_start runs. Your write should, under normal circumstances, fail.
2) echo is available as a bash builtin. No need to call /bin/echo.

Offline

#3 2011-12-10 23:52:41

unformatt
Member
Registered: 2011-03-02
Posts: 24

Re: hook not being executed before sysinit

@falconindy
Thanks for your clarifications,
1) I didn't know that / is mounted as readonly when sysinit_start runs. How can I write a file before starting daemons? Is there a way to accomplish that?
2) I put the absolute path because I wasn't sure if PATH was loadad in that time.

Offline

#4 2011-12-11 01:44:54

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: hook not being executed before sysinit

unformatt wrote:

@falconindy
Thanks for your clarifications,
1) I didn't know that / is mounted as readonly when sysinit_start runs. How can I write a file before starting daemons? Is there a way to accomplish that?

Look at /etc/rc.sysinit then. root is remounted read only 2-3 lines above where the hook runs. At this point, /run is mounted on tmpfs and writable. This is why it exists.

unformatt wrote:

2) I put the absolute path because I wasn't sure if PATH was loadad in that time.

Builtin means that it isn't executing a file on disk. It's an intrinsic of the shell (most shells have this, even lightweight POSIX shells like dash).

# mv /bin/echo{,~}
$ echo 'your shell knows how to do this'
your shell knows how to do this

Offline

#5 2011-12-11 02:46:06

unformatt
Member
Registered: 2011-03-02
Posts: 24

Re: hook not being executed before sysinit

Again, thank you!
I managed to do it with the multi_start hook! :-)

Offline

Board footer

Powered by FluxBB