daemon_config.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. /*
  2. Copyright (c) 2017-2019, Feral Interactive
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are met:
  6. * Redistributions of source code must retain the above copyright notice,
  7. this list of conditions and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. * Neither the name of Feral Interactive nor the names of its contributors
  12. may be used to endorse or promote products derived from this software
  13. without specific prior written permission.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  15. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  17. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  18. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  19. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  20. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  21. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  22. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  23. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  24. POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #define _GNU_SOURCE
  27. #include "daemon_config.h"
  28. #include "logging.h"
  29. /* Ben Hoyt's inih library */
  30. #include "ini.h"
  31. #include <linux/limits.h>
  32. #include <pthread.h>
  33. #include <pwd.h>
  34. #include <stdio.h>
  35. #include <string.h>
  36. #include <sys/types.h>
  37. /* Name and possible location of the config file */
  38. #define CONFIG_NAME "gamemode.ini"
  39. /* Default value for the reaper frequency */
  40. #define DEFAULT_REAPER_FREQ 5
  41. /* Helper macro for defining the config variable getter */
  42. #define DEFINE_CONFIG_GET(name) \
  43. long config_get_##name(GameModeConfig *self) \
  44. { \
  45. long value = 0; \
  46. memcpy_locked_config(self, &value, &self->values.name, sizeof(long)); \
  47. return value; \
  48. }
  49. /**
  50. * The config holds various details as needed
  51. * and a rwlock to allow config_reload to be called
  52. */
  53. struct GameModeConfig {
  54. pthread_rwlock_t rwlock;
  55. int inotfd;
  56. int inotwd;
  57. struct {
  58. char whitelist[CONFIG_LIST_MAX][CONFIG_VALUE_MAX];
  59. char blacklist[CONFIG_LIST_MAX][CONFIG_VALUE_MAX];
  60. long script_timeout;
  61. char startscripts[CONFIG_LIST_MAX][CONFIG_VALUE_MAX];
  62. char endscripts[CONFIG_LIST_MAX][CONFIG_VALUE_MAX];
  63. char defaultgov[CONFIG_VALUE_MAX];
  64. char desiredgov[CONFIG_VALUE_MAX];
  65. char softrealtime[CONFIG_VALUE_MAX];
  66. long renice;
  67. char ioprio[CONFIG_VALUE_MAX];
  68. long inhibit_screensaver;
  69. long reaper_frequency;
  70. char apply_gpu_optimisations[CONFIG_VALUE_MAX];
  71. long gpu_device;
  72. long nv_core_clock_mhz_offset;
  73. long nv_mem_clock_mhz_offset;
  74. long nv_powermizer_mode;
  75. char amd_performance_level[CONFIG_VALUE_MAX];
  76. long require_supervisor;
  77. char supervisor_whitelist[CONFIG_LIST_MAX][CONFIG_VALUE_MAX];
  78. char supervisor_blacklist[CONFIG_LIST_MAX][CONFIG_VALUE_MAX];
  79. } values;
  80. };
  81. /*
  82. * Add values to a char list
  83. */
  84. static bool append_value_to_list(const char *list_name, const char *value,
  85. char list[CONFIG_LIST_MAX][CONFIG_VALUE_MAX])
  86. {
  87. unsigned int i = 0;
  88. while (*list[i] && ++i < CONFIG_LIST_MAX)
  89. ;
  90. if (i < CONFIG_LIST_MAX) {
  91. strncpy(list[i], value, CONFIG_VALUE_MAX);
  92. if (list[i][CONFIG_VALUE_MAX - 1] != '\0') {
  93. LOG_ERROR("Config: Could not add [%s] to [%s], exceeds length limit of %d\n",
  94. value,
  95. list_name,
  96. CONFIG_VALUE_MAX);
  97. memset(list[i], 0, sizeof(list[i]));
  98. return false;
  99. }
  100. } else {
  101. LOG_ERROR("Config: Could not add [%s] to [%s], exceeds number of %d\n",
  102. value,
  103. list_name,
  104. CONFIG_LIST_MAX);
  105. return false;
  106. }
  107. return true;
  108. }
  109. /*
  110. * Get a long value from a string
  111. */
  112. static bool get_long_value(const char *value_name, const char *value, long *output)
  113. {
  114. char *end = NULL;
  115. long config_value = strtol(value, &end, 10);
  116. if (errno == ERANGE) {
  117. LOG_ERROR("Config: %s overflowed, given [%s]\n", value_name, value);
  118. return false;
  119. } else if (!(*value != '\0' && end && *end == '\0')) {
  120. LOG_ERROR("Config: %s was invalid, given [%s]\n", value_name, value);
  121. return false;
  122. } else {
  123. *output = config_value;
  124. }
  125. return true;
  126. }
  127. /*
  128. * Get a long value from a hex string
  129. */
  130. __attribute__((unused)) static bool get_long_value_hex(const char *value_name, const char *value,
  131. long *output)
  132. {
  133. char *end = NULL;
  134. long config_value = strtol(value, &end, 16);
  135. if (errno == ERANGE) {
  136. LOG_ERROR("Config: %s overflowed, given [%s]\n", value_name, value);
  137. return false;
  138. } else if (!(*value != '\0' && end && *end == '\0')) {
  139. LOG_ERROR("Config: %s was invalid, given [%s]\n", value_name, value);
  140. return false;
  141. } else {
  142. *output = config_value;
  143. }
  144. return true;
  145. }
  146. /**
  147. * Simple strstr scheck
  148. * Could be expanded for wildcard or regex
  149. */
  150. static bool config_string_list_contains(const char *needle,
  151. char haystack[CONFIG_LIST_MAX][CONFIG_VALUE_MAX])
  152. {
  153. for (unsigned int i = 0; i < CONFIG_LIST_MAX && haystack[i][0]; i++) {
  154. if (strstr(needle, haystack[i])) {
  155. return true;
  156. }
  157. }
  158. return false;
  159. }
  160. /*
  161. * Get a string value
  162. */
  163. static bool get_string_value(const char *value, char output[CONFIG_VALUE_MAX])
  164. {
  165. strncpy(output, value, CONFIG_VALUE_MAX - 1);
  166. output[CONFIG_VALUE_MAX - 1] = '\0';
  167. return true;
  168. }
  169. /* Controls whether to read the protected config variables */
  170. static bool load_protected = false;
  171. /*
  172. * Handler for the inih callback
  173. */
  174. static int inih_handler(void *user, const char *section, const char *name, const char *value)
  175. {
  176. GameModeConfig *self = (GameModeConfig *)user;
  177. bool valid = false;
  178. if (strcmp(section, "filter") == 0) {
  179. /* Filter subsection */
  180. if (strcmp(name, "whitelist") == 0) {
  181. valid = append_value_to_list(name, value, self->values.whitelist);
  182. } else if (strcmp(name, "blacklist") == 0) {
  183. valid = append_value_to_list(name, value, self->values.blacklist);
  184. }
  185. } else if (strcmp(section, "general") == 0) {
  186. /* General subsection */
  187. if (strcmp(name, "reaper_freq") == 0) {
  188. valid = get_long_value(name, value, &self->values.reaper_frequency);
  189. } else if (strcmp(name, "defaultgov") == 0) {
  190. valid = get_string_value(value, self->values.defaultgov);
  191. } else if (strcmp(name, "desiredgov") == 0) {
  192. valid = get_string_value(value, self->values.desiredgov);
  193. } else if (strcmp(name, "softrealtime") == 0) {
  194. valid = get_string_value(value, self->values.softrealtime);
  195. } else if (strcmp(name, "renice") == 0) {
  196. valid = get_long_value(name, value, &self->values.renice);
  197. } else if (strcmp(name, "ioprio") == 0) {
  198. valid = get_string_value(value, self->values.ioprio);
  199. } else if (strcmp(name, "inhibit_screensaver") == 0) {
  200. valid = get_long_value(name, value, &self->values.inhibit_screensaver);
  201. }
  202. } else if (strcmp(section, "gpu") == 0) {
  203. /* Protect the user - don't allow these config options from unsafe config locations */
  204. if (!load_protected) {
  205. LOG_ERROR(
  206. "The [gpu] config section is not configurable from unsafe config files! Option %s "
  207. "will be ignored!\n",
  208. name);
  209. LOG_ERROR(
  210. "Consider moving this option to /etc/gamemode.ini or "
  211. "/usr/share/gamemode/gamemode.ini\n");
  212. }
  213. /* GPU subsection */
  214. if (strcmp(name, "apply_gpu_optimisations") == 0) {
  215. valid = get_string_value(value, self->values.apply_gpu_optimisations);
  216. } else if (strcmp(name, "gpu_device") == 0) {
  217. valid = get_long_value(name, value, &self->values.gpu_device);
  218. } else if (strcmp(name, "nv_core_clock_mhz_offset") == 0) {
  219. valid = get_long_value(name, value, &self->values.nv_core_clock_mhz_offset);
  220. } else if (strcmp(name, "nv_mem_clock_mhz_offset") == 0) {
  221. valid = get_long_value(name, value, &self->values.nv_mem_clock_mhz_offset);
  222. } else if (strcmp(name, "nv_powermizer_mode") == 0) {
  223. valid = get_long_value(name, value, &self->values.nv_powermizer_mode);
  224. } else if (strcmp(name, "amd_performance_level") == 0) {
  225. valid = get_string_value(value, self->values.amd_performance_level);
  226. }
  227. } else if (strcmp(section, "supervisor") == 0) {
  228. /* Supervisor subsection */
  229. if (strcmp(name, "supervisor_whitelist") == 0) {
  230. valid = append_value_to_list(name, value, self->values.supervisor_whitelist);
  231. } else if (strcmp(name, "supervisor_blacklist") == 0) {
  232. valid = append_value_to_list(name, value, self->values.supervisor_blacklist);
  233. } else if (strcmp(name, "require_supervisor") == 0) {
  234. valid = get_long_value(name, value, &self->values.require_supervisor);
  235. }
  236. } else if (strcmp(section, "custom") == 0) {
  237. /* Custom subsection */
  238. if (strcmp(name, "start") == 0) {
  239. valid = append_value_to_list(name, value, self->values.startscripts);
  240. } else if (strcmp(name, "end") == 0) {
  241. valid = append_value_to_list(name, value, self->values.endscripts);
  242. } else if (strcmp(name, "script_timeout") == 0) {
  243. valid = get_long_value(name, value, &self->values.script_timeout);
  244. }
  245. }
  246. if (!valid) {
  247. /* Simply ignore the value, but with a log */
  248. LOG_MSG("Config: Value ignored [%s] %s=%s\n", section, name, value);
  249. }
  250. return 1;
  251. }
  252. /*
  253. * Load the config file
  254. */
  255. static void load_config_files(GameModeConfig *self)
  256. {
  257. /* grab the current dir */
  258. char *config_location_local = get_current_dir_name();
  259. /* Get home config location */
  260. char *config_location_home = NULL;
  261. const char *cfg = getenv("XDG_CONFIG_HOME");
  262. if (cfg) {
  263. config_location_home = realpath(cfg, NULL);
  264. } else {
  265. cfg = getenv("HOME");
  266. if (cfg) {
  267. char *cfg_full = NULL;
  268. if (asprintf(&cfg_full, "%s/.config", cfg) > 0) {
  269. config_location_home = realpath(cfg_full, NULL);
  270. free(cfg_full);
  271. }
  272. } else {
  273. struct passwd *p = getpwuid(getuid());
  274. if (p) {
  275. config_location_home = realpath(p->pw_dir, NULL);
  276. }
  277. }
  278. }
  279. /* Take the write lock for the internal data */
  280. pthread_rwlock_wrlock(&self->rwlock);
  281. /* Clear our config values */
  282. memset(&self->values, 0, sizeof(self->values));
  283. /* Set some non-zero defaults */
  284. self->values.inhibit_screensaver = 1; /* Defaults to on */
  285. self->values.reaper_frequency = DEFAULT_REAPER_FREQ;
  286. self->values.gpu_device = -1; /* 0 is a valid device ID so use -1 to indicate no value */
  287. self->values.nv_powermizer_mode = -1;
  288. self->values.nv_core_clock_mhz_offset = -1;
  289. self->values.nv_mem_clock_mhz_offset = -1;
  290. self->values.script_timeout = 10; /* Default to 10 seconds for scripts */
  291. /*
  292. * Locations to load, in order
  293. * Arrays merge and values overwrite
  294. */
  295. struct ConfigLocation {
  296. const char *path;
  297. bool protected;
  298. };
  299. struct ConfigLocation locations[] = {
  300. { "/usr/share/gamemode", true }, /* shipped default config */
  301. { "/etc", true }, /* administrator config */
  302. { config_location_home, false }, /* $XDG_CONFIG_HOME or $HOME/.config/ */
  303. { config_location_local, false } /* local data eg. $PWD */
  304. };
  305. /* Load each file in order and overwrite values */
  306. for (unsigned int i = 0; i < sizeof(locations) / sizeof(locations[0]); i++) {
  307. char *path = NULL;
  308. if (locations[i].path && asprintf(&path, "%s/" CONFIG_NAME, locations[i].path) > 0) {
  309. FILE *f = fopen(path, "r");
  310. if (f) {
  311. LOG_MSG("Loading config file [%s]\n", path);
  312. load_protected = locations[i].protected;
  313. int error = ini_parse_file(f, inih_handler, (void *)self);
  314. /* Failure here isn't fatal */
  315. if (error) {
  316. LOG_MSG("Failed to parse config file - error on line %d!\n", error);
  317. }
  318. }
  319. free(path);
  320. }
  321. }
  322. /* clean up memory */
  323. free(config_location_home);
  324. free(config_location_local);
  325. /* Release the lock */
  326. pthread_rwlock_unlock(&self->rwlock);
  327. }
  328. /*
  329. * Copy a config parameter with a lock
  330. */
  331. static void memcpy_locked_config(GameModeConfig *self, void *dst, void *src, size_t n)
  332. {
  333. /* Take the read lock */
  334. pthread_rwlock_rdlock(&self->rwlock);
  335. /* copy the data */
  336. memcpy(dst, src, n);
  337. /* release the lock */
  338. pthread_rwlock_unlock(&self->rwlock);
  339. }
  340. /*
  341. * Create a context object
  342. */
  343. GameModeConfig *config_create(void)
  344. {
  345. GameModeConfig *newconfig = (GameModeConfig *)malloc(sizeof(GameModeConfig));
  346. return newconfig;
  347. }
  348. /*
  349. * Initialise the config
  350. */
  351. void config_init(GameModeConfig *self)
  352. {
  353. pthread_rwlock_init(&self->rwlock, NULL);
  354. /* load the initial config */
  355. load_config_files(self);
  356. }
  357. /*
  358. * Re-load the config file
  359. */
  360. void config_reload(GameModeConfig *self)
  361. {
  362. load_config_files(self);
  363. }
  364. /*
  365. * Destroy the config
  366. */
  367. void config_destroy(GameModeConfig *self)
  368. {
  369. pthread_rwlock_destroy(&self->rwlock);
  370. /* Finally, free the memory */
  371. free(self);
  372. }
  373. /*
  374. * Checks if the client is whitelisted
  375. */
  376. bool config_get_client_whitelisted(GameModeConfig *self, const char *client)
  377. {
  378. /* Take the read lock for the internal data */
  379. pthread_rwlock_rdlock(&self->rwlock);
  380. /* If the whitelist is empty then everything passes */
  381. bool found = true;
  382. if (self->values.whitelist[0][0]) {
  383. /*
  384. * Check if the value is found in our whitelist
  385. * Currently is a simple strstr check, but could be modified for wildcards etc.
  386. */
  387. found = config_string_list_contains(client, self->values.whitelist);
  388. }
  389. /* release the lock */
  390. pthread_rwlock_unlock(&self->rwlock);
  391. return found;
  392. }
  393. /*
  394. * Checks if the client is blacklisted
  395. */
  396. bool config_get_client_blacklisted(GameModeConfig *self, const char *client)
  397. {
  398. /* Take the read lock for the internal data */
  399. pthread_rwlock_rdlock(&self->rwlock);
  400. /*
  401. * Check if the value is found in our whitelist
  402. * Currently is a simple strstr check, but could be modified for wildcards etc.
  403. */
  404. bool found = config_string_list_contains(client, self->values.blacklist);
  405. /* release the lock */
  406. pthread_rwlock_unlock(&self->rwlock);
  407. return found;
  408. }
  409. /*
  410. * Gets the reaper frequency
  411. */
  412. DEFINE_CONFIG_GET(reaper_frequency)
  413. /*
  414. * Gets the screensaver inhibit setting
  415. */
  416. bool config_get_inhibit_screensaver(GameModeConfig *self)
  417. {
  418. long val;
  419. memcpy_locked_config(self, &val, &self->values.inhibit_screensaver, sizeof(long));
  420. return val == 1;
  421. }
  422. /*
  423. * Get a set of scripts to call when gamemode starts
  424. */
  425. void config_get_gamemode_start_scripts(GameModeConfig *self,
  426. char scripts[CONFIG_LIST_MAX][CONFIG_VALUE_MAX])
  427. {
  428. memcpy_locked_config(self,
  429. scripts,
  430. self->values.startscripts,
  431. sizeof(self->values.startscripts));
  432. }
  433. /*
  434. * Get a set of scripts to call when gamemode ends
  435. */
  436. void config_get_gamemode_end_scripts(GameModeConfig *self,
  437. char scripts[CONFIG_LIST_MAX][CONFIG_VALUE_MAX])
  438. {
  439. memcpy_locked_config(self, scripts, self->values.endscripts, sizeof(self->values.startscripts));
  440. }
  441. /*
  442. * Get the script timemout value
  443. */
  444. DEFINE_CONFIG_GET(script_timeout)
  445. /*
  446. * Get the chosen default governor
  447. */
  448. void config_get_default_governor(GameModeConfig *self, char governor[CONFIG_VALUE_MAX])
  449. {
  450. memcpy_locked_config(self, governor, self->values.defaultgov, sizeof(self->values.defaultgov));
  451. }
  452. /*
  453. * Get the chosen desired governor
  454. */
  455. void config_get_desired_governor(GameModeConfig *self, char governor[CONFIG_VALUE_MAX])
  456. {
  457. memcpy_locked_config(self, governor, self->values.desiredgov, sizeof(self->values.desiredgov));
  458. }
  459. /*
  460. * Get the chosen soft realtime behavior
  461. */
  462. void config_get_soft_realtime(GameModeConfig *self, char softrealtime[CONFIG_VALUE_MAX])
  463. {
  464. memcpy_locked_config(self,
  465. softrealtime,
  466. self->values.softrealtime,
  467. sizeof(self->values.softrealtime));
  468. }
  469. /*
  470. * Get the renice value
  471. */
  472. long config_get_renice_value(GameModeConfig *self)
  473. {
  474. long value = 0;
  475. memcpy_locked_config(self, &value, &self->values.renice, sizeof(long));
  476. return value;
  477. }
  478. /*
  479. * Get the ioprio value
  480. */
  481. long config_get_ioprio_value(GameModeConfig *self)
  482. {
  483. long value = 0;
  484. char ioprio_value[CONFIG_VALUE_MAX] = { 0 };
  485. memcpy_locked_config(self, ioprio_value, &self->values.ioprio, sizeof(self->values.ioprio));
  486. if (0 == strncmp(ioprio_value, "off", sizeof(self->values.ioprio)))
  487. value = IOPRIO_DONT_SET;
  488. else if (0 == strncmp(ioprio_value, "default", sizeof(self->values.ioprio)))
  489. value = IOPRIO_RESET_DEFAULT;
  490. else
  491. value = atoi(ioprio_value);
  492. return value;
  493. }
  494. /*
  495. * Get various config info for gpu optimisations
  496. */
  497. void config_get_apply_gpu_optimisations(GameModeConfig *self, char value[CONFIG_VALUE_MAX])
  498. {
  499. memcpy_locked_config(self,
  500. value,
  501. &self->values.apply_gpu_optimisations,
  502. sizeof(self->values.apply_gpu_optimisations));
  503. }
  504. /* Define the getters for GPU values */
  505. DEFINE_CONFIG_GET(gpu_device)
  506. DEFINE_CONFIG_GET(nv_core_clock_mhz_offset)
  507. DEFINE_CONFIG_GET(nv_mem_clock_mhz_offset)
  508. DEFINE_CONFIG_GET(nv_powermizer_mode)
  509. void config_get_amd_performance_level(GameModeConfig *self, char value[CONFIG_VALUE_MAX])
  510. {
  511. memcpy_locked_config(self,
  512. value,
  513. &self->values.amd_performance_level,
  514. sizeof(self->values.amd_performance_level));
  515. }
  516. /*
  517. char supervisor_whitelist[CONFIG_LIST_MAX][CONFIG_VALUE_MAX];
  518. char supervisor_blacklist[CONFIG_LIST_MAX][CONFIG_VALUE_MAX];
  519. */
  520. DEFINE_CONFIG_GET(require_supervisor)
  521. /*
  522. * Checks if the supervisor is whitelisted
  523. */
  524. bool config_get_supervisor_whitelisted(GameModeConfig *self, const char *supervisor)
  525. {
  526. /* Take the read lock for the internal data */
  527. pthread_rwlock_rdlock(&self->rwlock);
  528. /* If the whitelist is empty then everything passes */
  529. bool found = true;
  530. if (self->values.supervisor_whitelist[0][0]) {
  531. /*
  532. * Check if the value is found in our whitelist
  533. * Currently is a simple strstr check, but could be modified for wildcards etc.
  534. */
  535. found = config_string_list_contains(supervisor, self->values.supervisor_whitelist);
  536. }
  537. /* release the lock */
  538. pthread_rwlock_unlock(&self->rwlock);
  539. return found;
  540. }
  541. /*
  542. * Checks if the supervisor is blacklisted
  543. */
  544. bool config_get_supervisor_blacklisted(GameModeConfig *self, const char *supervisor)
  545. {
  546. /* Take the read lock for the internal data */
  547. pthread_rwlock_rdlock(&self->rwlock);
  548. /*
  549. * Check if the value is found in our whitelist
  550. * Currently is a simple strstr check, but could be modified for wildcards etc.
  551. */
  552. bool found = config_string_list_contains(supervisor, self->values.supervisor_blacklist);
  553. /* release the lock */
  554. pthread_rwlock_unlock(&self->rwlock);
  555. return found;
  556. }