From: juuso.alasuutari@tamperelainen.org
To: linux-hotplug@vger.kernel.org
Subject: Re: CD Symlinks Solution Idea
Date: Mon, 12 Jun 2006 00:13:38 +0000 [thread overview]
Message-ID: <1150071218.448cb1b2dbe38@cs1.alpha12.l-secure.net> (raw)
In-Reply-To: <44677DD3.80801@jg555.com>
Continuing on the subject of cdrom symlinks creation.
I looked at the debian script and copied its use of a lock directory to enforce
a queue for parallel processes. Otherwise my script just normally looks in /dev
to see whether e.g. a symlink named cdrom already exists, and if so, checks if
cdrom1 exists, etc. until the first available name comes up.
I didn't find a way to make the link names persistent, so that e.g. cdrom would
always point at the same device. But on the other hand, I've never heard of
cdrom devices being loaded in random order during boot. Is it nevertheless
possible that this might happen, like it does with network devices? I can't
test it, because I only have one cdrom drive.
I'm posting this so that all those interested can evaluate and point out
possible bugs in the script. Thank you for your help and your time. :)
Juuso
== Begin script ==
#!/bin/bash
if [[ -z "$1" ]]; then
echo "Not enough input!"
echo "Usage: $@ %k"
exit 1
fi
# Prevent conflicts between parallel processes by creating a lock dir
# and using it as a queue ticket. Only the process that can create it
# (meaning it doesn't already exist from another process) is allowed to
# proceed, others have to wait. Maximum queue time is 5 seconds, queue
# check happens every 20 milliseconds.
lock()
{
[[ -d /dev/.udev ]] ||
if ! mkdir -p /dev/.udev; then
echo "Cannot create /dev/.udev!"
exit 1
fi
LOCK_DIR=/dev/.udev/.lock-cdsymlink
local retry%0
while ! mkdir $LOCK_DIR 2>/dev/null; do
if ((retry=0)); then
echo "Cannot lock $LOCK_DIR!" >&2
exit 2
fi
sleep 0.02
((retry-=1))
done
}
# Once the process is finished, delete lock dir so that the next process
# may step forward in queue.
unlock()
{
[[ "$LOCK_DIR" ]] || return 0
rm -r $LOCK_DIR 2>/dev/null || return 0
}
# Find the next available symlink name for device. $1 is the device name
# from kernel (udev's %k value), $2 is the desired symlink basename
# (e.g. basename "cdrom" will be used to create symlinks /dev/cdrom,
# /dev/cdrom1, etc.)
echo_link()
{
local num
while [[ -e /dev/$2$num ]] &&
[[ "$(readlink /dev/$2$num)" != "$1" ]]; do
((num+=1))
done
echo -n "$2$num "
}
lock
# Output symlink name for cdrom, and then for dvd if needed.
echo_link $1 cdrom
[[ "$ID_CDROM_DVD" ]] && echo_link $1 dvd
unlock
----------------------------------------------------------------
This mail sent through L-secure: http://www.l-secure.net/
_______________________________________________
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
next prev parent reply other threads:[~2006-06-12 0:13 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-05-14 18:58 CD Symlinks Solution Idea Jim Gifford
2006-05-14 19:11 ` Jim Gifford
2006-05-15 0:52 ` Jim Gifford
2006-05-16 8:23 ` juuso.alasuutari
2006-05-16 15:30 ` Marco d'Itri
2006-05-19 16:03 ` Harald Hoyer
2006-05-21 1:00 ` juuso.alasuutari
2006-05-21 4:01 ` Alexander E. Patrakov
2006-05-22 16:20 ` Jim Gifford
2006-05-22 17:21 ` Darren Salt
2006-06-12 0:13 ` juuso.alasuutari [this message]
2006-06-12 0:17 ` juuso.alasuutari
2006-06-12 7:18 ` Marco d'Itri
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1150071218.448cb1b2dbe38@cs1.alpha12.l-secure.net \
--to=juuso.alasuutari@tamperelainen.org \
--cc=linux-hotplug@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).