Tomas-M / xlunch

Graphical app launcher for X with minimal dependencies
http://xlunch.org
GNU General Public License v3.0
219 stars 37 forks source link

Wrong permissions of /tmp/xlunch.lock ? #92

Closed fredx181 closed 6 years ago

fredx181 commented 6 years ago

Probably depends on how umask is set, for me it's:

# umask
0022

When switching to another user, xlunch doesn't run (and doesn't show any error message)
I assume (looking at xlunch.c) it's intended that /tmp/xlunch.lock should have permissions 0666. But it has 0644 for me, resulting that it is not read/write for another user. From a web search I found solution by clearing the umask value first before creating /tmp/xlunch.lock.
(and bring it back to how it was after /tmp/xlunch.lock has been created) From line 2307 on, I changed to:

    if (!multiple_instances)
    {
    mode_t old_mask;
    old_mask = umask( 0 );
        lock=open("/tmp/xlunch.lock",O_CREAT | O_RDWR,0666);
        int rc = flock(lock, LOCK_EX | LOCK_NB);
        if (rc) {
            if (errno == EWOULDBLOCK) fprintf(stderr,"xlunch already running. You may want to consider --multiple\nIf this is an error, you may remove /tmp/xlunch.lock\n");
            exit(LOCKERROR);
        }
    umask( old_mask );
    }

It works for me, xlunch.lock has permissions 0666 now, but I'm not sure if this the correct way to do it.

Fred

fredx181 commented 6 years ago

Why no reply ?

PMunch commented 6 years ago

I simply haven't had time to try it or look into the issue. 0644 should give other users read access to the lock, but I guess what's happening is that it's able to see that the lock is free but not actually lock it. But as you say the file should probably be 0666. Could you create a PR for this with your fix?

fredx181 commented 6 years ago

Could you create a PR for this with your fix?

Hi PMunch, thanks for responding. However I'm certain about that it is required that /tmp/xlunch.lock should have permissions 0666 to be able to run from another user, I'm not really certain about the fix I found. It gives warning when running make: (but does compile well though)

gcc xlunch.c -o xlunch -lImlib2 -lX11 -O2 -s
xlunch.c: In function ‘main’:
xlunch.c:2310:16: warning: implicit declaration of function ‘umask’ [-Wimplicit-function-declaration]
     old_mask = umask( 0 );
                ^~~~~

As I said earlier, C programming is not my thing, so I'll leave finding the correct fix up to you guys. When you have time of course :)

PMunch commented 6 years ago

You were pretty close, just forgot to import the header for umask. Just pushed this fix now: https://github.com/Tomas-M/xlunch/commit/1c1fc28e1e65cf3bad373c0b3eb2d15b4d3ad5a0