WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: TCE extension name and executable mismatch...  (Read 12844 times)

Offline nitram

  • Hero Member
  • *****
  • Posts: 1054
TCE extension name and executable mismatch...
« on: September 20, 2015, 09:36:29 PM »
Hi all.

Repeatedly loading an extension from OnDemand works for most extensions but not others. It appears related to a mismatch between the .tcz extension name and executable and how OnDemand handles this scenario.

For a non-problematic extension, emelfm for example, I can open an instance of emelfm from OnDemand, close when done and re-open repeatedly during the same session from OnDemand no problem. If i try the same with beaver2.tcz or vlc2.tcz for example, CPU usage spikes to 100%, numerous vlc2 processes are created and repeated killall vlc2 must be issued.

Placing a soft link in the extension's /bin directory appears to fix, see below. Now beaver can be closed and re-opened as many times as desired from beaver2 OnDemand without issue. This simple fix appears to:

- negate the need to create a seperate vlc or beaver menu entry in the Window Manager menu/just use OnDemand

- prevents the processor spike/infinite loop scenario

- ...especially if the user forgets the extension was alreadly loaded from OnDemand

- and actually opens the application upon first OnDemand selection (not just loads it)

Would like to update the extension wiki here:
http://wiki.tinycorelinux.net/wiki:creating_extensions#all_extension_creators_please_note

...but wouldn't mind testers to confirm this behaviour/fix. If okay, will add a wiki entry similar to:

Quote
Mismatch between extension name and primary executable: If the extension and executable names differ, creating a soft link in the extension's /bin folder linking the extension name to the executable name prevents issues when calling the extension from the OnDemand menu. Example:

    Extension name: beaver2.tcz
    Executable: beaver
    Soft link beaver2 to the executable beaver: tc@box:/tmp/squashfs-root/usr/local/bin$ ln -s beaver beaver2

Offline Misalf

  • Hero Member
  • *****
  • Posts: 1702
Re: TCE extension name and executable mismatch...
« Reply #1 on: September 21, 2015, 04:21:50 AM »
I suspect the issue to be in /usr/bin/ondemand .

Code: [Select]
if [ ! -e "$INSTALLED"/"$APPNAME" ]; then
shift 1 && ${COMMAND} "$FROMWHERE""$APPNAME"."$TYPE" && launchApp "$APPNAME" $@
else
if [ "$(which $APPNAME)" ]
then
exec $APPNAME
else
echo "Already loaded. Call from regular menu or terminal."
printf "\a"
fi
fi

exec $APPNAME  will execute  /etc/sysconfig/tcedir/ondemand/beaver2 .

I'd suggest to make sure that  /usr/bin/ondemand  never executes anything from within  /etc/sysconfig/tcedir/ondemand .
Only use  exec $APPNAME  if there is no  /usr/local/share/applications/$APPNAME.desktop ,
otherwise use the  launchApp  function.

Download a copy and keep it handy: Core book ;)

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11049
Re: TCE extension name and executable mismatch...
« Reply #2 on: September 21, 2015, 04:50:18 AM »
Fixed in git, thanks for reporting.
The only barriers that can stop you are the ones you create yourself.

Offline Misalf

  • Hero Member
  • *****
  • Posts: 1702
Re: TCE extension name and executable mismatch...
« Reply #3 on: September 21, 2015, 07:42:39 AM »
Thanks, tested ; works.

Code: [Select]
fullpath=`which $APPNAME`
if [ "$?" -eq 0 ] && `echo $fullpath | grep -qv ondemand`
then
exec $APPNAME
else
echo "Already loaded. Call from regular menu or terminal."
printf "\a"
fi

However, as I get it, the OnDemand feature is also supposed to run a certain app with the shipped parameters.
F.e.: "beaver2 /home/tc/some-file.txt".
Since, in this case, the executable file is actually "beaver", nothing will be run if beaver2.tcz is already loaded.
Shouldn't  /usr/bin/ondemand  do another check for an  $APPNAME.desktop  file to get the correct  Exec=  value, so one can configure the file manager of choice to always open, let's say. txt files with beaver2?

Like so (NOTE: untested)
Code: [Select]
if [ -e "$FREEDESKTOP"/"$APPNAME".desktop ]
then
shift 1 && launchApp "$APPNAME" $@
else
fullpath=`which $APPNAME`
if [ "$?" -eq 0 ] && `echo $fullpath | grep -qv ondemand`
then
exec $APPNAME
else
echo "Already loaded. Call from regular menu or terminal."
printf "\a"
fi
fi

Or just using  launchApp()  adding the  else exec  part to the launchApp function, maybe slightly more elegant?
Code: [Select]
launchApp() {
FREEDESKTOP=/usr/local/share/applications
if [ -e "$FREEDESKTOP"/"$1".desktop ]
then
E=`awk 'BEGIN{FS="="}/^Exec/{print $2}' "$FREEDESKTOP"/"$1".desktop`
  E="${E% \%*}"
  shift 1
exec ${E} $@
else
fullpath=`which $1`
if [ "$?" -eq 0 ] && `echo $fullpath | grep -qv ondemand`
then
exec $1
else
echo "Already loaded. Call from regular menu or terminal."
printf "\a"
fi
fi
}

Otherwise, the OnDemand feature becomes kind of obsolete I think.
Download a copy and keep it handy: Core book ;)

Offline Misalf

  • Hero Member
  • *****
  • Posts: 1702
Re: TCE extension name and executable mismatch...
« Reply #4 on: September 21, 2015, 08:25:25 AM »
hmm...
/etc/sysconfig/tcedir/ondemand/beaver2:
Code: [Select]
#!/bin/sh
ondemand -e beaver2.tcz


This doesn't look right. Has it been changed recently?
I expected something like this:
Code: [Select]
#!/bin/sh
ondemand -e beaver2.tcz "$@"


I see this in  /usr/bin/ondemand :
Code: [Select]
echo '#!/bin/sh' > "$FILE"
echo "ondemand -e $EXTN" >> "$FILE"

What about this?
Code: [Select]
echo '#!/bin/sh' > "$FILE"
echo 'ondemand -e '"$EXTN"' "$@"' >> "$FILE"
« Last Edit: September 21, 2015, 08:26:56 AM by Misalf »
Download a copy and keep it handy: Core book ;)

Offline Misalf

  • Hero Member
  • *****
  • Posts: 1702
Re: TCE extension name and executable mismatch...
« Reply #5 on: September 21, 2015, 09:04:47 AM »
I changed the exec part in  /usr/bin/ondemand  to this:
Code: [Select]
if [ "$EXECITEM" ]; then
TYPE="${1##*.}"
if [ "$TYPE" == "tcz" ]
then
FROMWHERE="$TCEDIR"/"optional/"
COMMAND="tce-load -is"
fi
INSTALLED=/usr/local/tce.installed
if [ ! -e "$INSTALLED"/"$APPNAME" ]; then
shift 1 && ${COMMAND} "$FROMWHERE""$APPNAME"."$TYPE" && launchApp "$APPNAME" $@
else
shift 1 && launchApp "$APPNAME" $@
fi
exit 0
fi

And added  "$@"  for newly created OnDemand items:
Code: [Select]
echo 'ondemand -e '"$EXTN"' "$@"' >> "$FILE"

Also changed the  launchApp function from  /etc/init.d/tc-functions  to this:
Code: [Select]
launchApp() {
FREEDESKTOP=/usr/local/share/applications
if [ -e "$FREEDESKTOP"/"$1".desktop ]
then
E=`awk 'BEGIN{FS="="}/^Exec/{print $2}' "$FREEDESKTOP"/"$1".desktop`
  E="${E% \%*}"
  shift 1
exec ${E} $@
else
fullpath=`which $1`
if [ "$?" -eq 0 ] && `echo $fullpath | grep -qv ondemand`
then
exec $1
else
echo "Already loaded. Call from regular menu or terminal."
printf "\a"
fi
fi
}

So far things seem to work.
Sorry for not providing a diff, my ondemand script is highly modified.

Cheers!
Download a copy and keep it handy: Core book ;)

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11049
Re: TCE extension name and executable mismatch...
« Reply #6 on: September 21, 2015, 10:27:56 AM »
Good changes, can you upload a patch for the tc-functions change at least?

I'd prefer a tested patch for ondemand too, as I don't use it, but let's have some progress at least ;)
The only barriers that can stop you are the ones you create yourself.

Offline Misalf

  • Hero Member
  • *****
  • Posts: 1702
Re: TCE extension name and executable mismatch...
« Reply #7 on: September 21, 2015, 11:02:24 AM »
K then

Code: [Select]
--- /tmp/tc-functions
+++ /tmp/tc-functions.new
@@ -337,5 +337,14 @@
  E="${E% \%*}"
  shift 1
  exec ${E} $@
+ else
+ fullpath=`which $1`
+ if [ "$?" -eq 0 ] && `echo $fullpath | grep -qv ondemand`
+ then
+ exec $1
+ else
+ echo "Already loaded. Call from regular menu or terminal."
+ printf "\a"
+ fi
  fi
 }


Code: [Select]
--- /tmp/ondemand
+++ /tmp/ondemand.new
@@ -103,13 +103,7 @@
  if [ ! -e "$INSTALLED"/"$APPNAME" ]; then
  shift 1 && ${COMMAND} "$FROMWHERE""$APPNAME"."$TYPE" && launchApp "$APPNAME" $@
  else
- if [ "$(which $APPNAME)" ]
- then
- exec $APPNAME
- else
- echo "Already loaded. Call from regular menu or terminal."
- printf "\a"
- fi
+ shift 1 && launchApp "$APPNAME" $@
  fi
  exit 0
 fi
@@ -120,7 +114,7 @@
 [ -d "$TCEDIR"/ondemand ] || mkdir -p "$TCEDIR"/ondemand
 FILE="$TCEDIR"/ondemand/"$APPNAME"
 echo '#!/bin/sh' > "$FILE"
-echo "ondemand -e $EXTN" >> "$FILE"
+echo 'ondemand -e '"$EXTN"' "$@"' >> "$FILE"
 chmod +x "$FILE"
 
 # Optional as flwm does not need a make_ondemand.


(;
Download a copy and keep it handy: Core book ;)

Offline Misalf

  • Hero Member
  • *****
  • Posts: 1702
Re: TCE extension name and executable mismatch...
« Reply #8 on: September 21, 2015, 11:05:12 AM »
This is for Core 6.4 x86.
Download a copy and keep it handy: Core book ;)

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11049
Re: TCE extension name and executable mismatch...
« Reply #9 on: September 21, 2015, 12:53:43 PM »
Applied, thanks.
The only barriers that can stop you are the ones you create yourself.

Offline Misalf

  • Hero Member
  • *****
  • Posts: 1702
Re: TCE extension name and executable mismatch...
« Reply #10 on: September 21, 2015, 01:45:19 PM »
Great!
One more thing though, in both files  $@  should be quoted (i.e. "$@") to prevent messing up file names containing spaces.

tc-functions
Code: [Select]
exec ${E} "$@"

ondemand
Code: [Select]
shift 1 && ${COMMAND} "$FROMWHERE""$APPNAME"."$TYPE" && launchApp "$APPNAME" "$@"
and
Code: [Select]
shift 1 && launchApp "$APPNAME" "$@"

Sorry (again) for not providing diffs. I hope this is eye-spottable enough.
Thanks.
Download a copy and keep it handy: Core book ;)

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11049
Re: TCE extension name and executable mismatch...
« Reply #11 on: September 21, 2015, 02:31:17 PM »
Done.
The only barriers that can stop you are the ones you create yourself.

Offline Misalf

  • Hero Member
  • *****
  • Posts: 1702
Re: TCE extension name and executable mismatch...
« Reply #12 on: September 21, 2015, 08:46:18 PM »
Thank you, will do further testing and report if there will occur any problems.
Ideas, by anyone, for special use cases welcome.
Download a copy and keep it handy: Core book ;)

Offline Misalf

  • Hero Member
  • *****
  • Posts: 1702
Re: TCE extension name and executable mismatch...
« Reply #13 on: September 22, 2015, 01:07:31 PM »
Another small edit for making it possible to ship parameters to an OnDemand item where the extension doesn't contain a *.desktop file.
Code: [Select]
--- tc-functions.old
+++ tc-functions.new
@@ -341,7 +341,9 @@
  fullpath=`which $1`
  if [ "$?" -eq 0 ] && `echo $fullpath | grep -qv ondemand`
  then
- exec $1
+ E=$1
+ shift 1
+ exec $E "$@"
  else
  echo "Already loaded. Call from regular menu or terminal."
  printf "\a"

Download a copy and keep it handy: Core book ;)

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11049
Re: TCE extension name and executable mismatch...
« Reply #14 on: September 22, 2015, 01:21:48 PM »
Applied, thanks!
The only barriers that can stop you are the ones you create yourself.