@EXEC on network init?

Posted by: tms13

@EXEC on network init? - 08/04/2003 10:18

Is it possible in Hijack to detect when the network interface is available and run a command at that time? I don't mind if I have to put a script in a /usr/local/etc/net-up.d directory or name it in the config.ini or anything else reasonable.

The reason I ask is that my player's clock gains seconds per day, and I want to run ntpdate whenever I boot with Ethernet plugged in. I tried writing
[hijack]
;@AC ;@EXEC /usr/local/bin/ntpdate -b timeserver
where timeserver is a machine with an NTP server, but this fails because my player is on DHCP and so has no network address until after the player has started:
8 Apr 17:05:57 ntpdate[10]: sendto(10.70.x.x): Network is unreachable
8 Apr 17:05:58 ntpdate[10]: sendto(10.70.x.x): Network is unreachable
8 Apr 17:05:59 ntpdate[10]: sendto(10.70.x.x): Network is unreachable
8 Apr 17:06:00 ntpdate[10]: sendto(10.70.x.x): Network is unreachable
8 Apr 17:06:01 ntpdate[1hijack_exec("/usr/local/bin/ntpdate -b 10.70.x.x"), rc=1 (ERROR)


I guess I could read up on binding commands to the Hijack menu, but then I'd have to manually invoke it every time, rather than it happening automatically.

Incidentally, couldn't find anything on EXEC/EXEC_ONCE in the Hijack FAQ - I think it's probably stable enough now, Loren?
Posted by: genixia

Re: @EXEC on network init? - 08/04/2003 10:24

Odd. I currently still have the equivalent running from preinit and it works.
I can't understand why it's not working for you, I would have thought that the preinit called ntpdate would run earlier than the EXEC one. I usually see one 'network unreachable' before a sync.

Sanity check - does it work from a command line after boot?

Maybe you've got a slow dhcp server!
Posted by: cushman

Re: @EXEC on network init? - 08/04/2003 10:28

This is a feature that I have asked for before. Basically, you would like to have an EXEC_AFTER_PLAYER or such command to run some program after the player has started. I need the same thing, since my Palantir program needs to irattach the IrDA port after the player has loaded.

You could check out my script that comes with the empire (server side IrDA listener) package here. It's a hack to delay until the player has started, it just uses 'sleep' to wait for 10 seconds, then continues execution of the script. It's messy, but it works.
Posted by: mlord

Re: @EXEC on network init? - 08/04/2003 10:31

EXEC after player won't solve this particular problem.

Rather, I believe his command needs to be modified run a script to poll for the network before running ntpdate.. Sometimes the network comes up very quickly (static settings), and sometimes very slowly (DHCP). On my network here, DHCP no longer functions at all from any of my Empegs (dunno why, they try and try, but seem to be ignoring the replies sent from the server).

Cheers
Posted by: tms13

Re: @EXEC on network init? - 08/04/2003 10:32

What I have works if I quit and restart the player app from the serial terminal (or when I sync from JEmplode), but not if I reboot the player from Hijack or cold-boot by removing power. Like you, I think my player is too fast for our DHCP server.

Synchronising when I sync my music is a start, but I tend to go two months and then buy two dozen albums rather than the steady trickle that I used to (when I worked near town)...
Posted by: tms13

Re: @EXEC on network init? - 08/04/2003 10:38

Something I should have asked - does @EXEC fork the child and abandon it, or does it wait() for it before returning from the syscall that's reading config.ini? If the latter, then a polling script would cause the player to hang indefinitely at home (where it's not on the network). My reading of the source is that it waits - right?
Posted by: cushman

Re: @EXEC on network init? - 08/04/2003 11:02

Ahh.. never mind then :^) I guess I didn't understand the problem fully.

One thing that I was thinking about though was a way to order the commands in config.ini. What if we used EXEC in config.ini to execute the player? If Hijack gets to the end of the EXEC list and there was no command to EXEC the player, then it would start up the player anyway. This would allow us to:

@EXEC "some program"
@EXEC "/path/to/player"
@EXEC "irattach /dev/ttyS2"

and no new commands would have to be added. Doesn't Hijack use the same exec function anyway to start the player?
Posted by: mlord

Re: @EXEC on network init? - 08/04/2003 11:07

It hangs around and waits for it. But the script could fork off a child to do the polling while the main script exits.

Cheers
Posted by: mlord

Re: @EXEC on network init? - 08/04/2003 11:10

Actually, Hijack is running in the players context when it does all of the EXEC lines..
Posted by: drakino

Re: @EXEC on network init? - 24/07/2003 22:23

Just wondering if you ever got this working. I'd like to add time syncing onto my empeg, and this would probably be the easiest way since I have an NTP server on my network.
Posted by: image

Re: @EXEC on network init? - 25/07/2003 13:54

well, the way i've done it was to make a bash script sleeping for 30 seconds while dhcp acquires an ip address.
Posted by: tms13

Re: @EXEC on network init? - 25/07/2003 17:19

Yes, I did make it work.

I wrote a short script called /usr/local/bin/timesync.sh as follows:


#!/bin/sh
(sleep 10; /usr/local/bin/ntpdate $@) &


and put the following in config.ini:

;@AC ;@EXEC /usr/local/bin/timesync.sh 10.70.x.x 10.70.x.x 10.70.x.x


where the x.x are replaced with the correct values for the time servers here.
If I was doing it again, I wouldn't hard-code the 10 in the script, but would make that the first command-line argument:


#!/bin/sh
#untested!
DELAY=$1
shift
(sleep $DELAY; exec /usr/local/bin/ntpdate $@) &

Posted by: fede

Re: @EXEC on network init? - 01/08/2003 06:43

I have gotten this approach to work now but I have a different problem. Apparently this is setting the UTC time on my player. How can I adjust an offset so that the clock displayed on my player appears correct for my time zone (US CST)?
Posted by: mtempsch

Re: @EXEC on network init? - 01/08/2003 08:26

How can I adjust an offset so that the clock displayed on my player appears correct for my time zone (US CST)?

Settings->Timezone (on the player)

/Michael