Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Readers > Amazon Kindle > Kindle Developer's Corner

Notices

Reply
 
Thread Tools Search this Thread
Old 11-22-2020, 12:35 PM   #1
bmsleight
Member
bmsleight will become famous soon enoughbmsleight will become famous soon enoughbmsleight will become famous soon enoughbmsleight will become famous soon enoughbmsleight will become famous soon enoughbmsleight will become famous soon enough
 
Posts: 24
Karma: 540
Join Date: Aug 2010
Device: Kindle 3
Running a command from KUAL using pipes not as expected

Hi

[TL/DR] Running a command from KUAL using pipes not as expected

I have a PI 3B+ running openwrt and four Amazon Kindle Paperwhite 1 Wi-Fi, I have v2.7.23-g9f3694a of KUAL installed, with USB networking. I can successfully transfer data between machines, by ssh into each machine and running scripts with the scripts and applications using netcat (aka nc).

I am trying to convert to an KUAL extension so finish the project and release. However I must be doing something wrong with piping.

Minimal working example from SSH - not KUAL

On a separate machine (running OpenWRT)

Code:
root@OpenWrt:~# mkfifo /tmp/example.pipe
root@OpenWrt:~# cat /tmp/example.pipe  | netcat -l -vvv  -p  5001 &
root@OpenWrt:~# Listening on any address 5001
Note: "Listening on any address 5001" is the verbose output of netcat

ssh onto Kindle

Code:
[root@kindle root]# nc 192.168.1.126 5001 | tee -i
On the OpenWrt machine, then issue an echo

Code:
root@OpenWrt:~# mkfifo /tmp/example.pipe
root@OpenWrt:~# cat /tmp/example.pipe  | netcat -l -vvv  -p  5001 &
root@OpenWrt:~# Listening on any address 5001
Connection from 192.168.1.105:47765
root@OpenWrt:~# echo "hi" >/tmp/example.pipe 
root@OpenWrt:~#
On Kindle I get:-

Code:
[root@kindle root]# nc 192.168.1.126 5001 | tee -i  
hi
Nb: Note pipe is still open and I can continue to send data from openwrt machine

Minimal working example Using KUAL


Now again using KUAL, using extension as:-

Code:
[root@kindle root]# cat /mnt/us/extensions/OkMonitor/menu.json 
{
	"items": [
	{
		"name": "NC Examples",
		"priority": -998,
		"items": [
		{
			"name": "nc example 1",
			"action": "nc 192.168.1.126 5001 | tee -i ",
			"internal": "Example"
		}
		]
	}
	]
}
[root@kindle root]#
Same commands
Code:
root@OpenWrt:~# mkfifo /tmp/example.pipe
root@OpenWrt:~# cat /tmp/example.pipe  | netcat -l -vvv  -p  5001 &
root@OpenWrt:~# Listening on any address 5001
Then Kindle: KUAL -> NC Examples -> nc example 1

Code:
root@OpenWrt:~# mkfifo /tmp/example.pipe
root@OpenWrt:~# cat /tmp/example.pipe  | netcat -l -vvv  -p  5001 &
root@OpenWrt:~# Listening on any address 5001
Connection from 192.168.1.105:59820
Total received bytes: 0
Total sent bytes: 0
In the second example nc sucessfully but then disconnects. I require nc to remain open. The only difference is that in the first example I running the command when conencted via ssh, the second via KUAL menu.

I need nc to pipe to a different compiled application, but using tee as the application in this examples.

Things I have tried:-
  • openWRT difference option -c, -k
  • openWRT difference version of netcat, nc, ncat
  • From KUAL run a script the ssh localhost then trying to pipe
  • From login -F root
  • on Kindle tee -i in the pipe
  • Pulling hair out and eating chocolate.

Any pointers would be great. Or any ideas how I can debug further.



Thanks,
Brendan
bmsleight is offline   Reply With Quote
Old 11-22-2020, 12:40 PM   #2
NiLuJe
BLAM!
NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.
 
NiLuJe's Avatar
 
Posts: 13,506
Karma: 26047202
Join Date: Jun 2010
Location: Paris, France
Device: Kindle 2i, 3g, 4, 5w, PW, PW2, PW5; Kobo H2O, Forma, Elipsa, Sage, C2E
There's massive I/O redirections involved in KUAL, so I'm not suite sure this'll ever work, period.

EDIT: (This is what actually ends up being passed to ash -c after being wrapped in an actual shell script).

That said, you definitely should not be doing that straight from an action. Do that in a shell script, and run *that* instead.
That should allow you to deal more sanely with any I/O redirection constraints, and possibly background more sanely so you don't block the UI, because I also don't remember how that's dealt with, but that was never the intended usecase .

EDIT²: Well, the action is force-backgrounded anyway, see above edit ;p.

Last edited by NiLuJe; 11-22-2020 at 12:46 PM.
NiLuJe is offline   Reply With Quote
Advert
Old 11-22-2020, 12:47 PM   #3
bmsleight
Member
bmsleight will become famous soon enoughbmsleight will become famous soon enoughbmsleight will become famous soon enoughbmsleight will become famous soon enoughbmsleight will become famous soon enoughbmsleight will become famous soon enough
 
Posts: 24
Karma: 540
Join Date: Aug 2010
Device: Kindle 3
Quote:
Originally Posted by NiLuJe View Post
Do that in a shell script, and run *that* instead.
That should allow you to deal more sanely with any I/O redirection constraints, and possibly background more sanely so you don't block the UI, because I also don't remember how that's dealt with, but that was never the intended usecase .
Thanks or the reply. Tried running a shell script that does the piping, but that does not work either.

Hey KUAL is so good, wanted to give it a try. Any pointers in making a customers "Book?" .az2 like KUAL ?

Any pointer on the source for KUAL so I can see if I can try and debug further ?
bmsleight is offline   Reply With Quote
Old 11-22-2020, 12:51 PM   #4
NiLuJe
BLAM!
NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.
 
NiLuJe's Avatar
 
Posts: 13,506
Karma: 26047202
Join Date: Jun 2010
Location: Paris, France
Device: Kindle 2i, 3g, 4, 5w, PW, PW2, PW5; Kobo H2O, Forma, Elipsa, Sage, C2E
See a couple of EDITs in my original answer . I'd try ripping the I/O & backgrounding stuff out, and see what shakes out.

I would highly, highly, highy recommend *NOT* trying to deal with the Kindlet (deprecated) / Booklet (private, highly obfuscated) APIs yourself, unless you have severe masochistic tendencies .

As you might find out, even rebuilding KUAL itself requires a shitload of hoop-jumping, and full dumps from scarily old FW versions (or not, I may be mixing things up with CM. Kindlets are hell. Java is pain.). I do know that you won't be able to use anything newer than a JDK 8, as they all dropped support for the crappy old language version we need.

EDIT: Okay, for KUAL, you actually "just" need two or three old dumps, one for the KDK1 API, one for the KDK2 API, and one for the Booklet API. ;p. See the readme in the lib folder, which might not be entirely up-to-date.

Fun example (and I stopped caring a good long while ago, so I probably can't build current CollectionsManager versions).

Code:
┌─(niluje@illyria:pts/4)───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────(~)─┐
└─(0.13:26%:18:51:%)── du -h -d1 ~/Kindle/Kindlet-Dev                                                                                                                                                                                                                                                                                                  ──(Sun, Nov 22)─┘
30M     /home/niluje/Kindle/Kindlet-Dev/fw-520
26M     /home/niluje/Kindle/Kindlet-Dev/fw-538
68M     /home/niluje/Kindle/Kindlet-Dev/JDK-1.4.2_19
26M     /home/niluje/Kindle/Kindlet-Dev/fw-534
15M     /home/niluje/Kindle/Kindlet-Dev/Decompilers
19M     /home/niluje/Kindle/Kindlet-Dev/fw-5371
37M     /home/niluje/Kindle/Kindlet-Dev/fw-5442
20M     /home/niluje/Kindle/Kindlet-Dev/fw-532
26M     /home/niluje/Kindle/Kindlet-Dev/fw-539
40M     /home/niluje/Kindle/Kindlet-Dev/fw-592
20M     /home/niluje/Kindle/Kindlet-Dev/fw-512
26M     /home/niluje/Kindle/Kindlet-Dev/fw-536
26M     /home/niluje/Kindle/Kindlet-Dev/fw-530
26M     /home/niluje/Kindle/Kindlet-Dev/fw-531
19M     /home/niluje/Kindle/Kindlet-Dev/fw-5372
30M     /home/niluje/Kindle/Kindlet-Dev/fw-544
26M     /home/niluje/Kindle/Kindlet-Dev/fw-535
288K    /home/niluje/Kindle/Kindlet-Dev/fw-411
268K    /home/niluje/Kindle/Kindlet-Dev/fw-258
26M     /home/niluje/Kindle/Kindlet-Dev/fw-5381
31M     /home/niluje/Kindle/Kindlet-Dev/fw-5432
26M     /home/niluje/Kindle/Kindlet-Dev/fw-533
31M     /home/niluje/Kindle/Kindlet-Dev/fw-5431
37M     /home/niluje/Kindle/Kindlet-Dev/fw-5451
20M     /home/niluje/Kindle/Kindlet-Dev/fw-5321
30M     /home/niluje/Kindle/Kindlet-Dev/fw-542
30M     /home/niluje/Kindle/Kindlet-Dev/fw-5421
31M     /home/niluje/Kindle/Kindlet-Dev/fw-545
19M     /home/niluje/Kindle/Kindlet-Dev/fw-537
30M     /home/niluje/Kindle/Kindlet-Dev/fw-5441
31M     /home/niluje/Kindle/Kindlet-Dev/fw-543
4.0K    /home/niluje/Kindle/Kindlet-Dev/MAIN
34M     /home/niluje/Kindle/Kindlet-Dev/fw-540
46M     /home/niluje/Kindle/Kindlet-Dev/fw-565
882M    /home/niluje/Kindle/Kindlet-Dev

Last edited by NiLuJe; 11-22-2020 at 01:21 PM.
NiLuJe is offline   Reply With Quote
Old 11-22-2020, 01:17 PM   #5
NiLuJe
BLAM!
NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.
 
NiLuJe's Avatar
 
Posts: 13,506
Karma: 26047202
Join Date: Jun 2010
Location: Paris, France
Device: Kindle 2i, 3g, 4, 5w, PW, PW2, PW5; Kobo H2O, Forma, Elipsa, Sage, C2E
You could also just try strace'ing netcat and/or tee (log to a file), to see what actually makes it die.

(Wild guess: something throws an EPIPE somewhere, somehow).

Last edited by NiLuJe; 11-22-2020 at 01:20 PM.
NiLuJe is offline   Reply With Quote
Advert
Old 11-22-2020, 03:42 PM   #6
bmsleight
Member
bmsleight will become famous soon enoughbmsleight will become famous soon enoughbmsleight will become famous soon enoughbmsleight will become famous soon enoughbmsleight will become famous soon enoughbmsleight will become famous soon enough
 
Posts: 24
Karma: 540
Join Date: Aug 2010
Device: Kindle 3
Wow - rabbit hole.....

I think I may have an <ugly> way forward.
Automating screen sessions

(Which is ironic)!
bmsleight is offline   Reply With Quote
Old 11-22-2020, 04:05 PM   #7
bmsleight
Member
bmsleight will become famous soon enoughbmsleight will become famous soon enoughbmsleight will become famous soon enoughbmsleight will become famous soon enoughbmsleight will become famous soon enoughbmsleight will become famous soon enough
 
Posts: 24
Karma: 540
Join Date: Aug 2010
Device: Kindle 3
From the openwrt machine

Code:
root@OpenWrt:~# cat ./test.sh 
rm  /tmp/example.pipe
mkfifo /tmp/example.pipe
cat /tmp/example.pipe  | netcat -l -vvv  -p  5001 &
sleep 1

screen -dmS default_session -t screen_name 
screen -S default_session -p screen_name  -X stuff 'ssh  root@192.168.1.105 "nc 192.168.1.126 5001 | tee -i" \r'


sleep 1
echo "hi" >/tmp/example.pipe 
echo "world" >/tmp/example.pipe 

root@OpenWrt:~# /bin/ash test.sh 
Listening on any address 5001
Connection from 192.168.1.105:37688
root@OpenWrt:~# screen -S default_session -p screen_name  -X kill
root@OpenWrt:~# Total received bytes: 0
Total sent bytes: 9
I can have KUAL trigger the openwrt machine

Thanks for the replies. Back to tidying up and finding the next snag.
bmsleight is offline   Reply With Quote
Old 11-22-2020, 06:29 PM   #8
yparitcher
Connoisseur
yparitcher ought to be getting tired of karma fortunes by now.yparitcher ought to be getting tired of karma fortunes by now.yparitcher ought to be getting tired of karma fortunes by now.yparitcher ought to be getting tired of karma fortunes by now.yparitcher ought to be getting tired of karma fortunes by now.yparitcher ought to be getting tired of karma fortunes by now.yparitcher ought to be getting tired of karma fortunes by now.yparitcher ought to be getting tired of karma fortunes by now.yparitcher ought to be getting tired of karma fortunes by now.yparitcher ought to be getting tired of karma fortunes by now.yparitcher ought to be getting tired of karma fortunes by now.
 
Posts: 52
Karma: 616590
Join Date: Feb 2019
Device: K4 KT4 PW4 PW5
Actually rebuilding KUAL is not too hard, the necessary libs are easy to dump straight from the device. I built a stripped down version that just launches Koreader as KUAL was being too slow for me
https://github.com/yparitcher/KUAL_Booklet
yparitcher is offline   Reply With Quote
Old 11-22-2020, 07:53 PM   #9
NiLuJe
BLAM!
NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.
 
NiLuJe's Avatar
 
Posts: 13,506
Karma: 26047202
Join Date: Jun 2010
Location: Paris, France
Device: Kindle 2i, 3g, 4, 5w, PW, PW2, PW5; Kobo H2O, Forma, Elipsa, Sage, C2E
The Booklet variant has the advantage of only needing a single source, since it gets rid of the two (older) APIs, which means you can actually get those from an Amazon update package, no digging up old devices/backups necessary .

Unfortunately, the OP appears to be on a K3, so, KDK1 .
NiLuJe is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Issue by running a plugin in the command line interface RbnJrg Plugins 4 06-13-2018 11:27 AM
How to install KUAL and mods on KOA running 5.9.2.0.1? tigrisg Kindle Developer's Corner 5 01-10-2018 10:21 AM
Install Kual and Mods on KT3 Running 539.2.0.1 seba20xx Kindle Developer's Corner 1 12-22-2017 08:00 PM
How to convert linux apps for running in kual? Aeris Kindle Developer's Corner 8 09-19-2013 09:37 AM
Running from command line in Leopard iain_benson Calibre 1 06-05-2009 10:49 AM


All times are GMT -4. The time now is 06:23 PM.


MobileRead.com is a privately owned, operated and funded community.