NUKI 1.2

I hadn't worked on my demo for almost a year NUKI. Today I have time to fix things because there were a lot of things that were not quite good. I added some new functionality. I rearranged the code, with more features so I shortened it and it became clearer.

The main new functionality I introduced is the signal trap. At some point as the demon rotates the dreambox the receiver decides to kill it and thus stops monitoring my process, which in itself is a rather unpleasant moment. And I can't figure out what's going on because the space for logs is ungodly small and I have to make complex network sharing schemes that I don't care about.. In general, the signal trap is a nice feature of bash scripts to intercept signals from outputs or those sent to them by the kernel via kill say 😉 and thus we can prevent some of the immediate subsequent events. Just insert that SIGKIL or kill -9 it cannot be intercepted and prevented, so is the design in the kernel. It terminates the PID submitted to it directly. Now the corresponding code

#trapping signals I know -9 dosent work but we try it just in case ; )
trap on_exit 0 14 1 2 9 13 15 6 8 4 3 11 5
on_exit () {
make_debug 10 #unexpected error
#reboot now if we hawe trapped signal
reboot -d 0
exit 0
}

The first line tells us what action to take and at which signals we will intercept more for the signals. man signals 😉 In this case, I am interested in these. As you can see, they lead to a simple function that debugs a message and restarts the receiver. I'm not having lunch, that will lead to the result I expect, понеже мисля че всичко което пречи е избива с kill -9 но нищо не пречи да се пробва.

Другите кардинални промени са функциите повечето неща които се повтарят от кода ги наблъсках в функции, that was a little awkward to watch no, that is now de 😉 I had a slight drama with return in bash – I put my return in one function and expect behavior like all other programming languages ​​I know, but it turned out that return returns only integer values ​​and that maximum 2 😀 and I wanted to return my string. There was an ugly pig. The solution to the problem is simple

#---cuted---

if [ $T -eq $N ]
 then
 echo "Cam is down! Reboot..."
make_debug 4 # cam is down
 else
echo $rcam
 fi

# ---cuted----

#finding real cam1
 rcam1=$(find_cam $cam1)

Първата част е края на функцията ми и чрез echo изплювам резултата. Взимането му е елементарно с последния ред в горния пасаж.

Хммм мисля, че това е интересната част от кода.

Искам да изкажа благодарност на вдъхновението 😉

http://www.youtube.com/watch?v=SilMJ0O13UI&feature=related

Leave a Reply

Your email address will not be published. Required fields are marked *

Anti SPAM *