Minor changes

This commit is contained in:
Loic Guegan 2023-07-15 22:06:22 +02:00
parent adee9af472
commit 9f4eb5b6b8

View file

@ -17,7 +17,6 @@ void publish(void *publisher, char *filepath, char* client, long int interval);
int main (int argc, char *argv [])
{
printf("%s\n",ZMQ_TOKEN);
if(argc != 6){
printf("Usage: %s <abslogdir> <loginterval> <ip> <port> <key>",argv[0]);
exit(1);
@ -37,7 +36,7 @@ int main (int argc, char *argv [])
sprintf(bindto,"tcp://%s:%d",__ip,__port);
int rc = zmq_connect (publisher, bindto);
if(rc!=0){
printf("Failed to bind zmq on %s\n",bindto);
printf("Failed to connect to %s\n",bindto);
exit(1);
}
@ -47,27 +46,32 @@ int main (int argc, char *argv [])
int interval=INTERVAL(__loginterval);
int interval_next=INTERVAL_NEXT(__loginterval);
DIR *dr = opendir(__logdir);
while ((de = readdir(dr)) != NULL){
if(strcmp(de->d_name,".") && strcmp(de->d_name,"..")){
char *client=de->d_name;
char logfile[255];
char logfile_next[255];
sprintf(logfile,"%s/%s/%ld",__logdir,client,interval);
sprintf(logfile_next,"%s/%s/%ld",__logdir,client,interval_next);
// As long as next logfile is not available, we should wait
// for sending the current one
printf("Waiting for %s...%s\n",client,logfile_next);
while(!FILE_EXISTS(logfile_next)){
sleep(1);
}
// Send current one
if(FILE_EXISTS(logfile)){
publish(publisher,logfile,client,interval);
remove(logfile);
if(dr !=NULL){
while ((de = readdir(dr)) != NULL){
if(strcmp(de->d_name,".") && strcmp(de->d_name,"..")){
char *client=de->d_name;
char logfile[255];
char logfile_next[255];
sprintf(logfile,"%s/%s/%ld",__logdir,client,interval);
sprintf(logfile_next,"%s/%s/%ld",__logdir,client,interval_next);
// As long as next logfile is not available, we should wait
// for sending the current one
printf("Waiting for %s logger measurements...\n",client);
while(!FILE_EXISTS(logfile_next)){
sleep(1);
}
// Send current one
if(FILE_EXISTS(logfile)){
publish(publisher,logfile,client,interval);
remove(logfile);
}
}
}
closedir(dr);
}
else {
sleep(1);
}
closedir(dr);
}
zmq_close (publisher);
@ -77,7 +81,7 @@ int main (int argc, char *argv [])
}
void publish(void *publisher, char *filepath, char* client, long int interval){
printf("Publish!\n");
printf("Publishing %s measurements\n",client);
char buffer[ZMQ_MSG_SIZE];
sprintf(buffer,"%s\n%s\n%s\n%ld\n",ZMQ_TOKEN,__key,client,interval);
int msglen=strlen(buffer);