示例#1
0
/**
 * Parse a given command line
 *   command - the command line to parse
 *   request - the request to fill
 */ 
static ConsoleResult read_request(char* command, Request* request) {
	if ( command == NULL || request == NULL) {
		error_msg = "Internal error.";
		return ERROR;
	}

	char *token = strtok(command, " \t\n");
	if (token == NULL)
		return IGNORE;
			
	if (strcmp(token, "help") == 0) {
		usage();
		return IGNORE;
	}
	
	if (strcmp(token, "exit") == 0 || strcmp(token, "quit") == 0) 
		return EXIT;
	
	// Make event
		
	if (strcmp(token, "add") == 0) {
		operation(request) = ADD;	
		int res = fill_event(request);
		
		// The user supplied values are not being validated
		// If you want to do so, implement the validation functions
		// of file event.c and call them here
		
		return res;
	} 
	else if (strcmp(token, "listall") == 0) {
		operation(request) = LIST_ALL;
		return OK;
	}
	else if (strcmp(token, "list") == 0) {
		//error_msg = "Not implemented.";
		operation(request) = LIST;
		int res = fill_id(request);
		return res;
	}
	else if (strcmp(token, "remove") == 0) {
		//error_msg = "Not implemented.";
		operation(request) = REMOVE; //request->event_op.type
		int res = fill_id(request);
		return res;
	}
	else {
		error_msg = "Unknown command.";
		return ERROR;
	}
}
示例#2
0
static void hotplug_button(struct work_struct *work)
{
	struct event_t *event = container_of(work, struct event_t, wq);
	char *s;

	event->skb = alloc_skb(2048, GFP_KERNEL);

	s = skb_put(event->skb, strlen(event->action) + 2);
	sprintf(s, "%s@", event->action);
	fill_event(event);

	NETLINK_CB(event->skb).dst_group = 1;
	broadcast_uevent(event->skb, 0, 1, GFP_KERNEL);

	kfree(event);
}