From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Patterson Date: Wed, 06 Oct 2004 22:28:57 +0000 Subject: Re: Problems using scsi_id with udevstart Message-Id: <1097101738.8753.39.camel@bluto.andrew> MIME-Version: 1 Content-Type: multipart/mixed; boundary="=-KB7LhUdCIh1d7ykkSt75" List-Id: References: <1097019226.2300.38.camel@bluto.andrew> In-Reply-To: <1097019226.2300.38.camel@bluto.andrew> To: linux-hotplug@vger.kernel.org --=-KB7LhUdCIh1d7ykkSt75 Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On Wed, 2004-10-06 at 23:39 +0200, Kay Sievers wrote: > On Wed, Oct 06, 2004 at 03:22:03PM -0600, Andrew Patterson wrote: > > On Wed, 2004-10-06 at 21:13 +0200, Kay Sievers wrote: > > > On Wed, 2004-10-06 at 12:42 -0600, Andrew Patterson wrote: > > > > On Wed, 2004-10-06 at 09:59 -0700, Patrick Mansfield wrote: > > > > > On Wed, Oct 06, 2004 at 10:26:13AM -0600, Andrew Patterson wrote: > > > > >=20 > > > > > > Note: here is the error you get when scsi_id is run without any > > > > > > parameters: > > > > > >=20 > > > > > > # /sbin/scsi_id > > > > > > -s must be specified > > > > >=20 > > > > > For the udev PROGRAM rules with no arguments, it is effectively i= nvoked > > > > > like this (well there are other environment values but scsi_id on= ly cares > > > > > about DEVPATH): > > > > >=20 > > > > > DEVPATH=3D/block/sda /sbin/scsi_id block > > > > >=20 > > > >=20 > > > > This is what I thought was supposed to happen. I printed out the > > > > arguments and the environment when scsi_id was invoked through > > > > udevstart. No arguments were passed and UDEVPATH was always set > > > > to /class/net/lo for every path in /sys. Note that DEVNAME does se= em to > > > > be set correctly. > > >=20 > > > Yes, this is a bug. We need to export the DEVPATH for the callout if = we > > > run as udevstart. I will fix that now. > >=20 > > So did you confirm that the subsystem is indeed being passed as an > > argument when running udevstart as well? My testing shows no. I think > > you need both to make this work. >=20 > Yes, when udevstart was running we didn't set the environment and the > subsystem argument for the callouts the dev.d/ scripts. >=20 > Here is a fix, that sets that with every udevstart iteration, corrects > argv[0] to be the basename() only not the whole path and adds a test > for invoking callouts without arguments. >=20 > Thanks, > Kay This works fine. Thanks. Andrew > Plain text document attachment (udevstart-env-fix-01.patch) > =3D=3D=3D=3D=3D namedev.c 1.147 vs edited =3D=3D=3D=3D=3D > --- 1.147/namedev.c 2004-09-20 16:01:58 +02:00 > +++ edited/namedev.c 2004-10-06 23:27:35 +02:00 > @@ -412,7 +412,7 @@ static void fix_kernel_name(struct udevi > } > } > =20 > -static int execute_program(char *path, char *value, int len) > +static int execute_program(const char *path, char *value, int len) > { > int retval; > int count; > @@ -421,12 +421,12 @@ static int execute_program(char *path, c > pid_t pid; > char *pos; > char arg[PROGRAM_SIZE]; > - char *argv[sizeof(arg) / 2]; > + char *argv[(PROGRAM_SIZE / 2) + 1]; > int i; > =20 > + strfieldcpy(arg, path); > i =3D 0; > if (strchr(path, ' ')) { > - strfieldcpy(arg, path); > pos =3D arg; > while (pos !=3D NULL) { > if (pos[0] =3D=3D '\'') { > @@ -441,8 +441,19 @@ static int execute_program(char *path, c > dbg("arg[%i] '%s'", i, argv[i]); > i++; > } > + argv[i] =3D NULL; > + dbg("execute '%s' with parsed arguments", arg); > + } else { > + argv[0] =3D arg; > + argv[1] =3D main_argv[1]; > + argv[2] =3D NULL; > + dbg("execute '%s' with subsystem '%s' argument", arg, argv[1]); > } > - argv[i] =3D NULL; > + > + /* set basename() only */ > + pos =3D strrchr(argv[0], '/'); > + if (pos !=3D NULL) > + argv[0] =3D &pos[1]; > =20 > retval =3D pipe(fds); > if (retval !=3D 0) { > @@ -456,13 +467,7 @@ static int execute_program(char *path, c > /* child */ > /* dup2 write side of pipe to STDOUT */ > dup2(fds[1], STDOUT_FILENO); > - if (argv[0] !=3D NULL) { > - dbg("execute '%s' with given arguments", argv[0]); > - retval =3D execv(argv[0], argv); > - } else { > - dbg("execute '%s' with main argument", path); > - retval =3D execv(path, main_argv); > - } > + retval =3D execv(arg, argv); > =20 > info(FIELD_PROGRAM " execution of '%s' failed", path); > exit(1); > =3D=3D=3D=3D=3D udevstart.c 1.17 vs edited =3D=3D=3D=3D=3D > --- 1.17/udevstart.c 2004-09-14 15:13:59 +02:00 > +++ edited/udevstart.c 2004-10-06 22:43:28 +02:00 > @@ -86,6 +86,21 @@ static char *first_list[] =3D { > NULL, > }; > =20 > +static void add_device(char *path, char *subsys, int fake) > +{ > + char *argv[3]; > + > + /* fake argument vector and environment for callouts and dev.d/ */ > + argv[0] =3D "udev"; > + argv[1] =3D subsys; > + argv[2] =3D NULL; > + > + main_argv =3D argv; > + setenv("DEVPATH", path, 1); > + setenv("ACTION", "add", 1); > + udev_add_device(path, subsys, fake); > +} > + > static void exec_list(struct list_head *device_list) > { > struct device *loop_device; > @@ -96,7 +111,7 @@ static void exec_list(struct list_head * > list_for_each_entry_safe(loop_device, tmp_device, device_list, list) { > for (i=3D0; first_list[i] !=3D NULL; i++) { > if (strncmp(loop_device->path, first_list[i], strlen(first_list[i])) = =3D=3D 0) { > - udev_add_device(loop_device->path, loop_device->subsys, NOFAKE); > + add_device(loop_device->path, loop_device->subsys, NOFAKE); > list_del(&loop_device->list); > free(loop_device); > break; > @@ -116,14 +131,14 @@ static void exec_list(struct list_head * > if (found) > continue; > =20 > - udev_add_device(loop_device->path, loop_device->subsys, NOFAKE); > + add_device(loop_device->path, loop_device->subsys, NOFAKE); > list_del(&loop_device->list); > free(loop_device); > } > =20 > /* handle the rest of the devices left over, if any */ > list_for_each_entry_safe(loop_device, tmp_device, device_list, list) { > - udev_add_device(loop_device->path, loop_device->subsys, NOFAKE); > + add_device(loop_device->path, loop_device->subsys, NOFAKE); > list_del(&loop_device->list); > free(loop_device); > } > =3D=3D=3D=3D=3D test/udev-test.pl 1.58 vs edited =3D=3D=3D=3D=3D > --- 1.58/test/udev-test.pl 2004-09-14 19:42:53 +02:00 > +++ edited/test/udev-test.pl 2004-10-06 23:11:09 +02:00 > @@ -256,6 +256,15 @@ BUS=3D"scsi", PROGRAM=3D"/bin/echo -n specia > EOF > }, > { > + desc =3D> "program result substitution (no argument should be subsyst= em)", > + subsys =3D> "block", > + devpath =3D> "/block/sda/sda3", > + exp_name =3D> "subsys_block" , > + conf =3D> < +BUS=3D"scsi", PROGRAM=3D"/bin/echo", RESULT=3D"block", NAME=3D"subsys_bl= ock" > +EOF > + }, > + { > desc =3D> "program result substitution (newline removal)", > subsys =3D> "block", > devpath =3D> "/block/sda/sda3", --=-KB7LhUdCIh1d7ykkSt75 Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (GNU/Linux) iD8DBQBBZHGpoKXgdXvblSgRAj3YAKCJ17Grf6PL7ELSvAwY/moCGRh97QCfVaFR 6sMiRRmBz6K+AnVjtrorM6s= =/XwI -----END PGP SIGNATURE----- --=-KB7LhUdCIh1d7ykkSt75-- ------------------------------------------------------- This SF.net email is sponsored by: IT Product Guide on ITManagersJournal Use IT products in your business? Tell us what you think of them. Give us Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more http://productguide.itmanagersjournal.com/guidepromo.tmpl _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net Linux-hotplug-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel