* Passing ADD/REMOVE events to logged on users
@ 2002-02-19 5:34 Shaun Jackman
2002-02-19 7:47 ` Oliver Neukum
0 siblings, 1 reply; 2+ messages in thread
From: Shaun Jackman @ 2002-02-19 5:34 UTC (permalink / raw)
To: linux-hotplug
I found it necessary to write a script that passes device hotplug events on
to the logged on users of the system. For example, the user plugs in an MP3
USB device and the device icon is added to the desktop (or the manager is
opened, etc).
It's not too long so I've simply attached it to this message. If this script
(or one that performs the same function) were standardized then other
packages could depend on the functionality provided by it.
This is only a first pass, so if anyone has any suggestions, I'd love to hear
'em. The intended functionality is this. This file lives as
/etc/hotplug/usb/user and any usb.usermap devices that wish to be manged by
it simply links 'ln -s /etc/hotplug/usb/user /etc/hotplug/usb/mydevice'.
Whenever mydevice is plugged into the usb chain hotplug calls
/etc/hotplug/usb/mydevice which in turn calls ~/.mydevicerc for each logged
in user. If that device distributes a standard script for its plugin/remove
action, the user can simply 'ln -s /etc/hotplug/usb/mydevicerc ~/.mydevicerc'.
Cheers,
Shaun
#!/usr/bin/perl -w
use English;
# read the hotplug environment
my $device = $ENV{'DEVICE'};
my $action = $ENV{'ACTION'};
die "$dev: missing hotplug environment\n"
unless defined $device && defined $action;
# derive the name of the managed device from the calling name
($dev = $action eq 'remove' ? readlink $0 : $0)
=~ s~.*/(.*)~$1~;
# change the permissions of the device so users can access it
chmod 0660, $device;
chown( (getpwnam "root")[2], (getgrnam $dev)[2], $device);
# set up a remover callback
symlink $0, $ENV{'REMOVER'} if defined $ENV{'REMOVER'};
delete $ENV{'DISPLAY'};
delete $ENV{'TERMINAL'};
foreach( `who`) {
my ($user, $terminal) = split;
chomp( my $rc = `echo ~$user/.${dev}rc`);
if( -x $rc && !fork) {
# set the DISPLAY/TERMINAL environment
$ENV{ $terminal =~ /^:[0-9]+$/ ?
'DISPLAY' : 'TERMINAL' } = $terminal;
# run the user script
exec "su $user -c $rc"
or die "$dev: exec failed";
}
}
_______________________________________________
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Passing ADD/REMOVE events to logged on users
2002-02-19 5:34 Passing ADD/REMOVE events to logged on users Shaun Jackman
@ 2002-02-19 7:47 ` Oliver Neukum
0 siblings, 0 replies; 2+ messages in thread
From: Oliver Neukum @ 2002-02-19 7:47 UTC (permalink / raw)
To: linux-hotplug
On Tuesday 19 February 2002 06:34, Shaun Jackman wrote:
> I found it necessary to write a script that passes device hotplug events on
> to the logged on users of the system. For example, the user plugs in an MP3
> USB device and the device icon is added to the desktop (or the manager is
> opened, etc).
>
> It's not too long so I've simply attached it to this message. If this
> script (or one that performs the same function) were standardized then
> other packages could depend on the functionality provided by it.
>
> This is only a first pass, so if anyone has any suggestions, I'd love to
> hear 'em. The intended functionality is this. This file lives as
> /etc/hotplug/usb/user and any usb.usermap devices that wish to be manged by
> it simply links 'ln -s /etc/hotplug/usb/user /etc/hotplug/usb/mydevice'.
> Whenever mydevice is plugged into the usb chain hotplug calls
> /etc/hotplug/usb/mydevice which in turn calls ~/.mydevicerc for each logged
> in user. If that device distributes a standard script for its plugin/remove
> action, the user can simply 'ln -s /etc/hotplug/usb/mydevicerc
> ~/.mydevicerc'.
Hi,
don't change the permissions. It's a security risk.
You must not die if a script fails, or a user can sabotage notification of other users.
Could you implement a blacklist of users who shall not be notified ?
Regards
Oliver
_______________________________________________
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-02-19 7:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-02-19 5:34 Passing ADD/REMOVE events to logged on users Shaun Jackman
2002-02-19 7:47 ` Oliver Neukum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).