char devpath[PATH_SIZE];
struct stat statbuf;
- dbg("add '%s'" , path);
+ dbg("add '%s'\n" , path);
/* we only have a device, if we have an uevent file */
strlcpy(filename, path, sizeof(filename));
fd = open(filename, O_WRONLY);
if (fd < 0) {
- dbg("error on opening %s: %s", filename, strerror(errno));
+ dbg("error on opening %s: %s\n", filename, strerror(errno));
return;
}
if (write(fd, action, strlen(action)) < 0)
- info("error writing '%s' to '%s': %s", action, filename, strerror(errno));
+ info("error writing '%s' to '%s': %s\n", action, filename, strerror(errno));
close(fd);
}
int len;
int err = 0;
+ if (verbose)
+ printf("%s\n", devpath);
+
udev_device_init(&udev);
udev_db_get_device(&udev, devpath);
list_for_each_entry_safe(loop_device, tmp_device, &device_list, node) {
if (delay_device(loop_device->name))
continue;
- if (sock)
+ if (sock >= 0)
pass_to_socket(loop_device->name, action);
else
trigger_uevent(loop_device->name, action);
/* trigger remaining delayed devices */
list_for_each_entry_safe(loop_device, tmp_device, &device_list, node) {
- if (sock)
+ if (sock >= 0)
pass_to_socket(loop_device->name, action);
else
trigger_uevent(loop_device->name, action);
logging_init("udevtrigger");
udev_config_init();
- dbg("version %s", UDEV_VERSION);
+ dbg("version %s\n", UDEV_VERSION);
sysfs_init();
while (1) {
}
if (sockpath != NULL) {
+ struct stat stats;
+
sock = socket(AF_LOCAL, SOCK_DGRAM, 0);
memset(&saddr, 0x00, sizeof(struct sockaddr_un));
saddr.sun_family = AF_LOCAL;
- /* abstract namespace only */
- strlcpy(&saddr.sun_path[1], sockpath, sizeof(saddr.sun_path)-1);
- saddrlen = offsetof(struct sockaddr_un, sun_path) + strlen(saddr.sun_path+1) + 1;
+ if (sockpath[0] == '@') {
+ /* abstract namespace socket requested */
+ strlcpy(&saddr.sun_path[1], &sockpath[1], sizeof(saddr.sun_path)-1);
+ saddrlen = offsetof(struct sockaddr_un, sun_path) + 1 + strlen(&saddr.sun_path[1]);
+ } else if (stat(sockpath, &stats) == 0 && S_ISSOCK(stats.st_mode)) {
+ /* existing socket file */
+ strlcpy(saddr.sun_path, sockpath, sizeof(saddr.sun_path));
+ saddrlen = offsetof(struct sockaddr_un, sun_path) + strlen(saddr.sun_path);
+ } else {
+ /* no socket file, assume abstract namespace socket */
+ strlcpy(&saddr.sun_path[1], sockpath, sizeof(saddr.sun_path)-1);
+ saddrlen = offsetof(struct sockaddr_un, sun_path) + 1 + strlen(&saddr.sun_path[1]);
+ }
}
if (failed) {