Howdy,
since "full support for OS X" is still in the TODO for the plugin, I
decided it was time to spend some time on the issue and try to sabotage
a piece of code.

I have written an inetd server that is launched on demand by launchd.
So the server executes as root, and can do all the things root can do.
No need for sudo.
This is insecure, so :
- the server uses a Unix socket. You need to be local to connect
- you can limit the number of actions -eg disable reboot- in the
configuration file, named "srvPowerControlHelper.plist". 
- the server starts by discovering an SC server on localhost. If it
can't find one, it quits.

I attach 2 tars:
- the plist (1 file) goes to /Library/LaunchDaemons/
- the daemon+applescript nagging window go to /Library/Application
Support/srvPowerControlHelper
All files must belong to root. You can't change the location of the
plist file. 
Modify  the plist to change the location of the srvPowerControlHelper
directory, and other settings. (don't do that at first)

Once the files are in the correct location, owned by root, executable
in the case of sudonot.pl, you can either reboot the machine or load the
new server from the terminal without rebooting: "sudo launchctl load
/Library/LaunchDaemons/srvPowerControlHelper.plist".
This loads the "com.slimdevices.plugins.srvPowerControl.Helper.MacOSX"
service (sudo launchctl list will give you the list)

On the local machine only, you can start the server with "telnet -u
/tmp/srvPowerControlHelper.sock". The app may say "no connection", but
there is one. Look at Console.app for messages, you'll see the trace.
>From the telnet session, type:
- wol on or wol off to set wol on or off,
- suspend to suspend to ram (there is no hibernate mode on macs, it is
only a failure mode used when the battery is drained completely),
- shutdown or reboot,
- rtcwake <unix date> to set a wake schedule. The mac uses UTC, so a
script might use %d when called by the plugin. The wake-up date is
rounded down to the previous minute,
- quit to end the session.
Every action that goes well returns 1. A user cancelation returns -1. A
system error (incl. unknown commands on input) returns 0. If SC can't be
detected, the script aborts silently (there is a short trace in the
log).

The server tries to be nice to desktop users. On sleep/shutdown/reboot,
if users are logged-in, a popup appears on the screen and offers the
possibility to cancel the action. Further, it uses System Events
applescript actions to perform shutdown/reboot, so applications that
have numerous or unsaved documents will offer the user the ability to
cancel the action once again.
When no one is logged-in, the server expedites the process by using the
unix "shutdown" command.
It offers the ability to set/unset wake-on-lan. It can program computer
wake-up from RTC.

I have tested it on OS 10.5.6 and it seems to work for me. However, it
is untested on X.4 and I suspect launchd+unix socket could be a problem
there.
In addition to using telnet I updated the srvrpowerctrl_helper.sh
script to wrap a few commands and connect easily with the plugin.
Unforunately, the server doesn't work when called from SC, or rather
only once, on my system. 
When it fails, my server starts and aborts with "No SC server running
on this host. Who called me ?", which means discovery has failed.
Indeed, the SC server seems to turn easily into a bad state (I used the
web interface to fire suspend, for example), where the web server still
runs, but the SqueezeCenter control panel proposes to "start the
server". 
I suspect the plugin does things my code is not aware of. Without
touching the plugin, only using telnet or netcat, it behaves much more
reliably. 

There are 2 issues I don't know how to clear: 
1. When changing the PM state of the machine, my code wraps the command
in a backgrounded system call, with a sleep in front. E.g system( (sleep
5; do-something-next)& ); This was designed to allow to return from the
command, enter "quit" and complete the session before PM state change.
This seems to work indeed, but unfortunately server exit only happens
when the last 'system' call returns... So the behavior looks exactly as
if the machine would start sleeping over the opened  telnet connection.
When the machine wakes up, you can see the session was indeed closed. I
don't know how the plugin would like that.
As far as I understand, the only way to escape this is to fork/exec. I
am out of my league, and launchd's documentation clearly states fork as
a no-no. I welcome suggestions.
2. I don't handle concurrency as I don't know how to do that reliably.
Normally a "wait" inetd statement would allow only one instance at a
time, and this alone would almost solve the problem. But in the plist
this setting failed, and I had to use nowait.


Thats a long readme, but installing should be really easy. Give it a
try if you'd like.


-- 
epoch1970
------------------------------------------------------------------------
epoch1970's Profile: http://forums.slimdevices.com/member.php?userid=16711
View this thread: http://forums.slimdevices.com/showthread.php?t=48521

_______________________________________________
plugins mailing list
plugins@lists.slimdevices.com
http://lists.slimdevices.com/mailman/listinfo/plugins

Reply via email to