#!/bin/sh script=${0##*/} script2=$1 case $script in wmexit|wmreboot|wmpoweroff|restartwm) OK=1 ;; esac case $script2 in wmexit|wmreboot|wmpoweroff|restartwm) script=$script2 ; OK=1 ;; esac [ ! "$OK" ] && echo "ERROR: $script is not valid" && exit 1 echo $script case $script in restartwm) #Exit from window manager will cause return to xwin, which reads #/tmp/wmexitmode.txt and will relaunch w.m. NEXTWM="$1" PREVIOUSWM="`cat /etc/windowmanager`" [ "$NEXTWM" = "" ] && NEXTWM="$PREVIOUSWM" #v1.0.7 precaution. echo -n "$NEXTWM" > /etc/windowmanager #this makes change permanent. #/sbin/pup_event_frontend_d will quit if this file exists... echo -n "$NEXTWM" > /tmp/wmexitmode.txt chmod 777 /tmp/wmexitmode.txt ;; wmexit) #Exit from X, will cause return to xwin. #/sbin/pup_event_frontend_d will quit if this file exists... echo -n "exit" > /tmp/wmexitmode.txt chmod 777 /tmp/wmexitmode.txt ;; wmlogout) echo -n "logout" > /tmp/wmexitmode.txt chmod 777 /tmp/wmexitmode.txt ;; wmreboot|wmpoweroff) #introduced v0.9.8 #called from /root/.fvwm95rc, .jwmrc at shutdown. #110918 call new script 'shutdownconfig'. #120216 offer to set default language in initrd. #130221 return code 255 to abort shutdown. . /etc/rc.d/PUPSTATE if [ $DISPLAY ];then #paranoid precaution, check X still running #120216 offer to set default language in initrd... if [ -d /initrd ];then GIVEITAGO='yes' LANG1=${LANG%_*} #ex: en [ "$LANG1" = "en" ] && GIVEITAGO='no' if [ -f /var/local/lang2initrd.log ];then #read log from /usr/sbin/lang2initrd [ "`grep "^DECLINED ${DISTRO_IDSTRING}" /var/local/lang2initrd.log`" != "" ] && GIVEITAGO='no' [ "`grep "^SUCCESS ${DISTRO_IDSTRING}" /var/local/lang2initrd.log`" != "" ] && GIVEITAGO='no' fi [ "$GIVEITAGO" = "yes" ] && /usr/sbin/lang2initrd $LANG fi HLESS="$(tr ' ' '\n' < /proc/cmdline | grep '^pfix=' | cut -d= -f2 | grep "headless")" if [ $PUPMODE -eq 5 ];then #first shutdown. if [ "$HLESS" == "" ]; then shutdownconfig #dlgs for creating save-file. #...writes results to /tmp/shutdownconfig_results, which /etc/rc.d/rc.shutdown reads. [ $? -eq 255 ] && exit #abort shutdown. 130221 fi fi fi #/sbin/pup_event_frontend_d will quit if this file exists... [ "$script" = 'wmreboot' ] && echo -n "reboot" > /tmp/wmexitmode.txt [ "$script" = 'wmpoweroff' ] && echo -n "poweroff" > /tmp/wmexitmode.txt chmod 777 /tmp/wmexitmode.txt ;; esac ########################################################### #give time for /sbin/pup_event_frontend_d to quit. #w478 testing 2.6.18.1 kernel, pup_event_frontend_d did not exit when it #detected /tmp/wmeximode.txt, but became 'defunct'... KCNT=0 PSPEFD="`ps -C pup_event_frontend_d | grep 'pup_event_front' | grep -v 'defunct'`" #while [ "`pidof pup_event_frontend_d`" != "" ];do while [ "$PSPEFD" != "" ];do sleep 0.5 KCNT=`expr $KCNT + 1` [ $KCNT -gt 60 ] && break #30 secs. PSPEFD="`ps -C pup_event_frontend_d | grep 'pup_event_front' | grep -v 'defunct'`" done sleep 0.2 sync #if [ "`pidof xfce4-panel`" != "" ];then ##killall xfce4-panel #kill `pidof xfce4-panel` #exit #fi #w003 CURRENTWM="`cat /etc/windowmanager`" #Replaced this seciton with blow for loop. #kill -9 `pidof $CURRENTWM` #killall -9 jwm #killall -9 openbox #killall -9 icewm #This looks like it might be inportant. while [ "`pidof snapmergepuppy`" ] ; do sleep 1 ; done sleep 0.2 sync kill_WMs(){ for i in xfce4-panel lxsession lxqt-session "$XDG_CURRENT_DESKTOP " `cat /etc/windowmanager` jwm icewm openbox compiz do case "$i" in #This was from SliTaz openbox) openbox --exit; ;; lxsession|LXDE|lxde) [ -n "$_LXSESSION_PID" ] && kill $_LXSESSION_PID ;; compiz) killall compiz ;; esac for pid in `pidof $i` ; do #This was from puppy kill $pid || kill -9 $pid done done } kill_Xorg(){ #This branch was taken from puppy for i in X Xorg do for pid in `pidof $i` ; do kill $pid || kill -9 $pid done done } if [ ! -z $EXIT_IN_XINITRC ] && [ $EXIT_IN_XINITRC -eq 0 ]; then #xfce #lxde #LXQt #window managers kill_WMs kill_Xorg elif [ "$script" = "wmpoweroff" ]; then exec /sbin/poweroff #see /usr/bin/wmpoweroff elif [ "$script" = "wmreboot" ]; then exec /sbin/reboot #see /usr/bin/wmpoweroff elif [ "$script" = "wmlogout" ] || [ ! "`id -u`" -eq 0 ]; then kill_WMs else # [ "$script" = "wmexit" ]; then if [ $(ps -aux | grep -c slim) -gt 1 ]; then /etc/init.d/slim stop else kill_WMs kill_Xorg fi fi #TO review handle inittab code from: https://github.com/puppylinux-woof-CE/woof-CE/blob/8c42322085ba71dcc96c1f2aebf36e01129cfeab/woof-code/rootfs-skeleton/sbin/poweroff#L33 ### END ###