You are not logged in.

#1 2010-01-16 18:54:41

some-guy94
Member
Registered: 2009-08-15
Posts: 360

wm-session: A wm agnostic session manager

wm-session is session manager that just loads an autostart file ($HOME/.config/wm-session/autostart.sh), and runs it. When closing itself, it sends SIGTERM to all of the child processes.

To start it, run 'wm-session'
To close the session run

wm-session-end --end (logout)
wm-session-end --shutdown (shutdown)
wm-session-end --reboot (reboot)
wm-session-end --hibernate (suspend to disk)
wm-session-end --suspend (suspend to ram)

The hibernate/suspend commands aren't necessary, but I just thought I'd throw them in anyway.

There is also a config file located in /etc/xdg/wm-session/config (move it to $HOME/.config/wm-session/config if you want to edit the defaults), where you can change the shutdown, reboot, etc commands, and the time given for processes to close (a multiple of 0.5).

NOTE: The default shutdown/reboot commands need wm-session to be started with ck-launch-session.

GitHub
AUR

Last edited by some-guy94 (2010-01-16 19:24:50)

Offline

#2 2010-01-17 04:04:20

dwindle
Member
From: /dev/urandom/
Registered: 2009-05-15
Posts: 85
Website

Re: wm-session: A wm agnostic session manager

Nice. Very KISS. This might be the first session manager I use since like 2008 big_smile


[nil]
[exists]

Offline

#3 2010-01-25 23:37:43

some-guy94
Member
Registered: 2009-08-15
Posts: 360

Re: wm-session: A wm agnostic session manager

wm-session now uses fifo's to manage sessions rather than

does $endsession exist?
no
sleep 1
does $endsession exist?
no
sleep 1
does $endsession exist?
no
...
does $endsession exist?
yes

Offline

#4 2010-01-26 06:53:52

the_isz
Member
Registered: 2009-04-14
Posts: 280

Re: wm-session: A wm agnostic session manager

How about giving one or two screenshots of your app? Maybe this way you could get some more people interested in this project...

Offline

#5 2010-01-26 07:27:07

res
Member
Registered: 2010-01-14
Posts: 55

Re: wm-session: A wm agnostic session manager

Nice, I like the idea a lot.

Looking at the code and trying it out.

Offline

#6 2010-01-26 22:00:35

some-guy94
Member
Registered: 2009-08-15
Posts: 360

Re: wm-session: A wm agnostic session manager

the_isz wrote:

How about giving one or two screenshots of your app? Maybe this way you could get some more people interested in this project...

Well, that's not really possible because it isn't a GUI app and it doesn't have any output.

It's a session manager, it logs you in and out.

Offline

#7 2010-01-26 23:46:44

res
Member
Registered: 2010-01-14
Posts: 55

Re: wm-session: A wm agnostic session manager

A few pointers:

No need for %separator% in $CHILD_PROCESSES, just make it an array instead. This is much saner.

Don't do `echo $var | sed 's|str|replacement|'`, use a here string instead: `sed 's|str|replacement|' <<<$var'

You don't need ppid nor command name in ps, and generally, this is a dangerous way of doing things: http://mywiki.wooledge.org/ProcessManagement, specially the section on PID/names and why is working with those completely random.

For the little stuff that doesn't really matter:

Don't do str=$str+1, just ((str++))

Don't do sleep 999. You are already working with fifos. The kernel will stop your process until receiving a signal without a performance drop, use that to your advantage.

Since it's not sh, don't use `test'; use [[ instead. If the parameter expands into nothingness, or even worse, splits incorrectly, `test' will break.

At the first function, define reboot=${shutdown/Shutdown/Restart}. Similar goes for suspend, instead of having to type it all over again.


I was thinking of writing a patch but I realized that this is just very hazardous. Good job though, it's good for a first script.

e: It'd be best to store child pids in a var and compare the time when killing them, instead of using ps and parsing its output.

Last edited by res (2010-01-26 23:48:29)

Offline

#8 2010-01-27 02:14:23

some-guy94
Member
Registered: 2009-08-15
Posts: 360

Re: wm-session: A wm agnostic session manager

res wrote:

A few pointers:

No need for %separator% in $CHILD_PROCESSES, just make it an array instead. This is much saner.

Thank you.
I was originally wanting to do it that way but didn't think it was possible.
Fixed.

Don't do `echo $var | sed 's|str|replacement|'`, use a here string instead: `sed 's|str|replacement|' <<<$var'

It no longer uses sed, but thanks.

You don't need ppid nor command name in ps, and generally, this is a dangerous way of doing things: http://mywiki.wooledge.org/ProcessManagement, specially the section on PID/names and why is working with those completely random.

I don't see how searching for a certain ppid(that's parent pid not pid) can be dangerous.
The script takes out put that looks like

PPID PID COMMAND

and if PPID == parent pid passed, then it records the pid and command name.

For the little stuff that doesn't really matter:

Don't do str=$str+1, just ((str++))

I switched from standard for loops and until to c-like for loops so...
Fixed.

Don't do sleep 999. You are already working with fifos. The kernel will stop your process until receiving a signal without a performance drop, use that to your advantage.

When that function is run, there are no fifos. This is just a backup solution in case $endsession exists. I plan on changing the way this works so a file with the name $endsession.PID is made, and wm-session-end finds it.

Since it's not sh, don't use `test'; use [[ instead. If the parameter expands into nothingness, or even worse, splits incorrectly, `test' will break.

Aren't test and [ identical? And I don't see how I could use [[ ]] for checking the existence of a file

At the first function, define reboot=${shutdown/Shutdown/Restart}. Similar goes for suspend, instead of having to type it all over again.

They aren't all identical, that works with shutdown/reboot and suspend/hibernate, but not between the two groups.

I was thinking of writing a patch but I realized that this is just very hazardous. Good job though, it's good for a first script.

e: It'd be best to store child pids in a var and compare the time when killing them, instead of using ps and parsing its output.

I don't understand the edit. It is trying to find out if they closed, and if they haven't, then it waits.

Thanks for the feedback.

Offline

#9 2010-01-27 07:08:04

the_isz
Member
Registered: 2009-04-14
Posts: 280

Re: wm-session: A wm agnostic session manager

res wrote:

Don't do `echo $var | sed 's|str|replacement|'`, use a here string instead: `sed 's|str|replacement|' <<<$var'

You can even do this:

${var/str/replacement}
some-guy94 wrote:

Aren't test and [ identical? And I don't see how I could use [[ ]] for checking the existence of a file

Yes, they are. Thus:

[[ -f /path/to/file ]]

Offline

#10 2010-01-27 08:34:03

res
Member
Registered: 2010-01-14
Posts: 55

Re: wm-session: A wm agnostic session manager

~ $ asd=''
~ $ [ $asd = foo ] || echo bar
bash: [: =: unary operator expected
~ $ [[ $asd = foo ]] || echo bar
bar

That's what I meant with expanding into nothing. [ is just `test', an ordinary command. [[ is a builtin.

You need to be very careful with word splitting when using [. Using Bash? Don't bother with [

Offline

#11 2010-01-27 21:48:51

some-guy94
Member
Registered: 2009-08-15
Posts: 360

Re: wm-session: A wm agnostic session manager

Fixed.

Offline

#12 2011-10-01 03:16:21

twilight0
Member
From: Greece
Registered: 2011-05-01
Posts: 227
Website

Re: wm-session: A wm agnostic session manager

The autostart file has to be executable?


Proud Arch Linux user since 2007.

Offline

Board footer

Powered by FluxBB