55 #define pr_fmt(fmt) "Udev control: "fmt 65 #include <sys/mount.h> 74 struct udev_monitor *
mon;
97 f = setmntent(
"/proc/mounts",
"r");
101 pr_error(
"Cannot read /proc/mounts\n");
105 while (
NULL != (ent = getmntent(f)))
107 if (strncmp(ent->mnt_fsname, dev_node, strlen(ent->mnt_fsname)) == 0)
109 mnt_point = strdup(ent->mnt_dir);
112 if (strlen(mnt_point))
117 (void) mount(
NULL, mnt_point,
NULL, MS_REMOUNT, ent->mnt_opts);
145 int logstorage_dev = 0;
152 pr_verbose(
"No partition structure given.\n");
158 if (!udev_device_get_devnode(part))
164 dev_node = strdup(udev_device_get_devnode(part));
192 pr_error(
"Can't send event for %s to DLT.\n", mnt_point);
215 struct udev_device *partition =
NULL;
219 pr_error(
"Not able to get logstorage control instance.\n");
225 if (!prvt || !prvt->
mon)
227 pr_error(
"Not able to get private data.\n");
231 partition = udev_monitor_receive_device(prvt->
mon);
235 pr_error(
"Not able to get partition.\n");
239 action = udev_device_get_action(partition);
243 pr_error(
"Not able to get action.\n");
244 udev_device_unref(partition);
248 pr_verbose(
"%s action received from udev for %s.\n",
250 udev_device_get_devnode(partition));
252 if (strncmp(action,
"add",
sizeof(
"add")) == 0)
264 else if (strncmp(action,
"remove",
sizeof(
"remove")) == 0)
269 udev_device_unref(partition);
286 struct udev_enumerate *enumerate = udev_enumerate_new(udev);
287 struct udev_list_entry *devices =
NULL;
288 struct udev_list_entry *dev_list_entry =
NULL;
292 pr_error(
"Can't enumerate devices.\n");
296 udev_enumerate_add_match_subsystem(enumerate,
"block");
297 udev_enumerate_add_match_property(enumerate,
"DEVTYPE",
"partition");
298 udev_enumerate_scan_devices(enumerate);
300 devices = udev_enumerate_get_list_entry(enumerate);
303 udev_list_entry_foreach(dev_list_entry, devices) {
305 struct udev_device *partition =
NULL;
310 path = udev_list_entry_get_name(dev_list_entry);
311 partition = udev_device_new_from_syspath(udev, path);
320 udev_device_get_devnode(partition),
321 udev_device_get_devtype(partition));
325 udev_device_unref(partition);
329 udev_enumerate_unref(enumerate);
354 udev_monitor_unref(prvt->
mon);
359 udev_unref(prvt->
udev);
385 pr_error(
"Not able to get logstorage control instance.\n");
393 pr_error(
"No memory to allocate private data.\n");
400 prvt->
udev = udev_new();
404 pr_error(
"Cannot initialize udev object\n");
412 prvt->
mon = udev_monitor_new_from_netlink(prvt->
udev,
"udev");
416 pr_error(
"Cannot initialize udev monitor\n");
421 ret = udev_monitor_filter_add_match_subsystem_devtype(prvt->
mon,
427 pr_error(
"Cannot attach filter to monitor: %s.\n", strerror(-ret));
432 ret = udev_monitor_enable_receiving(prvt->
mon);
436 pr_error(
"Cannot start receiving: %s.\n", strerror(-ret));
442 lctrl->
fd = udev_monitor_get_fd(prvt->
mon);
static DltLogstorageCtrl lctrl
char * logstorage_delete_dev_info(const char *node)
Remove a device from the list.
static int logstorage_udev_udevd_callback(void)
Handles the udev events.
DltLogstorageCtrl * get_logstorage_control(void)
static char * dlt_logstorage_udev_get_mount_point(char *dev_node)
Get mount point of a device node.
int dlt_logstorage_check_config_file(char *mnt_point)
Search for config file in given mount point.
struct udev_monitor * mon
int dlt_logstorage_udev_deinit(void)
Clean-up the udev data.
static int check_mountpoint_from_partition(int event, struct udev_device *part)
Check if the daemon needs to be notified by the event.
int logstorage_store_dev_info(const char *node, const char *path)
Add new device in the list.
#define pr_error(fmt,...)
int dlt_logstorage_send_event(int type, char *mount_point)
Send a logstorage event to DLT.
#define pr_verbose(fmt,...)
static int dlt_logstorage_udev_check_mounted(struct udev *udev)
Check all partitions on the system to find configuration file.
int dlt_logstorage_udev_init(void)
Initialize the private data.