1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include <cutils/uevent.h> 18 #include <stdio.h> 19 20 #define UEVENT_MSG_LEN 1024 21 22 int main(int argc, char *argv[]) 23 { 24 int device_fd; 25 char msg[UEVENT_MSG_LEN+2]; 26 int n; 27 int i; 28 29 device_fd = uevent_open_socket(64*1024, true); 30 if(device_fd < 0) 31 return -1; 32 33 while ((n = uevent_kernel_multicast_recv(device_fd, msg, UEVENT_MSG_LEN)) > 0) { 34 msg[n] = '\0'; 35 msg[n+1] = '\0'; 36 37 for (i = 0; i < n; i++) 38 if (msg[i] == '\0') 39 msg[i] = ' '; 40 41 printf("%s\n", msg); 42 } 43 44 return 0; 45 } 46