ikrabbe / plan9front

Automatically exported from code.google.com/p/plan9front
0 stars 0 forks source link

page/devmouse/rio: page changing an image can prevent another program starting #242

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I have a script which starts gif jpg or png at regular intervals. If I am 
looking at images in page at the same time, and I change the image in page when 
gif/jpg/png is starting, gif/jpg/png will fail to start, showing the following 
2 lines:

draw: einit: can't open mouse
: '/dev/mouse' file in use

This happened several times today. I used the keyboard not the mouse to change 
images in page. 

I put "rio" in the summary because rio multiplexes the mouse (if my memory 
isn't making things up again).

The example script, "pop", follows. The bug is easy to trigger, just run pop 
and page, and flip through images in page fast-ish. (That's on my R400; 2.7GHz 
dual core.) pop takes directory and image names, and writes /tmp/tt^$pid and 
/tmp/ttt^$pid. To quit pop normally, quit the image display and the script will 
quit after the timeout.

#!/bin/rc

rfork se
pause=3
list = /tmp/tt^$pid
dfile = /tmp/ttt^$pid

awkp = '{print $5-$3; exit}' # $4-$2 would be width 
ifs = '
'
tk=()
ls $* | grep -i '\.(jpe?g|png|gif)$' > $list
while() {
    file = `{fortune $list}
    fl = `{echo $file | tr A-Z a-z}
    switch($fl) {
    case *jpg *jpeg
        cmd=jpg
    case *png
        cmd=png
    case *gif
        cmd=gif
    }
    winsize = `{awk $awkp /dev/window}
    $cmd -t9 $file | resample -y $winsize | totif > $dfile
    if(! ~ $status '|') {
        echo file: $file >[1=2]
    }
    if(~ $#tk 1) {
        echo kill > /proc/^$tk^/note
    }
    tif $dfile &
    tk=$apid
    sleep $pause
}

Original issue reported on code.google.com by tereniao...@gmail.com on 12 Mar 2015 at 2:40

GoogleCodeExporter commented 9 years ago
Errata: s=gif/jpg/png=tif=g in the first paragraph. pop only uses tif for 
display.

Original comment by tereniao...@gmail.com on 12 Mar 2015 at 2:43

GoogleCodeExporter commented 9 years ago
this is a race condition in your script. the write to the note file will
*post* a note to the process, but not wait for the process to have actually
been killed. so you start another tif/gif/jpg before the previous one has
exited and the /dev/mouse file has been closed by the kernel.

page just changes the timing enougth for this race to happen more likely.

what you need is to wait for that process to exit with "wait" rc function.

Original comment by cinap_le...@felloff.net on 12 Mar 2015 at 3:34

GoogleCodeExporter commented 9 years ago

Original comment by cinap_le...@felloff.net on 12 Mar 2015 at 3:43