commands over unix socket
[pandora_liveinfo.git] / custom.c
diff --git a/custom.c b/custom.c
new file mode 100644 (file)
index 0000000..728e831
--- /dev/null
+++ b/custom.c
@@ -0,0 +1,48 @@
+/*
+ * This file is licensed under the Creative Commons Zero License,
+ * version 1.0, available at
+ * http://creativecommons.org/publicdomain/zero/1.0/legalcode
+ */
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <unistd.h>
+
+/*
+ * example usage:
+ * ./custom "fps: 60"
+ */
+int main(int argc, char *argv[])
+{
+  static const char socket_name[] = "\0liveinfo";
+  struct sockaddr_un sun;
+  int sock;
+  int ret;
+
+  if (argv[1] == NULL) {
+    fprintf(stderr, "usage:\n%s \"label: value\"\n", argv[0]);
+    return 1;
+  }
+
+  sock = socket(PF_UNIX, SOCK_DGRAM, 0);
+  if (sock == -1) {
+    perror("socket PF_UNIX");
+    return 1;
+  }
+
+  memset(&sun, 0, sizeof(sun));
+  sun.sun_family = AF_UNIX;
+  memcpy(sun.sun_path, socket_name, sizeof(socket_name));
+
+  ret = sendto(sock, argv[1], strlen(argv[1]), 0,
+    (struct sockaddr *)&sun, sizeof(sun));
+  if (ret < 0) {
+    perror("sendto");
+    return 1;
+  }
+
+  close(sock);
+  return 0;
+}