本文整理汇总了C++中OPT_ARG函数的典型用法代码示例。如果您正苦于以下问题:C++ OPT_ARG函数的具体用法?C++ OPT_ARG怎么用?C++ OPT_ARG使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了OPT_ARG函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update_server_color
//*******************************************************************
// UPDATE SERVER COLOR
//*******************************************************************
static void update_server_color(trx *t, struct probe_result *prv)
{
dbi_result result;
int maxcolor, newcolor;
if (t->def->server < 2) return;
if (t->probe->fuse && (t->res->color < prv->color)) {
// if this probe acts like a fuse, use the previous color if it's higher
newcolor = prv->color;
} else {
newcolor = t->res->color;
}
maxcolor = newcolor; // init
result = db_query(t->probe->db, 0,
"select max(color) as color from pr_status where server = '%u'", t->def->server);
if (result && dbi_result_next_row(result)) {
maxcolor = dbi_result_get_uint(result, "color");
}
dbi_result_free(result);
//if (t->res->color <= maxcolor) return;
result = db_query(t->probe->db, 0,
// update server set color = '200' where id = '345'
"update %s set %s = '%u' where %s = '%u'",
OPT_ARG(SERVER_TABLE_NAME), OPT_ARG(SERVER_TABLE_COLOR_FIELD),
maxcolor, OPT_ARG(SERVER_TABLE_ID_FIELD), t->def->server);
dbi_result_free(result);
}
示例2: load_cert
static gnutls_x509_crt_t
load_cert (void)
{
gnutls_x509_crt_t crt;
int ret;
gnutls_datum_t dat;
size_t size;
if (!HAVE_OPT(LOAD_CERT))
error (EXIT_FAILURE, 0, "missing --load-cert");
ret = gnutls_x509_crt_init (&crt);
if (ret < 0)
error (EXIT_FAILURE, 0, "crt_init: %s", gnutls_strerror (ret));
dat.data = (void*)read_binary_file (OPT_ARG(LOAD_CERT), &size);
dat.size = size;
if (!dat.data)
error (EXIT_FAILURE, errno, "reading --load-cert: %s", OPT_ARG(LOAD_CERT));
ret = gnutls_x509_crt_import (crt, &dat, encoding);
free (dat.data);
if (ret < 0)
error (EXIT_FAILURE, 0, "importing --load-cert: %s: %s",
OPT_ARG(LOAD_CERT), gnutls_strerror (ret));
return crt;
}
示例3: run
int run(void)
{
database *db;
if (!cache) {
cache = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, free_probe);
}
LOG(LOG_INFO, "reading info from database (group %u)", (unsigned)OPT_VALUE_GROUPID);
uw_setproctitle("reading info from database (group %u)", (unsigned)OPT_VALUE_GROUPID);
db = open_database(OPT_ARG(DBTYPE), OPT_ARG(DBHOST), OPT_VALUE_DBPORT, OPT_ARG(DBNAME),
OPT_ARG(DBUSER), OPT_ARG(DBPASSWD));
if (db) {
refresh_database(db);
close_database(db);
}
if (g_hash_table_size(cache) > 0) {
LOG(LOG_INFO, "running %d probes from group %u", g_hash_table_size(cache), (unsigned)OPT_VALUE_GROUPID);
uw_setproctitle("running %d probes from group %u", g_hash_table_size(cache), (unsigned)OPT_VALUE_GROUPID);
run_actual_probes(); /* this runs the actual probes */
LOG(LOG_INFO, "writing results");
uw_setproctitle("writing results");
write_results();
}
return(g_hash_table_size(cache));
}
示例4: run
int run(void)
{
#ifdef USE_ST
st_usleep(1); //force context switch so timers will work
#endif
g_hash_table_foreach(hash, create_q_threads, NULL);
#ifdef USE_ST
if (debug > 3) { LOG(LOG_DEBUG, "waiting for all threads to finish"); }
while (thread_count) {
st_usleep(10000); /* 10 ms */
}
#endif
if (HAVE_OPT(HANGUPSCRIPT) && online) {
int status;
status = system(OPT_ARG(HANGUPSCRIPT));
if (WIFEXITED(status)) {
if (WEXITSTATUS(status) != 0) {
LOG(LOG_WARNING, "%s: error %d", OPT_ARG(HANGUPSCRIPT), WEXITSTATUS(status));
}
} else {
LOG(LOG_ERR, "%s exited abnormally", OPT_ARG(HANGUPSCRIPT));
}
}
online = FALSE;
uw_setproctitle("sleeping");
return 0;
}
示例5: find_expired_probes
int find_expired_probes(struct dbspec *dbspec)
{
xmlDocPtr doc;
xmlNodePtr probe;
dbi_result result;
dbi_conn conn;
int count = 0;
char buf[10];
sprintf(buf, "%d", dbspec->port);
conn = open_database(OPT_ARG(DBTYPE), dbspec->host, buf, dbspec->db,
dbspec->user, dbspec->password);
if (!conn) return 0;
doc = UpwatchXmlDoc("result", NULL);
// find all expired probes, but skip those for which processing
// has been stopped for some reason
result = db_query(conn, 0, "select probe.name, pr_status.probe, "
" pr_status.server, pr_status.color, "
" pr_status.expires "
"from pr_status, probe "
"where probe.id = pr_status.class and color <> 400 "
" and expires < UNIX_TIMESTAMP()-30 "
" and expires < probe.lastseen"
" and probe.expiry = 'yes'");
if (!result) goto errexit;
while (dbi_result_next_row(result)) {
char buffer[256];
time_t now = time(NULL);
probe = xmlNewChild(xmlDocGetRootElement(doc), NULL, dbi_result_get_string(result, "name"), NULL);
xmlSetProp(probe, "realm", dbspec->realm);
xmlSetProp(probe, "id", dbi_result_get_string(result, "probe"));
xmlSetProp(probe, "server", dbi_result_get_string(result, "server"));
sprintf(buffer, "%u", (int) now); xmlSetProp(probe, "date", buffer);
xmlSetProp(probe, "expires", dbi_result_get_string(result, "expires"));
xmlNewChild(probe, NULL, "color", "400"); // PURPLE
xmlNewChild(probe, NULL, "prevcolor", dbi_result_get_string(result, "color"));
LOG(LOG_INFO, "%s: purpled %s %d", dbspec->realm, dbi_result_get_string(result, "name"),
dbi_result_get_uint(result, "probe"));
count++;
}
if (count) {
xmlSetDocCompressMode(doc, OPT_VALUE_COMPRESS);
spool_result(OPT_ARG(SPOOLDIR), OPT_ARG(OUTPUT), doc, NULL);
LOG(LOG_INFO, "%s: purpled %u probes", dbspec->realm, count);
}
errexit:
if (result) dbi_result_free(result);
if (conn) close_database(conn);
if (doc) xmlFreeDoc(doc);
return count;
}
示例6: main
int main(int argc, char **argv)
{
int ret;
if ((ret = gnutls_global_init()) < 0) {
fprintf(stderr, "global_init: %s\n", gnutls_strerror(ret));
exit(1);
}
optionProcess(&ocsptoolOptions, argc, argv);
gnutls_global_set_log_function(tls_log_func);
gnutls_global_set_log_level(OPT_VALUE_DEBUG);
if (HAVE_OPT(OUTFILE)) {
outfile = fopen(OPT_ARG(OUTFILE), "wb");
if (outfile == NULL) {
fprintf(stderr, "%s\n", OPT_ARG(OUTFILE));
exit(1);
}
} else
outfile = stdout;
if (HAVE_OPT(INFILE)) {
infile = fopen(OPT_ARG(INFILE), "rb");
if (infile == NULL) {
fprintf(stderr, "%s\n", OPT_ARG(INFILE));
exit(1);
}
} else
infile = stdin;
if (ENABLED_OPT(INDER))
encoding = GNUTLS_X509_FMT_DER;
else
encoding = GNUTLS_X509_FMT_PEM;
if (HAVE_OPT(REQUEST_INFO))
request_info();
else if (HAVE_OPT(RESPONSE_INFO))
response_info();
else if (HAVE_OPT(GENERATE_REQUEST))
generate_request(NULL);
else if (HAVE_OPT(VERIFY_RESPONSE))
verify_response(NULL);
else if (HAVE_OPT(ASK))
ask_server(OPT_ARG(ASK));
else {
USAGE(1);
}
return 0;
}
示例7: printHeader
static xmlNodePtr
printHeader( xmlDocPtr pDoc )
{
tSCC zDef[] = "AutoGen Definitions %s%s;\n";
char const* pzSfx = ".tpl";
xmlNodePtr pRootNode = xmlDocGetRootElement( pDoc );
xmlChar* pTpl = NULL;
xmlChar* pzTpl;
if (pRootNode == NULL) {
fprintf( stderr, "Root node not found\n" );
exit( EXIT_FAILURE );
}
if (HAVE_OPT( OVERRIDE_TPL )) {
if (strchr( OPT_ARG( OVERRIDE_TPL ), '.' ) != NULL)
pzSfx = "";
pzTpl = (xmlChar*)(void*)OPT_ARG( OVERRIDE_TPL );
}
else {
pTpl = xmlGetProp( pRootNode, (xmlChar*)(void*)"template" );
if (pTpl == NULL) {
fprintf( stderr, "No template was specified.\n" );
exit( EXIT_FAILURE );
}
pzTpl = pTpl;
if (strchr( (char*)pzTpl, '.' ) != NULL)
pzSfx = "";
}
fprintf( outFp, zDef, pzTpl, pzSfx );
if (pTpl != NULL)
free( pTpl );
if (pDoc->name != NULL)
fprintf( outFp, "XML-name = '%s';\n", TRIM( pDoc->name, NULL ));
if (pDoc->version != NULL)
fprintf( outFp, "XML-version = '%s';\n", TRIM( pDoc->version, NULL ));
if (pDoc->encoding != NULL)
fprintf( outFp, "XML-encoding = '%s';\n", TRIM( pDoc->encoding, NULL ));
if (pDoc->URL != NULL)
fprintf( outFp, "XML-URL = '%s';\n", TRIM( pDoc->URL, NULL ));
if (pDoc->standalone)
fputs( "XML-standalone = true;\n", outFp );
return pRootNode;
}
示例8: bin_syserror
static int
bin_syserror(char *nam, char **args, Options ops, UNUSED(int func))
{
int num = 0;
char *errvar = NULL, *msg, *pfx = "", *str;
/* variable in which to write error message */
if (OPT_ISSET(ops, 'e')) {
errvar = OPT_ARG(ops, 'e');
if (!isident(errvar)) {
zwarnnam(nam, "not an identifier: %s", errvar);
return 1;
}
}
/* prefix for error message */
if (OPT_ISSET(ops, 'p'))
pfx = OPT_ARG(ops, 'p');
if (!*args)
num = errno;
else {
char *ptr = *args;
while (*ptr && idigit(*ptr))
ptr++;
if (!*ptr && ptr > *args)
num = atoi(*args);
else {
const char **eptr;
for (eptr = sys_errnames; *eptr; eptr++) {
if (!strcmp(*eptr, *args)) {
num = (eptr - sys_errnames) + 1;
break;
}
}
if (!*eptr)
return 2;
}
}
msg = strerror(num);
if (errvar) {
str = (char *)zalloc(strlen(msg) + strlen(pfx) + 1);
sprintf(str, "%s%s", pfx, msg);
setsparam(errvar, str);
} else {
fprintf(stderr, "%s%s\n", pfx, msg);
}
return 0;
}
示例9: request_info
static void
request_info (void)
{
gnutls_ocsp_req_t req;
int ret;
gnutls_datum_t dat;
size_t size;
ret = gnutls_ocsp_req_init (&req);
if (ret < 0)
error (EXIT_FAILURE, 0, "ocsp_req_init: %s", gnutls_strerror (ret));
if (HAVE_OPT(LOAD_REQUEST))
dat.data = (void*)read_binary_file (OPT_ARG(LOAD_REQUEST), &size);
else
dat.data = (void*)fread_file (infile, &size);
if (dat.data == NULL)
error (EXIT_FAILURE, errno, "reading request");
dat.size = size;
ret = gnutls_ocsp_req_import (req, &dat);
free (dat.data);
if (ret < 0)
error (EXIT_FAILURE, 0, "importing request: %s", gnutls_strerror (ret));
ret = gnutls_ocsp_req_print (req, GNUTLS_OCSP_PRINT_FULL, &dat);
if (ret != 0)
error (EXIT_FAILURE, 0, "ocsp_req_print: %s", gnutls_strerror (ret));
printf ("%.*s", dat.size, dat.data);
gnutls_free (dat.data);
gnutls_ocsp_req_deinit (req);
}
示例10: verify_response
static void verify_response(gnutls_datum_t *nonce)
{
gnutls_datum_t dat;
size_t size;
gnutls_x509_crt_t signer;
int v;
if (HAVE_OPT(LOAD_RESPONSE))
dat.data =
(void *) read_binary_file(OPT_ARG(LOAD_RESPONSE),
&size);
else
dat.data = (void *) fread_file(infile, &size);
if (dat.data == NULL) {
fprintf(stderr, "error reading response\n");
exit(1);
}
dat.size = size;
signer = load_signer();
v = _verify_response(&dat, nonce, signer);
if (v && !HAVE_OPT(IGNORE_ERRORS))
exit(1);
}
示例11: bin_sysopen
static int
bin_sysopen(char *nam, char **args, Options ops, UNUSED(int func))
{
int read = OPT_ISSET(ops, 'r');
int write = OPT_ISSET(ops, 'w');
int append = OPT_ISSET(ops, 'a') ? O_APPEND : 0;
int flags = O_NOCTTY | append | ((append || write) ?
(read ? O_RDWR : O_WRONLY) : O_RDONLY);
char *opt, *ptr, *nextopt, *fdvar;
int o, fd, explicit = -1;
mode_t perms = 0666;
#if defined(FD_CLOEXEC) && !defined(O_CLOEXEC)
int fdflags;
#endif
if (!OPT_ISSET(ops, 'u')) {
zwarnnam(nam, "file descriptor not specified");
return 1;
}
/* file descriptor, either 0-9 or a variable name */
fdvar = OPT_ARG(ops, 'u');
if (idigit(*fdvar) && !fdvar[1]) {
explicit = atoi(fdvar);
} else if (!isident(fdvar)) {
示例12: cmd_parser
static void cmd_parser(int argc, char **argv)
{
const char *rest = NULL;
int optct = optionProcess(&gnutls_cli_debugOptions, argc, argv);
argc -= optct;
argv += optct;
if (rest == NULL && argc > 0)
rest = argv[0];
if (HAVE_OPT(PORT))
port = OPT_VALUE_PORT;
else {
if (HAVE_OPT(STARTTLS_PROTO))
port = starttls_proto_to_port(OPT_ARG(STARTTLS_PROTO));
else
port = 443;
}
if (rest == NULL)
hostname = "localhost";
else
hostname = rest;
if (HAVE_OPT(DEBUG))
debug = OPT_VALUE_DEBUG;
if (HAVE_OPT(VERBOSE))
verbose++;
}
示例13: bb_cpu_find_realm
// determine - given the servername - the db realm it belongs to.
int bb_cpu_find_realm(trx *t)
{
int i, server;
query_server_by_name = NULL;
for (i=0; i < dblist_cnt; i++) {
t->probe->db = open_realm(dblist[i].realm, OPT_ARG(DBTYPE), OPT_ARG(DBHOST), OPT_VALUE_DBPORT, OPT_ARG(DBNAME), OPT_ARG(DBUSER), OPT_ARG(DBPASSWD));
server = realm_server_by_name(dblist[i].realm, t->res->hostname);
if (server > 1) {
t->res->server = server;
t->res->realm = strdup(dblist[i].realm);
query_server_by_name = dblist[i].srvrbyname;
break;
}
}
return 1;
}
示例14: bin_syswrite
static int
bin_syswrite(char *nam, char **args, Options ops, UNUSED(int func))
{
int outfd = 1, len, count, totcount;
char *countvar = NULL;
/* -o: output file descriptor if not stdout */
if (OPT_ISSET(ops, 'o')) {
outfd = getposint(OPT_ARG(ops, 'o'), nam);
if (outfd < 0)
return 1;
}
/* -c: variable in which to store count of bytes written */
if (OPT_ISSET(ops, 'c')) {
countvar = OPT_ARG(ops, 'c');
if (!isident(countvar)) {
zwarnnam(nam, "not an identifier: %s", countvar);
return 1;
}
}
totcount = 0;
unmetafy(*args, &len);
while (len) {
while ((count = write(outfd, *args, len)) < 0) {
if (errno != EINTR || errflag || retflag || breaks || contflag)
{
if (countvar)
setiparam(countvar, totcount);
return 2;
}
}
*args += count;
totcount += count;
len -= count;
}
if (countvar)
setiparam(countvar, totcount);
return 0;
}
示例15: add_sysstat_info
void add_sysstat_info(xmlNodePtr node)
{
char info[32768];
if (st.load) {
if (st.load->min1 >= atof(OPT_ARG(LOADAVG_YELLOW))) {
char cmd[1024];
char buffer[24];
FILE *in;
if (st.load->min1 >= atof(OPT_ARG(LOADAVG_YELLOW))) sprintf(buffer, "%d", STAT_YELLOW);
if (st.load->min1 >= atof(OPT_ARG(LOADAVG_RED))) sprintf(buffer, "%d", STAT_RED);
xmlSetProp(node, "color", buffer);
sprintf(cmd, "%s > /tmp/.uw_sysstat.tmp", OPT_ARG(TOP_COMMAND));
LOG(LOG_INFO, cmd);
uw_setproctitle("running %s", OPT_ARG(TOP_COMMAND));
system(cmd);
in = fopen("/tmp/.uw_sysstat.tmp", "r");
if (in) {
signed char *s = info;
size_t len;
for (len=0; len < sizeof(info)-1; len++) {
int c;
if ((c = fgetc(in)) != EOF) {
if (c < 0) c = ' ';
*s++ = c;
}
}
*s = 0;
fclose(in);
} else {
strcpy(info, strerror(errno));
}
unlink("/tmp/.uw_sysstat.tmp");
xmlNewTextChild(node, NULL, "info", info);
}
}
}