Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Fri 31 Oct 2014, 17:03
All times are UTC - 4
 Forum index » Advanced Topics » Cutting edge
pup_event_frontend_d
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [4 Posts]  
Author Message
Karl Godt


Joined: 20 Jun 2010
Posts: 3972
Location: Kiel,Germany

PostPosted: Fri 09 Aug 2013, 08:33    Post subject:  pup_event_frontend_d
Subject description: cutting edge scribble
 

WARNING !! OUTDATED !!

I will put here some diff lines to clean up my pup_event_frontend_d experiments and sync it to my dozen installations, which all look differently .

Today some lines to reduce writing to /tmp/ .
Variables should be kept inside the program .
This is relevant mostly for Puppy running non-RAM .

Varibles are
BLOCKDIFF ,
which reduces the usage of some external binaries like diff , which outputs differently in busybox and regular diff , which would needs adjustments if busybox ash would be configured full-featured and use applets first .

and
CURPOS[1|2] .


Code:
@@ -492,6 +492,11 @@ if [ "$BACKENDON" = "false" ];then #see
 fi
 [ "$HOTPLUGON" = "false" ] && exit #turn off all frontend hotplug support. see /etc/eventmanager.
 
+#ls -1 --hide=ram* --hide=loop* /sys/block > /tmp/pup_event_frontend_block2
+#cp /tmp/pup_event_frontend_block2 /tmp/pup_event_frontend_block1
+
+BLOCK1=`ls -1 --hide=ram* --hide=loop* /sys/block`
+CURPOS1=`getcurpos`
 
 ###################################################################
 #now go into a two-second loop...
@@ -503,31 +508,35 @@ do
  [ -f /tmp/wmexitmode.txt ] && break
 
  #test for any change in /sys/block...
- ls -1 --hide=ram* --hide=loop* /sys/block > /tmp/pup_event_frontend_block2
+ #ls -1 --hide=ram* --hide=loop* /sys/block > /tmp/pup_event_frontend_block2
+ BLOCK2=`ls -1 --hide=ram* --hide=loop* /sys/block`
  if [ -f /tmp/pup_event_frontend_block_request ];then #w015
   sleep 0.1
   REMOVEBLOCK='^'"`cat /tmp/pup_event_frontend_block_request`"'$'
-  BLOCKS2="`grep -v "$REMOVEBLOCK" /tmp/pup_event_frontend_block2`"
-  echo "$BLOCKS2" > /tmp/pup_event_frontend_block2
+  BLOCK2=`echo "$BLOCK2" | grep -v "$REMOVEBLOCK"`
+  #BLOCKS2="`grep -v "$REMOVEBLOCK" /tmp/pup_event_frontend_block2`"
+  #echo "$BLOCKS2" > /tmp/pup_event_frontend_block2
   rm -f /tmp/pup_event_frontend_block_request
  fi
- [ ! -f /tmp/pup_event_frontend_block1 ] && cp /tmp/pup_event_frontend_block2 /tmp/pup_event_frontend_block1
- BLOCKDIFF="`diff /tmp/pup_event_frontend_block1 /tmp/pup_event_frontend_block2`"
-
+ #[ ! -f /tmp/pup_event_frontend_block1 ] && cp /tmp/pup_event_frontend_block2 /tmp/pup_event_frontend_block1
+ #BLOCKDIFF="`diff /tmp/pup_event_frontend_block1 /tmp/pup_event_frontend_block2`"
+
  #########hotplug block event##########
- if [ "$BLOCKDIFF" != "" ];then
-
-  cp -f /tmp/pup_event_frontend_block2 /tmp/pup_event_frontend_block1
-
-  BLOCKSADD="`echo "$BLOCKDIFF" | grep '^> ' | cut -f 2-9 -d ' ' | tr '\n' ' '`"
-  BLOCKSREM="`echo "$BLOCKDIFF" | grep '^< ' | cut -f 2-9 -d ' ' | tr '\n' ' '`"

+ #if [ "$BLOCKDIFF" != "" ];then
+ if [ "$BLOCK1" != "$BLOCK2" ] ; then
+  #cp -f /tmp/pup_event_frontend_block2 /tmp/pup_event_frontend_block1
+  #BLOCKSADD="`echo "$BLOCKDIFF" | grep '^> ' | cut -f 2-9 -d ' ' | tr '\n' ' '`"
+  BLOCKSADD=`echo "$BLOCK2" | grep -v "$BLOCK1"`
+  #BLOCKSREM="`echo "$BLOCKDIFF" | grep '^< ' | cut -f 2-9 -d ' ' | tr '\n' ' '`"
+  BLOCKSREM=`echo "$BLOCK1" | grep -v "$BLOCK2"`
+  BLOCK1="$BLOCK2"
+
   ACTION=add
   SUBSYSTEM=block
   DEVTYPE=disk
   for DRV_NAME in $BLOCKSADD
   do
-   [ ! -e /sys/block/$DRV_NAME ] && continue #precaution
+   [ -e /sys/block/$DRV_NAME ] || continue #precaution
    DEVPATH=/block/$DRV_NAME
    odPATTERN='^/dev/'"$DRV_NAME"'|'
    PROBEDISK="`probedisk2`"
@@ -538,7 +547,7 @@ do
    [ "$ICONDESK" = "true" ] && create_icon_func #uses DRV_NAME, DRV_CATEGORY, DRV_DESCRIPTION
    [ "$HOTPLUGNOISY" = "true" ] && /root/.pup_event/drive_${DRV_NAME}/AppRun ${DRV_CATEGORY} & #handler script.
   done
-
+
   ACTION=remove
   for DRV_NAME in $BLOCKSREM
   do
@@ -554,7 +563,7 @@ do
    remove_pinboard_func #needs DRV_NAME
    rm -rf /root/.pup_event/drive_${DRV_NAME}* 2>/dev/null
   done
-
+
  fi
 
  if [ $TOGGLE -eq 0 ];then #slow down to every 4 seconds.
@@ -576,8 +585,8 @@ do
   if [ $MINUTECNT -gt 59 ];then #come in here every minute...
    MINUTECNT=0
    CURPOS2="`getcurpos`"
-   echo "MOUSECNT=$MOUSECNT CURPOS2=$CURPOS2" >> /tmp/pup_event_frontend_d_curpos.log
-   [ "$CURPOS1" = "" ] && CURPOS1="$CURPOS2"
+   #echo "MOUSECNT=$MOUSECNT CURPOS2=$CURPOS2" >> /tmp/pup_event_frontend_d_curpos.log
+   #[ "$CURPOS1" = "" ] && CURPOS1="$CURPOS2"
    [ "$CURPOS1" != "$CURPOS2" ] && MOUSECNT=0
    CURPOS1="$CURPOS2"
    [ $MOUSECNT -gt $POWERTIMEOUT ] && wmpoweroff &
@@ -589,7 +598,7 @@ do
Back to top
View user's profile Send private message Visit poster's website 
Karl Godt


Joined: 20 Jun 2010
Posts: 3972
Location: Kiel,Germany

PostPosted: Fri 09 Aug 2013, 16:53    Post subject: probe_optical_func with eval
Subject description: instead of writing to /tmp/*indentify* file
 

Here's some code I learned from Brad ( technosaurus ) for the probe_optical_func using eval to work around missing support for arrays in ash :
Code:
#!/bin/ash

probe_optical_func() { #passed param is sr<0-9> or hd<a-z>

 DRV_NAME="$1"
 DRV_CATEGORY="optical"
 CDSTATUS2="0";
 eval CDSTATUS0=`echo \\$CDSTATUS1$DRV_NAME`

 opticalPATTERN='^/dev/'"${DRV_NAME}"' '
 [ "`grep "$opticalPATTERN" /proc/mounts`" ] && return #only check cd if unmounted.
 cddetect_quick -d/dev/${DRV_NAME} #>/dev/null 2>&1 #very fast.
 #...returns 0 if disc inserted, else 255.
 CDSTATUS2="$?"

 [ "$CDSTATUS2" != "0" ] && [ -d /root/.pup_event/drive_${DRV_NAME} ] && rm -rf /root/.pup_event/drive_${DRV_NAME} #v410 ensure no drive directory if drive empty.
 #echo "$CDSTATUS2" > /tmp/pup_event_frontend_identify2_${DRV_NAME}
 #[ ! -f /tmp/pup_event_frontend_identify1_${DRV_NAME} ] && cp /tmp/pup_event_frontend_identify2_${DRV_NAME} /tmp/pup_event_frontend_identify1_${DRV_NAME}
 [ "$CDSTATUS0" ] || eval `echo CDSTATUS1$DRV_NAME=$CDSTATUS2`  #DSTATUS0="$CDSTATUS2"
 #CDSTATUS1="`cat /tmp/pup_event_frontend_identify1_${DRV_NAME}`"
 #eval `echo CDSTATUS1$DRV_NAME=`
 eval CDSTATUS0=`echo \\$CDSTATUS1$DRV_NAME`

 [ "$CDSTATUS0" = "$CDSTATUS2" ] && return
 #cp -f /tmp/pup_event_frontend_identify2_${DRV_NAME} /tmp/pup_event_frontend_identify1_${DRV_NAME}
 eval `echo CDSTATUS1$DRV_NAME=$CDSTATUS2`
 #CDSTATUS1= "$CDSTATUS2"

 if [ "$CDSTATUS2" = "0" ];then
  #VENDOR="`cat /sys/block/${DRV_NAME}/device/vendor | tr -s ' '`"
  #MODEL="`cat /sys/block/${DRV_NAME}/device/model | tr -s ' '`"
  #DRV_DESCRIPTION="$VENDOR $MODEL"
  opticalPATTERN='^/dev/'"${DRV_NAME}"'|'
  DRV_DESCRIPTION="`echo "$PROBEDISK" | grep "$opticalPATTERN" | cut -f 3 -d '|'`"
  create_icon_func #requires DRV_NAME, DRV_CATEGORY, DRV_DESCRIPTION.
  [ "$HOTPLUGNOISY" = "true" ] && /root/.pup_event/drive_${DRV_NAME}/AppRun optical & #handler script.
 else
  rm -rf /root/.pup_event/drive_${DRV_NAME} #2>/dev/null
  remove_pinboard_func #needs DRV_NAME
 fi
}

##enable it to test from cli. add or remove sr* devices as needed .
#while [ running ]
#do
#for d in sr0 sr1
#do
#echo $d
#probe_optical_func $d
#sleep 2
#done
#done

That above seems to work for me today,
cannot test the similar probe_floppy_func :
Code:
probe_floppy_func() { #passed param is drive name (exs: hdc, sdc)
 DRV_NAME="$1"
 DRVMAIN="`echo -n "$DRV_NAME" | cut -c 1,2`" #sd or hd.
 DRV_CATEGORY="floppy"
 eval FLOPPYSTATUS0=`echo \\$FLOPPYSTATUS1$DRV_NAME`

 floppyPATTERN="^/dev/$DRV_NAME"
 [ "`grep "$floppyPATTERN" /proc/mounts`" ] && return #mounted.

 if [ "$DRVMAIN" = "hd" ];then
  #cat /proc/ide/${DRV_NAME}/identify > /tmp/pup_event_frontend_identify2_${DRV_NAME}
  read FLOPPYSTATUS2 </proc/ide/${DRV_NAME}/identify
 else
  #this method not as good, as only detects disc if it has a partition...
  floppyPATTERN=" ${DRV_NAME}"
  #grep "$floppyPATTERN" /proc/partitions > /tmp/pup_event_frontend_identify2_${DRV_NAME}
  FLOPPYSTATUS2=`grep "$floppyPATTERN" /proc/partitions`
 fi

 #[ -f /tmp/pup_event_frontend_identify1_${DRV_NAME} ] || cp /tmp/pup_event_frontend_identify2_${DRV_NAME} /tmp/pup_event_frontend_identify1_${DRV_NAME}
 [ "$FLOPPYSTATUS0" ] || eval `echo FLOPPYSTATUS1$DRV_NAME=$FLOPPYSTATUS2`
 #[ "`diff -s /tmp/pup_event_frontend_identify1_${DRV_NAME} /tmp/pup_event_frontend_identify2_${DRV_NAME} | grep ' are identical'`" ] && return
 eval FLOPPYSTATUS0=`echo \\$FLOPPYSTATUS1$DRV_NAME`
 [ "$FLOPPYSTATUS0" = "$FLOPPYSTATUS2" ] && return
 #cp -f /tmp/pup_event_frontend_identify2_${DRV_NAME} /tmp/pup_event_frontend_identify1_${DRV_NAME}
 eval `echo FLOPPYSTATUS1$DRV_NAME=$FLOPPYSTATUS2`
 FLOPPYSTATUS=1
 [ "`disktype /dev/${DRV_NAME} 2>&1 | grep 'I/O error'`" ] || FLOPPYSTATUS=0

 if [ "$FLOPPYSTATUS" = "0" ];then
  if [ "$DRVMAIN" = "hd" ];then
   #DRV_DESCRIPTION="`cat /proc/ide/${DRV_NAME}/model`"
   read DRV_DESCRIPTION </proc/ide/${DRV_NAME}/model
  else
   #DRV_DESCRIPTION="`cat /sys/block/${DRV_NAME}/device/model | tr -s ' '`"
   read DRV_DESCRIPTION <sys/block/${DRV_NAME}/device/model
  fi
  create_icon_func #requires DRV_NAME, DRV_CATEGORY, DRV_DESCRIPTION.
  [ "$HOTPLUGNOISY" = "true" ] && /root/.pup_event/drive_${DRV_NAME}/AppRun floppy & #handler script.
 else
  rm -rf /root/.pup_event/drive_${DRV_NAME} #2>/dev/null
  remove_pinboard_func #needs DRV_NAME
 fi
}
Back to top
View user's profile Send private message Visit poster's website 
Karl Godt


Joined: 20 Jun 2010
Posts: 3972
Location: Kiel,Germany

PostPosted: Sat 10 Aug 2013, 14:24    Post subject: start stop restart status  

Here's some codelines to add
start | restart | status | stop
options
as any common daemon scripts ( ie /etc/init.d/cups ) have,
plus some more : version | help | debug | verbose | codecheck .

The stop | restart options relay on a
Code:
 trap "kill_jobs;exit $?" HUP INT QUIT ABRT TRAP KILL TERM

line somewhere instead of the test for /tmp/wmexitmode.txt every 2 seconds in the daemon while loop .
Code:

Version='1.1-kill Macpup_Opera_2-Puppy_Linux_431-KRG'

usage(){
MSG="
$0 [ help | version ]
$0 [ debug | verbose ] [ start | restart ]
$0 [ stop | status ]
$0 [ codecheck ]
Puppy Daemon to manage the Drive Icons on the desktop.
Is configurable by /usr/sbin/eventmanager gtkdialog GUI.

Help Options :
-V|version) show version information
-h|help) show this usage information

Development Options :
codecheck)    run with set -n
-d|debug)     run with set -x
-v|verbose) show variables to stdout

Main Options :
stop ) stop
start) start
restart) stop and start
status) say if already running
"

[ "$2" ] && "MSG=$MSG
$2
"

echo "$MSG"

exit $1
}

out=/dev/null;err=$out;QUIET='-q'

while getopts Vhvd opt; do
 case $opt in
  V) echo -e "\n$0: Version '$Version'\nTry -h for more info.\n";exit 0;;
  h) usage 0;;
  v) VERB=-v;L_VERB=--verbose;A_VERB=-verbose;out=/dev/stdout;err=/dev/stderr;DEBUG=1;ME_VERB=1;QUIET='';;
  d) set -x;;
  *) :;;
  esac
done


ME_PROGRAM=`readlink -f "$0"`  ##+-2013-08-10 should be readlink -e but busybox readlink treats -f as -e option
ME_PID=$$
PIDS_OTHER_MES=`pidof -o $$ -o %PPID ${ME_PROGRAM##*/}`

PARAMETER_LINE="$@"

while [ "$1" ];do
CASEPARAM=$1;shift

case "$CASEPARAM" in
help|-*help|-h) usage 0
;;
version|-*version|-V)
echo -e "\n$0: Version '$Version'\nTry -h for more info.\n";exit 0
;;
codecheck|-*codecheck|checkcode|-*checkcode)
#BASH set -n
bn=${0##*/}
cp $0 /tmp/
sed -i '1d' /tmp/"$bn"
sed -i '1i\#!/bin/bash -n' /tmp/"$bn"
/tmp/"$bn" $PARAMETER_LINE
echo "<$?>"
echo "Codecheck finished"
echo "Attention :
Normally uses ash, this had been done in bash,
because ash has no -n parameter"
exit 0
;;
debug|-*debug|-d) set -x
;;
verbose|-*verbose|-v) ME_VERB=1
VERB=-v;L_VERB=--verbose;A_VERB=-verbose;out=/dev/stdout;err=/dev/stderr;QUIET=''
;;

stop)
for pid in $PIDS_OTHER_MES ; do
kill $pid
RETVAL=$((RETVAL+$?))
done
echo
exit "$RETVAL"
;;

restart)
for pid in $PIDS_OTHER_MES ; do
kill $pid
done
echo
pidof -o $$ -o %PPID ${ME_PROGRAM##*/} && { echo " Already Running.";exit 1; }
break
;;

start)
pidof -o $$ -o %PPID ${ME_PROGRAM##*/} && { echo " Already Running.";exit 1; }
break
;;

status)
echo -n "$ME_PROGRAM : "
[ "`echo $PIDS_OTHER_MES | wc -w`" = 1 ] && IS=is || IS=are
[ "$PIDS_OTHER_MES" ] && echo "$PIDS_OTHER_MES $IS already running." || echo "not already running."
exit 0
;;

esac
done
### OPTIONS ###

Here are the two relevant functions to kill pup_event_frontend_d with the stop | restart option :

Code:
get_jobs_pids(){
ps-FULL -o ppid,lwp,tty,start,s,psr,pcpu,args -C ${ME_PROGRAM##*/} --no-headers | while read PPid Pid rest ; do
Pids="$Pids
$Pid"
echo "$Pids" | grep $QUIET -w "$PPid" && echo "$Pid"
done
}

kill_jobs(){
JOBS=`get_jobs_pids`
for Pid in $JOBS ; do
ps -p "$Pid" && kill $Pid
done
}

_________________
«Give me GUI or Death» -- I give you [[Xx]term[inal]] [[Cc]on[s][ole]] .
Macpup user since 2010 on full installations.
People who want problems with Puppy boot frugal Razz
Back to top
View user's profile Send private message Visit poster's website 
Karl Godt


Joined: 20 Jun 2010
Posts: 3972
Location: Kiel,Germany

PostPosted: Sun 11 Aug 2013, 18:06    Post subject: function for /sbin/clean_desk_icons replacement
Subject description: in /sbin/pup_event_frontend_d
 

This is code that redraws the drive icons each time X starts . Mainly to redraw in restart mode .
It greps $HOME/Choices/ROX-Filer/PuppyPin for the actual icons .
Former I used probedisk2 or $(ls -1U /sys/class/block |grep -e '[0-9]$' |grep -vE '^loop|^md|^ram')
for this, but if HDs are swapped then the old icons might not be removed .
Code:
CLEAN_DESK_ICONS_func(){
while read part;do
DRV_NAME=$part remove_pinboard_func #$DRV_NAME
done << _EOI
$(grep -o '/\.pup_event/drive.*' $HOME/Choices/ROX-Filer/PuppyPin |sed -r 's,(.*)(drives)(.*),\2,;s,(.*drive_)(.*)(<.*),\2,')
_EOI
rm -rf $HOME/.pup_event/*
}
CLEAN_DESK_ICONS_func

It must start before the current drive icons are processed :
Quote:
#stuff to setup at entry...
mkdir -p $HOME/.pup_event
#build the desktop icons...
Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 1 of 1 [4 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Advanced Topics » Cutting edge
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0930s ][ Queries: 12 (0.0061s) ][ GZIP on ]