You are not logged in.

#76 2014-04-24 14:35:32

rebootl
Member
Registered: 2012-01-10
Posts: 431
Website

Re: sinit - suckless init

@jpgg:

Is there an advantage of doing that instead of killing all processes (except init) with "kill -s TERM -1; kill -s KILL -1"?

One thing I get out of this: When you call that from a script and it does what is said (man kill: "kill all processes w/ a pid larger than 1") then this would kill the script itself too...
Though I'm not really sure what it's effectively doing...
I think this is different when it's e.g. in an inittab that init (pid 1) itself is processing, like e.g. busybox does.

Btw. Thanks dimigon for explaining.
Edit: Ah, dimigon we just crossposted, I meant the above explanation wink.

@MrGreen: It depends... You specify the script or whatever you want and it's argument to be executed by this.

So this would call

/sbin/rc init

at boot

/sbin/rc shutdown

when sinit receives SIGUSR1

/sbin/rc reboot

when sinit receives SIGINT.

So for this to work you would need an init script "rc" in /sbin/ (/sbin is symlinked to /usr/bin on Arch). This script needs to accept the arguments "init", "shutdown" and "reboot".

The process of shutting down is usually as explained by progandy above.

Remember that this is compiled into sinit, so you need to rebuild sinit after modifiyng.
To avoid this you could, e.g. w/ this configuration put a simple script under /sbin/rc that calls
the real init scripts. Like:

#!/bin/bash

# $1 is the first argument
case $1 in
init)
    # put the real init script command here e.g.
    /usr/bin/realcommand realargument
    ;;
shutdown)
    # put the real init script command here e.g.
    /usr/bin/realcommand realargument
    ;;
reboot)
    # put the real init script command here e.g.
    /usr/bin/realcommand realargument
    ;;
esac

This must be executable (chmod 755 /sbin/rc).
Might be useful for experimenting but also a bit clumsy wink.

Edit: What might be confusing here is that for shutting down you now usually don't call "/sbin/rc shutdown" directly, but instead you signal (s)init w/ the respective signal (as mentioned by progandy). (s)init then calls the shutdown script. The reasons for this were indicated above.
As it's a bit clumsy to input "kill -s USR1 1" to shutdown you would usually put this in another script or e.g. an alias. I think it should also be possible to put all of these commands in a single script... but e.g. separated by a case as in the example I gave. As of typing this I realize that I'll may try that w/ my dependency init.

Last edited by rebootl (2014-04-24 14:51:38)


Personal website: reboot.li
GitHub: github.com/rebootl

Offline

#77 2014-04-24 14:51:50

Mr Green
Forum Fellow
From: U.K.
Registered: 2003-12-21
Posts: 5,896
Website

Re: sinit - suckless init

My rc script based on servman was in sbin and had those functions. Compiled sinit with above config.h. Script runs shutdown function but then either hangs or jumps back to login. The opt commands are not working well not for me anyway. Busybox worked out of the box without any real issue other than it is slower to boot.

Have a feeling with all the messing about I have been doing the poor vm does not know which way up is... Can set up a new one and try again, base does not take long to set up and then I can test properly

Thanks rebootl


Mr Green

Offline

#78 2014-04-24 14:57:55

rebootl
Member
Registered: 2012-01-10
Posts: 431
Website

Re: sinit - suckless init

Well, I'd need to see an up to date version of the script to comment on this.
Good Luck


Personal website: reboot.li
GitHub: github.com/rebootl

Offline

#79 2014-04-24 15:08:42

Mr Green
Forum Fellow
From: U.K.
Registered: 2003-12-21
Posts: 5,896
Website

Re: sinit - suckless init


Mr Green

Offline

#80 2014-04-24 16:54:47

rebootl
Member
Registered: 2012-01-10
Posts: 431
Website

Re: sinit - suckless init

Yeah ok, but that already got commented on.

In the rc script you still have "busybox reboot" and "busybox shutdown -h now". Review the comments above. Those are not the right commands at that point, even when using busybox.

And the kill commands may be a problem too as discussed in the latest comments above.

Last edited by rebootl (2014-04-24 16:57:44)


Personal website: reboot.li
GitHub: github.com/rebootl

Offline

#81 2014-04-24 18:46:19

Mr Green
Forum Fellow
From: U.K.
Registered: 2003-12-21
Posts: 5,896
Website

Re: sinit - suckless init

I made my script work with busybox for testing, it was based of course on servman. Seems to be an issue with any other init system, power down as user. Systemd does it without too much fuss.


Mr Green

Offline

#82 2014-04-27 06:26:20

Mr Green
Forum Fellow
From: U.K.
Registered: 2003-12-21
Posts: 5,896
Website

Re: sinit - suckless init

Have done some searching and reading up on shutdown as user, two things creating /etc/shutdown.allow with list of users (that did not make any difference) and setting the s bit

chmod +s /usr/bin/shutdown

Allows my user to use shutdown, you can of course apply to reboot.

Do not know how safe this method is or the affect on a multi user system but just thought I would mention it.


Mr Green

Offline

#83 2014-04-27 10:41:20

rebootl
Member
Registered: 2012-01-10
Posts: 431
Website

Re: sinit - suckless init

Do not know how safe this method is or the affect on a multi user system

Probably not safe at all.

What is /usr/bin/shutdown in this case, a link ?

(You should be able to use sudo/visudo for this as discussed before. You may look at the (ugly) script I posted.

E.g. for sinit:
As mentioned for sinit to poweroff you would send

kill -s USR1 1

. This needs to be done as root to work, so -->

sudo kill -s USR1 1

Now, if you dont want to enter a password you need to adapt sudo, using visudo add the line:

<your_username> ALL=NOPASSWD: /usr/bin/kill -s USR1 1, <evtl._more_commands>

replace the <..> by yours, see the sudo wiki for more information.

You can place the call in a script, e.g.
mypoweroff

#!/bin/bash
sudo kill -s USR1 1

)

Edit: In case your /usr/bin/poweroff is a symlink to busybox, be very careful. I noticed that the SUID (+s) is not applied to the symlink itself but to the target. That means that _every_ command executed using busybox, by any user, will be executed as the owner of busybox (most likely root) now...
And setting a SUID on a script doesn't work. It will be ignored by the system (kernel), too dangerous wink.

Last edited by rebootl (2014-04-27 10:57:45)


Personal website: reboot.li
GitHub: github.com/rebootl

Offline

#84 2014-04-27 13:03:26

Mr Green
Forum Fellow
From: U.K.
Registered: 2003-12-21
Posts: 5,896
Website

Re: sinit - suckless init

That is fine, I am only using it under a VM not a real machine. The problem I had was more done the line in rc script rather than commands themselves. It has been a while since I was using an init system. Thought with old Arch it was a group thing (power,wheel).

Still learning ;-)


Mr Green

Offline

#85 2014-04-27 15:18:53

rebootl
Member
Registered: 2012-01-10
Posts: 431
Website

Re: sinit - suckless init

No problem. I don't know how this was set up in the old Arch init. But I'm pretty sure groups could also be used in the sudoers file etc.. Just a matter of setting it up correctly, "wheel" is a typical group for sudoers.


Personal website: reboot.li
GitHub: github.com/rebootl

Offline

Board footer

Powered by FluxBB