Hi Hung/Zoran, published the new patch, with your comments.
Thanks, Neel. On Thursday 21 January 2016 09:42 PM, Hung Nguyen wrote: > Hi Neel, > > I got segfault when trying this: > > root@SC-1:~# immcfg -a multi+=10 -a multi+= test=1 > Segmentation fault (core dumped) > > ('multi' is a multi-valued attribute) > > > (gdb) bt > #0 0x000000000040ca70 in object_modify > (objectNames=objectNames@entry=0x11371e0, > optargs=optargs@entry=0x1137120, optargs_len=optargs_len@entry=2) at > imm_cfg.c:710 > #1 0x000000000040e4c4 in imm_operation (argc=6, argv=<optimized out>) > at imm_cfg.c:1661 > #2 0x00007f8a9886bec5 in __libc_start_main (main=0x4038b0 <main>, > argc=6, argv=0x7ffec455ad88, init=<optimized out>, fini=<optimized > out>, rtld_fini=<optimized out>, > stack_end=0x7ffec455ad78) at libc-start.c:287 > #3 0x0000000000403911 in _start () > > > > BR, > > Hung Nguyen - DEK Technologies > > > -------------------------------------------------------------------------------- > > > From: Neelakanta Reddy reddy.neelaka...@oracle.com > Sent: Thursday, January 21, 2016 11:13AM > To: Zoran Milinkovic, Hung Nguyen > zoran.milinko...@ericsson.com, hung.d.ngu...@dektech.com.au > Cc: Opensaf-devel > opensaf-devel@lists.sourceforge.net > Subject: [PATCH 1 of 1] immtool: immcfg allows creation and > modification of multiple values for multi attributes[#1626] > > > osaf/tools/safimm/immcfg/imm_cfg.c | 145 > ++++++++++++++++++++++++++++-------- > 1 files changed, 112 insertions(+), 33 deletions(-) > > > diff --git a/osaf/tools/safimm/immcfg/imm_cfg.c > b/osaf/tools/safimm/immcfg/imm_cfg.c > --- a/osaf/tools/safimm/immcfg/imm_cfg.c > +++ b/osaf/tools/safimm/immcfg/imm_cfg.c > @@ -150,6 +150,10 @@ static void usage(const char *progname) > printf("\t\tchange one attribute for one object\n"); > printf("\timmcfg -c SaAmfApplication -a saAmfAppType=Test > safApp=myTestApp1\n"); > printf("\t\tcreate one object setting one initialized attribute\n"); > + printf("\timmcfg -c class -a attrMulti=one -a attrMulti=two > obj=1\n"); > + printf("\t\tcreate object with multiple values for MULTI_VALUE > attribute\n"); > + printf("\timmcfg -a attrMulti=three -a attrMulti=four obj=1\n"); > + printf("\t\tModify object with multiple values for MULTI_VALUE > attribute\n"); > printf("\timmcfg -d safAmfNode=Node01,safAmfCluster=1\n"); > printf("\t\tdelete one object\n"); > printf("\timmcfg -d safAmfNode=Node01,safAmfCluster=1 > safAmfNode=Node02,safAmfCluster=1\n"); > @@ -298,6 +302,27 @@ static void free_attr_mod(SaImmAttrModif > } > } > > +static SaAisErrorT get_attrValueType(SaImmAttrDefinitionT_2 > **attrDefinitions, SaImmAttrNameT attrName, > + SaImmValueTypeT *attrValueType, SaImmAttrFlagsT * flags) { > + if(!attrDefinitions || !attrName) > + return SA_AIS_ERR_NOT_EXIST; > + > + int i=0; > + while(attrDefinitions[i]) { > + if(!strcmp(attrDefinitions[i]->attrName, attrName)) { > + if(attrValueType){ > + *attrValueType = attrDefinitions[i]->attrValueType; > + if(flags){ > + *flags = attrDefinitions[i]->attrFlags; > + } > + } > + return SA_AIS_OK; > + } > + i++; > + } > + return SA_AIS_ERR_NOT_EXIST; > +} > + > /** > * Alloc SaImmAttrModificationT_2 object and initialize its > attributes from nameval (x=y) > * @param objectName > @@ -305,7 +330,7 @@ static void free_attr_mod(SaImmAttrModif > * > * @return SaImmAttrModificationT_2* > */ > -static SaImmAttrModificationT_2 *new_attr_mod(const SaNameT > *objectName, char *nameval) > +static SaImmAttrModificationT_2 *new_attr_mod(const SaNameT > *objectName, char *nameval, SaImmAttrFlagsT * flags) > { > int res = 0; > char *name = strdup(nameval); > @@ -314,11 +339,19 @@ static SaImmAttrModificationT_2 *new_att > SaImmClassNameT className; > SaAisErrorT error; > SaImmAttrModificationTypeT modType = SA_IMM_ATTR_VALUES_REPLACE; > + SaImmClassCategoryT classCategory; > + SaImmAttrDefinitionT_2 **attrDefinitions = NULL; > > className = > object_info_get_class(osaf_extended_name_borrow(objectName)); > if(!className) { > className = immutil_get_className(objectName); > } > + > + if((error = saImmOmClassDescriptionGet_2(immHandle, className, > &classCategory, &attrDefinitions)) != SA_AIS_OK) { > + fprintf(stderr, "error - saImmOmClassDescriptionGet_2. > FAILED: %s\n", saf_error(error)); > + goto done; > + } > + > > if (className == NULL) { > fprintf(stderr, "Object with DN '%s' does not exist\n", > osaf_extended_name_borrow(objectName)); > @@ -345,7 +378,7 @@ static SaImmAttrModificationT_2 *new_att > *value = '\0'; > value++; > > - error = immutil_get_attrValueType(className, name, > &attrMod->modAttr.attrValueType); > + error = get_attrValueType(attrDefinitions, name, > &attrMod->modAttr.attrValueType, flags); > if (error == SA_AIS_ERR_NOT_EXIST) { > fprintf(stderr, "Class '%s' does not exist\n", className); > res = -1; > @@ -358,6 +391,8 @@ static SaImmAttrModificationT_2 *new_att > goto done; > } > > + > + > attrMod->modType = modType; > attrMod->modAttr.attrName = name; > name = NULL; > @@ -384,26 +419,12 @@ static SaImmAttrModificationT_2 *new_att > attrMod = NULL; > } > } > + if(attrDefinitions) > + saImmOmClassDescriptionMemoryFree_2(immHandle, attrDefinitions); > + > return attrMod; > } > > -static SaAisErrorT get_attrValueType(SaImmAttrDefinitionT_2 > **attrDefinitions, SaImmAttrNameT attrName, SaImmValueTypeT > *attrValueType) { > - if(!attrDefinitions || !attrName) > - return SA_AIS_ERR_NOT_EXIST; > - > - int i=0; > - while(attrDefinitions[i]) { > - if(!strcmp(attrDefinitions[i]->attrName, attrName)) { > - if(attrValueType) > - *attrValueType = attrDefinitions[i]->attrValueType; > - return SA_AIS_OK; > - } > - i++; > - } > - > - return SA_AIS_ERR_NOT_EXIST; > -} > - > /** > * Alloc SaImmAttrValuesT_2 object and initialize its attributes from > nameval (x=y) > * @param attrDefinitions > @@ -412,7 +433,8 @@ static SaAisErrorT get_attrValueType(SaI > * > * @return SaImmAttrValuesT_2* > */ > -static SaImmAttrValuesT_2 *new_attr_value(SaImmAttrDefinitionT_2 > **attrDefinitions, char *nameval, int isRdn) > +static SaImmAttrValuesT_2 *new_attr_value(SaImmAttrDefinitionT_2 > **attrDefinitions, char *nameval, int isRdn, > + SaImmAttrFlagsT * flags) > { > int res = 0; > char *name = strdup(nameval), *p; > @@ -435,7 +457,7 @@ static SaImmAttrValuesT_2 *new_attr_valu > name = NULL; > VERBOSE_INFO("new_attr_value attrValue->attrName: '%s' > value:'%s'\n", attrValue->attrName, isRdn ? nameval : value); > > - error = get_attrValueType(attrDefinitions, attrValue->attrName, > &attrValue->attrValueType); > + error = get_attrValueType(attrDefinitions, attrValue->attrName, > &attrValue->attrValueType, flags); > > if (error != SA_AIS_OK) { > fprintf(stderr, "Attribute '%s' does not exist in class\n", > attrValue->attrName); > @@ -490,6 +512,8 @@ int object_create(const SaNameT **object > const SaStringT* errStrings=NULL; > SaImmClassCategoryT classCategory; > SaImmAttrDefinitionT_2 **attrDefinitions = NULL; > + SaImmAttrFlagsT flags=0; > + SaBoolT attrAdded = SA_FALSE; > > if((error = saImmOmClassDescriptionGet_2(immHandle, className, > &classCategory, &attrDefinitions)) != SA_AIS_OK) { > fprintf(stderr, "error - saImmOmClassDescriptionGet_2. > FAILED: %s\n", saf_error(error)); > @@ -498,15 +522,37 @@ int object_create(const SaNameT **object > > for (i = 0; i < optargs_len; i++) { > VERBOSE_INFO("object_create optargs[%d]: '%s'\n", i, > optargs[i]); > - if ((attrValue = new_attr_value(attrDefinitions, optargs[i], > 0)) == NULL){ > + if ((attrValue = new_attr_value(attrDefinitions, optargs[i], > 0, &flags)) == NULL){ > fprintf(stderr, "error - creating attribute from '%s'\n", > optargs[i]); > goto done; > } > > - attrValues = realloc(attrValues, (attr_len + 1) * > sizeof(SaImmAttrValuesT_2 *)); > - attrValues[attr_len - 1] = attrValue; > - attrValues[attr_len] = NULL; > - attr_len++; > + if(attrValues && (flags & SA_IMM_ATTR_MULTI_VALUE)){ > + int j=0; > + while(attrValues[j]){ > + if(!strcmp(attrValue->attrName, > attrValues[j]->attrName)){ > + attrValues[j]->attrValues = > realloc(attrValues[j]->attrValues, > + (attrValues[j]->attrValuesNumber+1) * sizeof(SaImmAttrValueT *)); > + attrValues[j]->attrValues[attrValues[j]->attrValuesNumber] = > attrValue->attrValues[0]; > + attrValues[j]->attrValuesNumber++; > + attrAdded = SA_TRUE; > + > + free(attrValue->attrName); > + free(attrValue->attrValues); > + free(attrValue); > + break; > + } > + j++; > + } > + } > + if(!attrAdded){ > + > + attrValues = realloc(attrValues, (attr_len + 1) * > sizeof(SaImmAttrValuesT_2 *)); > + attrValues[attr_len - 1] = attrValue; > + attrValues[attr_len] = NULL; > + attr_len++; > + } > + attrAdded = SA_FALSE; > } > > attrValues = realloc(attrValues, (attr_len + 1) * > sizeof(SaImmAttrValuesT_2 *)); > @@ -560,7 +606,7 @@ int object_create(const SaNameT **object > } > > VERBOSE_INFO("object_create rdn attribute attrValues[%d]: > '%s' \n", attr_len - 1, str); > - if ((attrValue = new_attr_value(attrDefinitions, str, 1)) == > NULL){ > + if ((attrValue = new_attr_value(attrDefinitions, str, 1, > NULL)) == NULL){ > fprintf(stderr, "error - creating rdn attribute from > '%s'\n", str); > goto done; > } > @@ -636,23 +682,56 @@ done: > int object_modify(const SaNameT **objectNames, char **optargs, int > optargs_len) > { > SaAisErrorT error; > - int i; > + int i, j; > int attr_len = 1; > int rc = EXIT_FAILURE; > SaImmAttrModificationT_2 *attrMod; > SaImmAttrModificationT_2 **attrMods = NULL; > const SaStringT* errStrings=NULL; > + SaImmAttrFlagsT flags=0; > + SaBoolT attrAdded = SA_FALSE; > + > > for (i = 0; i < optargs_len; i++) { > - if ((attrMod = new_attr_mod(objectNames[0], optargs[i])) == > NULL) { > + if ((attrMod = new_attr_mod(objectNames[0], optargs[i], > &flags)) == NULL) { > fprintf(stderr, "error - creating attribute from '%s'\n", > optargs[i]); > goto done; > } > + > + if(attrMods && (flags & SA_IMM_ATTR_MULTI_VALUE)){ > + j = 0; > + while(attrMods[j]){ > + if(!strcmp(attrMod->modAttr.attrName, > attrMods[j]->modAttr.attrName)){ > + if(attrMod->modType == attrMods[j]->modType){ > + attrMods[j]->modAttr.attrValues = > realloc(attrMods[j]->modAttr.attrValues, > + (attrMods[j]->modAttr.attrValuesNumber+1) * > + sizeof(SaImmAttrValueT *)); > + > attrMods[j]->modAttr.attrValues[attrMods[j]->modAttr.attrValuesNumber] = > + attrMod->modAttr.attrValues[0]; > + attrMods[j]->modAttr.attrValuesNumber++; > + attrAdded = SA_TRUE; > > - attrMods = realloc(attrMods, (attr_len + 1) * > sizeof(SaImmAttrModificationT_2 *)); > - attrMods[attr_len - 1] = attrMod; > - attrMods[attr_len] = NULL; > - attr_len++; > + free(attrMod->modAttr.attrName); > + free(attrMod->modAttr.attrValues); > + free(attrMod); > + break; > + } else { > + fprintf(stderr, "error - Only one Modify > operation type is supported" > + " for attribute\n"); > + goto done; > + } > + } > + j++; > + } > + } > + > + if(!attrAdded) { > + attrMods = realloc(attrMods, (attr_len + 1) * > sizeof(SaImmAttrModificationT_2 *)); > + attrMods[attr_len - 1] = attrMod; > + attrMods[attr_len] = NULL; > + attr_len++; > + } > + attrAdded = SA_FALSE; > } > > if ((error = immutil_saImmOmAdminOwnerSet(ownerHandle, (const > SaNameT **)objectNames, SA_IMM_ONE)) != SA_AIS_OK) { > > ------------------------------------------------------------------------------ Site24x7 APM Insight: Get Deep Visibility into Application Performance APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month Monitor end-to-end web transactions and take corrective actions now Troubleshoot faster and improve end-user experience. Signup Now! http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140 _______________________________________________ Opensaf-devel mailing list Opensaf-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/opensaf-devel