Minor changes

This commit is contained in:
Loïc Guégan 2024-02-01 15:25:11 +01:00
parent bcd7e7f5ff
commit 5bb2a260f5
2 changed files with 11 additions and 4 deletions

View file

@ -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

View file

@ -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,6 +98,11 @@ 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);