Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--run-trigger argument #38

Closed
maltfield opened this issue Oct 6, 2022 · 4 comments
Closed

--run-trigger argument #38

maltfield opened this issue Oct 6, 2022 · 4 comments
Assignees
Labels

Comments

@maltfield
Copy link
Member

This issue will track adding a --run-trigger argument that will immediately execute the trigger (eg lock-screen or soft-shutdown)

Is your feature request related to a problem? Please describe.

There should be an easier way to test that triggers work without having to fiddle with USB drives. This is especially important for testing on VM or headless systems.

Describe the solution you'd like

I should be able to execute

./buskill --run-trigger lock-screen

...and the screen should lock (ok, maybe after confirming with the user that they really want to proceed)

@maltfield
Copy link
Member Author

I just implemented this. Here's a couple test runs on Linux

Lockscreen

This execution makes the buskill app immediately execute the lock-screen trigger. Note that this is on an AppVM in QubesOS, which is why the execution fails

user@buskill:~/sandbox/buskill-app$ /tmp/kivy_appdir/opt/python*/bin/python* src/main.py --run-trigger
===============================================================================
INFO: Writing to log file '/tmp/buskill.log'
buskill version {'VERSION': '', 'GITHUB_REF': '', 'GITHUB_SHA': '', 'SOURCE_DATE_EPOCH': ''}
usb1.__version__:|3.0.0|
DEBUG: EXE_PATH:|/home/user/sandbox/buskill-app/src/main.py|
DEBUG: EXE_DIR:|/home/user/sandbox/buskill-app/src|
DEBUG: EXE_FILE:|main.py|
DEBUG: APP_DIR:|/home/user/sandbox/buskill-app|
DEBUG: APPS_DIR:|/home/user/sandbox|
DEBUG: SRC_DIR:|/home/user/sandbox/buskill-app/src|
DEBUG: os.environ['PATH']:|/home/user/.local/bin:/home/user/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/user/sandbox/buskill-app/src:/home/user/sandbox/buskill-app|

INFO: using DATA_DIR:|/home/user/sandbox/.buskill|
DEBUG: Attempting to set 'trigger' set to 'lock-screen'
INFO: BusKill 'trigger' set to 'lock-screen'
DEBUG: attempting to arm BusKill via <bound method BusKill.armNix of <packages.buskill.BusKill object at 0x74bfbbebfdd0>>()
INFO: BusKill is armed. Listening for removal event.
INFO: To disarm the CLI, exit with ^C or close this terminal
DEBUG: Attempting to set 'trigger' set to 'lock-screen'
INFO: BusKill 'trigger' set to 'lock-screen'
Are you sure you want to execute the 'lock-screen' trigger RIGHT NOW? [Y/N]y
DEBUG: BusKill lockscreen trigger executing now
INFO: Attempting to execute `xdg-screensaver lock`
DEBUG: subprocess returncode|4|
DEBUG: subprocess stdout||
DEBUG: subprocess stderr||
WARNING: Failed to execute `xdg-scrensaver lock`!
INFO: Attempting to execute `xscreensaver -lock`
ERROR: Failed to execute `xscreensaver -lock`! [Errno 2] No such file or directory: 'xscreensaver': 'xscreensaver'
user@buskill:~/sandbox/buskill-app$ 

Use with yes

Of course, you can use a tool like yes to automate the execution without a human having to type y or yes

user@buskill:~/sandbox/buskill-app$ yes | /tmp/kivy_appdir/opt/python*/bin/python* src/main.py --run-trigger
===============================================================================
INFO: Writing to log file '/tmp/buskill.log'
buskill version {'VERSION': '', 'GITHUB_REF': '', 'GITHUB_SHA': '', 'SOURCE_DATE_EPOCH': ''}
usb1.__version__:|3.0.0|
DEBUG: EXE_PATH:|/home/user/sandbox/buskill-app/src/main.py|
DEBUG: EXE_DIR:|/home/user/sandbox/buskill-app/src|
DEBUG: EXE_FILE:|main.py|
DEBUG: APP_DIR:|/home/user/sandbox/buskill-app|
DEBUG: APPS_DIR:|/home/user/sandbox|
DEBUG: SRC_DIR:|/home/user/sandbox/buskill-app/src|
DEBUG: os.environ['PATH']:|/home/user/.local/bin:/home/user/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/user/sandbox/buskill-app/src:/home/user/sandbox/buskill-app|

INFO: using DATA_DIR:|/home/user/sandbox/.buskill|
DEBUG: Attempting to set 'trigger' set to 'lock-screen'
INFO: BusKill 'trigger' set to 'lock-screen'
DEBUG: attempting to arm BusKill via <bound method BusKill.armNix of <packages.buskill.BusKill object at 0x72504d0ebe50>>()
INFO: BusKill is armed. Listening for removal event.
INFO: To disarm the CLI, exit with ^C or close this terminal
DEBUG: Attempting to set 'trigger' set to 'lock-screen'
INFO: BusKill 'trigger' set to 'lock-screen'
Are you sure you want to execute the 'lock-screen' trigger RIGHT NOW? [Y/N] DEBUG: BusKill lockscreen trigger executing now
INFO: Attempting to execute `xdg-screensaver lock`
DEBUG: subprocess returncode|4|
DEBUG: subprocess stdout||
DEBUG: subprocess stderr||
WARNING: Failed to execute `xdg-scrensaver lock`!
INFO: Attempting to execute `xscreensaver -lock`
ERROR: Failed to execute `xscreensaver -lock`! [Errno 2] No such file or directory: 'xscreensaver': 'xscreensaver'
user@buskill:~/sandbox/buskill-app$ 

And the soft-shutdown trigger

user@buskill:~/sandbox/buskill-app$ /tmp/kivy_appdir/opt/python*/bin/python* src/main.py -t soft-shutdown --run-trigger
===============================================================================
INFO: Writing to log file '/tmp/buskill.log'
buskill version {'VERSION': '', 'GITHUB_REF': '', 'GITHUB_SHA': '', 'SOURCE_DATE_EPOCH': ''}
usb1.__version__:|3.0.0|
DEBUG: EXE_PATH:|/home/user/sandbox/buskill-app/src/main.py|
DEBUG: EXE_DIR:|/home/user/sandbox/buskill-app/src|
DEBUG: EXE_FILE:|main.py|
DEBUG: APP_DIR:|/home/user/sandbox/buskill-app|
DEBUG: APPS_DIR:|/home/user/sandbox|
DEBUG: SRC_DIR:|/home/user/sandbox/buskill-app/src|
DEBUG: os.environ['PATH']:|/home/user/.local/bin:/home/user/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/user/sandbox/buskill-app/src:/home/user/sandbox/buskill-app|

INFO: using DATA_DIR:|/home/user/sandbox/.buskill|
DEBUG: Attempting to set 'trigger' set to 'soft-shutdown'
DEBUG: shutdown binary path:|/usr/sbin/shutdown|
DEBUG: poweroff binary path:|/usr/sbin/poweroff|
DEBUG: systemctl binary path:|/usr/bin/systemctl|
INFO: BusKill 'trigger' set to 'soft-shutdown'
DEBUG: attempting to arm BusKill via <bound method BusKill.armNix of <packages.buskill.BusKill object at 0x7da354968e90>>()
INFO: BusKill is armed. Listening for removal event.
INFO: To disarm the CLI, exit with ^C or close this terminal
DEBUG: Attempting to set 'trigger' set to 'soft-shutdown'
DEBUG: shutdown binary path:|/usr/sbin/shutdown|
DEBUG: poweroff binary path:|/usr/sbin/poweroff|
DEBUG: systemctl binary path:|/usr/bin/systemctl|
INFO: BusKill 'trigger' set to 'soft-shutdown'
Are you sure you want to execute the 'soft-shutdown' trigger RIGHT NOW? [Y/N] Y
<aaand the AppVM turned off, so I couldn't capture the rest of the output after I typed '[enter]'>

@maltfield
Copy link
Member Author

maltfield commented Oct 16, 2022

I tried-out the latest build on my Mac Mini in the MacStadium cloud, and--for the first time ever--I was able to trigger a lockscreen on that system. Awesome.

user@host ~ % /Volumes/buskill-cli-shutdown-trigger/buskill-cli-shutdown-trigger.app/Contents/MacOS/buskill --run-trigger
Are you sure you want to execute the 'lock-screen' trigger RIGHT NOW? [Y/N] 
... <lots of debug output snipped> ...
y
23:17:35,803 packages.buskill INFO DEBUG: BusKill lockscreen trigger executing now
23:17:35,803 packages.buskill DEBUG INFO: Attempting to execute `CGSession -suspend`
23:17:36,150 packages.buskill DEBUG DEBUG: subprocess returncode|0|
23:17:36,151 packages.buskill DEBUG DEBUG: subprocess stdout||
23:17:36,152 packages.buskill DEBUG DEBUG: subprocess stderr||

Curiously, it spat out a ton of DEBUG output before waiting for my prompt, but it's good enough for now

@maltfield maltfield self-assigned this Oct 17, 2022
@maltfield
Copy link
Member Author

This has been implemented in the buskill-cli-shutdown-trigger branch and will likely be released with v0.6.0

maltfield added a commit that referenced this issue Oct 18, 2022
The previous implentation of --run-trigger just called `bk.TRIGGER_FUNCTION()` directly. This was a problem, however, because a *real* trigger would execute the callback function running inside a non-root child process. So testing via --run-trigger wouldn't work for simulating, for example, the non-root child process trying to communicate to the root child process for executing the soft-shutdown trigger on MacOS.

This commit changes the functionality to call the callback function, just as would happen with a *real* hotplug removal event.

 * #14 (comment)
 * #38
@maltfield
Copy link
Member Author

I had to make some changes to this implementation such that it would call the actual callback function, rather than the trigger function directly.

This allows us to properly test things like the non-root child that's listening for usb hotplug events to communicate with the root child that's needed to execute triggers like the soft-shutdown trigger.

For more info, see:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant