- retval = msgctl(msgid, IPC_STAT, &msg_queue);
- if (retval == -1) {
- dbg("error getting info on ipc queue");
- goto exit;
+ retval = sendto(sock, &msg, size, 0, (struct sockaddr *)&saddr, addrlen);
+ if (retval != -1) {
+ retval = 0;
+ goto close_and_exit;
+ }
+
+ if (errno != ECONNREFUSED) {
+ dbg("error sending message");
+ goto close_and_exit;
+ }
+
+ if (!started_daemon) {
+ dbg("connect failed, try starting daemon...");
+ retval = start_daemon();
+ if (retval) {
+ dbg("error starting daemon");
+ goto exit;
+ }
+
+ dbg("daemon started");
+ started_daemon = 1;
+ } else {
+ dbg("retry to connect %d", UDEVSEND_CONNECT_RETRY - loop);
+ tspec.tv_sec = 0;
+ tspec.tv_nsec = 100000000; /* 100 millisec */
+ nanosleep(&tspec, NULL);