dail8859 / dail8859/NotepadNext
/dev/shm permission denied on shared memory file with resolution
- Dominant language
- C++
- Stars
- 14.6k
- Forks
- 914
- Avg merge
- 6d 18h
- Merged PRs (30d)
- 7
Description
## Description
NotepadNext does not start with ```QSharedMemory::PermissionDenied``` message.
Problem may have happened because program was first run as root before closing and re-running as regular user.
Resolution included below.
## More Details
Linux Fedora-39
```dnf copr enable birkch/NotepadNext```
```dnf install NotepadNext```
package installed: NotepadNext-0.7-1.fc39.x86_64
I first ran NotepadNext as root, and it worked fine bringing up the window.
Then i closed window, and re-ran NotepadNext as regular user, but when running as user it fails to start and gives the error in the terminal. If started via the gui app menu, it fails silently.
```
gana@sirius:/var$ NotepadNext
[ 0.118] C: SingleApplication: Unable to attach to shared memory block.
[ 0.118] C: SingleApplication: QSharedMemory::PermissionDenied "QSharedMemory::attach (shm_open): permission denied"
```
**strace output**
```
gana@sirius:/var$ strace NotepadNext
:
:
clock_nanosleep(CLOCK_REALTIME, 0, {tv_sec=0, tv_nsec=16000000}, 0x7fff77a1be20) = 0
getrandom("\xd1\x9e\xe5\x6a\x83\xaa\x42\x71", 8, GRND_NONBLOCK) = 8
newfstatat(AT_FDCWD, "/dev/shm/sem.1EUIzf", 0x7fff77a1b800, AT_SYMLINK_NOFOLLOW) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/dev/shm/sem.1EUIzf", O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW|O_CLOEXEC, 0600) = 26
write(26, "\1\0\0\0\0\0\0\0\200\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 32) = 32
mmap(NULL, 32, PROT_READ|PROT_WRITE, MAP_SHARED, 26, 0) = 0x7fd8f43d3000
link("/dev/shm/sem.1EUIzf", "/dev/shm/sem.NQd7ehOB89VHFdGSy2fPICYNWen1ylD7GZQtd_a754Q=") = 0
newfstatat(26, "", {st_mode=S_IFREG|0600, st_size=32, ...}, AT_EMPTY_PATH) = 0
unlink("/dev/shm/sem.1EUIzf") = 0
close(26) = 0
openat(AT_FDCWD, "/dev/shm/NQd7ehOB89VHFdGSy2fPICYNWen1ylD7GZQtd_a754Q=", O_RDWR|O_NOFOLLOW|O_CLOEXEC) = -1 EACCES (Permission denied)
munmap(0x7fd8f43d3000, 32) = 0
unlink("/dev/shm/sem.NQd7ehOB89VHFdGSy2fPICYNWen1ylD7GZQtd_a754Q=") = 0
getrandom("\x33\xe4\x02\x9e\xee\x98\xaf\xde", 8, GRND_NONBLOCK) = 8
newfstatat(AT_FDCWD, "/dev/shm/sem.Nizx9r", 0x7fff77a1b7f0, AT_SYMLINK_NOFOLLOW) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/dev/shm/sem.Nizx9r", O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW|O_CLOEXEC, 0600) = 26
write(26, "\1\0\0\0\0\0\0\0\200\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 32) = 32
mmap(NULL, 32, PROT_READ|PROT_WRITE, MAP_SHARED, 26, 0) = 0x7fd8f43d3000
link("/dev/shm/sem.Nizx9r", "/dev/shm/sem.NQd7ehOB89VHFdGSy2fPICYNWen1ylD7GZQtd_a754Q=") = 0
newfstatat(26, "", {st_mode=S_IFREG|0600, st_size=32, ...}, AT_EMPTY_PATH) = 0
unlink("/dev/shm/sem.Nizx9r") = 0
close(26) = 0
openat(AT_FDCWD, "/dev/shm/NQd7ehOB89VHFdGSy2fPICYNWen1ylD7GZQtd_a754Q=", O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW|O_CLOEXEC, 0600) = -1 EEXIST (File exists)
openat(AT_FDCWD, "/dev/shm/NQd7ehOB89VHFdGSy2fPICYNWen1ylD7GZQtd_a754Q=", O_RDWR|O_NOFOLLOW|O_CLOEXEC) = -1 EACCES (Permission denied)
openat(AT_FDCWD, "/dev/tty", O_RDONLY|O_CLOEXEC) = 26
close(26) = 0
write(2, "[ 0.260] C: SingleApplicatio"..., 76[ 0.260] C: SingleApplication: Unable to attach to shared memory block.
) = 76
write(2, "[ 0.260] C: SingleApplicatio"..., 122[ 0.260] C: SingleApplication: QSharedMemory::PermissionDenied "QSharedMemory::attach (shm_open): permission denied"
) = 122
munmap(0x7fd8f43d3000, 32) = 0
unlink("/dev/shm/sem.NQd7ehOB89VHFdGSy2fPICYNWen1ylD7GZQtd_a754Q=") = 0
write(4, "\1\0\0\0\0\0\0\0", 8) = 8
futex(0x562204b81d90, FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, 0, NULL, FUTEX_BITSET_MATCH_ANY) = 0
futex(0x562204b81d40, FUTEX_WAKE_PRIVATE, 1) = 0
getpid() = 290191
getpid() = 290191
exit_group(1) = ?
+++ exited with 1 +++
```
## Resolution
When I had run NotepadNext as root, a file was created in ```/dev/shm``` with root ownership and permissions
```
oot@sirius:/dev/shm# ls -la
total 8
drwxrwxrwt. 2 root root 80 Feb 25 18:35 .
drwxr-xr-x. 22 root root 5060 Feb 23 20:56 ..
-rw-------. 1 root root 152 Feb 25 15:28 'NQd7ehOB89VHFdGSy2fPICYNWen1ylD7GZQtd_a754Q='
```
Delete the file, and next time NotepadNext when run as regular user, will recreate the file with regular user ownership and permissions and it will run fine.
mv-ing the file (and then later delete when problem resolved, which is what I really did at first) or chown-ing the file back to the regular user also will work
```
root@sirius:/dev/shm# ls -la
total 4
drwxrwxrwt. 2 root root 60 Feb 25 18:35 .
drwxr-xr-x. 22 root root 5060 Feb 23 20:56 ..
-rw-------. 1 gana gana 152 Feb 25 18:34 'NQd7ehOB89VHFdGSy2fPICYNWen1ylD7GZQtd_a754Q='
```
## Questions:
Q1) should NotepadNext, when run as root user, check to see if the desktop belongs to a user and create the shm-file with ownership of user, or maybe not?
Q2) should NotepadNext give a different filename to the shm-file per-User-per-Desktop in order to prevent name collision?
Q3) should NotepadNext give a better error message to inform the user as to how to correct the problem?
Q4) should NotepadNext delete the shm-file after the last user-process using it exits?
Q5) should the shm-file's filename have the string NotepadNext in it, in order to clue the user that the file was created by NotepadNext. At first, I was hesitant to delete the file as I did not know if it was created by some other process. The ```ls -l``` timestamp strongly hinted that the shm-file might have been freshly created by NotepadNext.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.