Skip to contentSkip to conversation

No-rmdir-patch

PATCH In review Chris Feist 2 participants 2 messages Jan 24, 2005 – Jan 25, 2005 Kernel automounter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 No-rmdir-patch

When you specify a directory where a map will be mounted in auto.master, if it does not exist, autofs will create it upon startup and remove the directory when it shuts down. However, if the directory already exists, autofs will still remove it when you shut down. I've attached a patch to autofs-4.1.3 which will prevent autofs from removing previously exisiting directories.

If you have any questions, let me know!

Thanks,
Chris

daemon/automount.c renamed from daemon/automount.c.orig +13 -4
@@ -426,9 +426,17 @@ static int mount_autofs(char *path)
 	ap.pipefd = ap.ioctlfd = -1;
 
 	/* In case the directory doesn't exist, try to mkdir it */
-	if (mkdir_path(path, 0555) < 0 && errno != EEXIST && errno != EROFS) {
-		crit("failed to create iautofs directory %s", ap.path);
-		return -1;
+	if (mkdir_path(path, 0555) < 0) {
+		if (errno != EEXIST && errno != EROFS) {
+			crit("failed to create iautofs directory %s", ap.path);
+			return -1;
+		}
+		/* If we recieve an error, and it's EEXIST or EROFS we know
+		   the directory was not created. */
+		ap.dir_created = 0;
+	} else {
+		/* No errors so the directory was successfully created */
+		ap.dir_created = 1;
 	}
 
 	/* Pipe for kernel communications */
@@ -1341,7 +1349,7 @@ static void cleanup_exit(const char *pat
 
 	closelog();
 
-	if ((!ap.ghost || !submount) && *(path + 1) != '-')
+	if ((!ap.ghost || !submount) && (*(path + 1) != '-') && ap.dir_created)
 		if (rmdir(path) == -1)
 			warn("failed to remove dir %s: %m", path);
 
@@ -1664,6 +1672,7 @@ int main(int argc, char *argv[])
 	ap.exp_timeout = DEFAULT_TIMEOUT;
 	ap.ghost = DEFAULT_GHOST_MODE;
 	ap.type = LKP_INDIRECT;
+	ap.dir_created = 0; /* We haven't created the main directory yet */
 
 	opterr = 0;
 	while ((opt = getopt_long(argc, argv, "+hp:t:vdVg", long_options, NULL)) != EOF) {
include/automount.h renamed from include/automount.h.orig +2 -0
@@ -111,6 +111,8 @@ struct autofs_point {
 	struct lookup_mod *lookup;		/* Lookup module */
 	enum states state;
 	int state_pipe[2];
+	unsigned dir_created;		/* Was a directory created for this
+					   mount? */
 };
 
 /* Standard function used by daemon or modules */

_______________________________________________
autofs mailing list
[email protected]
http://linux.kernel.org/mailman/listinfo/autofs

maintainer
#1 lore raw

Looks OK.

I'll merge it into 4.1.4 brta1.

It wuould be good if you could make your changes against a current CVS snapshot as there have been a lot of changes from 4.1.3.

Jeff has the CVS info.

Ian

Quoted 15 lines · Chris Feist

When you specify a directory where a map will be mounted in auto.master, if it does not exist, autofs will create it upon startup and remove the directory when it shuts down. However, if the directory already exists, autofs will still remove it when you shut down. I've attached a patch to autofs-4.1.3 which will prevent autofs from removing previously exisiting directories.

If you have any questions, let me know!

Thanks,
Chris