本文整理汇总了C++中parse_command函数的典型用法代码示例。如果您正苦于以下问题:C++ parse_command函数的具体用法?C++ parse_command怎么用?C++ parse_command使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_command函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
if (setsid() == -1)
{
perror("[controld] setsid");
return -1;
}
eventServer = new CEventServer;
struct sockaddr_un servaddr;
int clilen;
memset(&servaddr, 0, sizeof(struct sockaddr_un));
servaddr.sun_family = AF_UNIX;
strcpy(servaddr.sun_path, CONTROLD_UDS_NAME);
clilen = sizeof(servaddr.sun_family) + strlen(servaddr.sun_path);
unlink(CONTROLD_UDS_NAME);
//network-setup
if ((listenfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
{
perror("socket");
}
if ( bind(listenfd, (struct sockaddr*) &servaddr, clilen) <0 )
{
perror("[controld] bind failed...\n");
exit(-1);
}
if (listen(listenfd, 5) !=0)
{
perror("[controld] listen failed...\n");
exit( -1 );
}
//busyBox
signal(SIGHUP,sig_catch);
signal(SIGINT,sig_catch);
signal(SIGQUIT,sig_catch);
signal(SIGTERM,sig_catch);
/* load configuration */
config = new CConfigFile(',');
if (!config->loadConfig(CONF_FILE))
{
/* set defaults if no configuration file exists */
printf("[controld] %s not found\n", CONF_FILE);
}
settings.volume = config->getInt32("volume", 100);
settings.volume_avs = config->getInt32("volume_avs", 100);
settings.mute = config->getBool("mute", false);
settings.mute_avs = config->getBool("mute_avs", false);
settings.videooutput = config->getInt32("videooutput", 1); // fblk1 - rgb
settings.videoformat = config->getInt32("videoformat", 2); // fnc2 - 4:3
setBoxType(); // dummy set - liest den aktuellen Wert aus!
watchDog = new CEventWatchDog();
aspectRatioNotifier = new CControldAspectRatioNotifier();
watchDog->registerNotifier(WDE_VIDEOMODE, aspectRatioNotifier);
//init
audioControl::setVolume(map_volume(settings.volume_avs, true));
zapit.setVolume(map_volume(settings.volume, false), map_volume(settings.volume, false));
lcdd.setVolume(settings.volume_avs); // we could also display settings.volume at startup
audioControl::setMute(settings.mute_avs);
zapit.muteAudio(settings.mute);
lcdd.setMute(settings.mute || settings.mute_avs);
setvideooutput(settings.videooutput);
setVideoFormat(settings.videoformat, false);
try
{
struct CControld::Header rmessage;
while(true)
{
connfd = accept(listenfd, (struct sockaddr*) &servaddr, (socklen_t*) &clilen);
memset(&rmessage, 0, sizeof(rmessage));
read(connfd,&rmessage,sizeof(rmessage));
parse_command(connfd, &rmessage);
close(connfd);
}
}
catch (std::exception& e)
{
printf("[controld] caught std-exception in main-thread %s!\n", e.what());
}
catch (...)
{
printf("[controld] caught exception in main-thread!\n");
}
}
开发者ID:GWARDAR,项目名称:OpenPLi-1,代码行数:101,代码来源:controld.cpp
示例2: send_list_of_active_checks_json
/******************************************************************************
* *
* Function: send_list_of_active_checks_json *
* *
* Purpose: send list of active checks to the host *
* *
* Parameters: sock - open socket of server-agent connection *
* json - request buffer *
* *
* Return value: SUCCEED - list of active checks sent succesfully *
* FAIL - an error occured *
* *
* Author: Aleksander Vladishev *
* *
* Comments: *
* *
******************************************************************************/
int send_list_of_active_checks_json(zbx_sock_t *sock, struct zbx_json_parse *jp)
{
char host[HOST_HOST_LEN_MAX], *name_esc, params[MAX_STRING_LEN],
pattern[MAX_STRING_LEN], tmp[32];
DB_RESULT result;
DB_ROW row;
DB_ITEM item;
struct zbx_json json;
int res = FAIL;
zbx_uint64_t hostid;
char error[MAX_STRING_LEN];
char **regexp = NULL;
int regexp_alloc = 32;
int regexp_num = 0, n;
char *sql = NULL;
int sql_alloc = 2048;
int sql_offset;
zabbix_log(LOG_LEVEL_DEBUG, "In send_list_of_active_checks_json()");
if (FAIL == zbx_json_value_by_name(jp, ZBX_PROTO_TAG_HOST, host, sizeof(host)))
{
zbx_snprintf(error, MAX_STRING_LEN, "%s", zbx_json_strerror());
goto out;
}
if (FAIL == get_hostid_by_host(host, &hostid, error))
goto out;
regexp = zbx_malloc(regexp, regexp_alloc);
sql = zbx_malloc(sql, sql_alloc);
name_esc = DBdyn_escape_string(host);
sql_offset = 0;
zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, 1024,
"select %s where i.hostid=h.hostid and h.status=%d and i.type=%d and h.hostid=" ZBX_FS_UI64
" and h.proxy_hostid=0",
ZBX_SQL_ITEM_SELECT,
HOST_STATUS_MONITORED,
ITEM_TYPE_ZABBIX_ACTIVE,
hostid);
if (0 != CONFIG_REFRESH_UNSUPPORTED)
zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, 256, " and (i.status=%d or (i.status=%d and i.nextcheck<=%d))",
ITEM_STATUS_ACTIVE, ITEM_STATUS_NOTSUPPORTED, time(NULL));
else
zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, 256, " and i.status=%d",
ITEM_STATUS_ACTIVE);
zbx_free(name_esc);
zbx_json_init(&json, ZBX_JSON_STAT_BUF_LEN);
zbx_json_addstring(&json, ZBX_PROTO_TAG_RESPONSE, ZBX_PROTO_VALUE_SUCCESS, ZBX_JSON_TYPE_STRING);
zbx_json_addarray(&json, ZBX_PROTO_TAG_DATA);
result = DBselect("%s", sql);
while (NULL != (row = DBfetch(result)))
{
DBget_item_from_db(&item, row);
zbx_json_addobject(&json, NULL);
zbx_json_addstring(&json, ZBX_PROTO_TAG_KEY, item.key, ZBX_JSON_TYPE_STRING);
if (0 != strcmp(item.key, item.key_orig))
zbx_json_addstring(&json, ZBX_PROTO_TAG_KEY_ORIG, item.key_orig, ZBX_JSON_TYPE_STRING);
zbx_snprintf(tmp, sizeof(tmp), "%d", item.delay);
zbx_json_addstring(&json, ZBX_PROTO_TAG_DELAY, tmp, ZBX_JSON_TYPE_STRING);
zbx_snprintf(tmp, sizeof(tmp), "%d", item.lastlogsize);
zbx_json_addstring(&json, ZBX_PROTO_TAG_LOGLASTSIZE, tmp, ZBX_JSON_TYPE_STRING);
zbx_json_close(&json);
/* Special processing for log[] and eventlog[] items */
do { /* simple try realization */
if (0 != strncmp(item.key, "log[", 4) && 0 != strncmp(item.key, "eventlog[", 9))
break;
if (2 != parse_command(item.key, NULL, 0, params, MAX_STRING_LEN))
break;;
if (0 != get_param(params, 2, pattern, sizeof(pattern)))
//.........这里部分代码省略.........
开发者ID:rennhak,项目名称:zabbix,代码行数:101,代码来源:active.c
示例3: client
void client() {
int consock, registerfd, server_sockfd, client_sockfd;
int server_len, client_len;
struct sockaddr_in server_address;
struct sockaddr_in client_address;
int result;
char option[1024];
// consock=connect_client(2);
server_sockfd = socket(AF_INET, SOCK_STREAM, 0);
server_address.sin_family = AF_INET;
server_address.sin_addr.s_addr = htonl(INADDR_ANY);
server_address.sin_port = htons(PORTNO);
server_len = sizeof(server_address);
bind(server_sockfd, (struct sockaddr *) &server_address, server_len);
listen(server_sockfd, 5);
//initializing readfds to sockfd.
FD_ZERO(&readfds);
FD_SET(server_sockfd, &readfds);
FD_SET(0, &readfds);
while (1) // waiting for client requests
{
int fd;
int nread;
char ch[1024];
testfds = readfds;
result = select(FD_SETSIZE, &testfds, (fd_set *) 0, (fd_set *) 0,
(struct timeval *) 0);
if (result <= 0) {
perror("Error");
exit(1);
}
if (FD_ISSET(0, &testfds)) {
memset(option, '\0', 1024);
fgets(option, 1024, stdin);
option[strlen(option) - 1] = '\0';
parse_command(option);
}
else {
for (fd = 0; fd < FD_SETSIZE; fd++) {
if (FD_ISSET(fd, &testfds)) {
if (fd == server_sockfd)
{
client_sockfd = accept(server_sockfd,
(struct sockaddr *) &client_address,
&client_len);
FD_SET(client_sockfd, &readfds);
} else {
memset(ch, 0, 100);
ioctl(fd, FIONREAD, &nread);
if (nread == 0 && fd != 0)
{
close(fd);
int j;
////finding the fd in client connection////
for (j = 1; j < 4; j++) {
if (mycon[j].confd == fd) {
break;
}
}
////terminate the connection
terminate_con(mycon[j].con_id);
FD_CLR(fd, &readfds);
display_con();
} else {
char temp1[1024];
memset(ch, 0, 1024);
memset(temp1, 0, 1024);
read(fd, &ch, sizeof(ch));
strcpy(temp1, ch);
char *reader;
reader = strtok(temp1, " ");
if (reader != NULL) {
if (strcmp(reader, "send") == 0) {
read_table(fd, ch);
memset(ch, 0, 1024);
//.........这里部分代码省略.........
开发者ID:gvsurenderreddy,项目名称:Remote-File-Sharing-System-2,代码行数:101,代码来源:pdeshpan_proj1.c
示例4: switch
StompFrames StompCodec::loads(std::string& rxbuf)
{
const char* p;
char ch;
std::string name, value;
size_t n;
StompFrames frames;
const char *start = rxbuf.c_str();
const char *end = rxbuf.c_str() + rxbuf.size();
for (p = start; p != end; ++p) {
ch = *p;
switch (state_) {
case State::SW_COMMAND_BEGIN:
if (ch == CR || ch == LF) // heartbeat
break;
start = p;
frame_ = std::make_shared<StompFrame>();
state_ = State::SW_COMMAND;
break;
case State::SW_COMMAND:
if (ch == LF) {
n = p - start;
if (*(p - 1) == CR) --n;
frame_->cmd_ = parse_command(start, n);
state_ = State::SW_HEADER_BEGIN;
}
break;
case State::SW_HEADER_BEGIN:
if (ch == CR) {
if (*(p + 1) != LF)
goto dump_finish;
} else if (ch == LF) {
state_ = State::SW_BODY_BEGIN;
} else {
start = p;
state_ = State::SW_HEADER_NAME;
}
break;
case State::SW_HEADER_NAME:
if (ch == ':') {
n = p - start;
if (n == 0)
goto dump_finish;
else {
name.assign(start, n);
start = p + 1;
state_ = State::SW_HEADER_VALUE;
}
}
break;
case State::SW_HEADER_VALUE:
if (ch == LF) {
n = p - start;
if (*(p - 1) == CR) --n;
value.assign(start, n);
frame_->set_header(name, value);
state_ = State::SW_HEADER_BEGIN;
}
break;
case State::SW_BODY_BEGIN:
if (frame_->have_body()) {
if (expect_body_len_ == 0)
expect_body_len_ = frame_->get_content_length();
if (expect_body_len_ > 0) {
size_t remain = end - p;
if (remain > expect_body_len_) {
frame_->append_body(p, expect_body_len_);
frames.push_back(frame_);
state_ = State::SW_COMMAND_BEGIN;
} else {
frame_->append_body(p, remain);
expect_body_len_ -= remain;
}
} else {
start = p;
state_ = State::SW_BODY;
}
} else
state_ = State::SW_COMMAND_BEGIN;
break;
case State::SW_BODY:
if (ch == '\0') {
n = p - start;
frame_->append_body(start, n);
frames.push_back(frame_);
state_ = State::SW_COMMAND_BEGIN;
}
break;
}
}
if (state_ == State::SW_BODY) {
frame_->append_body(start, end - start);
rxbuf.clear();
} else
rxbuf.erase(0, start - rxbuf.c_str());
dump_finish:
return frames;
//.........这里部分代码省略.........
开发者ID:jiangzw,项目名称:gazellemq,代码行数:101,代码来源:stomp_codec.cpp
示例5: help_command_line
/* try to display help for current comand line
*/
static int help_command_line(tinysh_cmd_t *cmd, uchar *_str)
{
uchar *str=_str;
while(1)
{
int ret;
ret=parse_command(&cmd,&str);
if(ret==MATCH && *str==0) /* found unique match or empty line */
{
tinysh_cmd_t *cm;
int len=0;
if(cmd->child) /* display sub-commands help */
{
display_child_help(cmd->child);
return 0;
}
else /* no sub-command, show single help */
{
if(*(str-1)!=' ')
putchar(' ');
if(cmd->usage)
puts(cmd->usage);
puts(": ");
if(cmd->help)
puts(cmd->help);
else
puts("no help available");
putchar('\n');
}
return 0;
}
else if(ret==MATCH && *str)
{ /* continue processing the line */
cmd=cmd->child;
}
else if(ret==AMBIG)
{
puts("\nambiguity: ");
puts(str);
putchar('\n');
return 0;
}
else if(ret==UNMATCH)
{
puts("\nno match: ");
puts(str);
putchar('\n');
return 0;
}
else /* NULLMATCH */
{
if(cur_cmd_ctx)
display_child_help(cur_cmd_ctx->child);
else
display_child_help(root_cmd);
return 0;
}
}
}
开发者ID:hericz,项目名称:atinom_banyu,代码行数:63,代码来源:tinysh.c
示例6: main
//}}}
int main(int argc, char *argv[]){
int init_port;
int data_port;
int ctrl_socket;
int init_socket;
pid_t p;
int shmid_ctrl, shmid_mask, shmid_masklist;
int fd_s;
struct sockaddr_in cli;
char buffer[MAX_LENG];
socklen_t cli_len = sizeof(cli);
if(argc < 3){
fprintf(stderr, "get_raw hostname, port");
exit(1);
}
sscanf(argv[2],"%d", &init_port);
shmid_ctrl = shmget(SHMKEY_CTRL, SHLEN_CTRL, PERMS|IPC_CREAT); //share memory
shmid_mask = shmget(SHMKEY_MASK, SHLEN_MASK, PERMS|IPC_CREAT); //share memory
shmid_masklist = shmget(SHMKEY_MASKLIST, SHLEN_MASKLIST, PERMS|IPC_CREAT); //share memory
ctrl = (char *) shmat(shmid_ctrl, NULL, 0);
mask = (char *) shmat(shmid_mask, NULL, 0);
masklist = (char *) shmat(shmid_masklist, NULL, 0);
init();
data_port = get_data_socket_port(argv[1], init_port);
ctrl_socket = tcp_server(CTRL_PORT);
p = fork();
if(p <0){
fprintf(stderr, "fork error");
exit(1);
}
if(p == 0){
char buffer[MAX_LENG];
nice(3);
read_raw(argv[1], data_port);
exit(0);
}
nice(-1);
while(1){
if((fd_s = accept(ctrl_socket, (struct sockaddr*)&cli, &cli_len))<0){perror("ACCEPT error"); exit(1);}
if (!fork()){
read(fd_s, buffer, MAX_LENG);
if(parse_command(buffer, fd_s) ==1){
write(fd_s, "ok\r\n",4);
}
else
write(fd_s, "error\r\n",7);
exit(0);
close(fd_s);
}
close(fd_s);
while(waitpid(-1,NULL, WNOHANG)>0);
}
close(ctrl_socket);
}
开发者ID:goTJ,项目名称:tj,代码行数:62,代码来源:get_raw.c
示例7: do_in_parallel
/**
* Process two commands in parallel, by creating two children.
*/
static bool do_in_parallel(command_t *cmd1, command_t *cmd2, int level, command_t *father)
{
/* TODO execute cmd1 and cmd2 simultaneously */
BOOL ret_1, ret_2;
char* cmd;
SECURITY_ATTRIBUTES sa_1;
STARTUPINFO siStartupInfo_1;
PROCESS_INFORMATION piProcessInfo_1;
HANDLE hOutFile_1 = INVALID_HANDLE_VALUE;
HANDLE hInFile_1 = INVALID_HANDLE_VALUE;
HANDLE hErrFile_1 = INVALID_HANDLE_VALUE;
SECURITY_ATTRIBUTES sa_2;
STARTUPINFO siStartupInfo_2;
PROCESS_INFORMATION piProcessInfo_2;
HANDLE hOutFile_2 = INVALID_HANDLE_VALUE;
HANDLE hInFile_2 = INVALID_HANDLE_VALUE;
HANDLE hErrFile_2 = INVALID_HANDLE_VALUE;
BOOL changed = FALSE;
char buffer[100];
int x;
ZeroMemory(&sa_1, sizeof(SECURITY_ATTRIBUTES));
sa_1.nLength = sizeof(SECURITY_ATTRIBUTES);
sa_1.bInheritHandle = TRUE;
ZeroMemory(&siStartupInfo_1, sizeof(siStartupInfo_1));
ZeroMemory(&piProcessInfo_1, sizeof(piProcessInfo_1));
siStartupInfo_1.cb = sizeof(siStartupInfo_1);
ZeroMemory(&sa_2, sizeof(SECURITY_ATTRIBUTES));
sa_2.nLength = sizeof(SECURITY_ATTRIBUTES);
sa_2.bInheritHandle = TRUE;
ZeroMemory(&siStartupInfo_2, sizeof(siStartupInfo_2));
ZeroMemory(&piProcessInfo_2, sizeof(piProcessInfo_2));
siStartupInfo_2.cb = sizeof(siStartupInfo_2);
if(cmd2->up != NULL){
if(cmd2->up->op != OP_PARALLEL){
return parse_command(cmd2->up, level, father, (void*)(0)) == 0;
}
}
if(cmd1->scmd){
redirrect_command(cmd1->scmd, &siStartupInfo_1, &hInFile_1, &hOutFile_1, &hErrFile_1);
cmd = get_argv(cmd1->scmd);
ret_1 = CreateProcess(NULL,
(LPSTR)cmd,
(LPSECURITY_ATTRIBUTES)&sa_1,
NULL,
TRUE,
NORMAL_PRIORITY_CLASS,
NULL,
NULL,
&siStartupInfo_1,
&piProcessInfo_1);
free(cmd);
}
if(cmd2->scmd){
redirrect_command(cmd2->scmd, &siStartupInfo_2, &hInFile_2, &hOutFile_2, &hErrFile_2);
cmd = get_argv(cmd2->scmd);
ret_2 = CreateProcess(NULL,
(LPSTR)cmd,
(LPSECURITY_ATTRIBUTES)&sa_2,
NULL,
TRUE,
NORMAL_PRIORITY_CLASS,
NULL,
NULL,
&siStartupInfo_2,
&piProcessInfo_2);
free(cmd);
}
if(cmd1->scmd){
if(ret_1 == FALSE){
sprintf(buffer, "%s: No such file or directory\n", cmd);
WriteFile(hErrFile_1, buffer, strlen(buffer), &x, NULL);
}
else{
WaitForSingleObject(piProcessInfo_1.hProcess, INFINITE);
GetExitCodeProcess(piProcessInfo_1.hProcess, &ret_1);
CloseHandle(piProcessInfo_1.hProcess);
CloseHandle(piProcessInfo_1.hThread);
}
close_handles(hInFile_1, hOutFile_1, hErrFile_1);
}
if(cmd2->scmd){
if(ret_2 == FALSE){
sprintf(buffer, "%s: No such file or directory\n", cmd);
WriteFile(hErrFile_2, buffer, strlen(buffer), &x, NULL);
}
//.........这里部分代码省略.........
开发者ID:yonutix,项目名称:Minishell-WinAPI,代码行数:101,代码来源:utils-win.c
示例8: main
int main(void) {
bst_node_type *head;
data_item_type *item;
bst_stats_type stats;
long value;
char buffer[2048];
size_t size;
char **args;
int arg_count;
int i;
// loop forever receiving command strings from STDIN.
while (1) {
size=getline(buffer, sizeof(buffer));
// ignore that a blank line was entered
if (size==0)
continue;
// break the command into an array
arg_count=parse_command(buffer, '/', &args);
if (arg_count == -1)
continue;
// add a new element to the database
if (args[0][0]=='a' && arg_count==2 ) {
// if the string to add is less than 10 chars, ignore the add command
if (cgc_strlen(args[1]) < 10) {
free(args);
continue;
}
item=calloc(1, sizeof(data_item_type));
if (!item) {
printf("Unable to allocate memory\n");
return(-1);
}
strncpy(item->name, args[1], sizeof(item->name)-1);
item->next = 0;
insert_node(&head, item, make_key_from_name);
}
// search for elements of the database
else if (args[0][0]=='f' && arg_count==2) {
find_matches(head, arg_count, args);
}
// delete an element from the database
else if (args[0][0]=='d' && arg_count==2) {
delete_matches(&head, arg_count, args);
}
// time to cgc_exit
else if (args[0][0]=='x') {
return(0);
}
// walk the database and show all entries
else if (args[0][0]=='w' ) {
walk_tree(head);
}
else if (args[0][0]=='s' ) {
// clear the stats
bzero(&stats, sizeof(stats));
count_bst_stats(head, &stats);
printf("# of Nodes: @d\n", stats.node_count);
printf("\% left nodes: @d\n", stats.percent_left);
printf("\% right nodes: @d\n", stats.percent_right);
}
free(args);
}
开发者ID:trailofbits,项目名称:cb-multios,代码行数:90,代码来源:service.c
示例9: main
int main (){
int pid = 0;
command_t cmd = {NULL, 0, {NULL}};
char *commandline = (char *)NULL;
char* username = NULL;
config_t ag_config;
int bg_cmd = AG_FALSE;
char prompt[MAX_LINE_LEN];
/* Sets the username */
set_username (&username);
/* Opens the syslog file */
openlog (username, LOG_PID, LOG_USER);
/* Parses the config files for data */
parse_config (&ag_config, username);
/* Initializes GNU Readline */
initialize_readline(&ag_config);
/*
* Main loop:
* - print prompt
* - read input and parse it
* - either a built-in command ("cd", "?" or "exit)
* - or a system command, in which case the program forks and executes it with execvp()
*/
if (ag_config.welcome_message != NULL && strlen (ag_config.welcome_message) > 0) {
fprintf (stdout, "\n%s\n\n", ag_config.welcome_message);
}
while (AG_TRUE){
/* Set the prompt */
get_prompt(prompt, MAX_LINE_LEN, username);
/*
* Read a line of input
* commandline should be deallocated with free()
*/
commandline = read_input (prompt);
parse_command (commandline, &cmd);
switch (get_cmd_code (cmd.name)){
case EMPTY_CMD:
break;
case CD_CMD:
change_directory (cmd.argv[1], ag_config.loglevel);
break;
case HELP_CMD:
print_help(&ag_config);
break;
case ENV_CMD:
print_env (cmd.argv[1]);
break;
case EXIT_CMD:
free (commandline);
commandline = (char *)NULL;
closelog ();
return 0;
case OTHER_CMD:
/* Determines whether the command should run in the bg or not */
bg_cmd = runs_in_background (&cmd);
pid = vfork();
if (pid == 0){
if (!check_validity (cmd, ag_config)){
if (ag_config.loglevel == 3) syslog (LOG_NOTICE, "Using command: %s.", cmd.name);
execvp (cmd.argv[0], cmd.argv);
fprintf (stderr, "%s: Could not execute command!\nType '?' for help.\n", cmd.name);
if (ag_config.loglevel >= 2) syslog (LOG_NOTICE, "Could not execute: %s.", cmd.name);
}else {
fprintf (stdout, "Not allowed! \n");
if (ag_config.warnings >= 0) decrease_warnings (&ag_config);
if (ag_config.loglevel >= 1) syslog (LOG_ERR, "Trying to use forbidden command: %s.", cmd.name);
}
_exit(EXIT_FAILURE);
}else if (pid < 0){
fprintf (stderr, "Error! ... Negative PID. God knows what that means ...\n");
if (ag_config.loglevel >= 1) syslog (LOG_ERR, "Negative PID. Using command: %s.", cmd.name);
}else {
if (!bg_cmd)
wait (0);
}
break;
}
free (commandline);
commandline = (char *)NULL;
}
//.........这里部分代码省略.........
开发者ID:saeidw,项目名称:Agros,代码行数:101,代码来源:main.c
示例10: malloc
parse_info *parse (char *cmdline) {
parse_info *result;
int i = 0;
int pos;
int end = 0;
char command[MAXLINE];
int com_pos;
int is_comm_proper = 0;
if (cmdline[i] == '\n' && cmdline[i] == '\0')
return NULL;
result = malloc(sizeof(parse_info));
if (result == NULL) {
return NULL;
}
init_info(result);
com_pos = 0;
while (cmdline[i] != '\n' && cmdline[i] != '\0') {
if (cmdline[i] == '&') {
result->bool_background = 1;
if (cmdline[i+1] != '\n' && cmdline[i+1] != '\0')
fprintf(stderr, "Ignore anything beyond &.\n");
break;
}
else if (cmdline[i] == '<') {
result->bool_infile = 1;
while (isspace(cmdline[++i]));
pos = 0;
while (cmdline[i] != '\0' && !isspace(cmdline[i])) {
if (pos==FILE_MAX_SIZE) {
fprintf(stderr, "Error.The input redirection file name exceeds the size limit 40\n");
free_info(result);
return NULL;
}
result->in_file[pos++] = cmdline[i++];
}
result->in_file[pos]='\0';
end =1;
while (isspace(cmdline[i])) {
if (cmdline[i] == '\n')
break;
i++;
}
}
else if (cmdline[i] == '>') {
result->bool_outfile = 1;
while (isspace(cmdline[++i]));
pos = 0;
while (cmdline[i] != '\0' && !isspace(cmdline[i])) {
if (pos==FILE_MAX_SIZE) {
fprintf(stderr, "Error.The output redirection file name exceeds the size limit 40\n");
free_info(result);
return NULL;
}
result->out_file[pos++] = cmdline[i++];
}
result->out_file[pos]='\0';
end =1;
while (isspace(cmdline[i])) {
if (cmdline[i] == '\n')
break;
i++;
}
}
else if (cmdline[i] == '|') {
command[com_pos]='\0';
is_comm_proper = parse_command(command, &result->com_array[result->pipe_num]);
if (!is_comm_proper) {
free_info(result);
return NULL;
}
com_pos = 0;
end = 0;
result->pipe_num++;
i++;
}
else {
if (end == 1) {
fprintf(stderr, "Error.Wrong format of input\n");
free_info(result);
return NULL;
}
if (com_pos == MAXLINE-1) {
fprintf(stderr, "Error. The command length exceeds the limit 80\n");
free_info(result);
return NULL;
}
command[com_pos++] = cmdline[i++];
}
}
command[com_pos]='\0';
is_comm_proper = parse_command(command, &result->com_array[result->pipe_num]);
if (!is_comm_proper) {
free_info(result);
return NULL;
}
//Result->pipeNum++;
return result;
}
开发者ID:doubleotoo,项目名称:blam,代码行数:100,代码来源:parse.c
示例11: send_list_of_active_checks_json
//.........这里部分代码省略.........
if (0 == refresh_unsupported || dc_item.lastclock + refresh_unsupported > now)
{
DCconfig_clean_items(&dc_item, NULL, 1);
continue;
}
}
zabbix_log(LOG_LEVEL_DEBUG, "%s() Item '%s' was successfully found in the server cache. Sending.", __function_name, row[0]);
ZBX_STRDUP(key, row[0]);
substitute_key_macros(&key, NULL, &dc_item, NULL, MACRO_TYPE_ITEM_KEY, NULL, 0);
DCconfig_clean_items(&dc_item, NULL, 1);
zbx_json_addobject(&json, NULL);
zbx_json_addstring(&json, ZBX_PROTO_TAG_KEY, key, ZBX_JSON_TYPE_STRING);
if (0 != strcmp(key, row[0]))
zbx_json_addstring(&json, ZBX_PROTO_TAG_KEY_ORIG, row[0], ZBX_JSON_TYPE_STRING);
zbx_json_addstring(&json, ZBX_PROTO_TAG_DELAY, row[1], ZBX_JSON_TYPE_INT);
/* The agent expects ALWAYS to have lastlogsize and mtime tags. Removing those would cause older agents to fail. */
zbx_json_addstring(&json, ZBX_PROTO_TAG_LOGLASTSIZE, row[2], ZBX_JSON_TYPE_INT);
zbx_json_addstring(&json, ZBX_PROTO_TAG_MTIME, row[3], ZBX_JSON_TYPE_INT);
zbx_json_close(&json);
/* special processing for log[] and logrt[] items */
do { /* simple try realization */
/* log[filename,pattern,encoding,maxlinespersec] */
/* logrt[filename_format,pattern,encoding,maxlinespersec] */
if (0 != strncmp(key, "log[", 4) && 0 != strncmp(key, "logrt[", 6))
break;
if (2 != parse_command(key, NULL, 0, params, sizeof(params)))
break;
/* dealing with `pattern' parameter */
if (0 == get_param(params, 2, pattern, sizeof(pattern)) &&
*pattern == '@')
add_regexp_name(®exp, ®exp_alloc, ®exp_num, pattern + 1);
} while (0); /* simple try realization */
/* special processing for eventlog[] items */
do { /* simple try realization */
/* eventlog[filename,pattern,severity,source,logeventid,maxlinespersec] */
if (0 != strncmp(key, "eventlog[", 9))
break;
if (2 != parse_command(key, NULL, 0, params, sizeof(params)))
break;
/* dealing with `pattern' parameter */
if (0 == get_param(params, 2, pattern, sizeof(pattern)) &&
*pattern == '@')
add_regexp_name(®exp, ®exp_alloc, ®exp_num, pattern + 1);
/* dealing with `severity' parameter */
if (0 == get_param(params, 3, key_severity, sizeof(key_severity)) &&
*key_severity == '@')
add_regexp_name(®exp, ®exp_alloc, ®exp_num, key_severity + 1);
/* dealing with `logeventid' parameter */
if (0 == get_param(params, 5, key_logeventid, sizeof(key_logeventid)) &&
*key_logeventid == '@')
开发者ID:nabnut,项目名称:zabbix2.0-cookies,代码行数:67,代码来源:active.c
示例12: main
int main(int argc, char **argv)
{
int listenfd, connfd;
struct sockaddr_un servaddr;
int clilen;
bool do_fork = true;
bool no_wait = false;
doLoop=true;
dprintf("startup!!!\n\n");
if(argc > 1)
{
for(int i = 1; i < argc; i++)
{
if(strncmp(argv[i], "-f", 2) == 0)
{
do_fork = false;
}
else if(strncmp(argv[i], "-w", 2) == 0)
{
no_wait=true;
}
}
}
if(do_fork)
{
switch(fork())
{
case -1:
perror("[timerd] fork");
return -1;
case 0:
break;
default:
return 0;
}
if(setsid() == -1)
{
perror("[timerd] setsid");
return -1;
}
}
memset(&servaddr, 0, sizeof(struct sockaddr_un));
servaddr.sun_family = AF_UNIX;
strcpy(servaddr.sun_path, TIMERD_UDS_NAME);
clilen = sizeof(servaddr.sun_family) + strlen(servaddr.sun_path);
unlink(TIMERD_UDS_NAME);
//network-setup
if((listenfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
{
dperror("error while socket create");
}
if( bind(listenfd, (struct sockaddr*) &servaddr, clilen) <0 )
{
dperror("bind failed...");
exit(-1);
}
if(listen(listenfd, 15) !=0)
{
perror("listen failed...");
exit( -1 );
}
if(!no_wait)
{
// wait for correct date to be set...
CSectionsdClient sectionsd;
while(!sectionsd.getIsTimeSet())
sleep(1);
}
loadTimersFromConfig();
//startup Timer
try
{
CBasicMessage::Header rmessage;
while(doLoop) // wait for incomming messages
{
connfd = accept(listenfd, (struct sockaddr*) &servaddr, (socklen_t*) &clilen);
memset(&rmessage, 0, sizeof(rmessage));
read(connfd,&rmessage,sizeof(rmessage));
parse_command(connfd, &rmessage);
close(connfd);
}
}
catch(std::exception& e)
{
dprintf("caught std-exception in main-thread %s!\n", e.what());
}
catch(...)
{
dprintf("caught exception in main-thread!\n");
}
}
开发者ID:GWARDAR,项目名称:OpenPLi-1,代码行数:100,代码来源:timerd.cpp
示例13: process_trap_for_interface
/******************************************************************************
* *
* Function: process_trap_for_interface *
* *
* Purpose: add trap to all matching items for the specified interface *
* *
* Return value: SUCCEED - a matching item was found *
* FAIL - no matching item was found (including fallback items) *
* *
* Author: Rudolfs Kreicbergs *
* *
******************************************************************************/
static int process_trap_for_interface(zbx_uint64_t interfaceid, char *trap, zbx_timespec_t *ts)
{
DC_ITEM *items = NULL;
char cmd[MAX_STRING_LEN], params[MAX_STRING_LEN], regex[MAX_STRING_LEN],
error[ITEM_ERROR_LEN_MAX];
size_t num, i;
int ret = FAIL, fb = -1, *lastclocks = NULL, *errcodes = NULL;
zbx_uint64_t *itemids = NULL;
unsigned char *states = NULL;
AGENT_RESULT *results = NULL;
zbx_vector_ptr_t regexps;
zbx_vector_ptr_create(®exps);
num = DCconfig_get_snmp_items_by_interfaceid(interfaceid, &items);
itemids = zbx_malloc(itemids, sizeof(zbx_uint64_t) * num);
states = zbx_malloc(states, sizeof(unsigned char) * num);
lastclocks = zbx_malloc(lastclocks, sizeof(int) * num);
errcodes = zbx_malloc(errcodes, sizeof(int) * num);
results = zbx_malloc(results, sizeof(AGENT_RESULT) * num);
for (i = 0; i < num; i++)
{
init_result(&results[i]);
errcodes[i] = FAIL;
items[i].key = zbx_strdup(items[i].key, items[i].key_orig);
if (SUCCEED != substitute_key_macros(&items[i].key, NULL, &items[i], NULL,
MACRO_TYPE_ITEM_KEY, error, sizeof(error)))
{
SET_MSG_RESULT(&results[i], zbx_strdup(NULL, error));
errcodes[i] = NOTSUPPORTED;
continue;
}
if (0 == strcmp(items[i].key, "snmptrap.fallback"))
{
fb = i;
continue;
}
if (ZBX_COMMAND_ERROR == parse_command(items[i].key, cmd, sizeof(cmd), params, sizeof(params)))
continue;
if (0 != strcmp(cmd, "snmptrap"))
continue;
if (1 < num_param(params))
continue;
if (0 != get_param(params, 1, regex, sizeof(regex)))
continue;
if ('@' == *regex)
DCget_expressions_by_name(®exps, regex + 1);
if (SUCCEED != regexp_match_ex(®exps, trap, regex, ZBX_CASE_SENSITIVE))
continue;
if (SUCCEED == set_result_type(&results[i], items[i].value_type, items[i].data_type, trap))
errcodes[i] = SUCCEED;
else
errcodes[i] = NOTSUPPORTED;
ret = SUCCEED;
}
if (FAIL == ret && -1 != fb)
{
if (SUCCEED == set_result_type(&results[fb], items[fb].value_type, items[fb].data_type, trap))
errcodes[fb] = SUCCEED;
else
errcodes[fb] = NOTSUPPORTED;
ret = SUCCEED;
}
for (i = 0; i < num; i++)
{
switch (errcodes[i])
{
case SUCCEED:
if (ITEM_VALUE_TYPE_LOG == items[i].value_type)
{
calc_timestamp(results[i].logs[0]->value, &results[i].logs[0]->timestamp,
items[i].logtimefmt);
}
items[i].state = ITEM_STATE_NORMAL;
//.........这里部分代码省略.........
开发者ID:canghai908,项目名称:zabbix,代码行数:101,代码来源:snmptrapper.c
示例14: main
int main(int argc, char *argv[])
{
struct GModule *module;
struct GParams *params;
int i, ret;
int red, grn, blu;
float size;
double vp_height, z_exag; /* calculated viewpoint height, z-exag */
int width, height; /* output image size */
char *output_name;
nv_data data;
struct render_window *offscreen;
/* initialize GRASS */
G_gisinit(argv[0]);
module = G_define_module();
G_add_keyword(_("visualization"));
G_add_keyword(_("graphics"));
G_add_keyword(_("raster"));
G_add_keyword(_("vector"));
G_add_keyword(_("raster3d"));
module->label = _("Creates a 3D rendering of GIS data.");
module->description = _("Renders surfaces (raster data), "
"2D/3D vector data, and "
"volumes (3D raster data) in 3D.");
params = (struct GParams *)G_malloc(sizeof(struct GParams));
/* define options, call G_parser() */
parse_command(argc, argv, params);
/* check parameters consistency */
check_parameters(params);
width = atoi(params->size->answers[0]);
height = atoi(params->size->answers[1]);
G_asprintf(&output_name, "%s.%s", params->output->answer,
params->format->answer);
GS_libinit();
GVL_libinit();
GS_set_swap_func(swap_gl);
/* define render window */
offscreen = Nviz_new_render_window();
Nviz_init_render_window(offscreen);
if (Nviz_create_render_window(offscreen, NULL, width, height) == -1)
G_fatal_error(_("Unable to render data"));
Nviz_make_current_render_window(offscreen);
/* initialize nviz data */
Nviz_init_data(&data);
/* define default attributes for map objects */
Nviz_set_surface_attr_default();
/* set background color */
Nviz_set_bgcolor(&data, Nviz_color_from_str(params->bgcolor->answer));
/* init view, lights */
Nviz_init_view(&data);
/* load raster maps (surface topography) & set attributes (map/constant) */
load_rasters(params, &data);
/* set draw mode of loaded surfaces */
surface_set_draw_mode(params);
/* load line vector maps */
if (params->vlines->answer) {
load_vlines(params, &data);
/* set attributes of 2d lines */
vlines_set_attrb(params);
}
/* load point vector maps */
if (params->vpoints->answer) {
load_vpoints(params, &data);
/* set attributes for points */
vpoints_set_attrb(params);
}
/* load volumes */
if (params->volume->answer) {
load_rasters3d(params, &data);
}
/* define isosurfaces for displaying volumes */
if (params->isosurf_level->answer) {
add_isosurfs(params, &data);
}
/* define slices for displaying volumes */
if (params->slice->answer) {
add_slices(params, &data);
}
//.........这里部分代码省略.........
开发者ID:rashadkm,项目名称:grass_cmake,代码行数:101,代码来源:main.c
示例15: main
int main(int argc, char *argv[])
{
struct server_settings settings = {30000, 0, 1};
handle_arguments(argc, argv, &settings);
struct player_character hero;
init_player_character(&hero);
char stat_buffer[256];
randomize_player_character_stats(&hero);
snprintf(stat_buffer, 255, "STR - %i\r\nDEX - %i\r\nCON - %i\r\n", hero.strength, hero.dexterity, hero.constitution);
if (catch_signal(SIGINT, handle_shutdown) == -1) {
error("Can't set the interrupt handler");
} else if (settings.verbose) {
puts("Interrupt handler set");
}
listener_d = open_listener_socket();
bind_to_port(listener_d, settings.port_number);
if (listen(listener_d, 10) == -1) {
error("Can't listen");
} else if (settings.verbose) {
printf("Listening on port %i", settings.port_number);
}
struct sockaddr_storage client_addr;
unsigned int address_size = sizeof(client_addr);
if (settings.verbose) {
puts("Waiting for connection");
}
while(1) {
int connect_d = accept(listener_d, (struct sockaddr *)&client_addr, &address_size);
if (connect_d == -1) {
error("Can't open secondary socket");
} else if (settings.verbose) {
puts("New connection started");
}
if (!fork()) {
close(listener_d); char input_buffer[512];
char output_buffer[512];
char send_buffer[512];
char action_buffer[3];
send_version(connect_d);
while (1) {
get_command(connect_d, action_buffer);
puts(action_buffer);
if (action_buffer[0] == 's') {
puts("opening chat buffer");
listen_to_client(connect_d, input_buffer);
parse_command(input_buffer, output_buffer);
sprintf(send_buffer, "You said: \"%s\"\r\n", output_buffer);
puts(send_buffer);
send_to_client(connect_d, send_buffer);
} else {
handle_user_command(connect_d, action_buffer);
}
}
close(connect_d);
exit(0);
}
close(connect_d);
}
return 0;
}
开发者ID:dugword,项目名称:mmorpg,代码行数:74,代码来源:server.c
示例16: malloc
parseInfo *parse (char *cmdline) {
parseInfo *Result;
int i=0;
int pos;
int end=0;
char command[MAXLINE];
int com_pos;
if (cmdline[i] == '\n' && cmdline[i] == '\0')
return NULL;
Result = malloc(sizeof(parseInfo));
if (Result == NULL){
return NULL;
}
init_info(Result);
com_pos=0;
while (cmdline[i] != '\n' && cmdline[i] != '\0') {
if (cmdline[i] == '&') {
Result->boolBackground=1;
if (cmdline[i+1] != '\n' && cmdline[i+1] != '\0') {
fprintf(stderr, "Ignore anything beyond &.\n");
}
break;
}
else if (cmdline[i] == '<') {
Result->boolInfile=1;
while (isspace(cmdline[++i]));
pos=0;
while (cmdline[i] != '\0' && !isspace(cmdline[i])) {
if (pos==FILE_MAX_SIZE) {
fprintf(stderr, "Error.The input redirection file name exceeds the size limit 40\n");
free_info(Result);
return NULL;
}
Result->inFile[pos
|
请发表评论