Esempio n. 1
0
/*clean all events belonging to a MSFilter that is about to be destroyed*/
void ms_event_queue_clean(MSEventQueue *q, MSFilter *destroyed){
	int freeroom=q->freeroom;
	uint8_t *rptr=q->rptr;

	while(q->size>freeroom){
		MSFilter *f;
		unsigned int id;
		void *data;
		int argsize;
		int evsize;

		evsize=parse_event(rptr,&f,&id,&data,&argsize);
		if (f==destroyed){
			ms_message("Cleaning pending event of MSFilter [%s:%p]",destroyed->desc->name,destroyed);
			((MSEventHeader*)rptr)->filter = NULL;
		}
		rptr+=evsize;

		if (rptr>=q->endptr){
			rptr=q->buffer;
		}
		freeroom+=evsize;
	}
	if (q->current_notifier==destroyed){
		q->current_notifier=NULL;
	}
}
Esempio n. 2
0
int main(int argc, char* argv[])
{
    int device_fd = -1;
    char msg[UEVENT_MSG_LEN+2];
    int n;
	char *action = NULL, *minor = NULL;
	char *major = NULL, *driver = NULL;
    	char *physdevpath = NULL;
    device_fd = open_luther_gliethttp_socket();
    printf("device_fd = %d\n", device_fd);
	int i;
    do {
        while((n = recv(device_fd, msg, UEVENT_MSG_LEN, 0)) > 0) {
            struct luther_gliethttp luther_gliethttp;
            if(n == UEVENT_MSG_LEN) /* overflow -- discard */
                continue;
            msg[n] = '\0';
            msg[n+1] = '\0';
			
			if (!(action = getenv("ACTION")) ||
				!(minor = getenv("MINOR")) ||
				!(driver = getenv("PHYSDEVDRIVER")) ||
				!(major = getenv("MAJOR")) ||
				!(physdevpath  = getenv("PHYSDEVPATH"))
			)
			{
				printf("action ------------------ %s \n",action);
			}
	
            parse_event(msg, &luther_gliethttp);
        }
		
    } while(1);
}
Esempio n. 3
0
static void
callback(event_handle_t handle, event_notification_t notification, void *data)
{
	char		buf[7][64];
	char		args[256];
	int		len = 64;

	buf[0][0] = buf[1][0] = buf[2][0] = buf[3][0] = 0;
	buf[4][0] = buf[5][0] = buf[6][0] = 0;
	event_notification_get_site(handle, notification, buf[0], len);
	event_notification_get_expt(handle, notification, buf[1], len);
	event_notification_get_group(handle, notification, buf[2], len);
	event_notification_get_host(handle, notification, buf[3], len);
	event_notification_get_objtype(handle, notification, buf[4], len);
	event_notification_get_objname(handle, notification, buf[5], len);
	event_notification_get_eventtype(handle, notification, buf[6], len);
	event_notification_get_arguments(handle, notification,
					 args, sizeof(args));

#ifdef EVENTDEBUG
	{
		struct timeval now;
		static int ecount;

		gettimeofday(&now, NULL);
		fprintf(stderr, "Event %d: %lu.%03lu %s %s %s %s %s %s %s %s\n",
			++ecount, now.tv_sec, now.tv_usec / 1000,
			buf[0], buf[1], buf[2],
			buf[3], buf[4], buf[5], buf[6], args);
	}
#endif
	if (parse_event(&lastevent, buf[6], args))
		log("bogus event '%s %s' ignored", buf[6], args);
}
Esempio n. 4
0
static bool_t read_event(MSEventQueue *q){
	int available=q->size-q->freeroom;
	if (available>0){
		MSFilter *f;
		unsigned int id;
		void *data;
		int argsize;
		int evsize;

		ms_mutex_lock(&q->mutex);/*q->endptr can be changed by write_event() so mutex is needed*/
		if (q->rptr>=q->endptr){
			q->rptr=q->buffer;
		}
		ms_mutex_unlock(&q->mutex);

		evsize=parse_event(q->rptr,&f,&id,&data,&argsize);
		if (f) {
			q->current_notifier=f;
			ms_filter_invoke_callbacks(&q->current_notifier,id,argsize>0 ? data : NULL, OnlyAsynchronous);
			q->current_notifier=NULL;
		}
		q->rptr+=evsize;

		ms_mutex_lock(&q->mutex);
		q->freeroom+=evsize;
		ms_mutex_unlock(&q->mutex);
		return TRUE;
	}
	return FALSE;
}
Esempio n. 5
0
void initialize_watch_events(struct rmonitor_file_watch_info *f, struct jx *watch_spec) {

    struct jx *events_array = jx_lookup(watch_spec, "events");

    if(!events_array) {
        fatal("File watch for '%s' did not define any events", f->filename);
    }

    if(!jx_istype(events_array, JX_ARRAY)) {
        fatal("Value for key 'events' in file watch for '%s' is not an array.", f->filename);
    }

    f->events = list_create(0);

    struct jx *event_spec;
    int error = 0;
    for (void *i = NULL; (event_spec = jx_iterate_array(events_array, &i));) {
        struct rmonitor_file_watch_event *e = parse_event(f->filename, event_spec);
        if(e) {
            if(e->on_pattern) {
                // at least one event defines a pattern, thus we need line by
                // line processing.
                f->event_with_pattern = 1;
            }
            list_push_tail(f->events, e);
            debug(D_RMON, "Added event for file '%s', label '%s', max_count %" PRId64, f->filename, e->label, e->max_count);
        } else {
            error = 1;
        }
    }

    if(error) {
        fatal("Error parsing file watch for '%s'.", f->filename);
    }
}
Esempio n. 6
0
void parse_data_dirty_buffer(void)
{
	struct perf_event_header *header;
	int i = 0;

	if (perf_fd < 0)
		return;

	if (dump)
		printf(_("Disk accesses:\n"));

	while (pc->data_tail != pc->data_head && i++ < 5000) {
		while (pc->data_tail >= 128U * getpagesize())
			pc->data_tail -= 128 * getpagesize();

		header = data_mmap + pc->data_tail;

		if (header->size == 0)
			break;

		pc->data_tail += header->size;

		while (pc->data_tail >= 128U * getpagesize())
			pc->data_tail -= 128 * getpagesize();

		if (header->type == PERF_RECORD_SAMPLE)
			parse_event(header, dump);
	}
	pc->data_tail = pc->data_head;
}
Esempio n. 7
0
void key_button_event(xcb_generic_event_t *evt, uint8_t event_type)
{
	xcb_keysym_t keysym = XCB_NO_SYMBOL;
	xcb_button_t button = XCB_NONE;
	bool replay_event = false;
	uint16_t modfield = 0;
	uint16_t lockfield = num_lock | caps_lock | scroll_lock;
	parse_event(evt, event_type, &keysym, &button, &modfield);
	modfield &= ~lockfield & MOD_STATE_FIELD;
	if (keysym != XCB_NO_SYMBOL || button != XCB_NONE) {
		hotkey_t *hk = find_hotkey(keysym, button, modfield, event_type, &replay_event);
		if (hk != NULL) {
			run(hk->command, hk->sync);
			if (status_fifo != NULL)
				put_status(COMMAND_PREFIX, hk->command);
		}
	}
	switch (event_type) {
		case XCB_BUTTON_PRESS:
		case XCB_BUTTON_RELEASE:
			if (replay_event)
				xcb_allow_events(dpy, XCB_ALLOW_REPLAY_POINTER, XCB_CURRENT_TIME);
			else
				xcb_allow_events(dpy, XCB_ALLOW_SYNC_POINTER, XCB_CURRENT_TIME);
			break;
		case XCB_KEY_PRESS:
		case XCB_KEY_RELEASE:
			if (replay_event)
				xcb_allow_events(dpy, XCB_ALLOW_REPLAY_KEYBOARD, XCB_CURRENT_TIME);
			else
				xcb_allow_events(dpy, XCB_ALLOW_SYNC_KEYBOARD, XCB_CURRENT_TIME);
			break;
	}
	xcb_flush(dpy);
}
Esempio n. 8
0
/*
 * Parse all header fields that will be needed
 * to handle a PUBLISH request
 */
static int parse_publish_hfs(struct sip_msg* _m)
{
	int rc = 0;
	if ((rc = parse_headers(_m, HDR_FROM_F | HDR_EVENT_F | 
					HDR_EXPIRES_F | HDR_SIPIFMATCH_F | 
					HDR_CONTENTTYPE_F | HDR_CONTENTLENGTH_F, 0))
	    == -1) {
		paerrno = PA_PARSE_ERR;
		LOG(L_ERR, "parse_publish_hfs(): Error while parsing headers\n");
		return -1;
	}

	if (parse_from_header(_m) < 0) {
		paerrno = PA_FROM_ERR;
		LOG(L_ERR, "parse_publish_hfs(): From malformed or missing\n");
		return -6;
	}

	if (_m->event) {
		if (parse_event(_m->event) < 0) {
			paerrno = PA_EVENT_PARSE;
			LOG(L_ERR, "parse_publish_hfs(): Error while parsing Event header field\n");
			return -8;
		}
	} else {
		paerrno = PA_EVENT_PARSE;
		LOG(L_ERR, "parse_publish_hfs(): Missing Event header field\n");
		return -7;
	}

	if (_m->expires) {
		if (parse_expires(_m->expires) < 0) {
			paerrno = PA_EXPIRES_PARSE;
			LOG(L_ERR, "parse_publish_hfs(): Error while parsing Expires header field\n");
			return -9;
		}
	}

	/* patch from PIC-SER */
	if (_m->sipifmatch) {
		if (parse_sipifmatch(_m->sipifmatch) < 0) {
			paerrno = PA_PARSE_ERR;
			LOG(L_ERR, "parse_hfs(): Error while parsing SIP-If-Match header field\n");
			return -10;
		}
	}

	if (_m->content_type) {
		if (parse_content_type_hdr(_m) < 0) {
			LOG(L_ERR, "parse_hfs(): Can't parse Content-Type\n");
			return -12;
		}
	}
	
	return 0;
}
Esempio n. 9
0
/**
 * @brief Verifies and translates monitoring config string into
 *        internal monitoring configuration.
 *
 * @param str string passed to -m command line option
 */
static void
parse_monitor_event(char *str)
{
        int i = 0, n = 0;
        enum pqos_mon_event evt = 0;
        struct core_group cgrp_tab[PQOS_MAX_CORES];

        parse_event(str, &evt);

        n = strtocgrps(strchr(str, ':') + 1,
                       cgrp_tab, PQOS_MAX_CORES);
        if (n < 0) {
                printf("Error: Too many cores selected\n");
                exit(EXIT_FAILURE);
        }
        /**
         *  For each core group we are processing:
         *  - if it's already in the sel_monitor_core_tab
         *    =>  update the entry
         *  - else
         *    => add it to the sel_monitor_core_tab
         */
        for (i = 0; i < n; i++) {
                int j, found = 0;

                for (j = 0; j < sel_monitor_num &&
                             j < (int)DIM(sel_monitor_core_tab); j++) {
                        found = cmp_cgrps(&sel_monitor_core_tab[j],
                                          &cgrp_tab[i]);
                        if (found < 0) {
                                printf("Error: cannot monitor same "
                                       "cores in different groups\n");
                                exit(EXIT_FAILURE);
                        }
                        if (found) {
                                sel_monitor_core_tab[j].events |= evt;
                                break;
                        }
                }
                if (!found &&
                    sel_monitor_num < (int) DIM(sel_monitor_core_tab)) {
                        struct core_group *pg =
                                &sel_monitor_core_tab[sel_monitor_num];
                        *pg = cgrp_tab[i];
                        pg->events = evt;
                        pg->pgrp = malloc(sizeof(struct pqos_mon_data));
                        if (pg->pgrp == NULL) {
                                printf("Error with memory allocation");
                                exit(EXIT_FAILURE);
                        }
                        ++sel_monitor_num;
                }
        }
        return;
}
Esempio n. 10
0
void
loop(int toplevel)
{
    List list;
#ifdef DEBUG
    int oasp = toplevel ? 0 : alloc_stackp;
#endif

    pushheap();
    for (;;) {
	freeheap();
	errflag = 0;
	if (interact && isset(SHINSTDIN))
	    preprompt();
	hbegin();		/* init history mech        */
	intr();			/* interrupts on            */
	lexinit();              /* initialize lexical state */
	if (!(list = parse_event())) {	/* if we couldn't parse a list */
	    hend();
	    if (tok == ENDINPUT && !errflag)
		break;
	    continue;
	}
	if (hend()) {
	    int toksav = tok;

	    if (stopmsg)	/* unset 'you have stopped jobs' flag */
		stopmsg--;
	    execlist(list, 0, 0);
	    tok = toksav;
	    if (toplevel)
		noexitct = 0;
	}
	DPUTS(alloc_stackp != oasp, "BUG: alloc_stackp changed in loop()");
	if (ferror(stderr)) {
	    zerr("write error", NULL, 0);
	    clearerr(stderr);
	}
	if (subsh)		/* how'd we get this far in a subshell? */
	    exit(lastval);
	if (((!interact || sourcelevel) && errflag) || retflag)
	    break;
	if (trapreturn) {
	    lastval = trapreturn;
	    trapreturn = 0;
	}
	if (isset(SINGLECOMMAND) && toplevel) {
	    if (sigtrapped[SIGEXIT])
		dotrap(SIGEXIT);
	    exit(lastval);
	}
    }
    popheap();
}
Esempio n. 11
0
/** @param buf_ptr the raw data from the simple tunnel connection
 *
 * Parses a journal subcription using simple tunnel format and
 * fires Events on the specified CKNServer object as they are
 * found.  Data is passed in in an mb_buf_ptr structure.  The object
 * copies any data it needs from the buffer.  It returns an 
 * mb_buf_ptr struct that points to the unparsed portion of the buffer.
 * it should be called again with the return value until the returned 
 * mb_buf_ptr.len == 0.
 *
 */
mb_buf_ptr SimpleParser::parse(mb_buf_ptr buf_ptr)
{
	//if it is not found, look for the length first
	if (!len_found)
		buf_ptr = parse_len(buf_ptr);

	if (len_found)
		buf_ptr = parse_event(buf_ptr);

	//return wherever we have gotten to in the buffer
	return buf_ptr;
}
Esempio n. 12
0
/**
 * @brief Stores the process id's given in a table for future use
 *
 * @param str string of process id's
 */
static void
sel_store_process_id(char *str)
{
        uint64_t processes[PQOS_MAX_PIDS];
        unsigned i = 0, n = 0;
        enum pqos_mon_event evt = 0;

	parse_event(str, &evt);

        n = strlisttotab(strchr(str, ':') + 1, processes, DIM(processes));

        if (n == 0)
                parse_error(str, "No process id selected for monitoring");

        if (n >= DIM(sel_monitor_pid_tab))
                parse_error(str,
                            "too many processes selected "
                            "for monitoring");

        /**
         *  For each process:
         *  - if it's already there in the sel_monitor_pid_tab
         *  - update the entry
         *  - else - add it to the sel_monitor_pid_tab
         */
        for (i = 0; i < n; i++) {
                int j, found = 0;

                for (j = 0; j < sel_process_num &&
                             j < (int) DIM(sel_monitor_pid_tab); j++) {
                        if (sel_monitor_pid_tab[j].pid == (pid_t)processes[i]) {
                                sel_monitor_pid_tab[j].events |= evt;
                                found = 1;
                                break;
                        }
                }
		if (!found &&
                    sel_process_num < (int) DIM(sel_monitor_pid_tab)) {
                        struct pid_group *pg =
                                &sel_monitor_pid_tab[sel_process_num];
		        pg->pid = (pid_t)processes[i];
			pg->events = evt;
			pg->pgrp = malloc(sizeof(*pg->pgrp));
			if (pg->pgrp == NULL) {
			        printf("Error with memory allocation");
			        exit(EXIT_FAILURE);
			}
			++sel_process_num;
		}
        }
}
Esempio n. 13
0
int main(int argc, char *argv[])
{
        ALOGD("HotPlug Service Start argc:%d\n",argc);
        struct hotplug_info hotplug_info;
	parse_hotplug_info(&hotplug_info);
	if(argc == 2){
	        int print= strncmp(argv[1],"list-usb",strlen("list-usb"));
        	if(  print==0 || (!strncmp(argv[1],"preheated",strlen("preheated") )))
	        {
	                ALOGD("Warm me up then Preheating with argc:%d argv[1]=%s",argc,argv[1]);
               	        printf("Running hotplugd as preheated - looking for existing devicesmodeswitch.d:%s length:%u debug:%u\n",hotplug_info.modeswitch_d,hotplug_info.modeswitch_length,hotplug_info.debug);
        		return preheated(print,hotplug_info.modeswitch_d);
        	}       
        	return 0;
        }
	struct sockaddr_nl nls;
	struct pollfd pfd;
	char uevent_msg[1024];
	// Open hotplug event netlink socket
	ALOGI("Starting hotplugd For UsbModeSwitch Management - Settings:modeswitch.d:%s length:%u debug:%u",hotplug_info.modeswitch_d,hotplug_info.modeswitch_length,hotplug_info.debug);
	memset(&nls,0,sizeof(struct sockaddr_nl));
	nls.nl_family = AF_NETLINK;
	nls.nl_pid = getpid();
	nls.nl_groups = -1;  


	pfd.events = POLLIN;
	pfd.fd = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT);
	if (pfd.fd==-1)
		ALOGE("hotplugd cannot create socket, are you root?\n");

	// Listen to netlink socket

	if (bind(pfd.fd, (void *)&nls, sizeof(struct sockaddr_nl)))
		die("bind failed\n");
	ALOGD("Give us a go on your UEVENT");
	while (-1!=poll(&pfd, 1, -1)) {

		int uevent_buffer_length = recv(pfd.fd, uevent_msg, sizeof(uevent_msg), MSG_DONTWAIT);
		if (uevent_buffer_length == -1) 
			die("receive error\n");
		struct uevent uevent;
	        parse_event(uevent_msg, &uevent,hotplug_info.debug);
	        handle_event(&uevent,&hotplug_info);
	}
	die("poll error\n");

	// Dear gcc: shut up.
	return 0;
}
Esempio n. 14
0
static int
parse_event_alloc (Event **ev, char *s)
{
    Event tmp;
    int ret;

    *ev = NULL;
    ret = parse_event (&tmp, s);
    if (ret == 1) {
	*ev = malloc (sizeof (**ev));
	if (*ev == NULL)
	    krb5_errx (context, 1, "malloc: out of memory");
	**ev = tmp;
    }
    return ret;
}
Esempio n. 15
0
void handle_device_fd(int sock)
{
    char msg[UEVENT_MSG_LEN+2];
    int n;
    while ((n = uevent_kernel_multicast_recv(sock, msg, UEVENT_MSG_LEN)) > 0) {
        if(n >= UEVENT_MSG_LEN)   /* overflow -- discard */
            continue;

        msg[n] = '\0';
        msg[n+1] = '\0';

        struct uevent uevent;
        parse_event(msg, &uevent);
        handle_device_event(&uevent);
    }
}
Esempio n. 16
0
/* no = 0~ */
static int midi_start(int no, char *data, int datalen) {
	pid_t pid;
	
	pid = fork();
	if (pid == 0) {
#ifdef QUITE_MIDI
		close(1);
#endif
		sys_set_signalhandler(SIGTERM, SIG_DFL);
		
		if (NULL == (midi = mf_read_midifile(data, datalen))) {
			_exit(-1);
		}
		
		
		if (0 > (midifd = open(mididevname, O_RDWR))) {
			perror("open");
			_exit(-1);
		}
#ifdef ENABLE_SEQMIDI
		{ int nrsynths; 
		if (-1 == ioctl(mididev,  SNDCTL_SEQ_NRSYNTHS, &nrsynths)) {
			perror("SNDCTL_SEQ_NRSYNTHS");
			_exit(-1);
		}}
#endif

		send_reset();
		
		sys_set_signalhandler(SIGUSR1, signal_pause); /* pause   */
		sys_set_signalhandler(SIGUSR2, signal_pause); /* unpause */
		sys_set_signalhandler(SIGTERM, signal_pause); /* stop    */
		
		/* parse */
		parse_event();
		
		send_reset();
		mf_remove_midifile(midi);
		_exit(0);
	}
	
	midino  = no;
	midipid = pid;
	counter = get_high_counter(SYSTEMCOUNTER_MIDI);
	
	return OK;
}
Esempio n. 17
0
void* handle_device_fd(void *file_desc)
{   
    int fd = *((int*)file_desc);
    //printf("enter %s\n", __func__);
    for(;;) {
        char msg[UEVENT_MSG_LEN+2];
        char cred_msg[CMSG_SPACE(sizeof(struct ucred))];
        struct iovec iov = {msg, sizeof(msg)};
        struct sockaddr_nl snl;
        struct msghdr hdr = {&snl, sizeof(snl), &iov, 1, cred_msg, sizeof(cred_msg), 0};

        ssize_t n = recvmsg(fd, &hdr, 0);
        if (n <= 0) {
            break;
        }
        if ((snl.nl_groups != 1) || (snl.nl_pid != 0)) {
            /* ignoring non-kernel netlink multicast message */
            continue;
        }
        struct cmsghdr * cmsg = CMSG_FIRSTHDR(&hdr);
        if (cmsg == NULL || cmsg->cmsg_type != SCM_CREDENTIALS) {
            /* no sender credentials received, ignore message */
            continue;
        }
        struct ucred * cred = (struct ucred *)CMSG_DATA(cmsg);
        if (cred->uid != 0) {
            /* message from non-root user, ignore */
            continue;
        }
        if(n >= UEVENT_MSG_LEN) /* overflow -- discard */
            continue;

        msg[n] = '\0';
        msg[n+1] = '\0';

        struct uevent *uevent = (struct uevent*)malloc(sizeof(struct uevent));
        if(!parse_event(msg, uevent)){
            //printf("%s\n", msg);
            //printf("event { %s, %d, %s }\n", uevent->subsystem, uevent->host_id, uevent->what);
            pthread_exit((void *)uevent);
            return (void *)uevent;
        }
    }
    pthread_exit(NULL);
    return NULL;
}
Esempio n. 18
0
/*
 * Parse all header fields that will be needed
 * to handle a SUBSCRIBE request
 */
static int parse_hfs(struct sip_msg* _m, int accept_header_required)
{
	if ( (parse_headers(_m, HDR_FROM | HDR_EVENT | HDR_EXPIRES | HDR_ACCEPT, 0)
				== -1) || (_m->from==0)||(_m->event==0)||(_m->expires==0) ||
			(_m->accept==0) ) {
		paerrno = PA_PARSE_ERR;
		LOG(L_ERR, "parse_hfs(): Error while parsing headers\n");
		return -1;
	}

	if (parse_from_header(_m) < 0) {
		paerrno = PA_FROM_ERR;
		LOG(L_ERR, "parse_hfs(): From malformed or missing\n");
		return -6;
	}

	if (_m->event) {
		if (parse_event(_m->event) < 0) {
			paerrno = PA_EVENT_PARSE;
			LOG(L_ERR, "parse_hfs(): Error while parsing Event header field\n");
			return -8;
		}
	}

	if (_m->expires) {
		if (parse_expires(_m->expires) < 0) {
			paerrno = PA_EXPIRES_PARSE;
			LOG(L_ERR, "parse_hfs(): Error while parsing Expires header field\n");
			return -9;
		}
	}

	if (_m->accept) {
		if (parse_accept(_m->accept, &acc) < 0) {
			paerrno = PA_ACCEPT_PARSE;
			LOG(L_ERR, "parse_hfs(): Error while parsing Accept header field\n");
			return -10;
		}
	} else if (accept_header_required) {
		LOG(L_ERR, "no accept header\n");
		acc = DOC_XPIDF;
	}

	return 0;
}
Esempio n. 19
0
File: cshr.c Progetto: ec429/harris
int main(void)
{
	struct hist_record rec;
	char *line;
	char outbuf[80];
	int rc;

	while(!feof(stdin))
	{
		line = fgetl(stdin);
		if (!line)
		{
			fprintf(stderr, "Unexpected EOF\n");
			return 3;
		}
		if (!strncmp(line, "History:", 8))
		{
			free(line);
			break;
		}
	}

	while(!feof(stdin))
	{
		line = fgetl(stdin);
		if (!line) break;
		rc = parse_event(&rec, line);
		if (rc)
		{
			fprintf(stderr, "Error %d in line: %s\n", rc, line);
			free(line);
			return rc;
		}
		free(line);
		if (rec.type == HT_MISC)
		{
			if (rec.misc.type == ME_CASH)
			{
				writedate(rec.date, outbuf);
				printf("%s CA %d %d\n", outbuf, rec.misc.cash.delta, rec.misc.cash.current);
			}
		}
	}
	return 0;
}
Esempio n. 20
0
void UEventWatcher::run()
{
    if (uevent_init()) {
	char msg[UEVENT_MSG_LEN+2];
	int n;
	while ((n = uevent_next_event(msg, UEVENT_MSG_LEN)) > 0) {
	    if (n >= UEVENT_MSG_LEN)
		continue;
	    msg[n] = 0;
	    msg[n+1] = 0;
	    struct uevent uevent;
	    parse_event(msg, &uevent);
	    if (strcmp(uevent.subsystem,"power_supply") == 0) {
		emit activity();
	    }
	}
    }
}
Esempio n. 21
0
void handle_device_fd(int fd)
{
	printf("enter %s\n", __func__);
	for(;;) {
		char msg[UEVENT_MSG_LEN+2];
		char cred_msg[CMSG_SPACE(sizeof(struct ucred))];
		struct iovec iov = {msg, sizeof(msg)};
		struct sockaddr_nl snl;
		struct msghdr hdr = {&snl, sizeof(snl), &iov, 1, cred_msg, sizeof(cred_msg), 0};

		ssize_t n = recvmsg(fd, &hdr, 0);
		if (n <= 0) {
			break;
		}

		if ((snl.nl_groups != 1) || (snl.nl_pid != 0)) {
			/* ignoring non-kernel netlink multicast message */
			continue;
		}

		struct cmsghdr * cmsg = CMSG_FIRSTHDR(&hdr);
		if (cmsg == NULL || cmsg->cmsg_type != SCM_CREDENTIALS) {
			/* no sender credentials received, ignore message */
			continue;
		}

		struct ucred * cred = (struct ucred *)CMSG_DATA(cmsg);
		if (cred->uid != 0) {
			/* message from non-root user, ignore */
			continue;
		}

		if(n >= UEVENT_MSG_LEN) /* overflow -- discard */
			continue;

		msg[n] = '\0';
		msg[n+1] = '\0';

		struct uevent uevent;
		parse_event(msg, &uevent);
	}
}
Esempio n. 22
0
int select_event(str* res, select_t* s, struct sip_msg* msg)
{
	if (!msg->event && parse_headers(msg, HDR_EVENT_F, 0) == -1) {
		LM_ERR("Error while searching Event header field\n");
		return -1;
	}

	if (!msg->event) {
		LM_DBG("Event header field not found\n");
		return -1;
	}

	if (parse_event(msg->event) < 0) {
		LM_ERR("Error while parsing Event header field\n");
		return -1;
	}

	*res = ((event_t*)msg->event->parsed)->name;
	return 0;
}
Esempio n. 23
0
static int read_events(int fd, struct sockaddr_nl *sa)
{
	int len;
	char buf[32];
	struct iovec iov = { buf, sizeof(buf) };
	struct msghdr msg;
	int ret;

	logger(0, 0, "Started");

	while (1) {
		memset(&msg, 0, sizeof(msg));
		msg.msg_name = (void *)&sa;
		msg.msg_namelen = sizeof(sa);
		msg.msg_iov = &iov;
		msg.msg_iovlen = 1;

		len = recvmsg(fd, &msg, 0);
		if (len > 0) {
			buf[len] = '\0';
			parse_event(buf);
			set_log_ctid(0);
		} else if (len < 0) {
			if (errno != EINTR) {
				logger(-1, errno, "Error in recvmsg() "
						" (ret=%d, errno=%d)",
						len, errno);
				ret = 1;
				break;
			}
		} else /* len==0 */ {
			logger(0, 0, "Connection closed");
			ret = 0;
			break;
		}
	}
	close(fd);
	logger(0, 0, "Exiting...");
	return ret;
}
Esempio n. 24
0
int main(void)
{
	byte ret = MAIN_SUCCESS;
	event = EVENT_NOTHING_TO_DO;

	PE_low_level_init();
	Cpu_SetClockConfiguration(1);
	back_to_first_screen();

	do{
		if(event!=EVENT_NOTHING_TO_DO)
			ret = parse_event(&event);
		else{
			__asm("WFI\n\t");
			//Waitms(100);
		}

		//Waitms(100);

		if(ret!=MAIN_SUCCESS)
		{
			ret = reset_ST();
		}
	}while(TRUE);

	for(;;){}

	return 0;
	/*** Don't write any code pass this line, or it will be deleted during code generation. ***/
	/*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
#ifdef PEX_RTOS_START
	PEX_RTOS_START();                  /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
#endif
	/*** End of RTOS startup code.  ***/
	/*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
	for(;;){}
	/*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
}
Esempio n. 25
0
/*
 * Parse all header fields that will be needed
 * to handle a PUBLISH request
 */
static int parse_publish_hfs(struct sip_msg* _m)
{
	int rc = 0;
	if ((rc = parse_headers(_m, HDR_FROM_F | HDR_EVENT_F | HDR_EXPIRES_F, 0))
	    == -1) {
		paerrno = PA_PARSE_ERR;
		LOG(L_ERR, "parse_publish_hfs(): Error while parsing headers\n");
		return -1;
	}

	if (parse_from_header(_m) < 0) {
		paerrno = PA_FROM_ERR;
		LOG(L_ERR, "parse_publish_hfs(): From malformed or missing\n");
		return -6;
	}

	if (_m->event) {
		if (parse_event(_m->event) < 0) {
			paerrno = PA_EVENT_PARSE;
			LOG(L_ERR, "parse_publish_hfs(): Error while parsing Event header field\n");
			return -8;
		}
	} else {
		paerrno = PA_EVENT_PARSE;
		LOG(L_ERR, "parse_publish_hfs(): Missing Event header field\n");
		return -7;
	}

	if (_m->expires) {
		if (parse_expires(_m->expires) < 0) {
			paerrno = PA_EXPIRES_PARSE;
			LOG(L_ERR, "parse_publish_hfs(): Error while parsing Expires header field\n");
			return -9;
		}
	}

	return 0;
}
Esempio n. 26
0
/*
 * Check if a message received has been constructed properly
 */
int check_message(struct sip_msg* _m)
{
	if (_m->event) {
		event_t *event;

		if (!_m->event->parsed)
			parse_event(_m->event);
		event = (event_t*)(_m->event->parsed);

		if (event && (event->parsed != accepts_to_event_package[acc])) {
			char *accept_s = NULL;
			int accept_len = 0;
			if (_m->accept && _m->accept->body.len) {
				accept_s = _m->accept->body.s;
				accept_len = _m->accept->body.len;
			}
			LOG(L_ERR, "check_message(): Accepts %.*s not valid for event package et=%.*s\n",
			    _m->accept->body.len, _m->accept->body.s, event->text.len, event->text.s);
			return -1;
		}
	}
	return 0;
}
Esempio n. 27
0
File: sparse.c Progetto: hsiboy/ida
int main(int argc, char **argv)
{
  IDSA_EVENT *e;

  if (argc <= 1) {
    return 1;
  }

  e = idsa_event_new(0);
  if (e == NULL) {
    return 1;
  }

  idsa_request_init(e, "foo", "bar", "baz");

  parse_event(e, argv[1]);

  idsa_event_dump(e, stdout);

  idsa_event_free(e);

  return 0;
}
Esempio n. 28
0
static int
doit(const char *filename, int mergep)
{
    krb5_error_code ret;
    FILE *f;
    char s[8192]; /* XXX should fix this properly */
    char *p;
    int line;
    int flags = O_RDWR;
    struct entry e;
    hdb_entry_ex ent;
    HDB *db = _kadm5_s_get_db(kadm_handle);

    f = fopen(filename, "r");
    if(f == NULL){
	krb5_warn(context, errno, "fopen(%s)", filename);
	return 1;
    }
    ret = kadm5_log_truncate (kadm_handle);
    if (ret) {
	fclose (f);
	krb5_warn(context, ret, "kadm5_log_truncate");
	return 1;
    }

    if(!mergep)
	flags |= O_CREAT | O_TRUNC;
    ret = db->hdb_open(context, db, flags, 0600);
    if(ret){
	krb5_warn(context, ret, "hdb_open");
	fclose(f);
	return 1;
    }
    line = 0;
    ret = 0;
    while(fgets(s, sizeof(s), f) != NULL) {
	ret = 0;
	line++;

	p = s;
	while (isspace((unsigned char)*p))
	    p++;

	e.principal = p;
	for(p = s; *p; p++){
	    if(*p == '\\')
		p++;
	    else if(isspace((unsigned char)*p)) {
		*p = 0;
		break;
	    }
	}
	p = skip_next(p);
	
	e.key = p;
	p = skip_next(p);

	e.created = p;
	p = skip_next(p);

	e.modified = p;
	p = skip_next(p);

	e.valid_start = p;
	p = skip_next(p);

	e.valid_end = p;
	p = skip_next(p);

	e.pw_end = p;
	p = skip_next(p);

	e.max_life = p;
	p = skip_next(p);

	e.max_renew = p;
	p = skip_next(p);

	e.flags = p;
	p = skip_next(p);

	e.generation = p;
	p = skip_next(p);

	e.extensions = p;
	p = skip_next(p);

	memset(&ent, 0, sizeof(ent));
	ret = krb5_parse_name(context, e.principal, &ent.entry.principal);
	if(ret) {
	    fprintf(stderr, "%s:%d:%s (%s)\n", 
		    filename, 
		    line,
		    krb5_get_err_text(context, ret),
		    e.principal);
	    continue;
	}
	
	if (parse_keys(&ent.entry, e.key)) {
	    fprintf (stderr, "%s:%d:error parsing keys (%s)\n",
		     filename, line, e.key);
	    hdb_free_entry (context, &ent);
	    continue;
	}
	
	if (parse_event(&ent.entry.created_by, e.created) == -1) {
	    fprintf (stderr, "%s:%d:error parsing created event (%s)\n",
		     filename, line, e.created);
	    hdb_free_entry (context, &ent);
	    continue;
	}
	if (parse_event_alloc (&ent.entry.modified_by, e.modified) == -1) {
	    fprintf (stderr, "%s:%d:error parsing event (%s)\n",
		     filename, line, e.modified);
	    hdb_free_entry (context, &ent);
	    continue;
	}
	if (parse_time_string_alloc (&ent.entry.valid_start, e.valid_start) == -1) {
	    fprintf (stderr, "%s:%d:error parsing time (%s)\n",
		     filename, line, e.valid_start);
	    hdb_free_entry (context, &ent);
	    continue;
	}
	if (parse_time_string_alloc (&ent.entry.valid_end,   e.valid_end) == -1) {
	    fprintf (stderr, "%s:%d:error parsing time (%s)\n",
		     filename, line, e.valid_end);
	    hdb_free_entry (context, &ent);
	    continue;
	}
	if (parse_time_string_alloc (&ent.entry.pw_end,      e.pw_end) == -1) {
	    fprintf (stderr, "%s:%d:error parsing time (%s)\n",
		     filename, line, e.pw_end);
	    hdb_free_entry (context, &ent);
	    continue;
	}

	if (parse_integer_alloc (&ent.entry.max_life,  e.max_life) == -1) {
	    fprintf (stderr, "%s:%d:error parsing lifetime (%s)\n",
		     filename, line, e.max_life);
	    hdb_free_entry (context, &ent);
	    continue;

	}
	if (parse_integer_alloc (&ent.entry.max_renew, e.max_renew) == -1) {
	    fprintf (stderr, "%s:%d:error parsing lifetime (%s)\n",
		     filename, line, e.max_renew);
	    hdb_free_entry (context, &ent);
	    continue;
	}

	if (parse_hdbflags2int (&ent.entry.flags, e.flags) != 1) {
	    fprintf (stderr, "%s:%d:error parsing flags (%s)\n",
		     filename, line, e.flags);
	    hdb_free_entry (context, &ent);
	    continue;
	}

	if(parse_generation(e.generation, &ent.entry.generation) == -1) {
	    fprintf (stderr, "%s:%d:error parsing generation (%s)\n",
		     filename, line, e.generation);
	    hdb_free_entry (context, &ent);
	    continue;
	}

	if(parse_extensions(e.extensions, &ent.entry.extensions) == -1) {
	    fprintf (stderr, "%s:%d:error parsing extension (%s)\n",
		     filename, line, e.extensions);
	    hdb_free_entry (context, &ent);
	    continue;
	}

	ret = db->hdb_store(context, db, HDB_F_REPLACE, &ent);
	hdb_free_entry (context, &ent);
	if (ret) {
	    krb5_warn(context, ret, "db_store");
	    break;
	}
    }
    db->hdb_close(context, db);
    fclose(f);
    return ret != 0;
}
Esempio n. 29
0
File: init.c Progetto: AMDmi3/zsh
enum loop_return
loop(int toplevel, int justonce)
{
    Eprog prog;
    int err, non_empty = 0;

    queue_signals();
    pushheap();
    if (!toplevel)
	zcontext_save();
    for (;;) {
	freeheap();
	if (stophist == 3)	/* re-entry via preprompt() */
	    hend(NULL);
	hbegin(1);		/* init history mech        */
	if (isset(SHINSTDIN)) {
	    setblock_stdin();
	    if (interact && toplevel) {
	        int hstop = stophist;
		stophist = 3;
		/*
		 * Reset all errors including the interrupt error status
		 * immediately, so preprompt runs regardless of what
		 * just happened.  We'll reset again below as a
		 * precaution to ensure we get back to the command line
		 * no matter what.
		 */
		errflag = 0;
		preprompt();
		if (stophist != 3)
		    hbegin(1);
		else
		    stophist = hstop;
		/*
		 * Reset all errors, including user interupts.
		 * This is what allows ^C in an interactive shell
		 * to return us to the command line.
		 */
		errflag = 0;
	    }
	}
	use_exit_printed = 0;
	intr();			/* interrupts on            */
	lexinit();              /* initialize lexical state */
	if (!(prog = parse_event(ENDINPUT))) {
	    /* if we couldn't parse a list */
	    hend(NULL);
	    if ((tok == ENDINPUT && !errflag) ||
		(tok == LEXERR && (!isset(SHINSTDIN) || !toplevel)) ||
		justonce)
		break;
	    if (exit_pending) {
		/*
		 * Something down there (a ZLE function?) decided
		 * to exit when there was stuff to clear up.
		 * Handle that now.
		 */
		stopmsg = 1;
		zexit(exit_pending >> 1, 0);
	    }
	    if (tok == LEXERR && !lastval)
		lastval = 1;
	    continue;
	}
	if (hend(prog)) {
	    enum lextok toksav = tok;

	    non_empty = 1;
	    if (toplevel &&
		(getshfunc("preexec") ||
		 paramtab->getnode(paramtab, "preexec" HOOK_SUFFIX))) {
		LinkList args;
		char *cmdstr;

		/*
		 * As we're about to freeheap() or popheap()
		 * anyway, there's no gain in using permanent
		 * storage here.
		 */
		args = newlinklist();
		addlinknode(args, "preexec");
		/* If curline got dumped from the history, we don't know
		 * what the user typed. */
		if (hist_ring && curline.histnum == curhist)
		    addlinknode(args, hist_ring->node.nam);
		else
		    addlinknode(args, "");
		addlinknode(args, dupstring(getjobtext(prog, NULL)));
		addlinknode(args, cmdstr = getpermtext(prog, NULL, 0));

		callhookfunc("preexec", args, 1, NULL);

		/* The only permanent storage is from getpermtext() */
		zsfree(cmdstr);
		/*
		 * Note this does *not* remove a user interrupt error
		 * condition, even though we're at the top level loop:
		 * that would be inconsistent with the case where
		 * we didn't execute a preexec function.  This is
		 * an implementation detail that an interrupting user
		 * does't care about.
		 */
		errflag &= ~ERRFLAG_ERROR;
	    }
	    if (stopmsg)	/* unset 'you have stopped jobs' flag */
		stopmsg--;
	    execode(prog, 0, 0, toplevel ? "toplevel" : "file");
	    tok = toksav;
	    if (toplevel)
		noexitct = 0;
	}
	if (ferror(stderr)) {
	    zerr("write error");
	    clearerr(stderr);
	}
	if (subsh)		/* how'd we get this far in a subshell? */
	    exit(lastval);
	if (((!interact || sourcelevel) && errflag) || retflag)
	    break;
	if (isset(SINGLECOMMAND) && toplevel) {
	    dont_queue_signals();
	    if (sigtrapped[SIGEXIT])
		dotrap(SIGEXIT);
	    exit(lastval);
	}
	if (justonce)
	    break;
    }
Esempio n. 30
0
int
parse_msg (struct sip_msg *msg, STRLIST * sender, STRLIST * recipient)
{

  char *tmp;
  char *end;
  int length;
  int offset;
  char *header;
  char address[80] = { 0 };
  char *body;
  int body_length;
  int off;
  int type;
  int evt;



  /* parse the data */
  tmp = msg->buf;
  end = msg->buf + msg->len;

  /* strip the beginning space */
  for (tmp; ((*tmp == '\n') || (*tmp == '\r'))
       && ((tmp - msg->buf) < length); tmp++);

  if (parse_first_line (&tmp, end, &(msg->type)))
    return 1;

  offset = tmp - msg->buf;
  do
    {
      switch (*tmp)
        {
        case 't':
        case 'T':
          {
            if (off = check ("TO", 2, tmp, end))
              {
                if (LOG_PARSER)
                  log_info ("Header To found in %u\n", tmp - msg->buf);
                offset += off;
                offset += find_end (tmp + off, end);

                /* find the user address */
                tmp += off;
                if (get_address
                    (tmp, address, msg->buf + offset - tmp, &(msg->sips)))
                  {

                    tmp = msg->buf + offset;
                    break;
                  }

                add_to_strlist2 (recipient, address, 0);
                if (LOG_PARSER)
                  log_info ("The address is : %s\n", address);

                /* We only need one to header */
                if (!msg->to)
                  msg->to = parser_create_address (address, 0, msg->sips);
                tmp = msg->buf + offset;

                break;
              }
          }


        case 'f':
        case 'F':
          {
            if (off = check ("FROM", 4, tmp, end))
              {
                if (LOG_PARSER)
                  log_info ("Header From found in %u\n", tmp - msg->buf);

                offset += off;
                /* find the end of this header */
                offset += find_end (tmp + off, end);

                /* find the user address */
                tmp += off;

                if (get_address
                    (tmp, address, msg->buf + offset - tmp, &(msg->sips)))
                  {
                    tmp = msg->buf + offset;
                    break;
                  }

                add_to_strlist2 (sender, address, 0);
                if (LOG_PARSER)
                  log_info ("The address is : %s\n", address);

                /* We only require one from */
                if (!msg->from)
                  {
                    /* copy from header to be used later */
                    msg->from = parser_create_address (address, 1, msg->sips);
                  }
                tmp = msg->buf + offset;


                break;
              }
          }

        case 'v':
        case 'V':
          {
            if (off = check ("VIA", 3, tmp, end))
              {
                if (LOG_PARSER)
                  log_info ("Header Via found in %u\n", tmp - msg->buf);

                offset += off;
                /* find the end of this header */
                offset += find_end (tmp + off, end);
                if (!msg->via1)
                  msg->via1 = tmp;
                else if (!msg->via2)
                  msg->via2 = tmp;
                tmp = msg->buf + offset;
                break;
              }
          }

        case 'e':
        case 'E':
          {
            if (off = check ("Event", 5, tmp, end))
              {
                if (LOG_PARSER)
                  log_info ("Header Event found in %u\n", tmp - msg->buf);

                offset += off;
                /* find the end of this header */
                offset += find_end (tmp + off, end);
                tmp += off;
                msg->evt = parse_event (tmp, msg->buf + offset);
                tmp = msg->buf + offset;
                break;
              }
          }

        case 'r':
        case 'R':
          {
            if (off = check ("REQ", 3, tmp, end))
              {

                if (LOG_PARSER)
                  log_info ("Header Requester found in %u\n", tmp - msg->buf);

                offset += off;
                /* find the end of this header */
                offset += find_end (tmp + off, end);

                /* find the user address */
                tmp += off;
                for (tmp; (*tmp == ' ') && ((tmp) < end); tmp++);
                if (!msg->req)
                  msg->req = parser_create_req (tmp);
                tmp = msg->buf + offset;
                break;
              }
          }

        default:
          {
            if (LOG_PARSER)
              log_info ("Other header found in %u\n", tmp - msg->buf);

            offset += find_end (tmp, end);
            tmp = msg->buf + offset;

          }
        }
    }
  while (not_out (&tmp) && tmp < end);

  msg->hdr_len = msg->hdr_len2 = tmp - msg->buf;
  /* We still have data left, it means body */
  if (tmp < end)
    {
      msg->body_len = end - tmp;
      msg->body = tmp;
    }

  return 0;
}