[DRBD-cvs] svn commit by lars - r2367 - trunk/user - drbdadm: * make sure progname gets set before it might

drbd-cvs at lists.linbit.com drbd-cvs at lists.linbit.com
Sat Aug 12 01:08:00 CEST 2006


Author: lars
Date: 2006-08-12 01:07:59 +0200 (Sat, 12 Aug 2006)
New Revision: 2367

Modified:
   trunk/user/drbdadm_main.c
   trunk/user/drbdmeta.c
Log:

drbdadm:
 * make sure progname gets set before it might be used
 * initialize drbdmeta command name pointer the same way
   as that of drbdsetup: let execvp sort it out...
 * fix compiler warning

drbdmeta:
 allow drbdmeta dump-md to be forced even when the corresponding device is
 configured and used. It may return stale data, but that might still be useful
 sometimes, especially for debugging the syncer related issues now.



Modified: trunk/user/drbdadm_main.c
===================================================================
--- trunk/user/drbdadm_main.c	2006-08-11 11:52:20 UTC (rev 2366)
+++ trunk/user/drbdadm_main.c	2006-08-11 23:07:59 UTC (rev 2367)
@@ -1424,26 +1424,37 @@
             "   PRETENDING that I am >>%s<<\n\n",nodeinfo.nodename);
   }
 
-  if(argc == 1) print_usage_and_exit("missing arguments"); // arguments missing.
-
   /* in case drbdadm is called with an absolut or relative pathname
    * look for the drbdsetup binary in the same location,
    * otherwise, just let execvp sort it out... */
   if( (progname=strrchr(argv[0],'/')) == 0 ) {
     progname=argv[0];
     drbdsetup = strdup("drbdsetup");
+    drbdmeta = strdup("drbdmeta");
   } else {
     size_t len = strlen(argv[0]) + 1;
     ++progname;
+
     len += strlen("drbdsetup") - strlen(progname);
     drbdsetup = malloc(len);
     if (drbdsetup) {
       strncpy(drbdsetup, argv[0], (progname - argv[0]));
       strcpy(drbdsetup + (progname - argv[0]), "drbdsetup");
     }
+
+    len += strlen("drbdmeta") - strlen(progname);
+    drbdmeta = malloc(len);
+    if (drbdmeta) {
+      strncpy(drbdmeta, argv[0], (progname - argv[0]));
+      strcpy(drbdmeta + (progname - argv[0]), "drbdmeta");
+    }
+
     argv[0] = progname;
   }
-  if (drbdsetup == NULL) {
+
+  if(argc == 1) print_usage_and_exit("missing arguments"); // arguments missing.
+
+  if (drbdsetup == NULL || drbdmeta == NULL) {
     fprintf(stderr,"could not strdup argv[0].\n");
     exit(E_exec_error);
   }
@@ -1602,14 +1613,6 @@
     }
   }
 
-  if(drbdsetup == NULL) {
-    find_drbdcmd(&drbdsetup,(char *[]){"./drbdsetup", "/sbin/drbdsetup", 0 });
-  }
-
-  if(drbdmeta == NULL) {
-    find_drbdcmd(&drbdmeta,(char *[]){"./drbdmeta", "/sbin/drbdmeta", 0 });
-  }
-
   uc_node(global_options.usage_count);
 
   if(cmd->res_name_required)

Modified: trunk/user/drbdmeta.c
===================================================================
--- trunk/user/drbdmeta.c	2006-08-11 11:52:20 UTC (rev 2366)
+++ trunk/user/drbdmeta.c	2006-08-11 23:07:59 UTC (rev 2367)
@@ -1350,7 +1350,7 @@
 		size_t i;
 		unsigned int percent_done = 0;
 		unsigned int percent_last_report = 0;
-		fprintf(stderr,"initialising bitmap (%u KB)\n", (bm_bytes>>10));
+		fprintf(stderr,"initialising bitmap (%u KB)\n", (unsigned int)(bm_bytes>>10));
 		/* give some progress */
 		for (i = 0; i < bm_bytes; i += chunk) {
 			MEMSET((char*)cfg->on_disk.bm+i, 0xff, chunk);
@@ -1360,11 +1360,11 @@
 				percent_last_report = percent_done;
 			}
 		}
+		fprintf(stderr,"\r100%%\n");
 #else
 		printf("initialising bitmap (%u KB)\n", (bm_bytes>>10));
 		MEMSET((void*)cfg->on_disk.bm, 0xff, bm_bytes);
 #endif
-		//fprintf(stderr,"\r100%%\n");
 	}
 #endif
 	return 0;
@@ -2460,16 +2460,6 @@
 		exit(20);
 	}
 
-	cfg->drbd_fd = dt_lock_open_drbd(cfg->drbd_dev_name, &cfg->lock_fd, 1);
-	if (cfg->drbd_fd > -1) {
-		if (is_attached(dt_minor_of_dev(cfg->drbd_dev_name))) {
-			fprintf(stderr, "Device '%s' is configured!\n",
-				cfg->drbd_dev_name);
-			exit(20);
-		}
-	}
-
-
 	for (i = 0; i < ARRY_SIZE(cmds); i++) {
 		if (!strcmp(cmds[i].name, argv[ai])) {
 			command = cmds + i;
@@ -2482,6 +2472,17 @@
 	}
 	ai++;
 
+	cfg->drbd_fd = dt_lock_open_drbd(cfg->drbd_dev_name, &cfg->lock_fd, 1);
+	if (cfg->drbd_fd > -1) {
+		if (is_attached(dt_minor_of_dev(cfg->drbd_dev_name))) {
+			if (!(force && (command->function == meta_dump_md))) {
+				fprintf(stderr, "Device '%s' is configured!\n",
+					cfg->drbd_dev_name);
+				exit(20);
+			}
+		}
+	}
+
 	return command->function(cfg, argv + ai, argc - ai);
 	/* and if we want an explicit free,
 	 * this would be the place for it.



More information about the drbd-cvs mailing list