App won't start on first run

For some reason, my snap application won’t start on first run after installation. On the second run, it starts right up. I decided to run my app under strace on that first run to see if I could see anything obvious. Looks like the app is hanging in a call to wait4(). I’m not 100% sure but it also looks to me like snap has not yet started Revere (my app) when it goes into that wait4().

Looks like one of the last thing its doing is writing “SNAP_DESKTOP_LAST_REVISION” to /root/snap/revere/11/.last_revision which is happening before Revere is actually started.

Has anyone seen anything like this before?

read(255, "##############################\n#"..., 8192) = 489
openat(AT_FDCWD, "/root/snap/revere/11/.last_revision", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
fcntl(1, F_GETFD)                       = 0
fcntl(1, F_DUPFD, 10)                   = 10
fcntl(1, F_GETFD)                       = 0
fcntl(10, F_SETFD, FD_CLOEXEC)          = 0
dup2(3, 1)                              = 1
close(3)                                = 0
write(1, "SNAP_DESKTOP_LAST_REVISION=11\n", 30) = 30
dup2(10, 1)                             = 1
fcntl(10, F_GETFD)                      = 0x1 (flags FD_CLOEXEC)
close(10)                               = 0
rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigaction(SIGINT, {sa_handler=0x55df898a3dc0, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f96d7675520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f96d7675520}, 8) = 0
wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 31256
rt_sigaction(SIGINT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f96d7675520}, {sa_handler=0x55df898a3dc0, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f96d7675520}, 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=31256, si_uid=0, si_status=0, si_utime=1, si_stime=8} ---
wait4(-1, 0x7ffd366453d0, WNOHANG, NULL) = 0
rt_sigreturn({mask=[]})                 = 0
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
mmap(NULL, 266240, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f96d7597000
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigaction(SIGINT, {sa_handler=0x55df898a3dc0, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f96d7675520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f96d7675520}, 8) = 0
rt_sigaction(SIGINT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f96d7675520}, {sa_handler=0x55df898a3dc0, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f96d7675520}, 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigaction(SIGINT, {sa_handler=0x55df898a3dc0, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f96d7675520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f96d7675520}, 8) = 0
wait4(-1,

FWIW it launches fine, first time, here. I’m on Kubuntu 23.10.

openat(AT_FDCWD, "/root/snap/revere/11/.last_revision"

Are you running this with sudo? sudo can cause problems with snap because Mandatory Access Control is usually stronger than sudo is, so things root could usually do (e.g access other users files) don’t actually work. Then you might end up with files pointing to wrong places and a permissions mess. Where possible, try avoid running snaps as root, since usually it won’t grant the permissions people expect anyway, but could have downsides.

Could you let us know if it’s still doing this having:

sudo snap remove revere --purge
sudo snap install revere
snap run --strace revere

Ahh! I didn’t know about “snap run --strace”… I was running it with sudo.

Hmm. Thank you. I wonder why it takes me twice on UB22? I am using the “desktop-launch” script from the snapcraft-desktop-helpers repo… I wonder if it has some first run work?

Snappy Desktop Helpers are deprecated and unless you have specific need to use them, you should definitely consider avoiding them here.

The modern alternative is extensions, and given GStreamer is mentioned explicitly, you’d probably want The gnome extension | Snapcraft documentation.

What do extensions do? Similar things to the legacy scripts but better,

  1. They’re actually designed for Core22, the legacy methods aren’t and probably need some updates. (E.G I’m forced to use them for one of my snaps and they cause problems with Wayland by making assumptions about the state of Qt in 2018).
  2. They do a load more than the legacy scripts did, including bringing backports to GTK3/GTK4, and other desktop related stuff
  3. They deduplicate across snaps using them, saving space/performance/etc
  4. They reduce security burden on yourself, since stuff thats in the extension will be updated separately to your snap.

When using the extensions, I’d recommend starting from scratch with your build-packages and stage-packages, because a lot of stuff (such as GTK, Pulseaudio libraries, etc), are actually implicit when using those extensions.

(That said it’s not mandatory, just good practise).

Tl;Dr Consider avoiding those legacy helpers for the modern stuff :).

1 Like

Ok, I ran it with “snap run --strace revere” on ub22 and it looks like its getting into a loop repeatedly writing to xml files under /home/td/snap/revere/11/.local/share/mime

[pid 34458] openat(AT_FDCWD, "/home/td/snap/revere/11/.local/share/mime/audio/vnd.rn-realaudio.xml.new", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
[pid 34458] newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=0, ...}, AT_EMPTY_PATH) = 0
[pid 34458] write(3, "<?xml version=\"1.0\" encoding=\"ut"..., 3203) = 3203
[pid 34458] close(3)                    = 0
[pid 34458] openat(AT_FDCWD, "/home/td/snap/revere/11/.local/share/mime/audio/vnd.rn-realaudio.xml.new", O_RDWR) = 3
[pid 34458] fdatasync(3)                = 0
[pid 34458] close(3)                    = 0
[pid 34458] rename("/home/td/snap/revere/11/.local/share/mime/audio/vnd.rn-realaudio.xml.new", "/home/td/snap/revere/11/.local/share/mime/audio/vnd.rn-realaudio.xml") = 0
[pid 34458] mkdir("/home/td/snap/revere/11/.local/share/mime/application", 0755) = -1 EEXIST (File exists)
[pid 34458] openat(AT_FDCWD, "/home/td/snap/revere/11/.local/share/mime/application/x-troff-man-compressed.xml.new", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
[pid 34458] newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=0, ...}, AT_EMPTY_PATH) = 0
[pid 34458] write(3, "<?xml version=\"1.0\" encoding=\"ut"..., 3895) = 3895
[pid 34458] close(3)                    = 0
[pid 34458] openat(AT_FDCWD, "/home/td/snap/revere/11/.local/share/mime/application/x-troff-man-compressed.xml.new", O_RDWR) = 3
[pid 34458] fdatasync(3)                = 0
[pid 34458] close(3)                    = 0
[pid 34458] rename("/home/td/snap/revere/11/.local/share/mime/application/x-troff-man-compressed.xml.new", "/home/td/snap/revere/11/.local/share/mime/application/x-troff-man-compressed.xml") = 0
[pid 34458] mkdir("/home/td/snap/revere/11/.local/share/mime/application", 0755) = -1 EEXIST (File exists)
[pid 34458] openat(AT_FDCWD, "/home/td/snap/revere/11/.local/share/mime/application/x-dar.xml.new", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
[pid 34458] newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=0, ...}, AT_EMPTY_PATH) = 0
[pid 34458] write(3, "<?xml version=\"1.0\" encoding=\"ut"..., 2786) = 2786
[pid 34458] close(3)                    = 0
[pid 34458] openat(AT_FDCWD, "/home/td/snap/revere/11/.local/share/mime/application/x-dar.xml.new", O_RDWR) = 3
[pid 34458] fdatasync(3)                = 0
[pid 34458] close(3)                    = 0
[pid 34458] rename("/home/td/snap/revere/11/.local/share/mime/application/x-dar.xml.new", "/home/td/snap/revere/11/.local/share/mime/application/x-dar.xml") = 0
[pid 34458] mkdir("/home/td/snap/revere/11/.local/share/mime/application", 0755) = -1 EEXIST (File exists)
[pid 34458] openat(AT_FDCWD, "/home/td/snap/revere/11/.local/share/mime/application/x-siag.xml.new", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
[pid 34458] newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=0, ...}, AT_EMPTY_PATH) = 0
[pid 34458] write(3, "<?xml version=\"1.0\" encoding=\"ut"..., 3123) = 3123
[pid 34458] close(3)                    = 0
[pid 34458] openat(AT_FDCWD, "/home/td/snap/revere/11/.local/share/mime/application/x-siag.xml.new", O_RDWR) = 3
[pid 34458] fdatasync(3)                = 0
[pid 34458] close(3)                    = 0
[pid 34458] rename("/home/td/snap/revere/11/.local/share/mime/application/x-siag.xml.new", "/home/td/snap/revere/11/.local/share/mime/application/x-siag.xml") = 0
[pid 34458] mkdir("/home/td/snap/revere/11/.local/share/mime/application", 0755) = -1 EEXIST (File exists)
[pid 34458] openat(AT_FDCWD, "/home/td/snap/revere/11/.local/share/mime/application/x-oleo.xml.new", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
[pid 34458] newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=0, ...}, AT_EMPTY_PATH) = 0
[pid 34458] write(3, "<?xml version=\"1.0\" encoding=\"ut"..., 3408) = 3408
[pid 34458] close(3)                    = 0
[pid 34458] openat(AT_FDCWD, "/home/td/snap/revere/11/.local/share/mime/application/x-oleo.xml.new", O_RDWR) = 3
[pid 34458] fdatasync(3)                = 0
[pid 34458] close(3)                    = 0
[pid 34458] rename("/home/td/snap/revere/11/.local/share/mime/application/x-oleo.xml.new", "/home/td/snap/revere/11/.local/share/mime/application/x-oleo.xml") = 0
[pid 34458] mkdir("/home/td/snap/revere/11/.local/share/mime/application", 0755) = -1 EEXIST (File exists)
[pid 34458] openat(AT_FDCWD, "/home/td/snap/revere/11/.local/share/mime/application/vnd.debian.binary-package.xml.new", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
[pid 34458] newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=0, ...}, AT_EMPTY_PATH) = 0
[pid 34458] write(3, "<?xml version=\"1.0\" encoding=\"ut"..., 3206) = 3206
[pid 34458] close(3)                    = 0
[pid 34458] openat(AT_FDCWD, "/home/td/snap/revere/11/.local/share/mime/application/vnd.debian.binary-package.xml.new", O_RDWR) = 3
[pid 34458] fdatasync(3)                = 0
[pid 34458] close(3)                    = 0
[pid 34458] rename("/home/td/snap/revere/11/.local/share/mime/application/vnd.debian.binary-package.xml.new", "/home/td/snap/revere/11/.local/share/mime/application/vnd.debian.binary-package.xml") = 0
[pid 34458] mkdir("/home/td/snap/revere/11/.local/share/mime/application", 0755) = -1 EEXIST (File exists)
[pid 34458] openat(AT_FDCWD, "/home/td/snap/revere/11/.local/share/mime/application/vnd.stardivision.math.xml.new", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
[pid 34458] newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=0, ...}, AT_EMPTY_PATH) = 0
[pid 34458] write(3, "<?xml version=\"1.0\" encoding=\"ut"..., 3091) = 3091
[pid 34458] close(3)                    = 0
[pid 34458] openat(AT_FDCWD, "/home/td/snap/revere/11/.local/share/mime/application/vnd.stardivision.math.xml.new", O_RDWR) = 3
[pid 34458] fdatasync(3)                = 0
[pid 34458] close(3)                    = 0
[pid 34458] rename("/home/td/snap/revere/11/.local/share/mime/application/vnd.stardivision.math.xml.new", "/home/td/snap/revere/11/.local/share/mime/application/vnd.stardivision.math.xml") = 0
[pid 34458] mkdir("/home/td/snap/revere/11/.local/share/mime/text", 0755) = -1 EEXIST (File exists)
[pid 34458] openat(AT_FDCWD, "/home/td/snap/revere/11/.local/share/mime/text/vtt.xml.new", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
[pid 34458] newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=0, ...}, AT_EMPTY_PATH) = 0
[pid 34458] write(3, "<?xml version=\"1.0\" encoding=\"ut"..., 2633) = 2633
[pid 34458] close(3)                    = 0
[pid 34458] openat(AT_FDCWD, "/home/td/snap/revere/11/.local/share/mime/text/vtt.xml.new", O_RDWR) = 3
[pid 34458] fdatasync(3)                = 0
[pid 34458] close(3)                    = 0
[pid 34458] rename("/home/td/snap/revere/11/.local/share/mime/text/vtt.xml.new", "/home/td/snap/revere/11/.local/share/mime/text/vtt.xml") = 0
[pid 34458] mkdir("/home/td/snap/revere/11/.local/share/mime/application", 0755) = -1 EEXIST (File exists)
[pid 34458] openat(AT_FDCWD, "/home/td/snap/revere/11/.local/share/mime/application/x-bcpio.xml.new", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
[pid 34458] newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=0, ...}, AT_EMPTY_PATH) = 0
[pid 34458] write(3, "<?xml version=\"1.0\" encoding=\"ut"..., 3226) = 3226
[pid 34458] close(3)                    = 0
[pid 34458] openat(AT_FDCWD, "/home/td/snap/revere/11/.local/share/mime/application/x-bcpio.xml.new", O_RDWR) = 3
[pid 34458] fdatasync(3)                = 0
[pid 34458] close(3)                    = 0
[pid 34458] rename("/home/td/snap/revere/11/.local/share/mime/application/x-bcpio.xml.new", "/home/td/snap/revere/11/.local/share/mime/application/x-bcpio.xml") = 0
[pid 34458] mkdir("/home/td/snap/revere/11/.local/share/mime/application", 0755) = -1 EEXIST (File exists)
[pid 34458] openat(AT_FDCWD, "/home/td/snap/revere/11/.local/share/mime/application/x-cpio-compressed.xml.new", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
[pid 34458] newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=0, ...}, AT_EMPTY_PATH) = 0
[pid 34458] write(3, "<?xml version=\"1.0\" encoding=\"ut"..., 4096) = 4096
[pid 34458] write(3, "p\"/>\n  <generic-icon name=\"packa"..., 91) = 91
[pid 34458] close(3)                    = 0
[pid 34458] openat(AT_FDCWD, "/home/td/snap/revere/11/.local/share/mime/application/x-cpio-compressed.xml.new", O_RDWR) = 3
[pid 34458] fdatasync(3)                = 0
[pid 34458] close(3)                    = 0
[pid 34458] rename("/home/td/snap/revere/11/.local/share/mime/application/x-cpio-compressed.xml.new", "/home/td/snap/revere/11/.local/share/mime/application/x-cpio-compressed.xml") = 0
[pid 34458] mkdir("/home/td/snap/revere/11/.local/share/mime/application", 0755) = -1 EEXIST (File exists)
[pid 34458] openat(AT_FDCWD, "/home/td/snap/revere/11/.local/share/mime/application/vnd.sun.xml.math.xml.new", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
[pid 34458] newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=0, ...}, AT_EMPTY_PATH) = 0
[pid 34458] write(3, "<?xml version=\"1.0\" encoding=\"ut"..., 3489) = 3489
[pid 34458] close(3)                    = 0
[pid 34458] openat(AT_FDCWD, "/home/td/snap/revere/11/.local/share/mime/application/vnd.sun.xml.math.xml.new", O_RDWR) = 3
[pid 34458] fdatasync(3)                = 0
[pid 34458] close(3)                    = 0
[pid 34458] rename("/home/td/snap/revere/11/.local/share/mime/application/vnd.sun.xml.math.xml.new", "/home/td/snap/revere/11/.local/share/mime/application/vnd.sun.xml.math.xml") = 0
[pid 34458] mkdir("/home/td/snap/revere/11/.local/share/mime/application", 0755) = -1 EEXIST (File exists)
[pid 34458] openat(AT_FDCWD, "/home/td/snap/revere/11/.local/share/mime/application/octet-stream.xml.new", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
[pid 34458] newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=0, ...}, AT_EMPTY_PATH) = 0
[pid 34458] write(3, "<?xml version=\"1.0\" encoding=\"ut"..., 2688) = 2688
[pid 34458] close(3)                    = 0
[pid 34458] openat(AT_FDCWD, "/home/td/snap/revere/11/.local/share/mime/application/octet-stream.xml.new", O_RDWR) = 3
[pid 34458] fdatasync(3)                = 0
[pid 34458] close(3)                    = 0
[pid 34458] rename("/home/td/snap/revere/11/.local/share/mime/application/octet-stream.xml.new", "/home/td/snap/revere/11/.local/share/mime/application/octet-stream.xml") = 0
[pid 34458] mkdir("/home/td/snap/revere/11/.local/share/mime/application", 0755) = -1 EEXIST (File exists)
[pid 34458] openat(AT_FDCWD, "/home/td/snap/revere/11/.local/share/mime/application/x-python-bytecode.xml.new", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
[pid 34458] newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=0, ...}, AT_EMPTY_PATH) = 0
[pid 34458] write(3, "<?xml version=\"1.0\" encoding=\"ut"..., 3181) = 3181
[pid 34458] close(3)                    = 0

I let it do this for about a minute and then I hit ctrl-c.

Do you still use the bin/desktop-launch script or is that no longer required? Any example snapcraft.yaml’s I can look it?

As an implementation detail there is a bin/desktop-launch, but you’re not expected to know that really.

I’ve a small GTK3 based Paint app using the Gnome extension for Gnome 22 that I’d say is pretty concise.

The whole extension is literally just one line, in comparison it makes the legacy helpers look like an insane amount of effort. (And they are).

https://github.com/MrCarroll/pinta-snap/blob/b42b0f01d5a73ebddbfc08e1d9cec592def2cb31/snap/snapcraft.yaml#L72

Yes, the extension code is literally just that one line.

(And because of the extensions, the GTK4 port doesn’t even need a single line changed, just the commit it’s building!)

What you can see here which people tend to not consider is that despite being a GTK3 app with the entire GTK ecosystem around it, the build-packages and stage-packages literally doesn’t mention GTK once.

1 Like

+1 to “just” using the extensions: [gnome] line in the apps/command and letting it doing the magic for you. No need for you to faff with launchers.

Thanks for all your help. I think I got everything working now and its simpler.

1 Like