LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   How do I get rc.inet1 to run when usb dev plugged in? (https://www.linuxquestions.org/questions/slackware-14/how-do-i-get-rc-inet1-to-run-when-usb-dev-plugged-in-613784/)

charger 01-15-2008 02:55 PM

How do I get rc.inet1 to run when usb dev plugged in?
 
Hi slackers,

I'm trying to get slack to configure my usb1000 ethernet device.

So far I've got it to load the right module (asix) automatically when the dev is plugged in. And made a udev rule to make sure it gets the if number that I want a'la:

KERNEL=="eth?", ATTR{address}=="00:12:17:f2:21:0c", NAME="eth1"

Now I want dhcpcd to run and grab an ip for the if.

Is adding a udev rule the only way to do this?

That is, adding a rule for the device that runs rc.inet1 when the "add" action for the device fires?

Any help?

Thanks

M

dracolich 01-15-2008 03:35 PM

Udev does have an option to run a command specified in the device rule. That might be what you're looking for. From my favorite udev rules howto:

Quote:

Running external programs upon certain events
Yet another reason for writing udev rules is to run a particular program when a device is connected or disconnected. For example, you might want to execute a script to automatically download all of your photos from your digital camera when it is connected.

Do not confuse this with the PROGRAM functionality described above. PROGRAM is used for running programs which produce device names (and they shouldn't do anything other than that). When those programs are being executed, the device node has not yet been created, so acting upon the device in any way is not possible.

The functionality introduced here allows you to run a program after the device node is put in place. This program can act on the device, however it must not run for any extended period of time, because udev is effectively paused while these programs are running. One workaround for this limitation is to make sure your program immediately detaches itself.

Here is an example rule which demonstrates the use of the RUN list assignment:

KERNEL=="sdb", RUN+="/usr/bin/my_program

"When /usr/bin/my_program is executed, various parts of the udev environment are available as environment variables, including key values such as SUBSYSTEM. You can also use the ACTION environment variable to detect whether the device is being connected or disconnected - ACTION will be either "add" or "remove" respectively.

udev does not run these programs on any active terminal, and it does not execute them under the context of a shell. Be sure to ensure your program is marked executable, if it is a shell script ensure it starts with an appropriate shebang (e.g. #!/bin/sh), and do not expect any standard output to appear on your terminal.
So you could try adding RUN+="/etc/rc.inet1" to the end of the rule for your device.

This is the howto:
http://reactivated.net/writing_udev_rules.html

I found it VERY useful and printed it for my own reference.

Alien Bob 01-15-2008 03:47 PM

If you plug in a USB device that has a driver in the kernel, then the default UDEV rules will load the driver and run "/etc/rc.d/rc.inet1 <interfacename>_start" if you plug it in. No custum UDEV rules required.

For instance, after I installed a package for the rt73 driver (RaLink based USB wireless dongle) and added configuration for the rausb0 device in rc.inet1.conf , plugging in the USB device was enough to bring the wireless interface up and configure it automatically.

Eric

charger 01-16-2008 08:55 AM

Thanks for the replies but...no joy
 
Hi,

so...heres what's happening:

plug in the device and udev loads up the driver...great!

I have an entry for the if in rc.inet1.conf:

# Config information for eth1:
IFNAME[4]="eth1"
IPADDR[1]=""
NETMASK[1]=""
USE_DHCP[1]="yes"
DHCP_HOSTNAME[1]=""

I also make sure that the device always gets the same name in /etc/udev/rules.d/75-network-devices.rules:

KERNEL=="eth?", ATTR{address}=="00:1c:23:2a:52:1b", NAME="eth0"
KERNEL=="wlan?", ATTR{address}=="00:1c:bf:62:21:66", NAME="wlan0"
KERNEL=="eth?", ATTR{address}=="00:12:17:f2:21:0c", NAME="eth1"


It appears as tough rc.inet1 is not running when I plug in the device BUT...don't believe everything you don't see. /var/log/messages shows me that in fact rc.inet1 does run:

Jan 16 09:36:48 charger kernel: usb 1-4: new high speed USB device using ehci_hcd and address 4
Jan 16 09:36:48 charger kernel: usb 1-4: configuration #1 chosen from 1 choice
Jan 16 09:36:49 charger kernel: eth1: register 'asix' at usb-0000:00:1a.7-4, ASIX AX88178 USB 2.0 Ethernet, 00:12:17:f2:21:0c
Jan 16 09:36:49 charger logger: /etc/rc.d/rc.inet1: /sbin/dhcpcd -d -t 30 eth1
Jan 16 09:36:49 charger kernel: eth1: link down
Jan 16 09:36:49 charger kernel: ADDRCONF(NETDEV_UP): eth1: link is not ready
Jan 16 09:36:51 charger kernel: ADDRCONF(NETDEV_CHANGE): eth1: link becomes ready
Jan 16 09:36:51 charger kernel: eth1: link up, 100Mbps, full-duplex, lpa 0x41E1


The problem seems to be that the link takes a couple of seconds to come up and rc.inet1 runs before the interface is ready.

How to fix?

I was thinking maybe add some sleeps to rc.inet1 but this just doesn't sit well with me. Is there some hook I can use to prevent rc.inet1 from running until the interface is ready?

Thanks

M


All times are GMT -5. The time now is 04:28 AM.