Exemplo n.º 1
0
static sg_error
set_valid_filesystems(char const *fslist) {
	char const **newfs;
	char const **given_fs;

	while(sg_is_spc(*fslist))
		++fslist;
	if('!' == *fslist) {
		size_t new_items = 0, given_items = 0;
		const char **old_valid_fs = sg_get_valid_filesystems(0);

		if( NULL == old_valid_fs )
			sg_die("sg_get_valid_filesystems()", 1);

		++fslist;
		while(*fslist && sg_is_spc(*fslist))
			++fslist;

		given_fs = split_list(fslist);
		for(newfs = given_fs; *newfs; ++newfs) {
			++given_items;
		}
		qsort(given_fs, given_items, sizeof(given_fs[0]), fsnmcmp);

		newfs = NULL;
		new_items = 0;

		while(*old_valid_fs) {
			if (NULL == bsearch(old_valid_fs, given_fs, given_items, sizeof(given_fs[0]), fsnmcmp)) {
				newfs = push_item(newfs, *old_valid_fs, new_items++);
			}
			++old_valid_fs;
		}
		newfs = push_item(newfs, NULL, new_items);
	}
	else {
		newfs = given_fs = split_list(fslist);
	}

        if( SG_ERROR_NONE != sg_set_valid_filesystems( newfs ) )
		sg_die("sg_set_valid_filesystems() failed", 1);

	for(newfs = given_fs; *newfs; ++newfs) {
		free((void *)(*newfs));
	}

	return SG_ERROR_NONE;
}
Exemplo n.º 2
0
bool
DataSourceStatgrab::InitStatgrab()
{
    if( SG_ERROR_NONE != sg_init(1) )
    {
        report_sg_error("InitDataSourceStatgrab", "sg_init() failed");

        return false;
    }

    const StatgrabSettings & sgs = Config::getInstance().getStatgrabSettings();
    if( !sgs.ValidFilesystems.empty() )
    {
        vector<const char *> newValidFs;
        set<string> buildValidFs;

        if( sgs.RemoveFilesystems )
        {
            const char **old_valid_fs = sg_get_valid_filesystems(0);
            if( 0 == old_valid_fs )
            {
                LOG_BEGIN(loggerModuleName, ERROR_LOG | 0);
                LOG("InitDataSourceStatgrab(): sg_get_valid_filesystems() failed");
                LOG_END;

                return false;
            }

            while( *old_valid_fs )
            {
                buildValidFs.insert(*old_valid_fs);
                ++old_valid_fs;
            }

            for( vector<string>::const_iterator iter = sgs.ValidFilesystems.begin();
                 iter != sgs.ValidFilesystems.end();
                 ++iter )
            {
                set<string>::iterator jter = buildValidFs.find( *iter );
                if( jter != buildValidFs.end() )
                    buildValidFs.erase(jter);
            }
        }
        else
        {
            for( vector<string>::const_iterator iter = sgs.ValidFilesystems.begin();
                 iter != sgs.ValidFilesystems.end();
                 ++iter )
            {
                buildValidFs.insert(*iter);
            }
        }

        newValidFs.reserve( buildValidFs.size() + 1 );
        for( set<string>::const_iterator iter = buildValidFs.begin();
             iter != buildValidFs.end();
             ++iter )
        {
            newValidFs.push_back( iter->c_str() );
        }
        newValidFs.push_back( 0 );

        if( SG_ERROR_NONE != sg_set_valid_filesystems( &newValidFs[0] ) )
        {
            report_sg_error("InitDataSourceStatgrab", "sg_set_valid_filesystems() failed");

            return false;
        }
    }

    return true;
}