source: src-sh/pbi-manager/pbime/pbisyscmd @ 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@…>, 8 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: 989 bytes
Line 
1#!/bin/sh
2
3if [ -z "$PBI_SYSPIPE" ] ; then exit 1; fi
4
5# Create the command return pipe
6RFIFO="`mktemp -u /tmp/.pbi-return-pipe-XXXXXXXXXXXXXXXX`"
7mkfifo ${RFIFO}
8if [ $? -ne 0 ] ; then
9   echo "Failed to create return pipe"
10   exit 1
11fi
12
13
14# Check for some common mime commands to open files with
15if [ "`basename $0`" = "openwith" ] ; then
16  echo "EXEC: ${RFIFO} openwith \"$@\"" > ${PBI_SYSPIPE}
17elif [ "`basename $0`" = "xdg-open" ] ; then
18  echo "EXEC: ${RFIFO} xdg-open \"$@\"" > ${PBI_SYSPIPE}
19else
20  # Send the raw command upstream
21  echo "EXEC: ${RFIFO} $@" > ${PBI_SYSPIPE}
22fi
23
24# Run the listener daemon loop, to keep an ear to the ground for output from the
25# system command we are running
26while :
27do
28   line="`cat ${RFIFO}`"
29   echo $line | grep -q "^CLOSE:"
30   if [ $? -eq 0 ]; then 
31      # Command finished! Cleanup and exit with the status
32      err="`echo $line | cut -d ' ' -f 2`"
33      rm ${RFIFO}
34      exit $err
35   fi
36
37   # Display the output
38   echo $line
39done
40
41exit 0
Note: See TracBrowser for help on using the repository browser.