add dead sensors' reinit, gathering all fresh data, fixed some little bugs

This commit is contained in:
2026-05-06 17:13:00 +03:00
parent c5b9d43797
commit 63f87d2283
17 changed files with 207 additions and 174 deletions

View File

@@ -120,28 +120,24 @@ static void *mainthread(void *s){
return NULL;
}
sensordata_t *sensor_new(int N, time_t pollt, const char *descr){
int sensor_init(sensordata_t *s){
FNAME();
if(!descr || !*descr) return NULL;
int fd = getFD(descr);
if(fd < 0) return NULL;
sensordata_t *s = common_new();
if(!s) return NULL;
if(!s) return FALSE;
int fd = getFD(s->path);
if(fd < 0) return FALSE;
s->fdes = fd;
s->PluginNo = N;
if(pollt) s->tpoll = pollt;
snprintf(s->name, NAME_LEN, "%s @ %s", SENSOR_NAME, descr);
snprintf(s->name, NAME_LEN, "%s", SENSOR_NAME);
s->values = MALLOC(val_t, NS);
// don't use memcpy, as `values` could be aligned
for(int i = 0; i < NS; ++i) s->values[i] = values[i];
if(!(s->ringbuffer = sl_RB_new(BUFSIZ))){
WARNX("Can't init ringbuffer!");
s->kill(s);
return NULL;
return FALSE;
}
if(pthread_create(&s->thread, NULL, mainthread, (void*)s)){
s->kill(s);
return NULL;
return FALSE;
}
return s;
return TRUE;
}