1076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross/*
2076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross * Copyright (C) 2012 The Android Open Source Project
3076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross *
4076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross * Licensed under the Apache License, Version 2.0 (the "License");
5076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross * you may not use this file except in compliance with the License.
6076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross * You may obtain a copy of the License at
7076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross *
8076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross *      http://www.apache.org/licenses/LICENSE-2.0
9076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross *
10076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross * Unless required by applicable law or agreed to in writing, software
11076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross * distributed under the License is distributed on an "AS IS" BASIS,
12076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross * See the License for the specific language governing permissions and
14076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross * limitations under the License.
15076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross */
16076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross
17076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross#include <cutils/uevent.h>
18076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross#include <stdio.h>
19076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross
20076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross#define UEVENT_MSG_LEN  1024
21076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross
22076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Crossint main(int argc, char *argv[])
23076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross{
24076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross    int device_fd;
25076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross    char msg[UEVENT_MSG_LEN+2];
26076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross    int n;
27076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross    int i;
28076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross
29076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross    device_fd = uevent_open_socket(64*1024, true);
30076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross    if(device_fd < 0)
31076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross        return -1;
32076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross
33076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross    while ((n = uevent_kernel_multicast_recv(device_fd, msg, UEVENT_MSG_LEN)) > 0) {
34076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross        msg[n] = '\0';
35076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross        msg[n+1] = '\0';
36076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross
37076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross        for (i = 0; i < n; i++)
38076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross            if (msg[i] == '\0')
39076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross                msg[i] = ' ';
40076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross
41076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross        printf("%s\n", msg);
42076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross    }
43076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross
44076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross    return 0;
45076c2ef0ed0889d983b4868ce6e88a85b02091f7Colin Cross}
46