Closing XTerm causes the GTK app to exit, inspite of disown/nohup on its PID - why?



https://www.reddit.com/r/bash/comments/axi4n6/closing_xterm_causes_the_app_to_exit_inspite_of/

Adding nohup works but ONLY for xclock xfontsel xpdf - hexchat and
firefox exit when the terminal exits - basically GTK apps.

Script creates a named-pipe .Xauthority to pass MIT-MAGIC-cookie data
to a app running as X_USER. It works great but I'm unable to detach
the process from its XTerm. Closing XTerm closes the app.

I want to use an XTerm because it supports -hold (for debugging) if
there's a problem I can insert a -hold to view the error message.

#!/usr/bin/bash
#Usage: bash run appname

set +xv

X_USER=veek
DIR_X_USER=/home/veek


function error
{
    echo "$@" >>/tmp/error.$0
}

function create_fifo
{
    error $FUNCNAME[0];
    mkfifo ${DIR_X_USER}/.Xauthority;
    chown $USER:$USER ${DIR_X_USER}/.Xauthority
}


getopts k myarg

case $myarg in
    k) pkill -KILL -u ${X_USER}; shift;;
    *) if [ $# -lt 1 ]; then
            echo "Usage: $0 [-k] app_name";
            exit 1;
       fi;;
esac

declare -A myapp_list=( [ff]=firefox
                        [hex]=hexchat
[pdf]='wine .wine/drive_c/Program Files/Tracker Software/PDF
Viewer/PDFXCview.exe' )

case $1 in
    pdf*) set ${myapp_list[$1]%% *} "${myapp_list[$1]#[a-z]* }";;
    *) set ${myapp_list[$1]:-"$@"};;
esac

[ ! -O ${DIR_X_USER}/.Xauthority ] && {
                                    error $FUNCNAME[0];
                                    rm ${DIR_X_USER}/.Xauthority;
                                    create_fifo;
                                    }
[ -f ${DIR_X_USER}/.Xauthority ] && {
                                    error $FUNCNAME[0]; exit
                                    exit 1;
                                    }
[ ! -p ${DIR_X_USER}/.Xauthority ] && {
                                    error $FUNCNAME[0];
                                    create_fifo;
                                    }

if [ -p ${DIR_X_USER}/.Xauthority ]; then
    xterm -geometry -0-0 -T 'sudoAuth' -e bash -c '
        if mkdir -v /tmp/fe.lock; then
            echo "start"; trap "rm -rf /tmp/fe.lock/" 0
            declare -g count=0
            while true; do
                #blocks waiting for an app to read fifo
                cat ~/.Xauthority >>$1/.Xauthority;
                echo $((count = count + 1)) ;
            done
        else
            exit 0
        fi
    ' junk_txt "${DIR_X_USER}"&
fi


#xterm -e "su - ${X_USER} -c 'export XAUTHORITY=~/.Xauthority; hexchat'"
#-hold to see the XTerm error msg
xterm -T "$1" -e sudo -u "${X_USER}" bash -c '
    export DISPLAY=:0.0
    export XAUTHORITY=/home/veek/.Xauthority
    progname="$1"; shift;
    cd;
    if [ ${#1} -gt 0 ]; then
        echo two args
        nohup "$progname" "$1"&
    else
        nohup "$progname"&
    fi
    for pid in $(jobs -p); do
        echo $pid
        disown $pid
    done
    echo done
    sleep 40' junk_txt "$1" "$2"&


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]