UtkarshVerma / dwmblocks-async

An efficient, lean, and asynchronous status feed generator for dwm.
GNU General Public License v2.0
232 stars 87 forks source link

Parent Process ID is not equal to PID of statusbar #28

Closed ghost closed 2 years ago

ghost commented 2 years ago

Hello, I've recently started using this for my statusbar. I must say that colours and clickability work perfectly, however I do have a simple issue.

I have all of my statusbar scripts check their $PPID so that colours are only shown when the script is executed by the statusbar. This makes the scripts usable on terminals too.

The problem: In if [ "$(ps -p $PPID -o comm=)" = "$STATUSBAR" ]; then,

$STATUSBAR is equal to dwmblocks and $(ps -p $PPID -o comm=) is equal to sh

I've tried to mess around with line 84 in main.c (execBlock()) but I haven't got much experience with C.

Is it possible to make execl("/bin/sh", "sh", "-c", blocks[i].command, (char*)NULL); run the scripts directly rather than with sh?

UtkarshVerma commented 2 years ago

It should work now. Also, it would be better if you simply use cat /proc/$PPID/comm.

ghost commented 2 years ago

Unfortunately that didn't seem to fix it. Adding notify-send "$(cat /proc/$PPID/comm)" to one of the statusbar modules still returns "sh".

UtkarshVerma commented 2 years ago

Yeah, I was in a rush so didn't notice. You'll have to check for the parent of parent process, i.e. the grandparent process. This is because dwmblocks-async wraps the block command inside an echo $(cmd) statement. This wrapping of the command is really important and is discussed in #24 .

To check the grandparent process, you can use this:

ps -p $(ps -o ppid:1= $PPID) -o comm=
ghost commented 2 years ago

Ah ok thanks