本文整理汇总了C++中STRERROR函数的典型用法代码示例。如果您正苦于以下问题:C++ STRERROR函数的具体用法?C++ STRERROR怎么用?C++ STRERROR使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了STRERROR函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: trunk_binlog_truncate
int trunk_binlog_truncate()
{
int result;
if (trunk_binlog_write_cache_len > 0)
{
if ((result=trunk_binlog_fsync(true)) != 0)
{
return result;
}
}
if (ftruncate(trunk_binlog_fd, 0) != 0)
{
result = errno != 0 ? errno : EIO;
logError("file: "__FILE__", line: %d, " \
"call ftruncate fail, " \
"errno: %d, error info: %s", \
__LINE__, result, STRERROR(result));
return result;
}
return 0;
}
示例2: main
int
main (int argc,
char **argv)
{
const char *basename;
const char *dirname;
basename = getenv ("GNUNET_PREFIX");
if (NULL == basename)
{
fprintf (stderr,
_("Environment variable GNUNET_PREFIX not set\n"));
fprintf (stderr,
_("Testcases will not work!\n"));
return 1;
}
dirname = DIR_SEPARATOR_STR ".." DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "gnunet" DIR_SEPARATOR_STR "config.d";
{
char tmp[strlen (basename) + strlen (dirname) + 1];
sprintf (tmp, "%s%s", basename, dirname);
if (0 != access (tmp, R_OK))
{
fprintf (stderr,
_("Failed to access `%s': %s\n"),
tmp,
STRERROR (errno));
fprintf (stderr,
_("Check that you did run `make install' and that GNUNET_PREFIX='%s' is the correct prefix.\n"),
basename);
fprintf (stderr,
_("Testcases will not work!\n"));
return 2;
}
}
return 0;
}
示例3: trunk_rename_mark_file
int trunk_rename_mark_file(const char *old_ip_addr, const int old_port, \
const char *new_ip_addr, const int new_port)
{
char old_filename[MAX_PATH_SIZE];
char new_filename[MAX_PATH_SIZE];
trunk_get_mark_filename_by_id_and_port(old_ip_addr, old_port, \
old_filename, sizeof(old_filename));
if (!fileExists(old_filename))
{
return ENOENT;
}
trunk_get_mark_filename_by_id_and_port(new_ip_addr, new_port, \
new_filename, sizeof(new_filename));
if (fileExists(new_filename))
{
logWarning("file: "__FILE__", line: %d, " \
"mark file %s already exists, " \
"ignore rename file %s to %s", \
__LINE__, new_filename, old_filename, new_filename);
return EEXIST;
}
if (rename(old_filename, new_filename) != 0)
{
logError("file: "__FILE__", line: %d, " \
"rename file %s to %s fail" \
", errno: %d, error info: %s", \
__LINE__, old_filename, new_filename, \
errno, STRERROR(errno));
return errno != 0 ? errno : EACCES;
}
return 0;
}
示例4: getFileContent
int getFileContent(const char *filename, char **buff, int64_t *file_size)
{
int fd;
fd = open(filename, O_RDONLY);
if (fd < 0)
{
*buff = NULL;
*file_size = 0;
logError("file: "__FILE__", line: %d, " \
"open file %s fail, " \
"errno: %d, error info: %s", __LINE__, \
filename, errno, STRERROR(errno));
return errno != 0 ? errno : ENOENT;
}
if ((*file_size=lseek(fd, 0, SEEK_END)) < 0)
{
*buff = NULL;
*file_size = 0;
close(fd);
logError("file: "__FILE__", line: %d, " \
"lseek file %s fail, " \
"errno: %d, error info: %s", __LINE__, \
filename, errno, STRERROR(errno));
return errno != 0 ? errno : EIO;
}
*buff = (char *)malloc(*file_size + 1);
if (*buff == NULL)
{
*file_size = 0;
close(fd);
logError("file: "__FILE__", line: %d, " \
"malloc %d bytes fail", __LINE__, \
(int)(*file_size + 1));
return errno != 0 ? errno : ENOMEM;
}
if (lseek(fd, 0, SEEK_SET) < 0)
{
*buff = NULL;
*file_size = 0;
close(fd);
logError("file: "__FILE__", line: %d, " \
"lseek file %s fail, " \
"errno: %d, error info: %s", __LINE__, \
filename, errno, STRERROR(errno));
return errno != 0 ? errno : EIO;
}
if (read(fd, *buff, *file_size) != *file_size)
{
free(*buff);
*buff = NULL;
*file_size = 0;
close(fd);
logError("file: "__FILE__", line: %d, " \
"read from file %s fail, " \
"errno: %d, error info: %s", __LINE__, \
filename, errno, STRERROR(errno));
return errno != 0 ? errno : EIO;
}
(*buff)[*file_size] = '\0';
close(fd);
return 0;
}
示例5: load_allow_hosts
int load_allow_hosts(IniContext *pIniContext, \
in_addr_t **allow_ip_addrs, int *allow_ip_count)
{
int count;
IniItem *pItem;
IniItem *pItemStart;
IniItem *pItemEnd;
char *pItemValue;
char *pStart;
char *pEnd;
char *p;
char *pTail;
int alloc_count;
int nHeadLen;
int i;
in_addr_t addr;
char hostname[256];
if ((pItemStart=iniGetValuesEx(NULL, "allow_hosts", \
pIniContext, &count)) == NULL)
{
*allow_ip_count = -1; /* -1 means match any ip address */
*allow_ip_addrs = NULL;
return 0;
}
pItemEnd = pItemStart + count;
for (pItem=pItemStart; pItem<pItemEnd; pItem++)
{
if (strcmp(pItem->value, "*") == 0)
{
*allow_ip_count = -1; /* -1 means match any ip address*/
*allow_ip_addrs = NULL;
return 0;
}
}
alloc_count = count;
*allow_ip_count = 0;
*allow_ip_addrs = (in_addr_t *)malloc(sizeof(in_addr_t) * alloc_count);
if (*allow_ip_addrs == NULL)
{
logError("file: "__FILE__", line: %d, " \
"malloc %d bytes fail, errno: %d, error info: %s.", \
__LINE__, (int)sizeof(in_addr_t) * alloc_count, \
errno, STRERROR(errno));
return errno != 0 ? errno : ENOMEM;
}
for (pItem=pItemStart; pItem<pItemEnd; pItem++)
{
if (*(pItem->value) == '\0')
{
continue;
}
pStart = strchr(pItem->value, '[');
if (pStart == NULL)
{
addr = getIpaddrByName(pItem->value, NULL, 0);
if (addr == INADDR_NONE)
{
logWarning("file: "__FILE__", line: %d, " \
"invalid host name: %s", \
__LINE__, pItem->value);
}
else
{
if (alloc_count < (*allow_ip_count) + 1)
{
alloc_count = (*allow_ip_count) + \
(pItemEnd - pItem);
*allow_ip_addrs = (in_addr_t *)realloc(
*allow_ip_addrs,
sizeof(in_addr_t)*alloc_count);
if (*allow_ip_addrs == NULL)
{
logError("file: "__FILE__", line: %d, "\
"malloc %d bytes fail, " \
"errno: %d, error info: %s", \
__LINE__, (int)sizeof(in_addr_t)
* alloc_count, \
errno, STRERROR(errno));
return errno != 0 ? errno : ENOMEM;
}
}
(*allow_ip_addrs)[*allow_ip_count] = addr;
(*allow_ip_count)++;
}
continue;
}
pEnd = strchr(pStart, ']');
if (pEnd == NULL)
{
logWarning("file: "__FILE__", line: %d, " \
//.........这里部分代码省略.........
示例6: free_queue_init_ex
int free_queue_init_ex(const int max_connections, const int init_connections,
const int alloc_task_once, const int min_buff_size,
const int max_buff_size, const int arg_size)
{
#define MAX_DATA_SIZE (256 * 1024 * 1024)
int64_t total_size;
struct mpool_node *mpool;
int alloc_size;
int alloc_once;
int result;
int loop_count;
int aligned_min_size;
int aligned_max_size;
int aligned_arg_size;
rlim_t max_data_size;
if ((result=init_pthread_lock(&(g_free_queue.lock))) != 0)
{
logError("file: "__FILE__", line: %d, " \
"init_pthread_lock fail, errno: %d, error info: %s", \
__LINE__, result, STRERROR(result));
return result;
}
aligned_min_size = MEM_ALIGN(min_buff_size);
aligned_max_size = MEM_ALIGN(max_buff_size);
aligned_arg_size = MEM_ALIGN(arg_size);
g_free_queue.block_size = ALIGNED_TASK_INFO_SIZE + aligned_arg_size;
alloc_size = g_free_queue.block_size * init_connections;
if (aligned_max_size > aligned_min_size)
{
total_size = alloc_size;
g_free_queue.malloc_whole_block = false;
max_data_size = 0;
}
else
{
struct rlimit rlimit_data;
if (getrlimit(RLIMIT_DATA, &rlimit_data) < 0)
{
logError("file: "__FILE__", line: %d, " \
"call getrlimit fail, " \
"errno: %d, error info: %s", \
__LINE__, errno, STRERROR(errno));
return errno != 0 ? errno : EPERM;
}
if (rlimit_data.rlim_cur == RLIM_INFINITY)
{
max_data_size = MAX_DATA_SIZE;
}
else
{
max_data_size = rlimit_data.rlim_cur;
if (max_data_size > MAX_DATA_SIZE)
{
max_data_size = MAX_DATA_SIZE;
}
}
if (max_data_size >= (int64_t)(g_free_queue.block_size + aligned_min_size) *
(int64_t)init_connections)
{
total_size = alloc_size + (int64_t)aligned_min_size *
init_connections;
g_free_queue.malloc_whole_block = true;
g_free_queue.block_size += aligned_min_size;
}
else
{
total_size = alloc_size;
g_free_queue.malloc_whole_block = false;
max_data_size = 0;
}
}
g_free_queue.max_connections = max_connections;
g_free_queue.alloc_connections = init_connections;
if (alloc_task_once <= 0)
{
g_free_queue.alloc_task_once = 256;
alloc_once = MAX_DATA_SIZE / g_free_queue.block_size;
if (g_free_queue.alloc_task_once > alloc_once)
{
g_free_queue.alloc_task_once = alloc_once;
}
}
else
{
g_free_queue.alloc_task_once = alloc_task_once;
}
g_free_queue.min_buff_size = aligned_min_size;
g_free_queue.max_buff_size = aligned_max_size;
g_free_queue.arg_size = aligned_arg_size;
logDebug("file: "__FILE__", line: %d, "
"max_connections: %d, init_connections: %d, alloc_task_once: %d, "
"min_buff_size: %d, max_buff_size: %d, block_size: %d, "
"arg_size: %d, max_data_size: %d, total_size: %"PRId64,
__LINE__, max_connections, init_connections,
//.........这里部分代码省略.........
示例7: doLogEx
static void doLogEx(LogContext *pContext, struct timeval *tv, \
const char *caption, const char *text, const int text_len, \
const bool bNeedSync, const bool bNeedLock)
{
struct tm tm;
int time_fragment;
int buff_len;
int result;
if ((pContext->time_precision == LOG_TIME_PRECISION_SECOND)
|| (pContext->time_precision == LOG_TIME_PRECISION_NONE))
{
time_fragment = 0;
}
else
{
if (pContext->time_precision == LOG_TIME_PRECISION_MSECOND)
{
time_fragment = tv->tv_usec / 1000;
}
else
{
time_fragment = tv->tv_usec;
}
}
if (bNeedLock && (result=pthread_mutex_lock(&pContext->log_thread_lock)) != 0)
{
fprintf(stderr, "file: "__FILE__", line: %d, " \
"call pthread_mutex_lock fail, " \
"errno: %d, error info: %s", \
__LINE__, result, STRERROR(result));
}
if (text_len + 64 > LOG_BUFF_SIZE)
{
fprintf(stderr, "file: "__FILE__", line: %d, " \
"log buff size: %d < log text length: %d ", \
__LINE__, LOG_BUFF_SIZE, text_len + 64);
if (bNeedLock)
{
pthread_mutex_unlock(&(pContext->log_thread_lock));
}
return;
}
if ((pContext->pcurrent_buff - pContext->log_buff) + text_len + 64 \
> LOG_BUFF_SIZE)
{
log_fsync(pContext, false);
}
if (pContext->time_precision != LOG_TIME_PRECISION_NONE)
{
localtime_r(&tv->tv_sec, &tm);
if (pContext->time_precision == LOG_TIME_PRECISION_SECOND)
{
buff_len = sprintf(pContext->pcurrent_buff, \
"[%04d-%02d-%02d %02d:%02d:%02d] ", \
tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, \
tm.tm_hour, tm.tm_min, tm.tm_sec);
}
else
{
buff_len = sprintf(pContext->pcurrent_buff, \
"[%04d-%02d-%02d %02d:%02d:%02d.%03d] ", \
tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, \
tm.tm_hour, tm.tm_min, tm.tm_sec, time_fragment);
}
pContext->pcurrent_buff += buff_len;
}
if (caption != NULL)
{
buff_len = sprintf(pContext->pcurrent_buff, "%s - ", caption);
pContext->pcurrent_buff += buff_len;
}
memcpy(pContext->pcurrent_buff, text, text_len);
pContext->pcurrent_buff += text_len;
*pContext->pcurrent_buff++ = '\n';
if (!pContext->log_to_cache || bNeedSync)
{
log_fsync(pContext, false);
}
if (bNeedLock && (result=pthread_mutex_unlock(&(pContext->log_thread_lock))) != 0)
{
fprintf(stderr, "file: "__FILE__", line: %d, " \
"call pthread_mutex_unlock fail, " \
"errno: %d, error info: %s", \
__LINE__, result, STRERROR(result));
}
}
示例8: log_rotate
int log_rotate(LogContext *pContext)
{
struct tm tm;
time_t current_time;
int len;
int result;
char old_filename[MAX_PATH_SIZE + 32];
bool exist;
if (*(pContext->log_filename) == '\0')
{
return ENOENT;
}
close(pContext->log_fd);
current_time = get_current_time();
localtime_r(¤t_time, &tm);
if (tm.tm_hour == 0 && tm.tm_min <= 1)
{
if (strstr(pContext->rotate_time_format, "%H") == NULL
&& strstr(pContext->rotate_time_format, "%M") == NULL
&& strstr(pContext->rotate_time_format, "%S") == NULL)
{
current_time -= 120;
localtime_r(¤t_time, &tm);
}
}
memset(old_filename, 0, sizeof(old_filename));
len = sprintf(old_filename, "%s.", pContext->log_filename);
strftime(old_filename + len, sizeof(old_filename) - len,
pContext->rotate_time_format, &tm);
if (access(old_filename, F_OK) == 0)
{
fprintf(stderr, "file: "__FILE__", line: %d, " \
"file: %s already exist, rotate file fail\n",
__LINE__, old_filename);
exist = true;
}
else if (rename(pContext->log_filename, old_filename) != 0)
{
fprintf(stderr, "file: "__FILE__", line: %d, " \
"rename %s to %s fail, errno: %d, error info: %s\n", \
__LINE__, pContext->log_filename, old_filename, \
errno, STRERROR(errno));
exist = false;
}
else
{
exist = true;
}
result = log_open(pContext);
if (exist && NEED_COMPRESS_LOG(pContext->compress_log_flags))
{
log_gzip(pContext);
}
return result;
}
示例9: gtmcrypt_entry
uint4 gtmcrypt_entry()
{
void_ptr_t handle, fptr;
char_ptr_t err_str, env_ptr, libname_ptr, libpath_ptr;
char *gtmcryptlib_fname[] = {
GTMCRYPT_INIT_FNAME,
GTMCRYPT_CLOSE_FNAME,
GTMCRYPT_HASH_GEN_FNAME,
GTMCRYPT_ENCRYPT_FNAME,
GTMCRYPT_DECRYPT_FNAME,
GTMCRYPT_GETKEY_BY_NAME,
GTMCRYPT_GETKEY_BY_HASH,
GTMCRYPT_STRERROR
};
void **gtmcryptlib_fptr[] = {
(void **)>mcrypt_init_fnptr,
(void **)>mcrypt_close_fnptr,
(void **)>mcrypt_hash_gen_fnptr,
(void **)>mcrypt_encrypt_fnptr,
(void **)>mcrypt_decrypt_fnptr,
(void **)>mcrypt_getkey_by_name_fnptr,
(void **)>mcrypt_getkey_by_hash_fnptr,
(void **)>mcrypt_strerror_fnptr
};
int findx, num_dlsyms, plugin_dir_len, save_errno;
char libpath[GTM_PATH_MAX], buf[MAX_GTMCRYPT_PLUGIN_STR_LEN], plugin_dir_path[GTM_PATH_MAX];
char resolved_libpath[GTM_PATH_MAX], resolved_gtmdist[GTM_PATH_MAX];
mstr trans, env_var = {0, SIZEOF(GTM_CRYPT_PLUGIN) - 1, GTM_CRYPT_PLUGIN};
if (NULL == (env_ptr = getenv(GTM_DIST)))
rts_error(VARLSTCNT(1) ERR_GTMDISTUNDEF);
if (NULL == realpath(env_ptr, &resolved_gtmdist[0]))
{
save_errno = errno;
SNPRINTF(dl_err, MAX_ERRSTR_LEN, "Failed to find symbolic link for %s. %s", env_ptr, STRERROR(save_errno));
return ERR_CRYPTDLNOOPEN;
}
SNPRINTF(plugin_dir_path, GTM_PATH_MAX, "%s/%s", resolved_gtmdist, PLUGIN_DIR_NAME);
plugin_dir_len = STRLEN(plugin_dir_path);
if ((SS_NORMAL != TRANS_LOG_NAME(&env_var, &trans, buf, SIZEOF(buf), do_sendmsg_on_log2long)) || (0 >= trans.len))
{ /* Either $gtm_crypt_plugin is not defined in the environment variable OR it is set to null-string. Fall-back to
* using libgtmcrypt.so
*/
libname_ptr = GTMCRYPT_LIBNAME;
} else
libname_ptr = &buf[0]; /* value of $gtm_crypt_plugin */
SNPRINTF(libpath, GTM_PATH_MAX, "%s/%s", plugin_dir_path, libname_ptr);
if (NULL == realpath(&libpath[0], &resolved_libpath[0]))
{
save_errno = errno;
SNPRINTF(dl_err, MAX_ERRSTR_LEN, "Failed to find symbolic link for %s. %s", libpath, STRERROR(save_errno));
return ERR_CRYPTDLNOOPEN;
}
/* Symbolic link found. dlopen resolved_libpath */
if (0 != memcmp(&resolved_libpath[0], plugin_dir_path, plugin_dir_len))
{ /* resolved_path doesn't contain $gtm_dist/plugin as the prefix */
SNPRINTF(dl_err, MAX_ERRSTR_LEN, "Symbolic link for %s must be relative to %s", libpath, plugin_dir_path);
return ERR_CRYPTDLNOOPEN;
}
handle = dlopen(&resolved_libpath[0], GTMCRYPT_LIBFLAGS);
if (NULL == handle)
{
COPY_DLLERR_MSG(err_str, dl_err);
return ERR_CRYPTDLNOOPEN;
}
num_dlsyms = ARRAYSIZE(gtmcryptlib_fptr); /* number of functions to be dlsym'ed */
for(findx = 0; findx < num_dlsyms; ++findx)
{
fptr = (void *)dlsym(handle, gtmcryptlib_fname[findx]);
if (NULL == fptr)
{
COPY_DLLERR_MSG(err_str, dl_err);
return ERR_CRYPTDLNOOPEN;
}
*gtmcryptlib_fptr[findx] = fptr;
}
return 0;
}
示例10: mupip_restore
void mupip_restore(void)
{
static readonly char label[] = GDS_LABEL;
char db_name[MAX_FN_LEN + 1], *inbuf, *p;
inc_list_struct *ptr;
inc_header *inhead;
sgmnt_data *old_data;
short iosb[4];
unsigned short n_len;
int4 status, vbn, rsize, temp, save_errno;
uint4 rest_blks, totblks;
trans_num curr_tn;
uint4 ii;
block_id blk_num;
bool extend;
uint4 cli_status;
BFILE *in;
int i, db_fd;
uint4 old_blk_size, old_tot_blks, bplmap;
short old_start_vbn;
off_t new_eof;
char buff[DISK_BLOCK_SIZE];
char msg_buffer[1024], *newmap, *newmap_bptr;
mstr msg_string;
char addr[SA_MAXLEN+1];
unsigned char tcp[5];
backup_type type;
unsigned short port;
int4 timeout, cut, match;
char debug_info[256];
void (*common_read)();
char *errptr;
pid_t waitpid_res;
error_def(ERR_MUPRESTERR);
error_def(ERR_MUPCLIERR);
error_def(ERR_IOEOF);
extend = TRUE;
if (CLI_NEGATED == (cli_status = cli_present("EXTEND")))
extend = FALSE;
mu_outofband_setup();
mu_gv_cur_reg_init();
n_len = sizeof(db_name);
if (cli_get_str("DATABASE", db_name, &n_len) == FALSE)
mupip_exit(ERR_MUPCLIERR);
strcpy((char *)gv_cur_region->dyn.addr->fname, db_name);
gv_cur_region->dyn.addr->fname_len = n_len;
if (!mu_rndwn_file(gv_cur_region, TRUE))
{
util_out_print("Error securing stand alone access to output file !AD. Aborting restore.", TRUE, n_len, db_name);
mupip_exit(ERR_MUPRESTERR);
}
OPENFILE(db_name, O_RDWR, db_fd);
if (-1 == db_fd)
{
save_errno = errno;
util_out_print("Error accessing output file !AD. Aborting restore.", TRUE, n_len, db_name);
errptr = (char *)STRERROR(save_errno);
util_out_print("open : !AZ", TRUE, errptr);
mupip_exit(save_errno);
}
murgetlst();
inbuf = (char*)malloc(INC_BACKUP_CHUNK_SIZE);
old_data = (sgmnt_data*)malloc(sizeof(sgmnt_data));
LSEEKREAD(db_fd, 0, old_data, sizeof(sgmnt_data), save_errno);
if (0 != save_errno)
{
util_out_print("Error accessing output file !AD. Aborting restore.", TRUE, n_len, db_name);
if (-1 != save_errno)
{
errptr = (char *)STRERROR(save_errno);
util_out_print("read : !AZ", TRUE, errptr);
db_ipcs_reset(gv_cur_region, TRUE);
mu_gv_cur_reg_free();
mupip_exit(save_errno);
} else
{
db_ipcs_reset(gv_cur_region, TRUE);
mu_gv_cur_reg_free();
mupip_exit(ERR_IOEOF);
}
}
if (memcmp(&old_data->label[0], &label[0], GDS_LABEL_SZ))
{
util_out_print("Output file !AD has an unrecognizable format", TRUE, n_len, db_name);
free(old_data);
free(inbuf);
db_ipcs_reset(gv_cur_region, TRUE);
mu_gv_cur_reg_free();
mupip_exit(ERR_MUPRESTERR);
}
curr_tn = old_data->trans_hist.curr_tn;
old_blk_size = old_data->blk_size;
old_tot_blks = old_data->trans_hist.total_blks;
old_start_vbn = old_data->start_vbn;
bplmap = old_data->bplmap;
free(old_data);
//.........这里部分代码省略.........
示例11: fdfs_dump_tracker_global_vars_to_file
int fdfs_dump_tracker_global_vars_to_file(const char *filename)
{
char buff[16 * 1024];
char szCurrentTime[32];
int len;
int result;
int fd;
FDFSGroupInfo **ppGroup;
FDFSGroupInfo **ppGroupEnd;
fd = open(filename, O_WRONLY | O_CREAT | O_APPEND, 0644);
if (fd < 0)
{
logError("file: "__FILE__", line: %d, "
"open file %s fail, errno: %d, error info: %s",
__LINE__, filename, errno, STRERROR(errno));
return errno;
}
do
{
result = 0;
formatDatetime(g_current_time, "%Y-%m-%d %H:%M:%S",
szCurrentTime, sizeof(szCurrentTime));
len = sprintf(buff, "\n====time: %s DUMP START====\n",
szCurrentTime);
WRITE_TO_FILE(fd, buff, len)
len = fdfs_dump_global_vars(buff, sizeof(buff));
WRITE_TO_FILE(fd, buff, len)
len = fdfs_dump_tracker_servers(buff, sizeof(buff));
WRITE_TO_FILE(fd, buff, len)
len = fdfs_dump_groups_info(buff, sizeof(buff));
WRITE_TO_FILE(fd, buff, len)
len = sprintf(buff, "\ngroup name list:\n");
WRITE_TO_FILE(fd, buff, len)
len = 0;
ppGroupEnd = g_groups.groups + g_groups.count;
for (ppGroup=g_groups.groups; ppGroup<ppGroupEnd; ppGroup++)
{
len += sprintf(buff+len, "\t%s\n", (*ppGroup)->group_name);
}
len += sprintf(buff+len, "\n");
WRITE_TO_FILE(fd, buff, len)
ppGroupEnd = g_groups.sorted_groups + g_groups.count;
for (ppGroup=g_groups.sorted_groups; ppGroup<ppGroupEnd; ppGroup++)
{
len = sprintf(buff, "\nGroup %d.\n",
(int)(ppGroup - g_groups.sorted_groups) + 1);
WRITE_TO_FILE(fd, buff, len)
len = fdfs_dump_group_stat(*ppGroup, buff, sizeof(buff));
WRITE_TO_FILE(fd, buff, len)
}
len = sprintf(buff, "\n====time: %s DUMP END====\n\n",
szCurrentTime);
WRITE_TO_FILE(fd, buff, len)
} while(0);
close(fd);
return result;
}
示例12: fdfs_ping_leader
static int fdfs_ping_leader(ConnectionInfo *pTrackerServer)
{
TrackerHeader header;
int result;
int success_count;
int64_t in_bytes;
char in_buff[(FDFS_GROUP_NAME_MAX_LEN + FDFS_STORAGE_ID_MAX_SIZE) * \
FDFS_MAX_GROUPS];
char *pInBuff;
char *p;
char *pEnd;
FDFSGroupInfo *pGroup;
char group_name[FDFS_GROUP_NAME_MAX_LEN + 1];
char trunk_server_id[FDFS_STORAGE_ID_MAX_SIZE];
memset(&header, 0, sizeof(header));
header.cmd = TRACKER_PROTO_CMD_TRACKER_PING_LEADER;
result = tcpsenddata_nb(pTrackerServer->sock, &header, \
sizeof(header), g_fdfs_network_timeout);
if(result != 0)
{
logError("file: "__FILE__", line: %d, " \
"tracker server ip: %s, send data fail, " \
"errno: %d, error info: %s", \
__LINE__, pTrackerServer->ip_addr, \
result, STRERROR(result));
return result;
}
pInBuff = in_buff;
if ((result=fdfs_recv_response(pTrackerServer, &pInBuff, \
sizeof(in_buff), &in_bytes)) != 0)
{
return result;
}
if (in_bytes == 0)
{
return 0;
}
else if (in_bytes % (FDFS_GROUP_NAME_MAX_LEN + \
FDFS_STORAGE_ID_MAX_SIZE) != 0)
{
logError("file: "__FILE__", line: %d, " \
"tracker server ip: %s, invalid body length: " \
"%"PRId64, __LINE__, \
pTrackerServer->ip_addr, in_bytes);
return EINVAL;
}
success_count = 0;
memset(group_name, 0, sizeof(group_name));
memset(trunk_server_id, 0, sizeof(trunk_server_id));
pEnd = in_buff + in_bytes;
for (p=in_buff; p<pEnd; p += FDFS_GROUP_NAME_MAX_LEN + \
FDFS_STORAGE_ID_MAX_SIZE)
{
memcpy(group_name, p, FDFS_GROUP_NAME_MAX_LEN);
memcpy(trunk_server_id, p + FDFS_GROUP_NAME_MAX_LEN, \
FDFS_STORAGE_ID_MAX_SIZE - 1);
pGroup = tracker_mem_get_group(group_name);
if (pGroup == NULL)
{
logWarning("file: "__FILE__", line: %d, " \
"tracker server ip: %s, group: %s not exists", \
__LINE__, pTrackerServer->ip_addr, group_name);
continue;
}
if (*trunk_server_id == '\0')
{
*(pGroup->last_trunk_server_id) = '\0';
pGroup->pTrunkServer = NULL;
success_count++;
continue;
}
pGroup->pTrunkServer = tracker_mem_get_storage(pGroup, \
trunk_server_id);
if (pGroup->pTrunkServer == NULL)
{
logWarning("file: "__FILE__", line: %d, " \
"tracker server ip: %s, group: %s, " \
"trunk server: %s not exists", \
__LINE__, pTrackerServer->ip_addr, \
group_name, trunk_server_id);
}
snprintf(pGroup->last_trunk_server_id, sizeof( \
pGroup->last_trunk_server_id), "%s", trunk_server_id);
success_count++;
}
if (success_count > 0)
{
tracker_save_groups();
}
return 0;
//.........这里部分代码省略.........
示例13: do_notify_leader_changed
static int do_notify_leader_changed(ConnectionInfo *pTrackerServer, \
ConnectionInfo *pLeader, const char cmd, bool *bConnectFail)
{
char out_buff[sizeof(TrackerHeader) + FDFS_PROTO_IP_PORT_SIZE];
char in_buff[1];
ConnectionInfo *conn;
TrackerHeader *pHeader;
char *pInBuff;
int64_t in_bytes;
int result;
pTrackerServer->sock = -1;
if ((conn=tracker_connect_server(pTrackerServer, &result)) == NULL)
{
*bConnectFail = true;
return result;
}
*bConnectFail = false;
do
{
memset(out_buff, 0, sizeof(out_buff));
pHeader = (TrackerHeader *)out_buff;
pHeader->cmd = cmd;
sprintf(out_buff + sizeof(TrackerHeader), "%s:%d", \
pLeader->ip_addr, pLeader->port);
long2buff(FDFS_PROTO_IP_PORT_SIZE, pHeader->pkg_len);
if ((result=tcpsenddata_nb(conn->sock, out_buff, \
sizeof(out_buff), g_fdfs_network_timeout)) != 0)
{
logError("file: "__FILE__", line: %d, " \
"send data to tracker server %s:%d fail, " \
"errno: %d, error info: %s", __LINE__, \
pTrackerServer->ip_addr, \
pTrackerServer->port, \
result, STRERROR(result));
result = (result == ENOENT ? EACCES : result);
break;
}
pInBuff = in_buff;
result = fdfs_recv_response(conn, &pInBuff, \
0, &in_bytes);
if (result != 0)
{
break;
}
if (in_bytes != 0)
{
logError("file: "__FILE__", line: %d, " \
"tracker server %s:%d response data " \
"length: %"PRId64" is invalid, " \
"expect length: %d.", __LINE__, \
pTrackerServer->ip_addr, pTrackerServer->port, \
in_bytes, 0);
result = EINVAL;
break;
}
} while (0);
if (pTrackerServer->port == g_server_port && \
is_local_host_ip(pTrackerServer->ip_addr))
{
tracker_disconnect_server_ex(conn, true);
}
else
{
tracker_disconnect_server_ex(conn, result != 0);
}
return result;
}
示例14: iosocket_use
//.........这里部分代码省略.........
UNICODE_ONLY(newsocket.zff.char_len = 0); /* don't care */
memcpy(newsocket.zff.addr, stringpool.free, new_len);
} else
{ /* Store parm without conversion */
if (gtm_utf8_mode) /* Check if ZFF has any invalid UTF-8 character */
{ /* Note: the ZFF string originates from the source program, so is in UTF-8 mode or M mode
regardless of OCHSET of this device. ZFF is output on WRITE # command, and MUST contain
valid UTF-8 sequence. This validation is handled by gtm_conv in the path above.
*/
utf8_len_strict(zff_buffer, zff_len);
}
if (NULL == newsocket.zff.addr) /* we rely on newsocket.zff.addr being set to 0 in iosocket_create() */
newsocket.zff.addr = (char *)malloc(MAX_ZFF_LEN);
memcpy(newsocket.zff.addr, zff_buffer, zff_len);
}
}
if (ioerror_specified)
newsocket.ioerror = ('T' == ioerror || 't' == ioerror);
if (nodelay_specified || delay_specified)
newsocket.nodelay = nodelay_specified; /* defaults to DELAY */
if (ibfsize_specified)
newsocket.bufsiz = ibfsize;
if (moreread_specified)
{
newsocket.moreread_timeout = moreread_timeout;
newsocket.def_moreread_timeout = TRUE; /* need to know this was user-defined in iosocket_readfl.c */
}
if (!create_new_socket)
{
/* these changes apply to only pre-existing sockets */
if (bfsize_specified)
newsocket.buffer_size = bfsize;
#ifdef TCP_NODELAY
nodelay = newsocket.nodelay ? 1 : 0;
if ((socketptr->nodelay != newsocket.nodelay) &&
(-1 == tcp_routines.aa_setsockopt(newsocket.sd, IPPROTO_TCP,
TCP_NODELAY, &nodelay, SIZEOF(nodelay))))
{
save_errno = errno;
errptr = (char *)STRERROR(save_errno);
rts_error(VARLSTCNT(7) ERR_SETSOCKOPTERR, 5, LEN_AND_LIT("TCP_NODELAY"), save_errno, LEN_AND_STR(errptr));
return;
}
#endif
if ((socketptr->bufsiz != newsocket.bufsiz) &&
(-1 == tcp_routines.aa_setsockopt(newsocket.sd, SOL_SOCKET,
SO_RCVBUF, &newsocket.bufsiz, SIZEOF(newsocket.bufsiz))))
{
save_errno = errno;
errptr = (char *)STRERROR(save_errno);
rts_error(VARLSTCNT(7) ERR_SETSOCKOPTERR, 5, LEN_AND_LIT("SO_RCVBUF"), save_errno, LEN_AND_STR(errptr));
return;
}
if (socketptr->buffer_size != newsocket.buffer_size)
{
if (socketptr->buffered_length > bfsize)
rts_error(VARLSTCNT(4) ERR_SOCKBFNOTEMPTY, 2, bfsize, socketptr->buffered_length);
newsocket.buffer = (char *)malloc(bfsize);
if (0 < socketptr->buffered_length)
{
memcpy(newsocket.buffer, socketptr->buffer + socketptr->buffered_offset,
socketptr->buffered_length);
newsocket.buffered_offset = 0;
}
}
}
/* -------------------------------------- action -------------------------------------------- */
if ((listen_specified && (!iosocket_bind(&newsocket, NO_M_TIMEOUT, ibfsize_specified))) ||
(connect_specified && (!iosocket_connect(&newsocket, 0, ibfsize_specified))))
{ /* error message should be printed from bind/connect */
if (socketptr->sd > 0)
(void)tcp_routines.aa_close(socketptr->sd);
iosocket_delimiter((unsigned char *)NULL, 0, &newsocket, TRUE);
if (NULL != socketptr->zff.addr)
free(socketptr->zff.addr);
if (NULL != socketptr->buffer)
free(socketptr->buffer);
free(socketptr);
return;
}
/* ------------------------------------ commit changes -------------------------------------- */
if (create_new_socket)
{
if (gtm_max_sockets <= newdsocket->n_socket)
{
rts_error(VARLSTCNT(3) ERR_SOCKMAX, 1, gtm_max_sockets);
return;
}
/* a new socket is created. so add to the list */
newsocket.dev = dsocketptr;
newdsocket->socket[newdsocket->n_socket++] = socketptr;
newdsocket->current_socket = newdsocket->n_socket - 1;
}
else if (socketptr->buffer_size != newsocket.buffer_size)
free(socketptr->buffer);
*socketptr = newsocket;
memcpy(dsocketptr, newdsocket, d_socket_struct_len);
return;
}
示例15: GetRules
int GetRules(struct sockaddr_in ServerID, struct rule_format rule[], int max_rules, struct htx_data * stats)
{
SOCKET ToServerSock;
struct CoordMsg CMsg;
int rc;
int i;
int NoStanzas;
char msg[1024];
errno = 0;
ToServerSock = SetUpConnect(&ServerID, stats, 0);
memset(&CMsg, '\0', sizeof(CMsg));
CMsg.msg_type = htonl(CM_REQ_RULES);
CMsg.ID.Wsize.size = htonl((uint32_t)sizeof(struct rule_format));
rc = StreamWrite(ToServerSock, (char *) &CMsg, sizeof(CMsg));
if(rc == -1) {
sprintf(msg, "GetRules: Error writing to Server - %s\n", STRERROR(errno));
hxfmsg(stats, HTXERROR(EX_RULE1,ERRNO), HTX_HE_SOFT_ERROR, msg);
HE_exit(EX_RULE1);
}
StreamRead(ToServerSock, (char *) &CMsg, sizeof(CMsg));
CMsg.msg_type = ntohl(CMsg.msg_type);
CMsg.ID.Wsize.size = ntohl(CMsg.ID.Wsize.size);
if(CMsg.msg_type != CM_RULES_STANZA) {
sprintf(msg, "GetRules: Illegal Packet recvd.\n");
hxfmsg(stats, HTXERROR(EX_RULE3,0), HTX_HE_SOFT_ERROR, msg);
HE_exit(EX_RULE3);
}
#ifdef __DEBUG__
sprintf(msg, "GetRules: Sock = %d, Recvd msg = %x of size = %#x, rule_format size = %x, pid = %d \n", ToServerSock, CMsg.msg_type, sizeof(CMsg), (uint32_t)sizeof(struct rule_format), getpid());
hxfmsg(stats, 0, 7, msg);
#endif
memset(rule, '\0', sizeof(struct rule_format) * max_rules);
memset(&CMsg, '\0', sizeof(CMsg));
for(i=0; i < max_rules; i++) {
rc = StreamRead(ToServerSock, (char *) &CMsg.msg_type, sizeof(CMsg.msg_type));
CMsg.msg_type = ntohl(CMsg.msg_type);
#ifdef __DEBUG__
sprintf(msg, "i = %#x, GetRules: Recvd msg = %x, of size = %x \n", i, CMsg.msg_type, sizeof(CMsg.msg_type));
hxfmsg(stats, 0, 7, msg);
#endif
if(CMsg.msg_type == CM_RULES_FINISHED)
break;
if(CMsg.msg_type != CM_RULES_STANZA) {
sprintf(msg, "GetRules: Unable to obtain rules - type %x\n", (int)CMsg.msg_type);
hxfmsg(stats, HTXERROR(EX_RULE2,ERRNO), HTX_HE_SOFT_ERROR, msg);
HE_exit(EX_RULE2);
}
rc = StreamRead(ToServerSock, (char*) &rule[i], sizeof(struct rule_format));
if(rc != sizeof(struct rule_format)) {
sprintf(msg, "GetRules: Unable to read rules from server - %s\n", STRERROR(errno));
hxfmsg(stats, HTXERROR(EX_RULE4,ERRNO), HTX_HE_SOFT_ERROR, msg);
HE_exit(EX_RULE3);
}
NetToHostRules(&rule[i]);
}
NoStanzas = i;
closesocket(ToServerSock);
return NoStanzas;
}