Invoke app within a snap from another app (within same snap) & use ifconfig from snap to read network info


#1

Beginner to snapcraft. I have a project which has two applications. The first application invokes the second one and keeps it alive. While snapping these, I have snapped the two application within one snap as they have many common files and libraries required.

  1. I don’t understand how I can invoke the second app which is now inside the snap from the first app. Like what call can I use ?? The applications are written in C and before I used system() to invoke the second app. something like system(hello_world), I tried system(/snap/bin/./hello_world) , but this works only in devmode. Once it is in stable mode, I get permission denied script. is there any plugs slot kinda thing I can add? I couldn’t find any definitive documentation regarding that.
  2. My app uses ifconfig to read network info. It works in devmode, but again in stable mode, I get permission denied. When I check the dmesg, I can see that I’m getting apparmour denial. I have added every possible interface I could find wrt network in plugs.

#2

try grabbing $SNAP from the environemnt (getenv()) and do something like:

system($SNAP/path/to/your/binary/inside/the/snap)

i.e. if you binary is in /snap/<snapname>/current/usr/bin/foobar it becomes: $SNAP/usr/bin/foobar

for 2. use snappy-debug (snap install snappy-debug) to get suggestions based on the denials …

also, given that ifconfig is obsolete since several years now you should try to use “ip” not “ifconfig” …


#3

Sorry for the late reply. Thank you for the help. Invoking the snap using getenv() helped.
Regarding the permission denials, for now I have decided to go with classic.

My current problem is, I’m installing my snap on Raspbian stretch (latest Nov 2018 release). And Im getting the same error described in this post. Can this issue be resolved in any way? Or is the only option to use another distro for RPI b3+?


#4

By definition the debian armhf architecture provides binaries explicitly for the ARMv7 SoC family … raspbian breaks that standard by re-compiling the whole of debian against ARMv6 and still calling it “armhf” … that makes actual armhf binaries (from debian,ubuntu or third parties) incompatible with the Raspbian ones … armhf snaps follow the official debian/ubuntu standard …

To get armhf snaps working on your Pi you should either look if there is a raspbian that is explicitly build following the standard or you can use a plain Debian armhf …


#5

I flashed ubuntu core 18 on my raspberry pi 3b+ and tried to run my snap on it. I’m using the following in my yaml file to specify the architecture

architectures:
       - build-on: [i386]
         run-on: [armhf]

    grade: devel
    confinement: devmode

But when the snap command is being called I’m getting an “ELF4 not found” error and Syntax error: newline unexpected (expecting “)”)

When building the snap again I tried, adding the flag --target-arch=armhf. When I run this snap I’m getting EXEC format error.

My binaries are being compiled using gcc while building the snap. I’m building my snap on Ubuntu 16.04. So far what I understand is the binaries are not compatible with running on Ubuntu core 18. So what I want to know is, do I have to manually cross-compile all the required packages when I’m building the snap for a different architecture?? Or am I missing something?