本文整理汇总了C++中EUCA_FREE函数的典型用法代码示例。如果您正苦于以下问题:C++ EUCA_FREE函数的具体用法?C++ EUCA_FREE怎么用?C++ EUCA_FREE使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了EUCA_FREE函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update_sensors_list
//! Reads the list of enabled sensors from Eucalyptus configuration
//! files and ensures that only those are enabled on the system.
int update_sensors_list()
{
int ret = EUCA_OK;
char **names = NULL;
char *tmpstr = configFileValue(SENSOR_LIST_CONF_PARAM_NAME);
if (tmpstr == NULL) {
LOGDEBUG("%s parameter is missing from config file\n", SENSOR_LIST_CONF_PARAM_NAME);
} else {
names = from_var_to_char_list(tmpstr);
EUCA_FREE(tmpstr);
}
char **sensors = { NULL }; // if no config value or an empty list
if (names != NULL) {
sensors = names;
}
ret = conf_stats((const char **)sensors);
if (names) {
for (int i=0; names[i]; i++) {
EUCA_FREE(names[i]);
}
EUCA_FREE(names);
}
return ret;
}
示例2: scStubDestroy
//!
//! destroy an NC stub structure
//!
//! @param[in] pStub a pointer to the node controller (NC) stub structure
//!
//! @return Always returns EUCA_OK
//!
int scStubDestroy(scStub * pStub)
{
EUCA_FREE(pStub->client_home);
EUCA_FREE(pStub->endpoint_uri);
EUCA_FREE(pStub->node_name);
EUCA_FREE(pStub);
return (EUCA_OK);
}
示例3: cleanup_volume_attachment
//!
//! Refactored logic for detaching a local iSCSI device and unexporting the volume. To be invoked only by other functions in this file after acquiring the necessary lock.
//!
//! @param[in] sc_url - The URL to reach the cluster's SC at.
//! @param[in] use_ws_sec - boolean to determine use of WS-SEC.
//! @param[in] ws_sec_policy_file - Policy file path for WS-SEC
//! @param[in] vol_data - The ebs_volume_data struct pointer
//! @param[in] connect_string - The connection string to use for local connection
//! @param[in] local_ip - The local host's external IP
//! @param[in] local_iqn - The local host's IQN
//! @param[in] do_rescan - Set to false to indicate no rescan should be done on disconnect, or true to use rescan
//!
//! @return EUCA_OK on success, EUCA_ERROR on failure
//!
//! @pre
//!
//! @post
//!
//! @note should be invoked only by functions in this file that acquired the necessary lock.
//!
static int cleanup_volume_attachment(char *sc_url, int use_ws_sec, char *ws_sec_policy_file, ebs_volume_data * vol_data, char *connect_string, char *local_ip, char *local_iqn,
int do_rescan)
{
int rc = 0;
char *reencrypted_token = NULL;
char *refreshedDev = NULL;
if (vol_data == NULL || connect_string == NULL || local_ip == NULL || local_iqn == NULL) {
LOGERROR("Cannot cleanup volume attachment. Got NULL input parameters.\n");
return EUCA_ERROR;
}
LOGDEBUG("[%s] attempting to disconnect iscsi target\n", vol_data->volumeId);
if (disconnect_iscsi_target(connect_string, do_rescan) != 0) {
LOGERROR("[%s] failed to disconnect iscsi target\n", vol_data->volumeId);
LOGDEBUG("Skipping SC Call due to previous errors\n");
return EUCA_ERROR;
}
if (sc_url == NULL || strlen(sc_url) <= 0) {
LOGERROR("[%s] Cannot invoke SC UnexportVolume, SC URL is invalid\n", vol_data->volumeId);
return EUCA_ERROR;
}
rc = re_encrypt_token(vol_data->token, &reencrypted_token);
if (rc != EUCA_OK || reencrypted_token == NULL || strlen(reencrypted_token) <= 0) {
LOGERROR("Failed on re-encryption of token for call to SC\n");
if (reencrypted_token != NULL) {
EUCA_FREE(reencrypted_token);
}
return EUCA_ERROR;
} else {
LOGTRACE("Re-encrypted token for %s is %s\n", vol_data->volumeId, reencrypted_token);
}
threadCorrelationId* corr_id = get_corrid();
LOGTRACE("Calling scClientCall with url: %s and token %s\n", sc_url, vol_data->token);
if (scClientCall( corr_id == NULL ? NULL : corr_id->correlation_id, NULL, use_ws_sec, ws_sec_policy_file, request_timeout_sec, sc_url, "UnexportVolume", vol_data->volumeId, reencrypted_token, local_ip, local_iqn) !=
EUCA_OK) {
EUCA_FREE(reencrypted_token);
LOGERROR("ERROR unexporting volume %s\n", vol_data->volumeId);
return EUCA_ERROR;
} else {
EUCA_FREE(reencrypted_token);
//Ok, now refresh local session to be sure it's gone.
//Should return error of not found.
refreshedDev = get_iscsi_target(connect_string);
if (refreshedDev) {
//Failure, should have NULL.
return EUCA_ERROR;
} else {
//We're good
return EUCA_OK;
}
}
}
示例4: ensure_directories_exist
//!
//! given path=A/B/C and only A existing, create A/B and, unless
//! is_file_path==1, also create A/B/C directory
//!
//! @param[in] path
//! @param[in] is_file_path
//! @param[in] user
//! @param[in] group
//! @param[in] mode
//!
//! @return 0 = path already existed, 1 = created OK, -1 = error
//!
int ensure_directories_exist(const char *path, int is_file_path, const char *user, const char *group, mode_t mode)
{
int ret = 0;
int i = 0;
int len = strlen(path);
int try_dir = 0;
char *path_copy = NULL;
struct stat buf = { 0 };
if (len > 0)
path_copy = strdup(path);
if (path_copy == NULL)
return (-1);
for (i = 0; i < len; i++) {
try_dir = 0;
if ((path[i] == '/') && (i > 0)) {
// dir path, not root
path_copy[i] = '\0';
try_dir = 1;
} else if ((path[i] != '/') && ((i + 1) == len)) {
// last one
if (!is_file_path)
try_dir = 1;
}
if (try_dir) {
if (stat(path_copy, &buf) == -1) {
LOGINFO("creating path %s\n", path_copy);
if (mkdir(path_copy, mode) == -1) {
LOGERROR("failed to create path %s: %s\n", path_copy, strerror(errno));
EUCA_FREE(path_copy);
return (-1);
}
ret = 1; // we created a directory
if (diskutil_ch(path_copy, user, group, mode) != EUCA_OK) {
LOGERROR("failed to change perms on path %s\n", path_copy);
EUCA_FREE(path_copy);
return (-1);
}
}
path_copy[i] = '/'; // restore the slash
}
}
EUCA_FREE(path_copy);
return (ret);
}
示例5: main
//!
//! Main entry point of the application
//!
//! @param[in] argc the number of parameter passed on the command line
//! @param[in] argv the list of arguments
//!
//! @return EUCA_OK on success or EUCA_ERROR on failure.
//!
int main(int argc, char **argv)
{
//char *sc_url_prefix = "sc://";
//char *sc_ur1 = "http://192.168.1.1:8773/services/Storage";
//char *sc_ur1_slash = "http://192.168.1.1:8773/services/Storage/";
//char *sc_hostname_url = "http://testhost.com:8773/services/Storage";
//char *sc_hostname_ur1_slash = "http://testhost.com:8773/services/Storage/";
char *serialized1 = "sc://vol-123ABCD,10aavaeosvas-sd-adsf-asdfa-vasdva";
char *serialized2 = "sc://vol-123ABCD,10aavaeosvas-sd-adsf-asdfa-vasdva";
ebs_volume_data test_struct1 = { "testtoken123", "vol-AB123DD" };
ebs_volume_data test_struct2 = { "1aoivlna-adflnew-aavaa0an12zc", "vol-123ABCD" };
char *output = NULL;
ebs_volume_data *ebs_out = NULL;
int result;
printf("Testing serialization\n");
result = serialize_volume(&test_struct1, &output);
printf("Got serialized output: %s\n", output);
EUCA_FREE(output);
result = serialize_volume(&test_struct2, &output);
printf("Got serialized output: %s\n", output);
EUCA_FREE(output);
printf("Testing de-serialization\n");
result = deserialize_volume(serialized1, &ebs_out);
printf("Input %s\n\tGot de-serialized: %s %s\n", serialized1, ebs_out->volumeId, ebs_out->token);
EUCA_FREE(ebs_out);
result = deserialize_volume(serialized2, &ebs_out);
printf("Input %s\n\tGot de-serialized: %s %s\n", serialized2, ebs_out->volumeId, ebs_out->token);
EUCA_FREE(ebs_out);
//int replace_sc_url(const char * volume_string, const char * scUrl, char * restrict dest_string)
/*printf("Testing url replacement\n");
char url_out1[512];
result = replace_sc_url(serialized1, "http://localhost.com:8773/services/Storage", url_out1);
printf("Result string %s\n", url_out1);
char url_out2[512];
result = replace_sc_url(serialized2, "http://192.168.1.1:8773/services/Storage/", url_out2);
printf("Result string %s\n", url_out2);
char url_out3[512];
result = replace_sc_url(serialized3, "http://localhost.com:8773/services/Storage", url_out3);
printf("Result string %s\n", url_out3); */
return (0);
}
示例6: loop_through_volumes
int loop_through_volumes(const char *xml_path, eucaVolume volumes[EUCA_MAX_VOLUMES]){
char volxpath[128] = "";
#define MKVOLPATH(_suffix) snprintf(volxpath, sizeof(volxpath), "/instance/volumes/volume[%d]/%s", (i + 1), _suffix);
#define MKLIBVIRTVOLPATH(_suffix) snprintf(volxpath, sizeof(volxpath), "/instance/volumes/volume[%d]/libvirt/disk/%s", (i + 1), _suffix);
#define XGET_STR_FREE(_XPATH, _dest) \
{ \
if (get_xpath_content_at(xml_path, (_XPATH), 0, _dest, sizeof(_dest)) == NULL) { \
fprintf(stderr, "failed to read %s from %s\n", (_XPATH), xml_path); \
for (int z = 0; res_array[z] != NULL; z++) \
EUCA_FREE(res_array[z]); \
EUCA_FREE(res_array); \
return (EUCA_ERROR); \
} \
}
char **res_array = NULL;
if ((res_array = get_xpath_content(xml_path, "/instance/volumes/volume")) != NULL) {
for (int i = 0; (res_array[i] != NULL) && (i < EUCA_MAX_VOLUMES); i++) {
eucaVolume *v = &volumes[i];
MKVOLPATH("id");
XGET_STR_FREE(volxpath, v->id);
MKVOLPATH("attachmentToken");
XGET_STR_FREE(volxpath, v->attachment_token);
MKVOLPATH("stateName");
XGET_STR_FREE(volxpath, v->state);
MKVOLPATH("connectionString");
XGET_STR_FREE(volxpath, v->connection_string);
MKVOLPATH("devName");
XGET_STR_FREE(volxpath, v->device);
MKVOLPATH("libvirt");
if (strcmp(v->state, VOL_STATE_ATTACHING) && strcmp(v->state, VOL_STATE_ATTACHING_FAILED) && get_xpath_xml(xml_path, volxpath, v->libvirt_XML, sizeof(v->libvirt_XML)) != EUCA_OK) {
fprintf(stderr, "failed to read '%s' from '%s'\n", volxpath, xml_path);
for (int z = 0; res_array[z] != NULL; z++)
EUCA_FREE(res_array[z]);
EUCA_FREE(res_array);
return (EUCA_ERROR);
}
MKLIBVIRTVOLPATH("serial");
XGET_STR_FREE(volxpath, v->serial);
MKLIBVIRTVOLPATH("target/@bus");
XGET_STR_FREE(volxpath, v->bus);
}
// Free our allocated memory
for (int i = 0; res_array[i] != NULL; i++)
EUCA_FREE(res_array[i]);
EUCA_FREE(res_array);
}
return (EUCA_OK);
}
示例7: free_metadata
//!
//! Frees an allocated metadata structure.
//!
//! @param[in,out] ppMeta a pointer to the node controller (NC) metadata structure
//!
//! @see allocate_metadata()
//!
//! @pre The \p ppMeta field should not be NULL
//!
//! @post If the metadata pointer is valid, the structure is freed and \p (*ppMeta) will be set to NULL.
//!
void free_metadata(ncMetadata ** ppMeta)
{
ncMetadata *pMeta = NULL;
if (ppMeta != NULL) {
if ((pMeta = (*ppMeta)) != NULL) {
EUCA_FREE(pMeta->correlationId);
EUCA_FREE(pMeta->userId);
EUCA_FREE(pMeta);
*ppMeta = NULL;
}
}
}
示例8: ebt_chain_flush_rule
/**
* Deletes a ebtables rule specified in the argument.
*
* @param ebth [in] pointer to the EB table handler structure
* @param tablename [in] a string pointer to the table name
* @param chainname [in] a string pointer to the chain name
* @param findrule [in] a string pointer to the rule to be deleted
*
* @return 0 if the rule given in the argument is successfully deleted. 1 otherwise.
*/
int ebt_chain_flush_rule(ebt_handler *ebth, char *tablename, char *chainname, char *findrule) {
ebt_table *table = NULL;
ebt_chain *chain = NULL;
ebt_rule *rule = NULL;
ebt_rule *newrules = NULL;
int i;
int nridx;
if (!ebth || !tablename || !chainname || !findrule || !ebth->init) {
return (EUCA_INVALID_ERROR);
}
table = ebt_handler_find_table(ebth, tablename);
if (!table) {
return (EUCA_INVALID_ERROR);
}
chain = ebt_table_find_chain(ebth, tablename, chainname);
if (!chain) {
return (EUCA_INVALID_ERROR);
}
rule = ebt_chain_find_rule(ebth, tablename, chainname, findrule);
if (rule) {
if (chain->max_rules > 1) {
newrules = realloc(newrules, sizeof (ebt_rule) * (chain->max_rules - 1));
if (!newrules) {
LOGFATAL("out of memory!\n");
exit(1);
}
bzero(newrules, sizeof (ebt_rule) * (chain->max_rules - 1));
nridx = 0;
for (i = 0; i < chain->max_rules; i++) {
if (strcmp(chain->rules[i].ebtrule, findrule)) {
snprintf(newrules[nridx].ebtrule, 1024, "%s", chain->rules[i].ebtrule);
nridx++;
}
}
EUCA_FREE(chain->rules);
chain->rules = newrules;
chain->max_rules = nridx;
} else {
EUCA_FREE(chain->rules);
chain->max_rules = 0;
chain->counters[0] = '\0';
}
} else {
LOGDEBUG("Could not find (%s) from chain %s at table %s\n", findrule, chainname, tablename);
return (2);
}
return (0);
}
示例9: atomic_file_sort_tmpfile
//!
//! Function description.
//!
//! @param[in] file
//!
//! @return
//!
//! @see
//!
//! @pre List of pre-conditions
//!
//! @post List of post conditions
//!
//! @note
//!
int atomic_file_sort_tmpfile(atomic_file * file)
{
int currlines = 0;
int i = 0;
int fd = 0;
int ret = 0;
char **contents = NULL;
char buf[4096] = "";
char tmpfile[EUCA_MAX_PATH] = "";
FILE *IFH = NULL;
FILE *OFH = NULL;
snprintf(tmpfile, EUCA_MAX_PATH, "%s-XXXXXX", file->dest);
if ((fd = safe_mkstemp(tmpfile)) < 0) {
LOGERROR("cannot open tmpfile '%s': check permissions\n", tmpfile);
return (1);
}
if (chmod(tmpfile, 0600)) {
LOGWARN("chmod failed: was able to create tmpfile '%s', but could not change file permissions\n", tmpfile);
}
close(fd);
buf[0] = '\0';
if ((IFH = fopen(file->tmpfile, "r")) != NULL) {
while (fgets(buf, 4096, IFH)) {
currlines++;
if ((contents = realloc(contents, sizeof(char *) * currlines)) == NULL) {
LOGFATAL("out of memory!\n");
exit(1);
}
contents[currlines - 1] = strdup(buf);
}
fclose(IFH);
if (contents) {
qsort(contents, currlines, sizeof(char *), strcmp_ptr);
if ((OFH = fopen(tmpfile, "w")) != NULL) {
for (i = 0; i < currlines; i++) {
fprintf(OFH, "%s", contents[i]);
EUCA_FREE(contents[i]);
}
fclose(OFH);
if (rename(tmpfile, file->tmpfile)) {
LOGERROR("could not rename (move) source file '%s' to dest file '%s': check permissions\n", tmpfile, file->tmpfile);
ret = 1;
}
}
EUCA_FREE(contents);
}
}
return (ret);
}
示例10: atomic_file_free
//!
//! Function description.
//!
//! @param[in] file
//!
//! @return
//!
//! @see
//!
//! @pre List of pre-conditions
//!
//! @post List of post conditions
//!
//! @note
//!
int atomic_file_free(atomic_file * file)
{
if (!file)
return (1);
if (file->lasthash)
EUCA_FREE(file->lasthash);
if (file->currhash)
EUCA_FREE(file->currhash);
bzero(file, sizeof(atomic_file));
return (0);
}
示例11: LOGERROR
//!
//! read file 'path' into a new string
//!
//! @param[in] path
//!
//! @return the string content of the given file
//!
//! @note the caller must free the memory when done.
//!
char *file2str(const char *path)
{
int fp = 0;
int bytes = 0;
int bytes_total = 0;
int to_read = 0;
char *p = NULL;
char *content = NULL;
off_t file_size = 0;
struct stat mystat = { 0 };
if (stat(path, &mystat) < 0) {
LOGERROR("errno: %d could not stat file %s\n", errno, path);
return (content);
}
file_size = mystat.st_size;
if ((content = EUCA_ALLOC((file_size + 1), sizeof(char))) == NULL) {
LOGERROR("out of memory reading file %s\n", path);
return (content);
}
if ((fp = open(path, O_RDONLY)) < 0) {
LOGERROR("errno: %d failed to open file %s\n", errno, path);
EUCA_FREE(content);
return (content);
}
p = content;
to_read = (((SSIZE_MAX) < file_size) ? (SSIZE_MAX) : file_size);
while ((bytes = read(fp, p, to_read)) > 0) {
bytes_total += bytes;
p += bytes;
if (to_read > (file_size - bytes_total)) {
to_read = file_size - bytes_total;
}
}
close(fp);
if (bytes < 0) {
LOGERROR("failed to read file %s\n", path);
EUCA_FREE(content);
return (content);
}
*p = '\0';
return (content);
}
示例12: atomic_file_sort_tmpfile
//!
//! Function description.
//!
//! @param[in] file
//!
//! @return
//!
//! @see
//!
//! @pre List of pre-conditions
//!
//! @post List of post conditions
//!
//! @note
//!
int atomic_file_sort_tmpfile(atomic_file * file)
{
int cmp = 0;
int currlines = 0;
int i = 0;
int fd = 0;
int ret = 0;
char **contents = NULL;
char buf[4096] = "";
char tmpfile[MAX_PATH] = "";
FILE *IFH = NULL;
FILE *OFH = NULL;
snprintf(tmpfile, MAX_PATH, "%s-XXXXXX", file->dest);
if ((fd = safe_mkstemp(tmpfile)) < 0) {
LOGERROR("cannot open tmpfile '%s'\n", tmpfile);
return (1);
}
chmod(tmpfile, 0644);
close(fd);
buf[0] = '\0';
if ((IFH = fopen(file->tmpfile, "r")) != NULL) {
while (fgets(buf, 4096, IFH)) {
currlines++;
if ((contents = realloc(contents, sizeof(char *) * currlines)) == NULL) {
LOGFATAL("out of memory!\n");
exit(1);
}
contents[currlines - 1] = strdup(buf);
}
fclose(IFH);
if (contents) {
qsort(contents, currlines, sizeof(char *), strcmp_ptr);
if ((OFH = fopen(tmpfile, "w")) != NULL) {
for (i = 0; i < currlines; i++) {
fprintf(OFH, "%s", contents[i]);
EUCA_FREE(contents[i]);
}
fclose(OFH);
rename(tmpfile, file->tmpfile);
}
EUCA_FREE(contents);
}
}
return (ret);
}
示例13: ncDescribeResourceStub
//!
//! Handle the client describe resource request
//!
//! @param[in] pStub a pointer to the node controller (NC) stub structure
//! @param[in] pMeta a pointer to the node controller (NC) metadata structure
//! @param[in] resourceType UNUSED
//! @param[out] outRes a list of resources we retrieved data for
//!
//! @return EUCA_OK on success or EUCA_ERROR on failure.
//!
int ncDescribeResourceStub(ncStub * pStub, ncMetadata * pMeta, char *resourceType, ncResource ** outRes)
{
int ret = EUCA_OK;
ncResource *res = NULL;
loadNcStuff();
if (myconfig->res.memorySizeMax <= 0) {
// not initialized?
res = allocate_resource("OK", "iqn.1993-08.org.debian:01:736a4e92c588", 1024000, 1024000, 30000000, 30000000, 4096, 4096, "none");
if (!res) {
LOGERROR("fakeNC: describeResource(): failed to allocate fake resource\n");
ret = EUCA_ERROR;
} else {
memcpy(&(myconfig->res), res, sizeof(ncResource));
EUCA_FREE(res);
}
}
if (!ret) {
res = EUCA_ALLOC(1, sizeof(ncResource));
memcpy(res, &(myconfig->res), sizeof(ncResource));
*outRes = res;
} else {
*outRes = NULL;
}
saveNcStuff();
return (ret);
}
示例14: check_block
//!
//!
//!
//! @param[in] file
//!
//! @return 0 on success or 1 on failure
//!
int check_block(const char *file)
{
int rc = 0;
char *rpath = NULL;
struct stat mystat = { 0 };
if (!file) {
LOGERROR("Invalid file name");
return (1);
}
if ((rpath = realpath(file, NULL)) == NULL) {
LOGERROR("No canonical file found for %s", file);
return (1);
}
rc = lstat(rpath, &mystat);
EUCA_FREE(rpath);
if ((rc < 0) || !S_ISBLK(mystat.st_mode)) {
LOGERROR("No stat information found for %s", rpath);
return (1);
}
return (0);
}
示例15: network_driver_system_flush
//!
//! Responsible for flushing any networking artifacts implemented by this
//! network driver.
//!
//! @param[in] pGni a pointer to the Global Network Information structure
//!
//! @return 0 on success or 1 if any failure occurred.
//!
//! @see
//!
//! @pre
//! The driver must be initialized already
//!
//! @post
//! On success, all networking mode artifacts will be flushed from the system. If any
//! failure occurred. The system is left in a non-deterministic state and a subsequent
//! call to this API may resolve the remaining issues.
//!
static int network_driver_system_flush(globalNetworkInfo *pGni)
{
int rc = 0;
int ret = 0;
LOGINFO("Flushing '%s' network driver artifacts.\n", DRIVER_NAME());
// Is our driver initialized?
if (!IS_INITIALIZED()) {
LOGERROR("Failed to flush the networking artifacts for '%s' network driver. Driver not initialized.\n", DRIVER_NAME());
return (1);
}
// if (PEER_IS_NC(eucanetdPeer)) {
if (pMidoConfig) {
if ((rc = do_midonet_teardown(pMidoConfig)) != 0) {
ret = 1;
} else {
EUCA_FREE(pMidoConfig);
pMidoConfig = NULL;
gInitialized = FALSE;
}
}
// }
return (0);
}