Ticket #242 (closed enhancement: fixed)
Pass environment variables to 'CommandAction'
| Reported by: | peter@… | Owned by: | jluebbe |
|---|---|---|---|
| Priority: | minor | Milestone: | milestone5 |
| Component: | framework/oeventsd | Version: | milestone4 |
| Keywords: | Cc: |
Description
We are currently unable to set environment variables for 'Command' actions defined in rules.yaml. This prevents oeventsd from executing any application that affects the display as the DISPLAY environment variable can't be set.
Change History
comment:2 Changed 4 years ago by peppertarts
The reason I wanted to execute a program that affects X was to raise the Zhone window (Or any other window) when I received a call. I am doing this using wmctrl. It may be nice to include this app (It's in OE) and the below rule in future FSO images.
--- framework/etc/freesmartphone/oevents/rules.yaml
+++ framework/etc/freesmartphone/oevents/rules.yaml
@@ -47,6 +47,7 @@
actions:
- RingTone()
- SetDisplayBrightness("pcf50633_bl", 90)
+ - Command('wmctrl -a zhone', { 'DISPLAY':':0.0' })
-
while: CallStatus()
filters: Or(HasAttr(status, "outgoing"), HasAttr(status, "active"))
comment:3 Changed 3 years ago by stefan
- Owner changed from jluebbe to mickey
- Status changed from new to assigned
Note: See
TracTickets for help on using
tickets.

Here is my patch. I've also added some error checking as oeventsd does some strange things if you ask it to execute a program that doesn't exist.
--- framework/framework/subsystems/oeventsd/fso_actions.py 2008-11-16 18:58:06.000000000 +0000 +++ framework/framework/subsystems/oeventsd/fso_actions.py 2009-05-14 02:13:59.000000000 +0100 @@ -266,14 +268,18 @@ #=========================================================================# function_name = 'Command' - def __init__( self, cmd = 'true' ): + def __init__( self, cmd = 'true', env = { '':'' } ): self.cmd = cmd + self.env = env def trigger(self, **kargs): logger.info( "CommandAction %s", self.cmd ) - # FIXME check return value - result = subprocess.call( shlex.split( self.cmd ) ) + try: + result = subprocess.call( shlex.split( self.cmd ), env=self.env ) + logger.info("Command returned - %s", "Success" if result == 0 else "Failed") + except OSError, err: + logger.error( "Unable to execute command: %s", err ) def __repr__(self): return "CommandAction(%s)" % self.cmd