summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Guegan <loic.guegan@mailbox.org>2024-02-01 15:25:11 +0100
committerLoic Guegan <loic.guegan@mailbox.org>2024-02-01 15:25:11 +0100
commit5bb2a260f5f2ccde8379796b5666ac42e4a9422a (patch)
tree4a675ed207317730db23e66bd05f4447ec14f820
parentbcd7e7f5ff6e532c512c3c9ab43a65030417e63a (diff)
Minor changes
-rw-r--r--Makefile3
-rw-r--r--src/subscriber.c12
2 files changed, 11 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index 555653a..b39625f 100644
--- a/Makefile
+++ b/Makefile
@@ -7,7 +7,8 @@ MACROS=\
-DZMQ_TOKEN=\"$(ZMQ_TOKEN)\" \
-DZMQ_MSG_SIZE=$(ZMQ_MSG_SIZE) \
-DLOG_DELAY=$(LOG_DELAY) \
--DMAX_QUEUE=$(MAX_QUEUE)
+-DMAX_QUEUE=$(MAX_QUEUE) \
+-DRCV_CMD=":"
all: publisher subscriber
diff --git a/src/subscriber.c b/src/subscriber.c
index 44a2a41..1471a58 100644
--- a/src/subscriber.c
+++ b/src/subscriber.c
@@ -1,6 +1,7 @@
#include <zmq.h>
#include <assert.h>
#include <signal.h>
+#include <stdlib.h> // Access to system()
#include "utils.h"
/// @brief Set to non-zero to stop the processes
@@ -60,6 +61,7 @@ int main (int argc, char *argv [])
char client[STATIC_LEN];
long int interval;
FILE *fptr;
+ char path[STATIC_LEN]=""; // Output file path
int line=1;
while(token != NULL){
if(line==2)
@@ -72,7 +74,6 @@ int main (int argc, char *argv [])
if(line==4){
double size_mib=size/(1024*1024);
printf("Data received: key=%s client=%s interval=%ld msgsize=%.2lfMiB\n",key, client, interval,size_mib);
- char path[STATIC_LEN]="";
// Create dir if not exists:
sprintf(path,"%s/%s/%s/",cdatadir,key,client);
if(!DIR_EXISTS(path)){
@@ -81,7 +82,7 @@ int main (int argc, char *argv [])
// Now open output file:
sprintf(path,"%s/%s/%s/%ld",cdatadir,key,client,interval);
char exists=FILE_EXISTS(path);
- fptr=fopen(path,"a");
+ fptr=fopen(path,"a"); // AT SOME POINT WE MUST CHECK IF WORKED!! OTHERWISE PROBLEM
if(!exists){
fwrite(CSV_HEADER"\n", strlen(CSV_HEADER)+1, 1, fptr);
}
@@ -97,10 +98,15 @@ int main (int argc, char *argv [])
line++;
}
fclose(fptr);
+#ifdef RCV_CMD
+ char cmd[STATIC_LEN*2]="";
+ sprintf(cmd,"%s %s",STRINGIFY(RCV_CMD),path); // Run the command with new file as argument
+ system(cmd); // Allow to run a supplied user command on receive
+#endif
}
zmq_close (subscriber);
zmq_ctx_destroy (context);
return 0;
-} \ No newline at end of file
+}