Kms server timeout, move back kms unix domain socket to HOME because flatpak cant access it otherwise

This commit is contained in:
dec05eba
2023-04-17 23:53:18 +02:00
parent c0ebae365d
commit df2509c0aa
2 changed files with 35 additions and 25 deletions

View File

@@ -79,33 +79,18 @@ static int recv_msg_from_server(int server_fd, gsr_kms_response *response) {
return res;
}
/* We have to use $HOME because in flatpak there is no simple path that is accessible, read and write, that multiple flatpak instances can access */
static bool create_socket_path(char *output_path, size_t output_path_size) {
// Can't use /tmp because of flatpak, but fallback to it if we fail to get a valid runtime dir
char runtime_dir_path[PATH_MAX];
const char *runtime_dir = getenv("XDG_RUNTIME_DIR");
const char *flatpak_id = getenv("FLATPAK_ID");
if(runtime_dir) {
if(flatpak_id)
snprintf(runtime_dir_path, sizeof(runtime_dir_path), "%s/app/%s", runtime_dir, flatpak_id);
else
strcpy(runtime_dir_path, runtime_dir);
} else {
const uint32_t uid = getuid();
if(flatpak_id)
snprintf(runtime_dir_path, sizeof(runtime_dir_path), "/run/user/%u/app/%s", uid, flatpak_id);
else
snprintf(runtime_dir_path, sizeof(runtime_dir_path), "/run/user/%u", uid);
}
if(access(runtime_dir_path, F_OK) != 0)
strcpy(runtime_dir_path, "/tmp");
const char *home = getenv("HOME");
if(!home)
home = "/tmp";
char random_characters[11];
random_characters[10] = '\0';
if(!generate_random_characters(random_characters, 10, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 62))
return false;
snprintf(output_path, output_path_size, "%s/gsr-kms-socket-%s", runtime_dir_path, random_characters);
snprintf(output_path, output_path_size, "%s/.gsr-kms-socket-%s", home, random_characters);
return true;
}
@@ -221,6 +206,7 @@ int gsr_kms_client_init(gsr_kms_client *self, const char *card_path) {
int wait_result = waitpid(self->kms_server_pid, &status, WNOHANG);
if(wait_result != 0) {
fprintf(stderr, "gsr error: gsr_kms_client_init: kms server died or never started, error: %s\n", strerror(errno));
self->kms_server_pid = -1;
goto err;
}
}