Skip to content

Commit 7dd1e8e

Browse files
committed
Fix issue with shader IPC file permissions across user accounts, add config for opting out of metrics collection
#90
1 parent 236fcc1 commit 7dd1e8e

6 files changed

Lines changed: 21 additions & 3 deletions

File tree

bin/xr_driver_cli

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ then
122122
if [ -n "$2" ]; then
123123
config_value="$2"
124124
fi
125+
elif [ "$1" == "--disable-metrics" ] || [ "$1" == "-dm" ]; then
126+
config_key="metrics_disabled"
127+
config_value="true"
125128
elif [ "$1" == "--request-token" ] || [ "$1" == "--verify-token" ] || [ "$1" == "--refresh-license" ] || [ "$1" == "--get-hardware-id" ]; then
126129
config_type="string"
127130
config_key="hardware_id"
@@ -234,6 +237,7 @@ Options:
234237
-sbs3d, --sbs-content-3d [true|false]
235238
-sbsds, --sbs-display-size [display_size]
236239
-sbsdd, --sbs-display-distance [display_distance]
240+
-dm, --disable-metrics
237241
--request-token [email]
238242
--verify-token [token]
239243
--refresh-license

include/config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ struct driver_config_t {
99
int mouse_sensitivity;
1010
char *output_mode;
1111
bool multi_tap_enabled;
12+
bool metrics_disabled;
1213

1314
bool debug_threads;
1415
bool debug_joystick;

src/config.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ driver_config_type *default_config() {
2424
config->mouse_sensitivity = 30;
2525
config->output_mode = strdup(mouse_output_mode);
2626
config->multi_tap_enabled = false;
27+
config->metrics_disabled = false;
2728

2829
config->debug_threads = false;
2930
config->debug_joystick = false;
@@ -113,6 +114,8 @@ driver_config_type* parse_config_file(FILE *fp) {
113114
string_config(key, value, &config->output_mode);
114115
} else if (equal(key, "multi_tap_enabled")) {
115116
boolean_config(key, value, &config->multi_tap_enabled);
117+
} else if (equal(key, "metrics_disabled")) {
118+
boolean_config(key, value, &config->metrics_disabled);
116119
}
117120

118121
plugins.handle_config_line(plugin_configs, key, value);

src/driver.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,9 @@ void update_config_from_file(FILE *fp) {
281281
if (output_mode_changed)
282282
log_message("Output mode has been changed to '%s'\n", new_config->output_mode);
283283

284+
if (config()->metrics_disabled != new_config->metrics_disabled)
285+
log_message("Metrics have been %s\n", new_config->metrics_disabled ? "disabled" : "enabled");
286+
284287
if (!config()->debug_joystick && new_config->debug_joystick)
285288
log_message("Joystick debugging has been enabled, to see it, use 'watch -n 0.1 cat $XDG_RUNTIME_DIR/xr_driver/joystick_debug' in bash\n");
286289
if (config()->debug_joystick && !new_config->debug_joystick)

src/ipc.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "logging.h"
33

44
#include <errno.h>
5+
#include <fcntl.h>
56
#include <glob.h>
67
#include <pthread.h>
78
#include <sys/ipc.h>
@@ -10,6 +11,8 @@
1011
#include <stdlib.h>
1112
#include <stdio.h>
1213
#include <stdbool.h>
14+
#include <sys/stat.h>
15+
#include <sys/types.h>
1316

1417
const char *sombrero_ipc_file_prefix = "/tmp/shader_runtime_";
1518

@@ -66,12 +69,14 @@ void setup_ipc_value(const char *name, void **shmemValue, size_t size, bool debu
6669
strcpy(path, sombrero_ipc_file_prefix);
6770
strcat(path, name);
6871

69-
FILE *ipc_file = fopen(path, "w");
70-
if (ipc_file == NULL) {
72+
mode_t old_umask = umask(0);
73+
int fd = open(path, O_CREAT, 0666);
74+
if (fd == -1) {
7175
log_error("Could not create IPC shared file\n");
7276
exit(1);
7377
}
74-
fclose(ipc_file);
78+
close(fd);
79+
umask(old_umask);
7580

7681
key_t key = ftok(path, 0);
7782
if (debug) log_debug("ipc_key, got key %d for path %s\n", key, path);

src/plugins/metrics.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const char *UA_MEASUREMENT_ID = "G-Z94MXP18T6";
1515
const char *UA_CLIENT_ID="ARLinuxDriver";
1616
void log_metric(char *event_name) {
1717
#ifdef UA_API_SECRET
18+
if (config()->metrics_disabled) return;
19+
1820
CURL *curl;
1921
CURLcode res;
2022

0 commit comments

Comments
 (0)