]> datadissipation.net git - ust.git/commitdiff
add non-blocking i/o option
authorgit <redacted>
Tue, 24 Feb 2026 19:09:05 +0000 (14:09 -0500)
committergit <redacted>
Tue, 24 Feb 2026 19:09:05 +0000 (14:09 -0500)
add LICENSE

LICENSE [new file with mode: 0644]
config.def.h
ust.c

diff --git a/LICENSE b/LICENSE
new file mode 100644 (file)
index 0000000..fdddb29
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,24 @@
+This is free and unencumbered software released into the public domain.
+
+Anyone is free to copy, modify, publish, use, compile, sell, or
+distribute this software, either in source code form or as a compiled
+binary, for any purpose, commercial or non-commercial, and by any
+means.
+
+In jurisdictions that recognize copyright laws, the author or authors
+of this software dedicate any and all copyright interest in the
+software to the public domain. We make this dedication for the benefit
+of the public at large and to the detriment of our heirs and
+successors. We intend this dedication to be an overt act of
+relinquishment in perpetuity of all present and future rights to this
+software under copyright law.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+For more information, please refer to <https://unlicense.org>
index ddb69f9fd96411896205d1ba22a3396da000f46e..e9df03809fe0c5a49ab4ed6ce3a4ba8fce72363d 100644 (file)
@@ -22,6 +22,14 @@ const long nspulsedelay = 1000000;
 /* lock the opened device */
 const int exclusive = 1; /*(0|1)*/
 
+/*
+ * set the device to blocking mode,
+ * on some systems this will stop all threads
+ * of a process during read/write, thus rendering
+ * ust unusable
+ */
+const int blocking = 1; /*(0|1)*/
+
 /* escape character for interactive use */
 const char escapechar = '~';
 
@@ -30,7 +38,7 @@ int verbose = 0; /*(0|1)*/
 
 /* exit timeout after piped ust reaches EOF */
 long stimeout = 0;
-long nstimeout = 1000;
+long nstimeout = 10000;
 
 /*
  * device name
diff --git a/ust.c b/ust.c
index 8ad6dd1aa6b8bda4d157b3d34c16dd146c698064..e88bdccc104a2479dd8571bfeb9c0ab885a4d9c5 100644 (file)
--- a/ust.c
+++ b/ust.c
@@ -1,3 +1,4 @@
+/* see LICENSE for license details */
 #include <sys/ioctl.h>
 
 #include <errno.h>
 
 #define IXONXOFF (IXON | IXOFF)
 
+#if defined(CCDTR_IFLOW) && defined(CDSR_OFLOW)
+ #define CDTRDSR (CDTR_IFLOW | CDSR_OFLOW)
+#endif
+
 #ifdef __linux__
  #define TERMIOS_STRUCT termios2
 #else
  #define TERMIOS_STRUCT termios
 #endif
 
-#if defined(CCDTR_IFLOW) && defined(CDSR_OFLOW)
- #define CDTRDSR (CDTR_IFLOW | CDSR_OFLOW)
-#endif
-
 typedef struct {
        char find;
        char input;
@@ -154,15 +155,17 @@ openport()
        if (!isatty(fd))
                die(2, "device \"%s\" is not a TTY\n", line);
 
-       flags = fcntl(fd, F_GETFL, 0);
-       /* opened to check with non-blocking mode, now set to blocking */
-       flags &= ~(O_NONBLOCK | O_NDELAY); 
+       if (blocking) {
+               flags = fcntl(fd, F_GETFL, 0);
+               /* opened to check with non-blocking mode, now set to blocking */
+               flags &= ~(O_NONBLOCK | O_NDELAY); 
 
-       if (fcntl(fd, F_SETFL, flags) == -1) {
-               perror("fcntl");
-               die(1, "exiting now\n");
+               if (fcntl(fd, F_SETFL, flags) == -1) {
+                       perror("fcntl");
+                       die(1, "exiting now\n");
+               }
        }
-               
+
        if (gettermattr(fd, &cntrl) == -1)
                 die(1, "failed to get device attributes\n");
 
@@ -448,6 +451,8 @@ writeport(void *unused)
        /* ust kills itself upon receiving a signal so no fancy `nanosleep()` features needed */
        nanosleep(&timeout, NULL);
        die(0, "[EOF]\n");
+
+       /* unreachable */
        return NULL;
 }
 
@@ -490,6 +495,8 @@ readport(void *unused)
                }
                nanosleep(&ts, NULL);
        }
+
+       /* unreachable */
        return NULL;
 }
 
@@ -519,7 +526,7 @@ addchar(char *buff, ssize_t size, int *scratch, const Sizes *sizes, const Args *
        }
        if (!c)
                return(size);
-       if (size == 1 && c == 1 && scratch[0] == 0) {
+       if (size == 1 && c == 1 {
                buff[to ^ 1] = args->input;
                buff[to] = args->find;
                return 2;
@@ -548,7 +555,7 @@ rmchar(char *buff, ssize_t size, int *scratch, const Args *args)
        }
        if (!c)
                return(size);
-       if (size == 1 && c == 1 && scratch[0] == 0)
+       if (size == 1 && c == 1)
                return 0;
 
        for (int i = c; i >= 0; i--) {
@@ -983,4 +990,7 @@ main(int argc, char **argv)
        pthread_create(&readthread, NULL, readport, NULL);
        pthread_join(writethread, NULL);
        pthread_join(readthread, NULL);
+
+       /* unreachable */
+       return 0;
 }