I'm thinking about creating a new module for SMART disk monitoring. As far as I can tell, there are three options to implement this:
I'd prefer to use libatasmart as this would add native support with only a single additional dependency.
Does anyone know if it is possible to use libatasmart without root privileges?
libatasmart
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <atasmart.h>
int main(void) {
uint64_t mkelvin = 0;
const char *device = "/dev/sda";
SkDisk *d = NULL;
if (-1 == (sk_disk_open(device, &d))) {
fprintf(stderr, "Failed to open disk %s: %s\n", device, strerror(errno));
return 1;
}
if (-1 == (sk_disk_smart_read_data(d))) {
fprintf(stderr, "Failed to read SMART data: %s\n", strerror(errno));
goto finish;
}
if (-1 == (sk_disk_smart_get_temperature(d, &mkelvin))) {
fprintf(stderr, "Failed to get temperature: %s\n", strerror(errno));
goto finish;
}
printf("%llu\n", (unsigned long long)mkelvin);
finish:
if (NULL != d) {
sk_disk_free(d);
}
return 0;
}
smartmontools are cross-platform available and the *BSD flavours would benefit from it too.
Those like me that do not use init systemd will be forced to install additional dependencies.
Does anyone know if it is possible to use libatasmart without root privileges?
visudo
computer_name ALL=NOPASSWD:/usr/bin/program_name
@fonic OMFG. I can't wait to see this implemented. :scream:
Most helpful comment
@fonic OMFG. I can't wait to see this implemented. :scream: