Remove wrongly placed semicolon
[connman] / src / udev.c
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2007-2009  Intel Corporation. All rights reserved.
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License version 2 as
9  *  published by the Free Software Foundation.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <stdarg.h>
27 #include <sys/types.h>
28
29 #define LIBUDEV_I_KNOW_THE_API_IS_SUBJECT_TO_CHANGE
30 #include <libudev.h>
31
32 #include <glib.h>
33
34 #include "connman.h"
35
36 #ifdef NEED_UDEV_MONITOR_ENABLE_RECEIVING
37 static int udev_monitor_enable_receiving(struct udev_monitor *monitor)
38 {
39         return 0;
40 }
41 #endif
42
43 #ifdef NEED_UDEV_MONITOR_RECEIVE_DEVICE
44 static struct udev_device *udev_monitor_receive_device(struct udev_monitor *monitor)
45 {
46         return udev_monitor_get_device(monitor);
47 }
48 #endif
49
50 #ifdef NEED_UDEV_DEVICE_GET_ACTION
51 static const char *udev_device_get_action(struct udev_device *device)
52 {
53         return NULL;
54 }
55 #endif
56
57 static gboolean udev_event(GIOChannel *channel,
58                                 GIOCondition condition, gpointer user_data)
59 {
60         struct udev_monitor *monitor = user_data;
61         struct udev_device *device;
62         const char *action;
63
64         device = udev_monitor_receive_device(monitor);
65         if (device == NULL)
66                 return TRUE;
67
68         action = udev_device_get_action(device);
69         if (action == NULL)
70                 goto done;
71
72         connman_debug("=== %s ===", action);
73
74 done:
75         udev_device_unref(device);
76
77         return TRUE;
78 }
79
80 static struct udev *udev_ctx;
81 static struct udev_monitor *udev_mon;
82 static guint udev_watch = 0;
83
84 int __connman_udev_init(void)
85 {
86         GIOChannel *channel;
87         int fd;
88
89         DBG("");
90
91         udev_ctx = udev_new();
92         if (udev_ctx == NULL) {
93                 connman_error("Failed to create udev context");
94                 return -1;
95         }
96
97         udev_mon = udev_monitor_new_from_socket(udev_ctx,
98                                                 "@/org/moblin/connman/udev");
99         if (udev_mon == NULL) {
100                 connman_error("Failed to create udev monitor");
101                 udev_unref(udev_ctx);
102                 udev_ctx = NULL;
103                 return -1;
104         }
105
106         if (udev_monitor_enable_receiving(udev_mon) < 0) {
107                 connman_error("Failed to enable udev monitor");
108                 udev_unref(udev_ctx);
109                 udev_ctx = NULL;
110                 udev_monitor_unref(udev_mon);
111                 return -1;
112         }
113
114         fd = udev_monitor_get_fd(udev_mon);
115
116         channel = g_io_channel_unix_new(fd);
117         if (channel == NULL)
118                 return 0;
119
120         udev_watch = g_io_add_watch(channel, G_IO_IN, udev_event, udev_mon);
121
122         g_io_channel_unref(channel);
123
124         return 0;
125 }
126
127 void __connman_udev_cleanup(void)
128 {
129         DBG("");
130
131         if (udev_watch > 0)
132                 g_source_remove(udev_watch);
133
134         if (udev_ctx == NULL)
135                 return;
136
137         udev_monitor_unref(udev_mon);
138         udev_unref(udev_ctx);
139 }