Browse Source

Queue job by posting to socket

Yannick Ulrich 3 năm trước cách đây
mục cha
commit
1d6fba63d5
1 tập tin đã thay đổi với 8 bổ sung21 xóa
  1. 8 21
      main.c

+ 8 - 21
main.c

@@ -70,7 +70,7 @@ listen_on_socket()
 }
 
 int
-is_alive()
+queue_job(struct Job job)
 {
     int sock;
     struct sockaddr_un addr;
@@ -88,13 +88,12 @@ is_alive()
         err("failed to open socket");
         return 0;
     }
-    return 0;
-}
-
-void
-queue_job(struct Job job)
-{
-
+    if (write(sock, &job, sizeof(job)) < 0) {
+        err("failed to write");
+        return 0;
+    }
+    close(sock);
+    return 1;
 }
 
 void
@@ -136,19 +135,7 @@ main(int argc, char *argv[])
     }
 
     make_socket_path();
-
-    // Check if an existing instance is running, if not start a listener
-    if (is_alive() == 0) {
-        printf("first instance, listening\n");
-        listen_on_socket();
-    } else {
-        // A processing job is already running, queue this job on the existing process and block
-        printf("second instance, running\n");
-        queue_job(job);
-    }
-
-    start_processing(job);
-    wait(NULL);
+    queue_job(job);
 
     return 0;
 }