status = (char*)ha_malloc(sizeof(char)*arglen); strncpy(status, optarg, arglen);
status = ha_strdup(optarg); if (!status) { printf ("?? status option memory " "allocation failed ??\n"); argerr++; }
main(int argc, char ** argv){        cl_log_set_entity(daemon_name);    cl_log_enable_stderr(TRUE);    cl_log_set_facility(LOG_USER);        int	argerr = 0;    int flag;    list_add = (str_list_t *)ha_malloc(sizeof(struct str_list_s));    list_add_last = list_add;    list_del = (str_list_t *)ha_malloc(sizeof(struct str_list_s));    list_del_last = list_del;    list_add->num_items = 0;    list_del->num_items = 0;//    while ((flag = getopt(argc, argv, OPTARGS)) != EOF) {//    while ((flag = getopt_long(argc, argv, OPTARGS)) != EOF) {    while (1) {//	int this_option_optind = optind ? optind : 1;	int option_index = 0;	static struct option long_options[] = {	    // Top-level Options	    {"daemon"  , 0, 0, 0},	    {"query"   , 0, 0, 0},	    {"create"  , 0, 0, 0},	    {"modify"  , 0, 0, 0},	    {"delete"  , 0, 0, 0},	    {"instance"  , 0, 0, 0}, // undocumented, for testing only	    {"node"  , 0, 0, 0}, // undocumented, for testing only	    {"verbose" , 0, 0, 'V'},	    {"help" , 0, 0, '?'},	    // common options	    {"id"         , 1, 0, 'i'},	    {"obj_type"   , 1, 0, 'o'},	    {"description", 1, 0, 'D'},	    // daemon options	    {"reset"            , 1, 0, 'C'},	    {"status"           , 1, 0, 'S'},	    {"health"           , 0, 0, 'H'},	    {"disconnect"       , 1, 0, 'A'},	    {"unload_ha"        , 1, 0, 'U'},	    {"migrate_from"     , 1, 0, 'M'},	    {"migrate_res"      , 1, 0, 'I'},	    {"elect_dc"         , 0, 0, 'E'},	    {"whois_dc"         , 0, 0, 'W'},	    {"recalc_tree"      , 0, 0, 'R'},	    {"flush_recalc_tree", 0, 0, 'F'},	    // create_modify options	    {"subtype"       , 1, 0, 's'},	    {"max_instances" , 1, 0, 'm'},	    {"list_add"      , 1, 0, 'a'},	    {"list_del"      , 1, 0, 'd'},	    {"list_wipe"     , 0, 0, 'w'},	    {"clear"         , 1, 0, 'c'},	    {"resource"      , 1, 0, 'r'},	    {"priority"      , 1, 0, 'p'},	    {"res_timeout"   , 1, 0, 't'},	    {0, 0, 0, 0}	};	flag = getopt_long (argc, argv, OPTARGS,			    long_options, &option_index);	if (flag == -1)	    break;		int arglen = -1;	if(optarg != NULL) arglen = strlen(optarg);		switch(flag) {	    case 0:		printf ("option %s", long_options[option_index].name);		if (optarg)		    printf (" with arg %s", optarg);		printf ("\n");		if(     strcmp("create" , long_options[option_index].name) == 0) DO_CREATE  = TRUE;		else if(strcmp("modify" , long_options[option_index].name) == 0) DO_MODIFY  = TRUE;		else if(strcmp("delete" , long_options[option_index].name) == 0) DO_DELETE  = TRUE;		else if(strcmp("query"  , long_options[option_index].name) == 0) DO_QUERY   = TRUE;		else if(strcmp("instance"  , long_options[option_index].name) == 0)		{		    instance = (char*)ha_malloc(sizeof(char)*arglen);		    strncpy(instance, optarg, arglen);		}		else if(strcmp("node"  , long_options[option_index].name) == 0)		{		    node = (char*)ha_malloc(sizeof(char)*arglen);		    strncpy(node, optarg, arglen);		}		else 		{		    printf ("?? Long option (--%s) is not yet properly supported ??\n", long_options[option_index].name);		    ++argerr;		}		break;/* a sample test for multiple instance		if (digit_optind != 0 && digit_optind != this_option_optind)		    printf ("digits occur in two different argv-elements.\n");		digit_optind = this_option_optind;		printf ("option %c\n", c);*/	    case 'V':		BE_VERBOSE = TRUE;		verbose = "true";		break;	    case '?':		usage(daemon_name, LSB_EXIT_OK);		break;	    case 'i':		id = (char*)ha_malloc(sizeof(char)*arglen);		strncpy(id, optarg, arglen);		break;	    case 'o':		obj_type = (char*)ha_malloc(sizeof(char)*arglen);		strncpy(obj_type, optarg, arglen);		break;	    case 'D':		description = (char*)ha_malloc(sizeof(char)*arglen);		strncpy(description, optarg, arglen);		break;	    case 'C':		printf ("Option %c is not yet supported\n", flag);		++argerr;		break;	    case 'S':		DO_HEALTH       = TRUE;		status = (char*)ha_malloc(sizeof(char)*arglen);		strncpy(status, optarg, arglen);		break;	    case 'H':		DO_HEALTH       = TRUE;		break;	    case 'A':		printf ("Option %c is not yet supported\n", flag);		++argerr;		break;	    case 'U':		printf ("Option %c is not yet supported\n", flag);		++argerr;		break;	    case 'M':		printf ("Option %c is not yet supported\n", flag);		++argerr;		break;	    case 'I':		printf ("Option %c is not yet supported\n", flag);		++argerr;		break;	    case 'E':		DO_ELECT_DC     = TRUE;		printf ("Option %c is not yet supported\n", flag);		++argerr;		break;	    case 'W':		DO_WHOIS_DC     = TRUE;		printf ("Option %c is not yet supported\n", flag);		++argerr;		break;	    case 'R':		DO_RECALC_TREE  = TRUE;		printf ("Option %c is not yet supported\n", flag);		++argerr;		break;	    case 'F':		DO_FLUSH_RECALC = TRUE;		printf ("Option %c is not yet supported\n", flag);		++argerr;		break;	    case 'm':		max_instances = (char*)ha_malloc(sizeof(char)*arglen);		strncpy(max_instances, optarg, arglen);		break;	    case 'a':		list_add->num_items++;		if(list_add->num_items != 1)		    list_add_last->next = (str_list_t *)ha_malloc(sizeof(str_list_t));		list_add_last->value = (char*)ha_malloc(sizeof(char)*arglen);		strncpy(list_add_last->value, optarg, arglen);		list_add_last->next = NULL;		break;	    case 'd':		list_del->num_items++;		if(list_del->num_items != 1)		    list_del_last->next = (str_list_t *)ha_malloc(sizeof(str_list_t));		list_del_last->value = (char*)ha_malloc(sizeof(char)*arglen);		strncpy(list_del_last->value, optarg, arglen);		list_del_last->next = NULL;		break;	    case 'w':		list_wipe = TRUE;		break;	    case 'c':		clear = (char*)ha_malloc(sizeof(char)*arglen);		strncpy(clear, optarg, arglen);		break;	    case 'r':		if(num_resources < 2)		{		    resource[num_resources] = (char*)ha_malloc(sizeof(char)*arglen);		    strncpy(resource[num_resources], optarg, arglen);		    num_resources++;		}		break;	    case 't':		res_timeout = (char*)ha_malloc(sizeof(char)*arglen);		strncpy(res_timeout, optarg, arglen);		break;	    case 'p':		priority = (char*)ha_malloc(sizeof(char)*arglen);		strncpy(priority, optarg, arglen);		break;	    case 's':		subtype = (char*)ha_malloc(sizeof(char)*arglen);		strncpy(subtype, optarg, arglen);		break;	    default:		printf ("?? getopt returned character code 0%o ??\n", flag);		++argerr;		break;	}    }    if (optind < argc) {	printf ("non-option ARGV-elements: ");	while (optind < argc)	    printf ("%s ", argv[optind++]);	printf ("\n");    }        if (optind > argc) {	++argerr;    }        if (argerr) {	usage(daemon_name,LSB_EXIT_GENERIC);    }    ll_cluster_t *hb_fd = do_init();    if(hb_fd != NULL)    {	if(do_work(hb_fd) > 0)	{	    /* wait for the reply by creating a mainloop and running it until	     * the callbacks are invoked...	     */	    mainloop = g_main_new(FALSE);	    cl_log(LOG_INFO, "%s waiting for reply from the local CRM", daemon_name);	    	    g_main_run(mainloop);	    return_to_orig_privs();	}	else	{//	    cl_log(LOG_ERR, "No message to send");	    operation_status = -1;	}    }    else    {	cl_log(LOG_ERR, "Init failed, could not perform requested operations");		operation_status = -2;    }        cl_log(LOG_DEBUG, "%s exiting normally", daemon_name);	    return operation_status;}