#include <fcntl.h>
#include <unistd.h>
#include <math.h>
+#include <time.h>
#include "parser.h"
#include "debug.h"
return ret;
}
+static void enable_simultaneous_reading(const char *mountpoint)
+{
+ static time_t last_simultaneous;
+ static struct mutex lock = {
+ .lock = PTHREAD_MUTEX_INITIALIZER,
+ };
+
+ time_t now = time(0);
+ int fd;
+ int ret;
+ char path[4096];
+ char one = '1';
+
+ mutex_lock(&lock);
+ /* Arbitrary 10 second limit between simultaneous reads */
+ if (now < last_simultaneous + 10) {
+ mutex_unlock(&lock);
+ return;
+ }
+
+ last_simultaneous = now;
+ mutex_unlock(&lock);
+
+ /*
+ * We only protect setting the variable. From now on we have
+ * 10 seconds time until we could race writing multiple times
+ * to this file. If that happens, well, can't help it..
+ */
+
+ strncpy(path, mountpoint, sizeof(path) - 1);
+ strncat(path, "/simultaneous/temperature", sizeof(path) - 1);
+ path[sizeof(path) - 1 ] = '\0';
+
+ fd = open(path, O_WRONLY);
+ if (path < 0) {
+ pr_err("Failed to open %s for writing: %m\n", path);
+ return;
+ }
+
+ ret = write(fd, &one, 1);
+ if (ret < 0)
+ pr_warn("Failed to write to %s: %m\n", path);
+
+ close(fd);
+}
+
static int is_mount_point(const char *str)
{
/*
parse_opts(parser_data[i], ow_path, sizeof(ow_path), &offset);
+ if (is_mountpoint)
+ enable_simultaneous_reading(mount_point);
+
while (1) {
int j;
char *tmp2;