source: src-sh/pbi-manager/pbime/pbisyslisten @ a7429d5

releng/10.0releng/10.0.1releng/10.0.2releng/10.0.3
Last change on this file since a7429d5 was a7429d5, checked in by Kris Moore <kris@…>, 10 months ago

Add a cool new system callback function to PBIs on 10.x and beyond

This allows PBIs, which run in a container, to use the pbisyscmd, openwith
or xdg-open, and "talk" to applications on the outside of the container.

The use-case for this would be a application like Thunderbird, which may
want to use the "xdg-open" command to open a PDF file with something else
on the system.

It could be used by other apps, such as terminal emulators to run a shell on the system,
even though the GUI is run in the container

  • Property mode set to 100755
File size: 988 bytes
Line 
1#!/bin/sh
2
3if [ -z "$PBI_SYSPIPE" ] ; then exit 1; fi
4
5# Run the listener daemon loop, this will keep an ear on PBI_SYSPIPE
6# in case the PBI wants / needs to run a system command outside its container
7while :
8do
9   line="`cat ${PBI_SYSPIPE}`"
10   echo $line | grep -q "^CLOSE:"
11   if [ $? -eq 0 ]; then break; fi
12
13   echo $line | grep -q "^EXEC:"
14   if [ $? -eq 0 ]; then
15      RETURNPIPE="`echo $line | cut -d ' ' -f 2`"
16      CMD="`echo $line | cut -d ' ' -f 3-`"
17
18      # Run the system command, sending output back to client
19
20      # This is ugly, I know, but it works to preserve those pesky quotes on the command-line
21      CMDFILE=`mktemp "/tmp/.pbi-cmd-XXXXXXXXXXXXXXXX"`
22      if [ ! -e "$CMDFILE" ] ; then continue ; fi
23
24      # Create / run the command now
25      echo "$CMD 2>&1 >${RETURNPIPE} ; exit \$?" > $CMDFILE
26      sh $CMDFILE
27      err=$?
28      rm $CMDFILE
29
30      # Let the client know the app has finished
31      echo "CLOSE: $err" > ${RETURNPIPE}
32   fi
33done
34
35exit 0
Note: See TracBrowser for help on using the repository browser.