busybox
December 24, 2019, 10:37am
1
I have simple hello world snap which builds fine but gets permission denied on running.
O/P from device:
bot@localhost:/tmp$ helloapp.helloapp
/snap/helloapp/x8/command-helloapp.wrapper: 2: exec: /snap/helloapp/x8/bin/hello: Permission denied
bot@localhost:/tmp$
===
hello.c
#include <stdio.h>
#include <stdlib.h>
void main (void) {
printf ("\nSIMPLIFIED HELLO WORLD !!!\n");
}
Makefile:
hello: hello.c
gcc -c hello.c -o hello
snapcraft.yaml:
apps:
helloapp:
command: bin/hello
parts:
gnu-hello:
plugin: autotools
source: simplehello
source-subdir: .
override-build: |
make
mkdir -p $SNAPCRAFT_PART_INSTALL/bin
cp hello $SNAPCRAFT_PART_INSTALL/bin
What are the permissions on that binary you create? It seems you simply don’t have the right permissions to execute it. Is it readable and executable for all/others?
I would also suggest using base: core18
. This will build the snap in a clean environment, making sure that there is nothing funky going on with your install.
busybox
December 26, 2019, 10:32am
3
Thanks @galgalesh missed +x permission on the binary. With +x added, no ‘permission denied’ error.
But now this is what I get:
bot@localhost:~$ helloapp.helloapps
/snap/helloapp/x9/command-helloapps.wrapper: 2: exec: /snap/helloapp/x9/bin/hellobin: Exec format error
bot@localhost:~$ ls -l /snap/bin/helloapp.helloapps
lrwxrwxrwx 1 root root 13 Dec 26 10:28 /snap/bin/helloapp.helloapps -> /usr/bin/snap
aruba-iotadmin@localhost:~$
popey
December 26, 2019, 10:58am
4
Can you run that compiled C program outside of it being snapped? It doesn’t work here, so I don’t believe this is snap at fault.
alan@KinkPad-K450:~/Temp/forum$ cat hello.c
#include <stdio.h>
#include <stdlib.h>
void main (void) {
printf ("\nSIMPLIFIED HELLO WORLD !!!\n");
}
alan@KinkPad-K450:~/Temp/forum$ gcc -c hello.c -o hello
alan@KinkPad-K450:~/Temp/forum$ file hello
hello: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
alan@KinkPad-K450:~/Temp/forum$ chmod +x hello
alan@KinkPad-K450:~/Temp/forum$ ./hello
bash: ./hello: cannot execute binary file: Exec format error
busybox
December 26, 2019, 11:22am
5
You are right. It fails to run where it is built.
O/p of file shows this:
parts/gnu-hello/install/bin/hellobin: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
Both host and device are x86_64, still the binary fails to run on host as well as device.
dev:~/helloworld/snap$ uname -a
Linux dev 4.15.0-72-generic #81-Ubuntu SMP Tue Nov 26 12:20:02 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
dev:~/helloworld/snap$
popey
December 26, 2019, 12:59pm
6
This works:
#include <stdio.h>
#include <stdlib.h>
void main (void) {
printf ("\nSIMPLIFIED HELLO WORLD !!!\n");
}
$ g++ hello.c -o hello
$ ./hello
SIMPLIFIED HELLO WORLD !!!
busybox
December 26, 2019, 1:00pm
7
What does o/p of file on hello looks like?
popey
December 26, 2019, 1:02pm
8
$ file hello
hello: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=f4c7c5c0bbef5d5d2b7196c3f1874506ba445a84, for GNU/Linux 3.2.0, not stripped