mirror of
https://github.com/FeralInteractive/gamemode.git
synced 2025-06-07 08:07:20 +02:00
gamemode: Make game_mode_context_find_exe() thread-safe
Let's use our new safe_snprintf() helper. It's designed to make thread-safe usage easy and will also be used by the next commits. Reported-by: Alex Smith <alex@alex-smith.me.uk> Signed-off-by: Kai Krakow <kai@kaishome.de>
This commit is contained in:
parent
81a52ddc4d
commit
3a6d258eae
@ -677,13 +677,21 @@ GameModeContext *game_mode_context_instance()
|
|||||||
*/
|
*/
|
||||||
static char *game_mode_context_find_exe(pid_t pid)
|
static char *game_mode_context_find_exe(pid_t pid)
|
||||||
{
|
{
|
||||||
static char proc_path[PATH_MAX] = { 0 };
|
char buffer[PATH_MAX];
|
||||||
|
char *proc_path = NULL;
|
||||||
|
|
||||||
if (snprintf(proc_path, sizeof(proc_path), "/proc/%d/exe", pid) < 0) {
|
if (!(proc_path = safe_snprintf(buffer, "/proc/%d/exe", pid)))
|
||||||
LOG_ERROR("Unable to find executable for PID %d: %s\n", pid, strerror(errno));
|
goto fail;
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Allocate the realpath if possible */
|
/* Allocate the realpath if possible */
|
||||||
return realpath(proc_path, NULL);
|
char *exe = realpath(proc_path, NULL);
|
||||||
|
free(proc_path);
|
||||||
|
if (!exe)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
return exe;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
LOG_ERROR("Unable to find executable for PID %d: %s\n", pid, strerror(errno));
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user