Bladeren bron

Don't use pipes

Don't use pipes - write directly to the port instead.
Mateusz Bugdalski 13 jaren geleden
bovenliggende
commit
abdb1d5aa5
1 gewijzigde bestanden met toevoegingen van 6 en 3 verwijderingen
  1. 6 3
      sprog.c

+ 6 - 3
sprog.c

@@ -5,6 +5,7 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <sys/select.h>
+#include <sys/wait.h>
 #include <sprog.h>
 
 void sprog_process(const struct sprog_family *fam, void *arg, int nstdin, int nstdout);
@@ -35,15 +36,17 @@ void sprog_communicate(const struct sprog_family *fam, const char *port, int bau
   if(pid<0)
     sprog_error("Unable to fork: %s\n", strerror(errno));
   else {
-    if(pid==0) {
+    if(pid!=0) {
       close(pstdin[0]);
       close(pstdout[1]);
-      serial_communicate(&dev, pstdout[0], pstdin[1]);
+      /* serial_communicate(&dev, pstdout[0], pstdin[1]); */
+      waitpid(pid, NULL, 0);
       fam->close(arg);
     } else {
       close(pstdin[1]);
       close(pstdout[0]);
-      sprog_process(fam, arg, pstdin[0], pstdout[1]);
+      /* sprog_process(fam, arg, pstdin[0], pstdout[1]); */
+      sprog_process(fam, arg, dev.fd, dev.fd);
     }
   }
 }