- commit
- bb9a54105a5a188a05a59d0010677e2c4ccda5f0
- parent
- 7d3e5a9bd763f4c487b3cbdb8439b5dfa5d0fe44
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2024-08-04 12:38
add --app-id
Diffstat
| M | xiwrap.py | 28 | ++++++++++++++++++++++++++-- |
1 files changed, 26 insertions, 2 deletions
diff --git a/xiwrap.py b/xiwrap.py
@@ -12,6 +12,8 @@ Example: xiwrap --include host-os --setenv TERM -- bash 12 12 The following options are available: 13 13 14 14 -h, --help Print this message and exit -1 15 --app-id Set an ID that can be used by portals to reliably -1 16 identify the application. 15 17 --debug Print the bwrap command instead of executing it. 16 18 --share-pid Do not create new pid namespace. 17 19 --share-net Do not create new network namespace. @@ -96,11 +98,22 @@ def expandvars(path, env): 96 98 97 99 98 100 class DBusProxy:99 -1 def __init__(self, rules, dest, src, sync_fd):-1 101 def __init__(self, rules, dest, src, app_id, sync_fd): 100 102 self.cmd = ['xdg-dbus-proxy', f'--fd={sync_fd}', dest, src, '--filter'] 101 103 for value, typ in sorted(rules.items()): 102 104 self.cmd.append(f'--{typ}={value}')103 -1 self.fds = [sync_fd]-1 105 -1 106 wrapper = RuleSet() -1 107 wrapper.push_rule('tmpfs', ['/tmp']) -1 108 wrapper.push_rule('dev', ['/dev']) -1 109 wrapper.push_rule('proc', ['/proc']) -1 110 for path in ['/bin', '/lib', '/lib64', '/usr', '/etc', '/run']: -1 111 wrapper.push_rule('bind', [path]) -1 112 if app_id: -1 113 wrapper.push_rule('app-id', [app_id]) -1 114 -1 115 self.cmd = wrapper.build(self.cmd) -1 116 self.fds = [sync_fd, *wrapper.fds] 104 117 105 118 def popen(self): 106 119 return subprocess.Popen(self.cmd, pass_fds=self.fds) @@ -113,7 +126,9 @@ class RuleSet: 113 126 self.dbus_session = {} 114 127 self.dbus_system = {} 115 128 self.share = {} -1 129 self.app_id = None 116 130 self.sync_fds = None -1 131 self.fds = [] 117 132 self.debug = False 118 133 self.usage = False 119 134 self.userconfig = Path( @@ -158,6 +173,12 @@ class RuleSet: 158 173 raise RuleError(key, args) 159 174 path = self.find_config_file(args[0], cwd) 160 175 self.read_config_file(path) -1 176 elif key == 'app-id': -1 177 if len(args) != 1: -1 178 raise RuleError(key, args) -1 179 self.app_id = args[0] -1 180 info = f'[Application]\nname={self.app_id}\n' -1 181 self.push_rule('bind-text', [info, '/.flatpak-info']) 161 182 elif key in ['share-ipc', 'share-pid', 'share-net']: 162 183 if len(args) != 0: 163 184 raise RuleError(key, args) @@ -200,6 +221,7 @@ class RuleSet: 200 221 r, w = os.pipe2(0) 201 222 os.write(w, text.encode()) 202 223 os.close(w) -1 224 self.fds.append(r) 203 225 self.paths[target] = ('bind-data', str(r)) 204 226 elif key in ['tmpfs', 'dev', 'proc', 'mqueue', 'dir']: 205 227 if len(args) != 1: @@ -275,6 +297,7 @@ class RuleSet: 275 297 self.dbus_session, 276 298 os.getenv('DBUS_SESSION_BUS_ADDRESS'), 277 299 DBUS_SESSION_SRC, -1 300 self.app_id, 278 301 self.sync_fds[1], 279 302 ) 280 303 @@ -288,6 +311,7 @@ class RuleSet: 288 311 'unix:path=/var/run/dbus/system_bus_socket', 289 312 ), 290 313 DBUS_SYSTEM_SRC, -1 314 self.app_id, 291 315 self.sync_fds[1], 292 316 ) 293 317