]> git.mdlowis.com Git - proto/aos.git/commitdiff
remove old telemetry and use lib
authorMichael D. Lowis <mike@mdlowis.com>
Tue, 2 May 2023 03:03:13 +0000 (23:03 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Tue, 2 May 2023 03:03:13 +0000 (23:03 -0400)
bin/pick/io.h [deleted file]
bin/pick/telem.c [deleted file]
bin/pick/writefd.c [deleted file]
bin/pick/x11.c
bin/pick/x11_gc.c

diff --git a/bin/pick/io.h b/bin/pick/io.h
deleted file mode 100644 (file)
index d5fe389..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-/**
-    @file
-    Helper functions for reading and writing file descriptors as well as outputting telemetry data.
-*/
-void telem_send(char* fmt, ...);
-long writefd(int fd, char* data, long towrite);
-long readfd(int fd, char* data, long toread);
-char* readfile(char* path);
-char* abspath(char* path);
diff --git a/bin/pick/telem.c b/bin/pick/telem.c
deleted file mode 100644 (file)
index 913688d..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-#include <stdc.h>
-#include <time.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <pwd.h>
-#include "io.h"
-
-static int TelemFd = -1;
-static char TelemBuf[16384];
-
-static int open_telem(char* path)
-{
-    static unsigned long prev = 0;
-    unsigned long curr = time(NULL);
-    if ((TelemFd < 0) && ((curr - prev) >= 1))
-    {
-        struct stat st = {0};
-        if ((stat(path, &st) >= 0) && S_ISFIFO(st.st_mode))
-        {
-            TelemFd = open(path, O_WRONLY|O_NONBLOCK, 0);
-            prev = curr;
-        }
-    }
-    return TelemFd;
-}
-
-static void close_telem(void)
-{
-    close(TelemFd);
-    TelemFd = -1;
-}
-
-static char* advance(char* buf, size_t* p_len, long nwrite)
-{
-    if (nwrite >= 0)
-    {
-        *p_len -= nwrite;
-        buf = (buf + nwrite);
-    }
-    return buf;
-}
-
-static char* add_timestamp(char* buf, size_t* p_len)
-{
-    time_t rawtime;
-    time(&rawtime);
-    struct tm* timeinfo = localtime(&rawtime);
-    long nwrite = strftime(buf, *p_len, "[%F %T] ", timeinfo);
-    return advance(buf, p_len, nwrite);
-}
-
-static char* add_pid(char* buf, size_t* p_len)
-{
-    long nwrite = snprintf(buf, *p_len, "%s(%d) ", ARGV0, getpid());
-    return advance(buf, p_len, nwrite);
-}
-
-static char* add_message(char* buf, size_t* p_len, char* fmt, va_list args)
-{
-    long nwrite = vsnprintf(buf, *p_len, fmt, args);
-    return advance(buf, p_len, nwrite);
-}
-
-static char* get_fifo_path(void)
-{
-    static char path[1024] = {0};
-    if (!path[0])
-    {
-        snprintf(path, sizeof(path)-1,"%s/tide-telem", getpwuid(getuid())->pw_dir);
-    }
-    return path;
-}
-
-void telem_send(char* fmt, ...)
-{
-    char* str = TelemBuf;
-    size_t nleft = sizeof(TelemBuf);
-    int fd = open_telem(get_fifo_path());
-    if (fd >= 0)
-    {
-        void (*sigfn)(int) = signal(SIGPIPE, SIG_IGN);
-        va_list args;
-        va_start(args, fmt);
-        str = add_timestamp(str, &nleft);
-        str = add_pid(str, &nleft);
-        str = add_message(str, &nleft, fmt, args);
-        va_end(args);
-        if (writefd(fd, TelemBuf, str - TelemBuf) < 0)
-        {
-            close_telem();
-        }
-        signal(SIGPIPE, sigfn);
-    }
-}
diff --git a/bin/pick/writefd.c b/bin/pick/writefd.c
deleted file mode 100644 (file)
index c5c2eac..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-#include <stdc.h>
-#include "io.h"
-
-long writefd(int fd, char* data, long towrite)
-{
-    long nwrite = 0;
-    while (towrite && ((nwrite = write(fd, data, towrite)) > 0))
-    {
-        data += nwrite;
-        towrite -= nwrite;
-    }
-    return nwrite;
-}
index 8612a27dd5b138d3b3741300c3c17624f6b5ec05..bb030cb36e9978720862cf3bf7e825300ce89572 100644 (file)
@@ -1,7 +1,6 @@
 #include <liba.h>
 #include <stdc.h>
 #include "x11.h"
-#include "io.h"
 #include <locale.h>
 #include <signal.h>
 #include <sys/types.h>
@@ -103,7 +102,7 @@ void x11_process_events(XConf* x)
     /* process the entire event queue */
     while (XEventsQueued(x->display, QueuedAfterReading))
     {
-        telem_send("EV_READ_QUEUE(pending: %d)\n", XPending(x->display));
+        Telemetry_Send("EV_READ_QUEUE(pending: %d)\n", XPending(x->display));
         XGetMotionEvents(x->display, x->self, CurrentTime, CurrentTime, &nevents);
 
         for (XEvent e; XPending(x->display);)
@@ -112,12 +111,12 @@ void x11_process_events(XConf* x)
             update_state(x, &e);
             if (!XFilterEvent(&e, None) && x->eventfns[e.type])
             {
-                telem_send("EV_HANDLE(type: %d)\n", e.type);
+                Telemetry_Send("EV_HANDLE(type: %d)\n", e.type);
                 (x->eventfns[e.type])(x, &e);
             }
             else
             {
-                telem_send("EV_IGNORE(type: %d)\n", e.type);
+                Telemetry_Send("EV_IGNORE(type: %d)\n", e.type);
             }
 
             /* log error here */
@@ -126,7 +125,7 @@ void x11_process_events(XConf* x)
             {
                 char msg[8192];
                 XGetErrorText(x->display, err->error_code, msg, sizeof(msg));
-                telem_send("XERROR(%s)\n", msg);
+                Telemetry_Send("XERROR(%s)\n", msg);
                 x11_error_clear();
             }
         }
@@ -252,6 +251,6 @@ int x11_seturgent(XConf* x, int urgent)
         hints.flags &= ~XUrgencyHint;
     }
     status = XSetWMHints(x->display, x->self, &hints);
-    telem_send("URGENT(%d %d)\n", urgent, status);
+    Telemetry_Send("URGENT(%d %d)\n", urgent, status);
     return status;
 }
index d7d7a7d835549240527ed2fa305865215d3addff..c0cd4697c1b7d014dbbdb34c3dc266148d7365b3 100644 (file)
@@ -1,11 +1,11 @@
+#include <liba.h>
 #include <stdc.h>
 #include "x11.h"
-#include "io.h"
 #include <X11/extensions/Xinerama.h>
 
 void x11_resize(XConf* x, XEvent* e)
 {
-    telem_send("XRESIZE(w: %d, h: %d)\n", e->xconfigure.width, e->xconfigure.height);
+    Telemetry_Send("XRESIZE(w: %d, h: %d)\n", e->xconfigure.width, e->xconfigure.height);
     if (e->xconfigure.width != x->width || e->xconfigure.height != x->height)
     {
         x->width  = e->xconfigure.width;
@@ -19,12 +19,12 @@ void x11_resize(XConf* x, XEvent* e)
 void x11_mapnotify(XConf* x, XEvent* e)
 {
     (void)x;
-    telem_send("XMAPNOTIFY(0x%x)\n", e->xmap.window);
+    Telemetry_Send("XMAPNOTIFY(0x%x)\n", e->xmap.window);
 }
 
 void x11_enternotify(XConf* x, XEvent* e)
 {
-    telem_send("XENTERNOTIFY(0x%x)\n", e->xmap.window);
+    Telemetry_Send("XENTERNOTIFY(0x%x)\n", e->xmap.window);
     x11_seturgent(x, 0);
 }