From aeb96c2c8a46502d8178895deff77ec39fc34861 Mon Sep 17 00:00:00 2001 From: hummypkg Date: Tue, 10 Jun 2014 17:12:06 +0000 Subject: [PATCH] update to new lsof and fix things git-svn-id: file:///root/webif/svn/humax/pkg/src/webif/trunk@1949 2a923420-c742-0410-a762-8d5b09965624 --- CONTROL/control | 4 +-- webif/cgi-bin/channel.jim | 2 ++ webif/cgi-bin/status.jim | 60 +++++++++++++++++++++++++++---------- webif/html/browse/index.jim | 5 ++-- webif/lib/bin/lsof | 6 ++++ webif/lib/system.class | 30 +++++++++---------- webif/lib/ts.class | 3 +- 7 files changed, 73 insertions(+), 37 deletions(-) create mode 100755 webif/lib/bin/lsof diff --git a/CONTROL/control b/CONTROL/control index a8cdd10..9c385fe 100644 --- a/CONTROL/control +++ b/CONTROL/control @@ -1,10 +1,10 @@ Package: webif Priority: optional Section: web -Version: 1.0.14-6 +Version: 1.0.14-7 Architecture: mipsel Maintainer: af123@hummypkg.org.uk -Depends: webif-channelicons(>=1.1.11),lighttpd(>=1.4.35-2),jim(>=0.75-1),jim-oo,jim-sqlite3(>=0.75),jim-cgi(>=0.7),jim-binary(>=0.75),service-control(>=1.2),busybox(>=1.20.2-1),lsof,epg(>=1.0.13),hmt(>=1.1.19),ssmtp,anacron,trm(>=1.1),openssl-command,nicesplice,id3v2,file,rsvsync(>=1.0.2),webif-charts(>=1.2-1),stripts(>=1.2.5-3),smartmontools,tmenu(>=1.08),ffmpeg,id3v2,multienv(>=1.6),mongoose +Depends: webif-channelicons(>=1.1.11),lighttpd(>=1.4.35-2),jim(>=0.75-1),jim-oo,jim-sqlite3(>=0.75),jim-cgi(>=0.7),jim-binary(>=0.75),service-control(>=1.2),busybox(>=1.20.2-1),lsof(>=4.87),epg(>=1.0.13),hmt(>=1.1.19),ssmtp,anacron,trm(>=1.1),openssl-command,nicesplice,id3v2,file,rsvsync(>=1.0.2),webif-charts(>=1.2-1),stripts(>=1.2.5-3),smartmontools,tmenu(>=1.08),ffmpeg,id3v2,multienv(>=1.6),mongoose Suggests: Description: An evolving web interface for the Humax. Tags: http://hummy.tv/forum/threads/5031/ diff --git a/webif/cgi-bin/channel.jim b/webif/cgi-bin/channel.jim index 57ae179..93588f0 100755 --- a/webif/cgi-bin/channel.jim +++ b/webif/cgi-bin/channel.jim @@ -140,3 +140,5 @@ $(document).ready(function() { } +footer + diff --git a/webif/cgi-bin/status.jim b/webif/cgi-bin/status.jim index 7943992..c9e6bee 100755 --- a/webif/cgi-bin/status.jim +++ b/webif/cgi-bin/status.jim @@ -31,23 +31,39 @@ proc get_data {} { set ret {} if {[catch {set data \ - [exec /mod/bin/lsof -p $pid | grep Video]} msg]} { + [exec /mod/webif/lib/bin/lsof -X -Fns -p $pid]} msg]} { set ret {} } else { + + #aw + #s583700480 + #n/mnt/hd2/My Video/Real Lives Reunited_20140610_1002.ts + + # Unfortunately, the access flag isn't reliable for + # some reason. If it were, the sleep could be removed! + + set size 0 foreach line [split $data "\n"] { - regsub -all -- {[[:space:]]+} $line " " line - regsub -- { \([^\)]+\)$} $line "" line - set file [file tail $line] - set ext [file extension $line] - if {$ext ni $exts} continue - set name [file rootname $file] - if {[dict exists $ret $name]} { - if {$ext eq ".ts"} { - set ret($name) -1 + set typ [string index $line 0] + switch $typ { + s { + set size [string range $line 1 end] + } + n { + if {[string first Video $line] == -1} { + continue } - } else { - set size [lindex [split $line " "] 6] - set ret($name) $size + set ext [file extension $line] + if {$ext ni $exts} continue + set name [file tail [file rootname $line]] + # Handle chase play (same file open twice) + if {[dict exists $ret $name] && \ + $ext eq ".ts"} { + set ret($name) -1 + } else { + set ret($name) $size + } + } } } } @@ -59,15 +75,15 @@ set rec 0 set seen {} set output {} +set data {} if {$type eq "full"} { set data [get_data] -} else { - set data {} } - if {[llength $data]} { sleep 3 set ndata [get_data] +# puts " DATA: ($data)" +# puts " NDATA: ($ndata)" foreach name [array names ndata] { if {![dict exists $seen $name]} { set seen($name) 0 } if {![dict exists $data $name]} { set data($name) 0 } @@ -104,6 +120,9 @@ if {[llength $data]} { } } +###################################################################### +# Live viewing information + if {![system instandby] && $play < 1} { set hsvc [system param CUR_SVC Value USERCONFIG] @@ -144,6 +163,9 @@ if {![system instandby] && $play < 1} { } } +###################################################################### +# In standby + if {[system instandby]} { if {$runmode eq "cgi"} { lappend output [concat \ @@ -158,6 +180,9 @@ if {[system instandby]} { } } +###################################################################### +# Upcoming recordings + set events [rsv list tbl_reservation \ " where ersvtype = 3 and nsttime - [clock seconds] < $schedtime and nsttime > [clock seconds] "] @@ -181,6 +206,9 @@ foreach event $events { } } +###################################################################### +# Output + if {[llength $output]} { if {$runmode eq "cgi"} { puts [join $output "\n
\n"] diff --git a/webif/html/browse/index.jim b/webif/html/browse/index.jim index 74e9dde..fb47ea9 100755 --- a/webif/html/browse/index.jim +++ b/webif/html/browse/index.jim @@ -93,7 +93,7 @@ set dircount 0 set filecount 0 proc entry {file} {{i 0}} { - global dircount filecount + global dircount filecount dinuse set bfile [file tail $file] regsub -all " +" $bfile "" tbfile @@ -174,7 +174,7 @@ proc entry {file} {{i 0}} { set dlna 0 set shrunk 0 if {$type eq "ts"} { - if {[$ts inuse]} { + if {$bfile in $dinuse} { icon "/img/inuse.png" } set genre [$ts get genre] @@ -322,6 +322,7 @@ switch $order { default { set files [lsort -nocase $files] } } +set dinuse [system dirinuse $dir] foreach file $files { entry "$dir/$file" } puts " diff --git a/webif/lib/bin/lsof b/webif/lib/bin/lsof new file mode 100755 index 0000000..c50feb5 --- /dev/null +++ b/webif/lib/bin/lsof @@ -0,0 +1,6 @@ +#!/bin/sh + +# stderr is always unbuffered so use that... +/mod/bin/lsof "$@" 2>&1 +exit 0 + diff --git a/webif/lib/system.class b/webif/lib/system.class index b83a638..cda30f5 100644 --- a/webif/lib/system.class +++ b/webif/lib/system.class @@ -218,7 +218,8 @@ proc {system busy} {} { return 0 } set c 0 - foreach line [split [exec /mod/bin/lsof -p $pid] "\n"] { + foreach line [split [\ + exec /mod/webif/lib/bin/lsof -X -Fn -p $pid] "\n"] { if {[string match {*Video*.ts} $line]} { incr c } } if {$c > 0} { return 1 } @@ -226,23 +227,22 @@ proc {system busy} {} { } proc {system inuse} {file} { - # Is anything using the file? - set file [file rootname [file tail $file]] - - # Escape any unicode characters to match lsof output. - foreach range [lreverse [\ - regexp -inline -indices -all -- {[\x80-\xff]} $file]] { - set i [lindex $range 0] - binary scan [string index $file $i] H2 hex - set file [string replace $file $i $i "\\x$hex"] + set op [exec /mod/webif/lib/bin/lsof -X -Fn $file] + if {$op eq ""} { + return 0 + } else { + return 1 } +} - set c 0 - foreach line [split [exec /mod/bin/lsof] "\n"] { - if {[string first $file $line] >= 0} { incr c } +proc {system dirinuse} {dir} { + set files {} + foreach line [split [\ + exec /mod/webif/lib/bin/lsof -X -Fn +d $dir] "\n"] { + if {[string index $line 0] ne "n"} continue + lappend files [file tail $line] } - if {$c > 0} { return 1 } - return 0 + return $files } proc {system reboot} {} { diff --git a/webif/lib/ts.class b/webif/lib/ts.class index c63fb5a..72377e7 100644 --- a/webif/lib/ts.class +++ b/webif/lib/ts.class @@ -58,8 +58,7 @@ ts method lastmod {} { } ts method inuse {} { - if {[system inuse [file rootname $file]]} { return 1 } - return 0 + return [system inuse $file] } ts method bookmarks {} {