本文整理汇总了C++中WARNING函数的典型用法代码示例。如果您正苦于以下问题:C++ WARNING函数的具体用法?C++ WARNING怎么用?C++ WARNING使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了WARNING函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: proc_probe
bool
proc_probe(pid_t pid, int opt, proc_t * const pproc)
{
FUNC_BEGIN("%d,%d,%p", pid, opt, pproc);
assert(pproc);
if (pproc == NULL)
{
FUNC_RET("%d", false);
}
#ifdef HAVE_PROCFS
/* Grab preliminary information from procfs */
if (!check_procfs(pid))
{
WARNING("procfs entries missing or invalid");
FUNC_RET("%d", false);
}
char buffer[4096];
sprintf(buffer, PROCFS "/%d/stat", pid);
int fd = open(buffer, O_RDONLY);
if (fd < 0)
{
WARNING("procfs stat missing or unaccessable");
FUNC_RET("%d", false);
}
int len = read(fd, buffer, sizeof(buffer) - 1);
close(fd);
if (len < 0)
{
WARNING("failed to grab stat from procfs");
FUNC_RET("%d", false);
}
buffer[len] = '\0';
/* Extract interested information */
struct tms tm;
int offset = 0;
char * token = buffer;
do
{
switch (offset++)
{
case 0: /* pid */
sscanf(token, "%d", &pproc->pid);
break;
case 1: /* comm */
break;
case 2: /* state */
sscanf(token, "%c", &pproc->state);
break;
case 3: /* ppid */
sscanf(token, "%d", &pproc->ppid);
break;
case 4: /* pgrp */
case 5: /* session */
case 6: /* tty_nr */
case 7: /* tty_pgrp */
break;
case 8: /* flags */
sscanf(token, "%lu", &pproc->flags);
break;
case 9: /* min_flt */
sscanf(token, "%lu", &pproc->minflt);
break;
case 10: /* cmin_flt */
sscanf(token, "%lu", &pproc->cminflt);
break;
case 11: /* maj_flt */
sscanf(token, "%lu", &pproc->majflt);
break;
case 12: /* cmaj_flt */
sscanf(token, "%lu", &pproc->cmajflt);
break;
case 13: /* utime */
sscanf(token, "%lu", &tm.tms_utime);
break;
case 14: /* stime */
sscanf(token, "%lu", &tm.tms_stime);
break;
case 15: /* cutime */
sscanf(token, "%ld", &tm.tms_cutime);
break;
case 16: /* cstime */
sscanf(token, "%ld", &tm.tms_cstime);
break;
case 17: /* priority */
case 18: /* nice */
case 19: /* num_threads (since 2.6 kernel) */
case 20: /* it_real_value */
case 21: /* start_time */
break;
case 22: /* vsize */
//.........这里部分代码省略.........
示例2: goodix_tool_read
static s32 goodix_tool_read( char *page, char **start, off_t off, int count, int *eof, void *data )
{
if (2 == cmd_head.wr)
{
//memcpy(page, IC_TYPE, cmd_head.data_len);
memcpy(page, IC_TYPE, sizeof(IC_TYPE_NAME));
page[sizeof(IC_TYPE_NAME)] = 0;
DEBUG("Return ic type:%s len:%d\n", page, (s32)cmd_head.data_len);
return cmd_head.data_len;
//return sizeof(IC_TYPE_NAME);
}
else if (cmd_head.wr % 2)
{
return fail;
}
else if (!cmd_head.wr)
{
u16 len = 0;
s16 data_len = 0;
u16 loc = 0;
if (1 == cmd_head.flag)
{
if (fail == comfirm())
{
WARNING("[READ]Comfirm fail!\n");
return fail;
}
}
else if (2 == cmd_head.flag)
{
//Need interrupt!
}
memcpy(cmd_head.data, cmd_head.addr, cmd_head.addr_len);
DEBUG("[CMD HEAD DATA] ADDR:0x%02x%02x\n", cmd_head.data[0], cmd_head.data[1]);
DEBUG("[CMD HEAD ADDR] ADDR:0x%02x%02x\n", cmd_head.addr[0], cmd_head.addr[1]);
if (cmd_head.delay)
{
msleep(cmd_head.delay);
}
data_len = cmd_head.data_len;
while(data_len > 0)
{
if (data_len > DATA_LENGTH)
{
len = DATA_LENGTH;
}
else
{
len = data_len;
}
data_len -= DATA_LENGTH;
if (tool_i2c_read(cmd_head.data, len) <= 0)
{
WARNING("[READ]Read data failed!\n");
return fail;
}
memcpy(&page[loc], &cmd_head.data[ADDR_MAX_LENGTH], len);
loc += len;
//DEBUG_ARRAY(&cmd_head.data[ADDR_MAX_LENGTH], len);
DEBUG_ARRAY(page, len);
}
}
return cmd_head.data_len;
}
示例3: INFO
Decode_Status
VaapiDecoderBase::setupVA(uint32_t numSurface, VAProfile profile)
{
INFO("base: setup VA");
if (m_enableNativeBuffersFlag == true) {
numSurface = 20; //NATIVE_WINDOW_COUNT;
}
if (m_VAStarted) {
return DECODE_SUCCESS;
}
if (m_display != NULL) {
WARNING("VA is partially started.");
return DECODE_FAIL;
}
m_display = VaapiDisplay::create(m_externalDisplay);
if (!m_display) {
ERROR("failed to create display");
return DECODE_FAIL;
}
VAConfigAttrib attrib;
attrib.type = VAConfigAttribRTFormat;
attrib.value = VA_RT_FORMAT_YUV420;
ConfigPtr config = VaapiConfig::create(m_display, profile, VAEntrypointVLD,&attrib, 1);
if (!config) {
ERROR("failed to create config");
return DECODE_FAIL;
}
m_configBuffer.surfaceNumber = numSurface;
m_surfacePool = VaapiDecSurfacePool::create(m_display, &m_configBuffer);
DEBUG("surface pool is created");
if (!m_surfacePool)
return DECODE_FAIL;
std::vector<VASurfaceID> surfaces;
m_surfacePool->getSurfaceIDs(surfaces);
if (surfaces.empty())
return DECODE_FAIL;
int size = surfaces.size();
m_context = VaapiContext::create(config,
m_videoFormatInfo.width,
m_videoFormatInfo.height,
0, &surfaces[0], size);
if (!m_context) {
ERROR("create context failed");
return DECODE_FAIL;
}
if (!m_display->setRotation(m_configBuffer.rotationDegrees)) {
WARNING("set rotation failed");
}
if (!(m_configBuffer.flag & USE_NATIVE_GRAPHIC_BUFFER)) {
m_videoFormatInfo.surfaceWidth = m_videoFormatInfo.width;
m_videoFormatInfo.surfaceHeight = m_videoFormatInfo.height;
}
m_VAStarted = true;
return DECODE_SUCCESS;
}
示例4: apache_read_host
static int apache_read_host (user_data_t *user_data) /* {{{ */
{
int i;
char *ptr;
char *saveptr;
char *lines[16];
int lines_num = 0;
char *fields[4];
int fields_num;
apache_t *st;
st = user_data->data;
assert (st->url != NULL);
/* (Assured by `config_add') */
if (st->curl == NULL)
{
int status;
status = init_host (st);
if (status != 0)
return (-1);
}
assert (st->curl != NULL);
st->apache_buffer_fill = 0;
if (curl_easy_perform (st->curl) != CURLE_OK)
{
ERROR ("apache: curl_easy_perform failed: %s",
st->apache_curl_error);
return (-1);
}
/* fallback - server_type to apache if not set at this time */
if (st->server_type == -1)
{
WARNING ("apache plugin: Unable to determine server software "
"automatically. Will assume Apache.");
st->server_type = APACHE;
}
ptr = st->apache_buffer;
saveptr = NULL;
while ((lines[lines_num] = strtok_r (ptr, "\n\r", &saveptr)) != NULL)
{
ptr = NULL;
lines_num++;
if (lines_num >= 16)
break;
}
for (i = 0; i < lines_num; i++)
{
fields_num = strsplit (lines[i], fields, 4);
if (fields_num == 3)
{
if ((strcmp (fields[0], "Total") == 0)
&& (strcmp (fields[1], "Accesses:") == 0))
submit_derive ("apache_requests", "",
atoll (fields[2]), st);
else if ((strcmp (fields[0], "Total") == 0)
&& (strcmp (fields[1], "kBytes:") == 0))
submit_derive ("apache_bytes", "",
1024LL * atoll (fields[2]), st);
}
else if (fields_num == 2)
{
if (strcmp (fields[0], "Scoreboard:") == 0)
submit_scoreboard (fields[1], st);
else if ((strcmp (fields[0], "BusyServers:") == 0) /* Apache 1.* */
|| (strcmp (fields[0], "BusyWorkers:") == 0) /* Apache 2.* */)
submit_gauge ("apache_connections", NULL, atol (fields[1]), st);
else if ((strcmp (fields[0], "IdleServers:") == 0) /* Apache 1.x */
|| (strcmp (fields[0], "IdleWorkers:") == 0) /* Apache 2.x */)
submit_gauge ("apache_idle_workers", NULL, atol (fields[1]), st);
}
}
st->apache_buffer_fill = 0;
return (0);
} /* }}} int apache_read_host */
示例5: ReadConsoleOutputEx
//.........这里部分代码省略.........
nTick4 = GetTickCount();
}
}
else
{
DWORD nAttrsMax = bufSize.X;
DWORD nCharsMax = nAttrsMax/* *4 */; // -- максимум там вроде на некоторых CP - 4 байта
wchar_t* pszChars = (wchar_t*)malloc(nCharsMax*sizeof(*pszChars));
char* pszCharsA = (char*)malloc(nCharsMax*sizeof(*pszCharsA));
WORD* pnAttrs = (WORD*)malloc(bufSize.X*sizeof(*pnAttrs));
if (pszChars && pszCharsA && pnAttrs)
{
COORD crRead = {rgn.Left,Y1};
DWORD nChars, nAttrs, nCharsA;
CHAR_INFO* pLine = pData;
for (; crRead.Y <= Y2; crRead.Y++, pLine+=nBufWidth)
{
nTick3 = GetTickCount();
rgn.Bottom = rgn.Top;
nChars = nCharsA = nAttrs = 0;
BOOL lbRcTxt = ReadConsoleOutputCharacterA(hOut, pszCharsA, nCharsMax, crRead, &nCharsA);
dwErrCode = GetLastError();
if (!lbRcTxt || !nCharsA)
{
nCharsA = 0;
lbRcTxt = ReadConsoleOutputCharacterW(hOut, pszChars, nCharsMax, crRead, &nChars);
dwErrCode = GetLastError();
}
BOOL lbRcAtr = ReadConsoleOutputAttribute(hOut, pnAttrs, bufSize.X, crRead, &nAttrs);
dwErrCode = GetLastError();
lbRc = lbRcTxt && lbRcAtr;
if (!lbRc)
{
dwErrCode = GetLastError();
_ASSERTE(FALSE && "ReadConsoleOutputAttribute failed in MyReadConsoleOutput");
CHAR_INFO* p = pLine;
for (size_t i = 0; i < nAttrsMax; ++i, ++p)
{
p->Attributes = 4; // red on black
p->Char.UnicodeChar = 0xFFFE; // not a character
}
break;
}
else
{
if (nCharsA)
{
nChars = MultiByteToWideChar(nCP, 0, pszCharsA, nCharsA, pszChars, nCharsMax);
}
CHAR_INFO* p = pLine;
wchar_t* psz = pszChars;
WORD* pn = pnAttrs;
//int i = nAttrsMax;
//while ((i--) > 0)
//{
// p->Attributes = *(pn++);
// p->Char.UnicodeChar = *(psz++);
// p++;
//}
size_t x1 = min(nChars,nAttrsMax);
size_t x2 = nAttrsMax;
for (size_t i = 0; i < x1; ++i, ++p)
{
p->Attributes = *pn;
p->Char.UnicodeChar = *psz;
WARNING("Некорректно! pn может указывать на начало блока DBCS/QBCS");
pn++; // += MaxCharSize;
psz++;
}
WORD nLastAttr = pnAttrs[max(0,(int)nAttrs-1)];
for (size_t i = x1; i < x2; ++i, ++p)
{
p->Attributes = nLastAttr;
p->Char.UnicodeChar = L' ';
}
}
nTick4 = GetTickCount();
}
}
SafeFree(pszChars);
SafeFree(pszCharsA);
SafeFree(pnAttrs);
}
nTick5 = GetTickCount();
}
UNREFERENCED_PARAMETER(nTick1);
UNREFERENCED_PARAMETER(nTick2);
UNREFERENCED_PARAMETER(nTick3);
UNREFERENCED_PARAMETER(nTick4);
UNREFERENCED_PARAMETER(nTick5);
return lbRc;
}
示例6: disk_read
//.........这里部分代码省略.........
if (kc == NULL)
return (-1);
for (i = 0; i < numdisk; i++)
{
if (kstat_read (kc, ksp[i], &kio) == -1)
continue;
if (strncmp (ksp[i]->ks_class, "disk", 4) == 0)
{
disk_submit (ksp[i]->ks_name, "disk_octets",
kio.KIO_ROCTETS, kio.KIO_WOCTETS);
disk_submit (ksp[i]->ks_name, "disk_ops",
kio.KIO_ROPS, kio.KIO_WOPS);
/* FIXME: Convert this to microseconds if necessary */
disk_submit (ksp[i]->ks_name, "disk_time",
kio.KIO_RTIME, kio.KIO_WTIME);
}
else if (strncmp (ksp[i]->ks_class, "partition", 9) == 0)
{
disk_submit (ksp[i]->ks_name, "disk_octets",
kio.KIO_ROCTETS, kio.KIO_WOCTETS);
disk_submit (ksp[i]->ks_name, "disk_ops",
kio.KIO_ROPS, kio.KIO_WOPS);
}
}
/* #endif defined(HAVE_LIBKSTAT) */
#elif defined(HAVE_LIBSTATGRAB)
sg_disk_io_stats *ds;
int disks, counter;
char name[DATA_MAX_NAME_LEN];
if ((ds = sg_get_disk_io_stats(&disks)) == NULL)
return (0);
for (counter=0; counter < disks; counter++) {
strncpy(name, ds->disk_name, sizeof(name));
name[sizeof(name)-1] = '\0'; /* strncpy doesn't terminate longer strings */
disk_submit (name, "disk_octets", ds->read_bytes, ds->write_bytes);
ds++;
}
/* #endif defined(HAVE_LIBSTATGRAB) */
#elif defined(HAVE_PERFSTAT)
derive_t read_sectors;
derive_t write_sectors;
derive_t read_time;
derive_t write_time;
derive_t read_ops;
derive_t write_ops;
perfstat_id_t firstpath;
int rnumdisk;
int i;
if ((numdisk = perfstat_disk(NULL, NULL, sizeof(perfstat_disk_t), 0)) < 0)
{
char errbuf[1024];
WARNING ("disk plugin: perfstat_disk: %s",
sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
if (numdisk != pnumdisk || stat_disk==NULL) {
if (stat_disk!=NULL)
free(stat_disk);
stat_disk = (perfstat_disk_t *)calloc(numdisk, sizeof(perfstat_disk_t));
}
pnumdisk = numdisk;
firstpath.name[0]='\0';
if ((rnumdisk = perfstat_disk(&firstpath, stat_disk, sizeof(perfstat_disk_t), numdisk)) < 0)
{
char errbuf[1024];
WARNING ("disk plugin: perfstat_disk : %s",
sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
for (i = 0; i < rnumdisk; i++)
{
read_sectors = stat_disk[i].rblks*stat_disk[i].bsize;
write_sectors = stat_disk[i].wblks*stat_disk[i].bsize;
disk_submit (stat_disk[i].name, "disk_octets", read_sectors, write_sectors);
read_ops = stat_disk[i].xrate;
write_ops = stat_disk[i].xfers - stat_disk[i].xrate;
disk_submit (stat_disk[i].name, "disk_ops", read_ops, write_ops);
read_time = stat_disk[i].rserv;
read_time *= ((double)(_system_configuration.Xint)/(double)(_system_configuration.Xfrac)) / 1000000.0;
write_time = stat_disk[i].wserv;
write_time *= ((double)(_system_configuration.Xint)/(double)(_system_configuration.Xfrac)) / 1000000.0;
disk_submit (stat_disk[i].name, "disk_time", read_time, write_time);
}
#endif /* defined(HAVE_PERFSTAT) */
return (0);
} /* int disk_read */
示例7: config_add
/* Configuration handling functiions
* <Plugin apache>
* <Instance "instance_name">
* URL ...
* </Instance>
* URL ...
* </Plugin>
*/
static int config_add (oconfig_item_t *ci)
{
apache_t *st;
int i;
int status;
st = malloc (sizeof (*st));
if (st == NULL)
{
ERROR ("apache plugin: malloc failed.");
return (-1);
}
memset (st, 0, sizeof (*st));
status = cf_util_get_string (ci, &st->name);
if (status != 0)
{
sfree (st);
return (status);
}
assert (st->name != NULL);
for (i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
if (strcasecmp ("URL", child->key) == 0)
status = cf_util_get_string (child, &st->url);
else if (strcasecmp ("Host", child->key) == 0)
status = cf_util_get_string (child, &st->host);
else if (strcasecmp ("User", child->key) == 0)
status = cf_util_get_string (child, &st->user);
else if (strcasecmp ("Password", child->key) == 0)
status = cf_util_get_string (child, &st->pass);
else if (strcasecmp ("VerifyPeer", child->key) == 0)
status = cf_util_get_boolean (child, &st->verify_peer);
else if (strcasecmp ("VerifyHost", child->key) == 0)
status = cf_util_get_boolean (child, &st->verify_host);
else if (strcasecmp ("CACert", child->key) == 0)
status = cf_util_get_string (child, &st->cacert);
else if (strcasecmp ("Server", child->key) == 0)
status = cf_util_get_string (child, &st->server);
else
{
WARNING ("apache plugin: Option `%s' not allowed here.",
child->key);
status = -1;
}
if (status != 0)
break;
}
/* Check if struct is complete.. */
if ((status == 0) && (st->url == NULL))
{
ERROR ("apache plugin: Instance `%s': "
"No URL has been configured.",
st->name);
status = -1;
}
if (status == 0)
{
user_data_t ud;
char callback_name[3*DATA_MAX_NAME_LEN];
memset (&ud, 0, sizeof (ud));
ud.data = st;
ud.free_func = (void *) apache_free;
memset (callback_name, 0, sizeof (callback_name));
ssnprintf (callback_name, sizeof (callback_name),
"apache/%s/%s",
(st->host != NULL) ? st->host : hostname_g,
(st->name != NULL) ? st->name : "default"),
status = plugin_register_complex_read (/* group = */ NULL,
/* name = */ callback_name,
/* callback = */ apache_read_host,
/* interval = */ NULL,
/* user_data = */ &ud);
}
if (status != 0)
{
apache_free (st);
return (-1);
}
return (0);
} /* int config_add */
示例8: mysql_config
static int mysql_config (oconfig_item_t *ci) /* {{{ */
{
mysql_database_t *db;
int plugin_block;
int status = 0;
int i;
if ((ci->values_num != 1)
|| (ci->values[0].type != OCONFIG_TYPE_STRING))
{
WARNING ("mysql plugin: The `Database' block "
"needs exactly one string argument.");
return (-1);
}
db = (mysql_database_t *) malloc (sizeof (*db));
if (db == NULL)
{
ERROR ("mysql plugin: malloc failed.");
return (-1);
}
memset (db, 0, sizeof (*db));
/* initialize all the pointers */
db->host = NULL;
db->user = NULL;
db->pass = NULL;
db->database = NULL;
db->socket = NULL;
db->con = NULL;
/* trigger a notification, if it's not running */
db->slave_io_running = 1;
db->slave_sql_running = 1;
plugin_block = 1;
if (strcasecmp ("Plugin", ci->key) == 0)
{
db->instance = NULL;
}
else if (strcasecmp ("Database", ci->key) == 0)
{
plugin_block = 0;
status = mysql_config_set_string (&db->instance, ci);
if (status != 0)
{
sfree (db);
return (status);
}
assert (db->instance != NULL);
}
else
{
ERROR ("mysql plugin: mysql_config: "
"Invalid key: %s", ci->key);
return (-1);
}
/* Fill the `mysql_database_t' structure.. */
for (i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
if (strcasecmp ("Host", child->key) == 0)
status = mysql_config_set_string (&db->host, child);
else if (strcasecmp ("User", child->key) == 0)
status = mysql_config_set_string (&db->user, child);
else if (strcasecmp ("Password", child->key) == 0)
status = mysql_config_set_string (&db->pass, child);
else if (strcasecmp ("Port", child->key) == 0)
status = mysql_config_set_int (&db->port, child);
else if (strcasecmp ("Socket", child->key) == 0)
status = mysql_config_set_string (&db->socket, child);
/* Check if we're currently handling the `Plugin' block. If so,
* handle `Database' _blocks_, too. */
else if ((plugin_block != 0)
&& (strcasecmp ("Database", child->key) == 0)
&& (child->children != NULL))
{
/* If `plugin_block > 1', there has been at least one
* `Database' block */
plugin_block++;
status = mysql_config (child);
}
/* Now handle ordinary `Database' options (without children) */
else if ((strcasecmp ("Database", child->key) == 0)
&& (child->children == NULL))
status = mysql_config_set_string (&db->database, child);
else if (strcasecmp ("MasterStats", child->key) == 0)
status = mysql_config_set_boolean (&db->master_stats, child);
else if (strcasecmp ("SlaveStats", child->key) == 0)
status = mysql_config_set_boolean (&db->slave_stats, child);
else if (strcasecmp ("SlaveNotifications", child->key) == 0)
status = mysql_config_set_boolean (&db->slave_notif, child);
else
{
WARNING ("mysql plugin: Option `%s' not allowed here.", child->key);
status = -1;
}
//.........这里部分代码省略.........
示例9: mysql_read_slave_stats
static int mysql_read_slave_stats (mysql_database_t *db, MYSQL *con)
{
MYSQL_RES *res;
MYSQL_ROW row;
char *query;
int field_num;
/* WTF? libmysqlclient does not seem to provide any means to
* translate a column name to a column index ... :-/ */
const int READ_MASTER_LOG_POS_IDX = 6;
const int SLAVE_IO_RUNNING_IDX = 10;
const int SLAVE_SQL_RUNNING_IDX = 11;
const int EXEC_MASTER_LOG_POS_IDX = 21;
const int SECONDS_BEHIND_MASTER_IDX = 32;
query = "SHOW SLAVE STATUS";
res = exec_query (con, query);
if (res == NULL)
return (-1);
row = mysql_fetch_row (res);
if (row == NULL)
{
ERROR ("mysql plugin: Failed to get slave statistics: "
"`%s' did not return any rows.", query);
return (-1);
}
field_num = mysql_num_fields (res);
if (field_num < 33)
{
ERROR ("mysql plugin: Failed to get slave statistics: "
"`%s' returned less than 33 columns.", query);
return (-1);
}
if (db->slave_stats)
{
unsigned long long counter;
double gauge;
counter = atoll (row[READ_MASTER_LOG_POS_IDX]);
counter_submit ("mysql_log_position", "slave-read", counter, db);
counter = atoll (row[EXEC_MASTER_LOG_POS_IDX]);
counter_submit ("mysql_log_position", "slave-exec", counter, db);
if (row[SECONDS_BEHIND_MASTER_IDX] != NULL)
{
gauge = atof (row[SECONDS_BEHIND_MASTER_IDX]);
gauge_submit ("time_offset", NULL, gauge, db);
}
}
if (db->slave_notif)
{
notification_t n = { 0, time (NULL), "", "",
"mysql", "", "time_offset", "", NULL };
char *io, *sql;
io = row[SLAVE_IO_RUNNING_IDX];
sql = row[SLAVE_SQL_RUNNING_IDX];
set_host (db, n.host, sizeof (n.host));
set_plugin_instance (db,
n.plugin_instance, sizeof (n.plugin_instance));
if (((io == NULL) || (strcasecmp (io, "yes") != 0))
&& (db->slave_io_running))
{
n.severity = NOTIF_WARNING;
ssnprintf (n.message, sizeof (n.message),
"slave I/O thread not started or not connected to master");
plugin_dispatch_notification (&n);
db->slave_io_running = 0;
}
else if (((io != NULL) && (strcasecmp (io, "yes") == 0))
&& (! db->slave_io_running))
{
n.severity = NOTIF_OKAY;
ssnprintf (n.message, sizeof (n.message),
"slave I/O thread started and connected to master");
plugin_dispatch_notification (&n);
db->slave_io_running = 1;
}
if (((sql == NULL) || (strcasecmp (sql, "yes") != 0))
&& (db->slave_sql_running))
{
n.severity = NOTIF_WARNING;
ssnprintf (n.message, sizeof (n.message),
"slave SQL thread not started");
plugin_dispatch_notification (&n);
db->slave_sql_running = 0;
}
else if (((sql != NULL) && (strcasecmp (sql, "yes") == 0))
&& (! db->slave_sql_running))
//.........这里部分代码省略.........
示例10: values_to_kairosdb
static int values_to_kairosdb(char *buffer, size_t buffer_size, /* {{{ */
const data_set_t *ds, const value_list_t *vl,
int store_rates, size_t ds_idx) {
size_t offset = 0;
gauge_t *rates = NULL;
memset(buffer, 0, buffer_size);
#define BUFFER_ADD(...) \
do { \
int status; \
status = snprintf(buffer + offset, buffer_size - offset, __VA_ARGS__); \
if (status < 1) { \
sfree(rates); \
return -1; \
} else if (((size_t)status) >= (buffer_size - offset)) { \
sfree(rates); \
return -ENOMEM; \
} else \
offset += ((size_t)status); \
} while (0)
if (ds->ds[ds_idx].type == DS_TYPE_GAUGE) {
if (isfinite(vl->values[ds_idx].gauge)) {
BUFFER_ADD("[[");
BUFFER_ADD("%" PRIu64, CDTIME_T_TO_MS(vl->time));
BUFFER_ADD(",");
BUFFER_ADD(JSON_GAUGE_FORMAT, vl->values[ds_idx].gauge);
} else {
DEBUG("utils_format_kairosdb: invalid vl->values[ds_idx].gauge for "
"%s|%s|%s|%s|%s",
vl->plugin, vl->plugin_instance, vl->type, vl->type_instance,
ds->ds[ds_idx].name);
return -1;
}
} else if (store_rates) {
if (rates == NULL)
rates = uc_get_rate(ds, vl);
if (rates == NULL) {
WARNING("utils_format_kairosdb: uc_get_rate failed for %s|%s|%s|%s|%s",
vl->plugin, vl->plugin_instance, vl->type, vl->type_instance,
ds->ds[ds_idx].name);
return -1;
}
if (isfinite(rates[ds_idx])) {
BUFFER_ADD("[[");
BUFFER_ADD("%" PRIu64, CDTIME_T_TO_MS(vl->time));
BUFFER_ADD(",");
BUFFER_ADD(JSON_GAUGE_FORMAT, rates[ds_idx]);
} else {
WARNING("utils_format_kairosdb: invalid rates[ds_idx] for %s|%s|%s|%s|%s",
vl->plugin, vl->plugin_instance, vl->type, vl->type_instance,
ds->ds[ds_idx].name);
sfree(rates);
return -1;
}
} else if (ds->ds[ds_idx].type == DS_TYPE_COUNTER) {
BUFFER_ADD("[[");
BUFFER_ADD("%" PRIu64, CDTIME_T_TO_MS(vl->time));
BUFFER_ADD(",");
BUFFER_ADD("%" PRIu64, (uint64_t)vl->values[ds_idx].counter);
} else if (ds->ds[ds_idx].type == DS_TYPE_DERIVE) {
BUFFER_ADD("[[");
BUFFER_ADD("%" PRIu64, CDTIME_T_TO_MS(vl->time));
BUFFER_ADD(",");
BUFFER_ADD("%" PRIi64, vl->values[ds_idx].derive);
} else if (ds->ds[ds_idx].type == DS_TYPE_ABSOLUTE) {
BUFFER_ADD("[[");
BUFFER_ADD("%" PRIu64, CDTIME_T_TO_MS(vl->time));
BUFFER_ADD(",");
BUFFER_ADD("%" PRIu64, vl->values[ds_idx].absolute);
} else {
ERROR("format_kairosdb: Unknown data source type: %i", ds->ds[ds_idx].type);
sfree(rates);
return -1;
}
BUFFER_ADD("]]");
#undef BUFFER_ADD
DEBUG("format_kairosdb: values_to_kairosdb: buffer = %s;", buffer);
sfree(rates);
return 0;
} /* }}} int values_to_kairosdb */
示例11: davinci_musb_interrupt
static irqreturn_t davinci_musb_interrupt(int irq, void *__hci)
{
unsigned long flags;
irqreturn_t retval = IRQ_NONE;
struct musb *musb = __hci;
void __iomem *tibase = musb->ctrl_base;
struct cppi *cppi;
u32 tmp;
spin_lock_irqsave(&musb->lock, flags);
/* NOTE: DaVinci shadows the Mentor IRQs. Don't manage them through
* the Mentor registers (except for setup), use the TI ones and EOI.
*
* Docs describe irq "vector" registers associated with the CPPI and
* USB EOI registers. These hold a bitmask corresponding to the
* current IRQ, not an irq handler address. Would using those bits
* resolve some of the races observed in this dispatch code??
*/
/* CPPI interrupts share the same IRQ line, but have their own
* mask, state, "vector", and EOI registers.
*/
cppi = container_of(musb->dma_controller, struct cppi, controller);
if (is_cppi_enabled(musb) && musb->dma_controller && !cppi->irq)
retval = cppi_interrupt(irq, __hci);
/* ack and handle non-CPPI interrupts */
tmp = musb_readl(tibase, DAVINCI_USB_INT_SRC_MASKED_REG);
musb_writel(tibase, DAVINCI_USB_INT_SRC_CLR_REG, tmp);
DBG(4, "IRQ %08x\n", tmp);
musb->int_rx = (tmp & DAVINCI_USB_RXINT_MASK)
>> DAVINCI_USB_RXINT_SHIFT;
musb->int_tx = (tmp & DAVINCI_USB_TXINT_MASK)
>> DAVINCI_USB_TXINT_SHIFT;
musb->int_usb = (tmp & DAVINCI_USB_USBINT_MASK)
>> DAVINCI_USB_USBINT_SHIFT;
/* DRVVBUS irqs are the only proxy we have (a very poor one!) for
* DaVinci's missing ID change IRQ. We need an ID change IRQ to
* switch appropriately between halves of the OTG state machine.
* Managing DEVCTL.SESSION per Mentor docs requires we know its
* value, but DEVCTL.BDEVICE is invalid without DEVCTL.SESSION set.
* Also, DRVVBUS pulses for SRP (but not at 5V) ...
*/
if (tmp & (DAVINCI_INTR_DRVVBUS << DAVINCI_USB_USBINT_SHIFT)) {
int drvvbus = musb_readl(tibase, DAVINCI_USB_STAT_REG);
void __iomem *mregs = musb->mregs;
u8 devctl = musb_readb(mregs, MUSB_DEVCTL);
int err = musb->int_usb & MUSB_INTR_VBUSERROR;
err = is_host_enabled(musb)
&& (musb->int_usb & MUSB_INTR_VBUSERROR);
if (err) {
/* The Mentor core doesn't debounce VBUS as needed
* to cope with device connect current spikes. This
* means it's not uncommon for bus-powered devices
* to get VBUS errors during enumeration.
*
* This is a workaround, but newer RTL from Mentor
* seems to allow a better one: "re"starting sessions
* without waiting (on EVM, a **long** time) for VBUS
* to stop registering in devctl.
*/
musb->int_usb &= ~MUSB_INTR_VBUSERROR;
musb->xceiv->state = OTG_STATE_A_WAIT_VFALL;
mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ);
WARNING("VBUS error workaround (delay coming)\n");
} else if (is_host_enabled(musb) && drvvbus) {
MUSB_HST_MODE(musb);
musb->xceiv->default_a = 1;
musb->xceiv->state = OTG_STATE_A_WAIT_VRISE;
portstate(musb->port1_status |= USB_PORT_STAT_POWER);
del_timer(&otg_workaround);
} else {
musb->is_active = 0;
MUSB_DEV_MODE(musb);
musb->xceiv->default_a = 0;
musb->xceiv->state = OTG_STATE_B_IDLE;
portstate(musb->port1_status &= ~USB_PORT_STAT_POWER);
}
/* NOTE: this must complete poweron within 100 msec
* (OTG_TIME_A_WAIT_VRISE) but we don't check for that.
*/
davinci_musb_source_power(musb, drvvbus, 0);
DBG(2, "VBUS %s (%s)%s, devctl %02x\n",
drvvbus ? "on" : "off",
otg_state_string(musb),
err ? " ERROR" : "",
devctl);
retval = IRQ_HANDLED;
}
if (musb->int_tx || musb->int_rx || musb->int_usb)
retval |= musb_interrupt(musb);
/* irq stays asserted until EOI is written */
musb_writel(tibase, DAVINCI_USB_EOI_REG, 0);
//.........这里部分代码省略.........
示例12: connection_open_tcp
bool connection_open_tcp(connection *con, const char *host, const char *service)
{
EXPECT_FATAL(con);
EXPECT_FATAL(host);
EXPECT_FATAL(service);
EXPECT_FATAL(sizeof(con->mem) >= sizeof(SOCKET));
if (strnlen(host, 256) > 255) { X(bad_arg, XSTR_LIMIT": host must not exceed 255 octets"); }
SOCKET s = INVALID_SOCKET;
// method e.g. "GET"
// host e.g. "example.org"
// rsc e.g. "/index.html"
// port e.g. 80
const struct addrinfo hints =
{
AI_NUMERICSERV | AI_ADDRCONFIG, // ai_flags
AF_UNSPEC, // ai_family: AF_INET | AF_INET6 | AF_UNSPEC
SOCK_STREAM, // ai_socktype (TCP)
IPPROTO_TCP, // ai_protocol (TCP)
0,
NULL,
NULL,
NULL,
};
struct addrinfo *result;
int ret = getaddrinfo(host, service, &hints, &result);
if (ret != 0) { Xf(lookup_address, XSTR_NETWORK": (%s) %s", host, getaddrinfo_strerror(ret)); }
for (struct addrinfo *current = result; current; current = current->ai_next)
{
s = socket(current->ai_family, current->ai_socktype, current->ai_protocol);
if (s == INVALID_SOCKET) { Xf(socket, XSTR_NETWORK ": socket() errno=%d\n", socket_geterr()); }
ret = socket_connect(s, current->ai_addr, current->ai_addrlen);
if (ret != 0) { Xf(connect, XSTR_NETWORK ": connect() errno=%d\n", socket_geterr()); }
memset(con->address, '\0', CFW_INET6_ADDRSTRLEN);
# ifndef TARGET_WINDOWS
if(!inet_ntop(current->ai_family,
&((struct sockaddr_in *) current->ai_addr)->sin_addr,
con->address, CFW_INET6_ADDRSTRLEN)
) { WARNING("inet_ntop() IP lookup failure"); }
# endif
// success
break;
// fallthru
err_connect:
socket_close(s);
err_socket:
continue;
}
freeaddrinfo(result);
if (s == INVALID_SOCKET) { X(no_match, "No matching socket"); }
memcpy(con, &s, sizeof(SOCKET));
strcpy(con->host, host);
return true;
err_no_match:
freeaddrinfo(result);
err_lookup_address:
err_bad_arg:
return false;
}
示例13: nsc_dclm_pbc
int nsc_dclm_pbc(const rvec *coords, real *radius, int nat,
int densit, int mode,
real *value_of_area, real **at_area,
real *value_of_vol,
real **lidots, int *nu_dots,
atom_id index[], int ePBC, matrix box)
{
int iat, i, ii, iii, ix, iy, iz, ixe, ixs, iye, iys, ize, izs, i_ac;
int jat, j, jj, jjj, jx, jy, jz;
int distribution;
int l;
int maxnei, nnei, last, maxdots = 0;
int *wkdot = NULL, *wkbox = NULL, *wkat1 = NULL, *wkatm = NULL;
Neighb *wknb, *ctnb;
int iii1, iii2, iiat, lfnr = 0, i_at, j_at;
real dx, dy, dz, dd, ai, aisq, ajsq, aj, as, a;
real xi, yi, zi, xs = 0., ys = 0., zs = 0.;
real dotarea, area, vol = 0.;
real *xus, *dots = NULL, *atom_area = NULL;
int nxbox, nybox, nzbox, nxy, nxyz;
real xmin = 0, ymin = 0, zmin = 0, xmax, ymax, zmax, ra2max, d;
const real *pco;
/* Added DvdS 2006-07-19 */
t_pbc pbc;
rvec ddx, *x = NULL;
int iat_xx, jat_xx;
distribution = unsp_type(densit);
if (distribution != -last_unsp || last_cubus != 4 ||
(densit != last_densit && densit != last_n_dot))
{
if (make_unsp(densit, (-distribution), &n_dot, 4))
{
return 1;
}
}
xus = xpunsp;
dotarea = FOURPI/(real) n_dot;
area = 0.;
if (debug)
{
fprintf(debug, "nsc_dclm: n_dot=%5d %9.3f\n", n_dot, dotarea);
}
/* start with neighbour list */
/* calculate neighbour list with the box algorithm */
if (nat == 0)
{
WARNING("nsc_dclm: no surface atoms selected");
return 1;
}
if (mode & FLAG_VOLUME)
{
vol = 0.;
}
if (mode & FLAG_DOTS)
{
maxdots = (3*n_dot*nat)/10;
/* should be set to NULL on first user call */
if (dots == NULL)
{
snew(dots, maxdots);
}
else
{
srenew(dots, maxdots);
}
lfnr = 0;
}
if (mode & FLAG_ATOM_AREA)
{
/* should be set to NULL on first user call */
if (atom_area == NULL)
{
snew(atom_area, nat);
}
else
{
srenew(atom_area, nat);
}
}
/* Compute minimum size for grid cells */
ra2max = radius[index[0]];
for (iat_xx = 1; (iat_xx < nat); iat_xx++)
{
iat = index[iat_xx];
ra2max = max(ra2max, radius[iat]);
}
ra2max = 2*ra2max;
/* Added DvdS 2006-07-19 */
/* Updated 2008-10-09 */
if (box)
{
set_pbc(&pbc, ePBC, box);
snew(x, nat);
//.........这里部分代码省略.........
示例14: make_unsp
int make_unsp(int densit, int mode, int * num_dot, int cubus)
{
int *ico_wk, *ico_pt;
int ndot, ico_cube_cb, i, j, k, l, ijk, tn, tl, tl2;
real *xus;
int *work;
real x, y, z;
if (xpunsp)
{
free(xpunsp);
}
k = 1; if (mode < 0)
{
k = 0; mode = -mode;
}
if (mode == UNSP_ICO_ARC)
{
ndot = ico_dot_arc(densit);
}
else if (mode == UNSP_ICO_DOD)
{
ndot = ico_dot_dod(densit);
}
else
{
WARNING("make_unsp: mode %c%d not allowed", (k) ? '+' : '-', mode);
return 1;
}
last_n_dot = ndot; last_densit = densit; last_unsp = mode;
*num_dot = ndot; if (k)
{
return 0;
}
/* in the following the dots of the unit sphere may be resorted */
last_unsp = -last_unsp;
/* determine distribution of points in elementary cubes */
if (cubus)
{
ico_cube = cubus;
}
else
{
last_cubus = 0;
i = 1;
while (i*i*i*2 < ndot)
{
i++;
}
ico_cube = max(i-1, 0);
}
ico_cube_cb = ico_cube*ico_cube*ico_cube;
del_cube = 2./((real)ico_cube);
snew(work, ndot);
xus = xpunsp;
for (l = 0; l < ndot; l++)
{
i = max((int) floor((1.+xus[3*l])/del_cube), 0);
if (i >= ico_cube)
{
i = ico_cube-1;
}
j = max((int) floor((1.+xus[1+3*l])/del_cube), 0);
if (j >= ico_cube)
{
j = ico_cube-1;
}
k = max((int) floor((1.+xus[2+3*l])/del_cube), 0);
if (k >= ico_cube)
{
k = ico_cube-1;
}
ijk = i+j*ico_cube+k*ico_cube*ico_cube;
work[l] = ijk;
}
snew(ico_wk, 2*ico_cube_cb+1);
ico_pt = ico_wk+ico_cube_cb;
for (l = 0; l < ndot; l++)
{
ico_wk[work[l]]++; /* dots per elementary cube */
}
/* reordering of the coordinate array in accordance with box number */
tn = 0;
for (i = 0; i < ico_cube; i++)
{
for (j = 0; j < ico_cube; j++)
{
for (k = 0; k < ico_cube; k++)
{
tl = 0;
tl2 = tn;
ijk = i+ico_cube*j+ico_cube*ico_cube*k;
*(ico_pt+ijk) = tn;
//.........这里部分代码省略.........
示例15: iio_create_xml_context_helper
static struct iio_context * iio_create_xml_context_helper(xmlDoc *doc)
{
unsigned int i;
xmlNode *root, *n;
xmlAttr *attr;
int err = ENOMEM;
struct iio_context *ctx = calloc(1, sizeof(*ctx));
if (!ctx)
goto err_set_errno;
ctx->name = "xml";
ctx->ops = &xml_ops;
root = xmlDocGetRootElement(doc);
if (strcmp((char *) root->name, "context")) {
ERROR("Unrecognized XML file\n");
err = EINVAL;
goto err_free_ctx;
}
for (attr = root->properties; attr; attr = attr->next) {
if (!strcmp((char *) attr->name, "description"))
ctx->description = _strdup(
(char *) attr->children->content);
else if (strcmp((char *) attr->name, "name"))
WARNING("Unknown parameter \'%s\' in <context>\n",
(char *) attr->children->content);
}
for (n = root->children; n; n = n->next) {
struct iio_device **devs, *dev;
if (strcmp((char *) n->name, "device")) {
if (strcmp((char *) n->name, "text"))
WARNING("Unknown children \'%s\' in "
"<context>\n", n->name);
continue;
}
dev = create_device(ctx, n);
if (!dev) {
ERROR("Unable to create device\n");
goto err_free_devices;
}
devs = realloc(ctx->devices, (1 + ctx->nb_devices) *
sizeof(struct iio_device *));
if (!devs) {
ERROR("Unable to allocate memory\n");
free(dev);
goto err_free_devices;
}
devs[ctx->nb_devices++] = dev;
ctx->devices = devs;
}
iio_context_init(ctx);
return ctx;
err_free_devices:
for (i = 0; i < ctx->nb_devices; i++)
free_device(ctx->devices[i]);
if (ctx->nb_devices)
free(ctx->devices);
err_free_ctx:
free(ctx);
err_set_errno:
errno = err;
return NULL;
}