LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 01-15-2008, 02:55 PM   #1
charger
LQ Newbie
 
Registered: Dec 2004
Posts: 2

Rep: Reputation: 0
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
 
Old 01-15-2008, 03:35 PM   #2
dracolich
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 1,274

Rep: Reputation: 63
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.
 
Old 01-15-2008, 03:47 PM   #3
Alien Bob
Slackware Contributor
 
Registered: Sep 2005
Location: Eindhoven, The Netherlands
Distribution: Slackware
Posts: 8,559

Rep: Reputation: 8105Reputation: 8105Reputation: 8105Reputation: 8105Reputation: 8105Reputation: 8105Reputation: 8105Reputation: 8105Reputation: 8105Reputation: 8105Reputation: 8105
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
 
Old 01-16-2008, 08:55 AM   #4
charger
LQ Newbie
 
Registered: Dec 2004
Posts: 2

Original Poster
Rep: Reputation: 0
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to detect programatically if a USB device is is plugged-in / plugged out? franc Linux - Software 3 02-01-2007 04:01 AM
Un-plugged PS/2 mouse then plugged it into usb. mouse now dead deathman Mandriva 2 11-20-2006 07:35 AM
atheros wireless card trouble -- plugged into the wrong /dev device djhaskin987 Linux - Wireless Networking 2 10-03-2006 04:50 AM
Help mounting USB flash drive ... When plugged in I dont have /dev/sda1 device ... ebenh Ubuntu 2 09-17-2006 09:55 PM
Help mount usb to same /dev no matter which order plugged in. Brian1 Linux - Hardware 1 10-05-2004 08:31 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 07:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration