aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>1998-04-02 05:35:02 +0000
committerH. Peter Anvin <hpa@zytor.com>1998-04-02 05:35:02 +0000
commit862e693ff5ff45c91dc2d16eccff7e7272fde22b (patch)
tree6dde49b2ce093e52a56ddd065489a0959a1b94c8 /modules
parente5ba2317f9c9fea3111616496d3ddbcedf39b95e (diff)
downloadautofs3-862e693ff5ff45c91dc2d16eccff7e7272fde22b.tar.gz
autofs3-862e693ff5ff45c91dc2d16eccff7e7272fde22b.tar.xz
autofs3-862e693ff5ff45c91dc2d16eccff7e7272fde22b.zip
Don't release the cdchanger mount file for now. The race conditions here
are too nasty.
Diffstat (limited to 'modules')
-rw-r--r--modules/norel/mount_cdchanger.c (renamed from modules/mount_cdchanger.c)53
1 files changed, 50 insertions, 3 deletions
diff --git a/modules/mount_cdchanger.c b/modules/norel/mount_cdchanger.c
index 0f4e271..d4d1bcb 100644
--- a/modules/mount_cdchanger.c
+++ b/modules/norel/mount_cdchanger.c
@@ -37,11 +37,38 @@ int mount_init(void **context)
return 0;
}
+
+static int
+acquire_lock(char *lockfile, char *fullpath)
+{
+ char pgrpbuf[32];
+
+ sprintf(pgrpbuf, "%ld", (unsigned long) getpgrp());
+
+ /* Does the lockfile exist? If not, attempt to create it */
+
+ lockfd = open(lockfile, O_WRONLY|O_CREAT|O_EXCL, 0444);
+ if ( lockfd >= 0 ) {
+ /* We grabbed the lockfile. flock() it and write our information. */
+
+ flock(lockfd, LOCK_EX);
+
+ /* The lockfile exists. Attempt to flock() it. */
+
+ flock
+
+
+
+
int mount_mount(const char *root, const char *name, int name_len,
const char *what, const char *fstype, const char *options,
void *context)
{
- char *fullpath, *slotstr, *device, *colon;
+ char *fullpath, *slotstr, *eslot, *device, *colon;
+ char lockfile[64];
+ int lockfd;
+ unsigned long slot;
+ struct stat devstat;
int err;
fullpath = alloca(strlen(root)+name_len+2);
@@ -54,15 +81,35 @@ int mount_mount(const char *root, const char *name, int name_len,
strcpy(slotstr, what);
colon = strchr(slotstr, ':');
- if ( !colon || colon[1] != '/' ) {
- syslog(LOG_ERR, MODPREFIX "entry %s -> %s not in slot:device format",
+ if ( !colon || colon[1] != '/' || colon == slotstr ) {
+ syslog(LOG_NOTICE, MODPREFIX "entry %s -> %s not in slot:device format",
fullpath, slotstr);
return 1;
}
*colon = '\0';
device = colon+1;
+ errno = 0;
+ slot = strtoul(slotstr, &eslot, 10);
+ if ( errno || *eslot ) {
+ syslog(LOG_NOTICE, MODPREFIX "entry %s: \"%s\" is not a valid slot",
+ fullpath, slotstr);
+ return 1;
+ }
+
+ if ( stat(device, &devstat) || !S_ISBLK(devstat.st_mode) ) {
+ syslog(LOG_NOTICE, MODPREFIX "entry %s: %s is not a block device",
+ fullpath, device);
+ return 1;
+ }
+
+ /* This is nasty. This could be done so much cleaner in a daemon with real
+ multithreading. Something for autofs v4. */
+
+ sprintf(lockfile, "/var/lock/autofs.cdchanger.%lx",
+ (unsigned long) devstat.st_rdev);
+ acquire_lock(lockfile);
syslog(LOG_DEBUG, MODPREFIX "calling mkdir %s", fullpath);
if ( mkdir(fullpath, 0555) && errno != EEXIST ) {