+2003-08-27 Ion Badulescu <ionut@moisil.badula.org>
+
+ * conf/autofs/autofs_solaris_v1.c: convert relative targets to
+ absolute paths when using lofs mounts
+
+ * conf/autofs/autofs_solaris_v2_v3.c: ditto
+
+ * conf/autofs/autofs_linux.c: ditto
+
2003-08-27 Ion Badulescu <ionut@buggy.badula.org>
* README.autofs: added a paragraph about the resource consumption
* SUCH DAMAGE.
*
*
- * $Id: autofs_linux.c,v 1.39 2003/08/27 04:39:37 ib42 Exp $
+ * $Id: autofs_linux.c,v 1.40 2003/08/28 03:10:34 ib42 Exp $
*
*/
int
autofs_mount_fs(am_node *mp, mntfs *mf)
{
- char *target;
+ char *target, *target2 = NULL;
int err = 0;
if (mf->mf_flags & MFF_ON_AUTOFS) {
if (mf->mf_ops == &amfs_host_ops)
goto use_symlink;
+ if (target[0] != '/')
+ target2 = str3cat(NULL, mp->am_parent->am_path, "/", target);
+ else
+ target2 = strdup(target);
+
/*
* We need to stat() the destination, because the bind mount does not
* follow symlinks and/or allow for non-existent destinations.
if (!foreground) {
pid_t pgrp = getpgrp();
setpgrp();
- err = stat(target, &buf);
- if (setpgid(0, pgrp)) {
+ err = stat(target2, &buf);
+ if ((err = setpgid(0, pgrp))) {
plog(XLOG_ERROR, "autofs: cannot restore pgrp: %s", strerror(errno));
plog(XLOG_ERROR, "autofs: aborting the mount");
- return errno;
+ goto out;
}
if (err)
goto use_symlink;
}
- if ((err = lstat(target, &buf)))
+ if ((err = lstat(target2, &buf)))
goto use_symlink;
if (S_ISLNK(buf.st_mode))
goto use_symlink;
- plog(XLOG_INFO, "autofs: bind-mounting %s -> %s", mp->am_path, target);
+ plog(XLOG_INFO, "autofs: bind-mounting %s -> %s", mp->am_path, target2);
mkdir(mp->am_path, 0555);
- err = mount_lofs(mp->am_path, target, mf->mf_mopts, 1);
+ err = mount_lofs(mp->am_path, target2, mf->mf_mopts, 1);
if (err) {
rmdir(mp->am_path);
- plog(XLOG_INFO, "autofs: bind-mounting %s -> %s failed", mp->am_path, target);
+ plog(XLOG_INFO, "autofs: bind-mounting %s -> %s failed", mp->am_path, target2);
goto use_symlink;
}
goto out;
err = symlink(target, mp->am_path);
out:
+ if (target2)
+ free(target2);
+
if (err)
return errno;
return 0;
* SUCH DAMAGE.
*
*
- * $Id: autofs_solaris_v1.c,v 1.19 2003/08/22 05:16:11 ib42 Exp $
+ * $Id: autofs_solaris_v1.c,v 1.20 2003/08/28 03:10:34 ib42 Exp $
*
*/
autofs_mount_fs(am_node *mp, mntfs *mf)
{
int err = 0;
- char *target;
+ char *target, *target2 = NULL;
char *space_hack = autofs_strdup_space_hack(mp->am_path);
struct stat buf;
if (mf->mf_flags & MFF_ON_AUTOFS) {
- if ((err = mkdir(space_hack, 0555))) {
- err = errno;
+ if ((err = mkdir(space_hack, 0555)))
goto out;
- }
}
/*
if (err) {
if (mf->mf_flags & MFF_ON_AUTOFS)
rmdir(space_hack);
+ errno = err;
goto out;
}
else
target = mf->mf_mount;
- plog(XLOG_INFO, "autofs: converting from link to lofs (%s -> %s)", mp->am_path, target);
+ if (target[0] != '/')
+ target2 = str3cat(NULL, mp->am_parent->am_path, "/", target);
+ else
+ target2 = strdup(target);
+
+ plog(XLOG_INFO, "autofs: converting from link to lofs (%s -> %s)", mp->am_path, target2);
/*
* we need to stat() the destination, because the bind mount does not
* follow symlinks and/or allow for non-existent destinations.
* cause the recursive mount anyway if called from the parent amd.
*/
if (!foreground) {
- if (stat(target, &buf)) {
- err = errno;
+ if ((err = stat(target2, &buf))) {
goto out;
- }
}
- if (lstat(target, &buf)) {
- err = errno;
+ if ((err = lstat(target2, &buf)))
goto out;
- }
- if (mkdir(space_hack, 0555)) {
- err = errno;
+ if ((err = mkdir(space_hack, 0555)))
goto out;
- }
- err = mount_lofs(mp->am_path, target, mf->mf_mopts, 1);
+ if ((err = mount_lofs(mp->am_path, target2, mf->mf_mopts, 1))) {
+ errno = err;
+ goto out;
+ }
out:
free(space_hack);
- return err;
+ if (target2)
+ free(target2);
+
+ if (err)
+ return errno;
+ return 0;
}
* SUCH DAMAGE.
*
*
- * $Id: autofs_solaris_v2_v3.c,v 1.34 2003/08/05 04:27:46 ib42 Exp $
+ * $Id: autofs_solaris_v2_v3.c,v 1.35 2003/08/28 03:10:35 ib42 Exp $
*
*/
autofs_mount_fs(am_node *mp, mntfs *mf)
{
int err = 0;
- char *target;
+ char *target, *target2 = NULL;
struct stat buf;
/*
return err;
if (!(gopt.flags & CFM_AUTOFS_USE_LOFS))
- /* Symlinks are requested in autofs_mount_succeeded */
+ /* Symlinks will be requested in autofs_mount_succeeded */
return 0;
if (mp->am_link)
else
target = mf->mf_mount;
- plog(XLOG_INFO, "autofs: converting from link to lofs (%s -> %s)", mp->am_path, target);
+ if (target[0] != '/')
+ target2 = str3cat(NULL, mp->am_parent->am_path, "/", target);
+ else
+ target2 = strdup(target);
+
+ plog(XLOG_INFO, "autofs: converting from link to lofs (%s -> %s)", mp->am_path, target2);
/*
* we need to stat() the destination, because the bind mount does not
* cause the recursive mount anyway if called from the parent amd.
*/
if (!foreground) {
- err = stat(target, &buf);
- if (err)
- return errno;
+ if ((err = stat(target2, &buf)))
+ goto out;
}
- if ((err = lstat(target, &buf)))
- return errno;
+ if ((err = lstat(target2, &buf)))
+ goto out;
- if ((err = mkdirs(mp->am_path, 0555)))
- return errno;
+ if ((err = mount_lofs(mp->am_path, target2, mf->mf_mopts, 1))) {
+ errno = err;
+ goto out;
+ }
- if ((err = mount_lofs(mp->am_path, target, mf->mf_mopts, 1)))
- return err;
+ out:
+ if (target2)
+ free(target2);
+
+ if (err)
+ return errno;
return 0;
}