[DRBD-cvs] user by phil; Fixed the "double resource bug" [pointed...

drbd-user@lists.linbit.com drbd-user@lists.linbit.com
Thu, 1 Apr 2004 09:25:33 +0200 (CEST)


DRBD CVS committal

Author  : phil
Project : drbd
Module  : user

Dir     : drbd/user


Modified Files:
      Tag: rel-0_7-branch
	drbdadm.h drbdadm_main.c 


Log Message:
Fixed the "double resource bug" [pointed out by LGE]

===================================================================
RCS file: /var/lib/cvs/drbd/drbd/user/Attic/drbdadm.h,v
retrieving revision 1.1.2.18
retrieving revision 1.1.2.19
diff -u -3 -r1.1.2.18 -r1.1.2.19
--- drbdadm.h	24 Mar 2004 13:14:07 -0000	1.1.2.18
+++ drbdadm.h	1 Apr 2004 07:25:28 -0000	1.1.2.19
@@ -66,15 +66,22 @@
    freed automatically */
 
 /*
+  // This is the nicer version, that does not need the ss_buffer. 
+  // But it only works with very new glibcs.
+   
 #define ssprintf(...) \
          ({ int _ss_size = snprintf(0, 0, ##__VA_ARGS__);        \
          char *_ss_ret = __builtin_alloca(_ss_size+1);           \
          snprintf(_ss_ret, _ss_size+1, ##__VA_ARGS__);           \
          _ss_ret; })
-#endif
 */
 
 #define ssprintf(ptr,...) \
   ptr=strcpy(alloca(snprintf(ss_buffer,255,##__VA_ARGS__)+1),ss_buffer)
+
+#define for_each_resource(res,tmp,config)                 \
+	for (res = (config), tmp = 0;                     \
+	     ({ tmp != (config) && (tmp = res->next); }); \
+	     res = tmp)
 
 #endif
===================================================================
RCS file: /var/lib/cvs/drbd/drbd/user/Attic/drbdadm_main.c,v
retrieving revision 1.1.2.38
retrieving revision 1.1.2.39
diff -u -3 -r1.1.2.38 -r1.1.2.39
--- drbdadm_main.c	29 Mar 2004 14:25:26 -0000	1.1.2.38
+++ drbdadm_main.c	1 Apr 2004 07:25:28 -0000	1.1.2.39
@@ -40,14 +40,6 @@
 
 #include "drbdadm.h"
 
-#define for_each_resource(res,tmp,config)                 \
-	for (res = (config), tmp = 0;                     \
-	     ({ tmp != (config) && (tmp = res->next); }); \
-	     res = tmp)
-
-#define for_completed(res,tmp,config)                     \
-            ( (res) == (tmp) ) 
-
 // basic format
 #define INDENT "    "
 #define FMT    INDENT "%-12s"
@@ -689,9 +681,25 @@
 
   yyparse();
 
+  { // check uniqueness of resource names.
+    struct d_resource *res2,*tmp2;
+    char *name;
+    
+    for_each_resource(res,tmp,config) {
+      name = res->name;
+      for_each_resource(res2,tmp2,config) {
+	if( res != res2 && !strcmp(res2->name, name) ) {
+	  fprintf(stderr,"Multiple definitions of resource '%s' found.\n",
+		  name);
+	  exit(10);
+	}
+      }
+    }
+  }
+
   if(!config_valid) exit(10);
 
-  { // check if minor_count is sane.
+  {
     int mc=global_options.minor_count;
 
     for_each_resource(res,tmp,config) nr_resources++;