How to run command shadowed by /bin/test

I am new to snap. I am trying to create a simple snap with the executable in local directory and the aim of the snap is to open an URL.
I have added the network plug. The confinement and grade are strict and stable respectively. The executable when run as a snap doesn’t execute. Am I missing something?

Can you share the YAML? Are you seeing any error messages?

Do you mean in a browser? Or something downloading a URL for use by the app?

Thanks for your response.

Here is the YAML

name: test
version: ‘0.1’
summary: Test
description: |
Test

grade: stable
confinement: strict

parts:
only-part:
source: .
plugin: nil

apps:
test:
command: bin/test
plugs: [network]

The code I am using to open an URL in the application is similar to this.

system(“xdg-open ‘http://www.google.com’”);

The URL opens when the executable is triggered directly but not when packaged as a snap.
I do not get any error but there is no response when i trigger the snap.
Btw, I am testing the usage of interfaces in snap using small apps.

You need the unity7 interface in plugs to use xdg-open. Also, your only-part should be using dump instead of nil.

Made the changes. Still not opening.

are you aware of /bin/test on every linux installation ?
do not name your app “test” if you dont want to execute it with the full path (i.e. /snap/bin/test) to not have your shell run /bin/test by default…

1 Like

Solved the issue. It was due to the presence of multiple test’s in the distribution. Thanks for your timely help kalikiana and Ogra

We shouldn’t need any plugs to be able to run xdg-open. @morphis still has the improvements to have the server end of the support for this more widely available, though.

xdg-open requires a graphical desktop env (being a freedesktop implementation), so tieing it to some desktop related interface does actually not seem wrong.

quoting from the upstream manpage at https://portland.freedesktop.org/doc/xdg-open.html

“xdg-open is for use inside a desktop session only. It is not recommended to use xdg-open as root.”

The execution of our xdg-open is supposed to be safe, so there’s no need to ask for an interface to be connected for it to work.

Well, in the backend it will execute xdg-open which will just error out if there is no destop session to connect to.

While there is indeed no need, it prevents developers from running it unconditionally and users from receiving an error.

No, we don’t run xdg-open in the backend. And it will error out if it cannot perform its task in both cases.

So the runXdgOpen() function from safelauncher.go in https://github.com/snapcore/snapd/pull/3260 will be dropped before landing ? What will replace it ?

As you’ve noticed, this alternative implementation is not yet in use, and even if we use it, the data is validated before it gets there.

Plenty of details here.

1 Like

This topic was automatically opened after 21 hours.