- dbg("error connecting to daemon, start daemon failed");
- goto exit;
-
-send:
- size = build_hotplugmsg(&message, action, devpath, subsystem, seq);
- retval = send(sock, &message, size, 0);
- if (retval == -1) {
- dbg("error sending message");
- close (sock);
- goto exit;
+ /* older kernels passed the SUBSYSTEM only as the first argument */
+ if (!subsystem && argc == 2) {
+ bufpos += sprintf(&usend_msg.envbuf[bufpos], "SUBSYSTEM=%s", argv[1]) + 1;
+ dbg("add 'SUBSYSTEM=%s' to env[%i] buffer from argv", argv[1], i);
+ }
+
+ usend_msg_len = offsetof(struct udevd_msg, envbuf) + bufpos;
+ dbg("usend_msg_len=%i", usend_msg_len);
+
+ /* If we can't send, try to start daemon and resend message */
+ loop = UDEVSEND_WAIT_MAX_SECONDS * UDEVSEND_WAIT_LOOP_PER_SECOND;
+ while (--loop) {
+ retval = sendto(sock, &usend_msg, usend_msg_len, 0, (struct sockaddr *)&saddr, addrlen);
+ if (retval != -1) {
+ retval = 0;
+ goto exit;
+ }
+
+ if (errno != ECONNREFUSED) {
+ err("error sending message (%s)", strerror(errno));
+ goto exit;
+ }
+
+ if (!started_daemon) {
+ info("try to start udevd daemon");
+ retval = start_daemon();
+ if (retval) {
+ dbg("error starting daemon");
+ goto exit;
+ }
+ dbg("udevd daemon started");
+ started_daemon = 1;
+ } else {
+ dbg("retry to connect %d", UDEVSEND_WAIT_MAX_SECONDS * UDEVSEND_WAIT_LOOP_PER_SECOND - loop);
+ usleep(1000 * 1000 / UDEVSEND_WAIT_LOOP_PER_SECOND);
+ }