-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libnvidia-container: fix segfault if PATH is actually set
24d9b8a introduced a bug, that, if `PATH` was actually set to a value when libnvidia-container was ran, caused a segfault. This fixes this bug by scrapping the dynamic `PATH` behavior in favor of simply using the driver package's `driverLink` abstraction for that, which is more fit for the purpose than `PATH` either way.
- Loading branch information
Showing
1 changed file
with
8 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,42 +3,26 @@ From: Moritz Sanft <[email protected]> | |
Date: Fri, 20 Dec 2024 16:37:07 +0100 | ||
Subject: [PATCH] nvc: nvidia-docker-compatible binary lookups | ||
|
||
This patch maintains compatibility with NixOS' `virtualisation.docker.enableNvidia` option (which is to be removed soon), while also enabling supplying a custom PATH, to work with the modern CDI-based approach. | ||
This patch maintains compatibility with NixOS' `virtualisation.docker.enableNvidia` option (which is to be removed soon), while also including the driver package's path, to work with the modern CDI-based approach. | ||
--- | ||
src/nvc_info.c | 16 ++++++++++++++-- | ||
1 file changed, 14 insertions(+), 2 deletions(-) | ||
src/nvc_info.c | 5 ++++- | ||
1 file changed, 4 insertions(+), 1 deletion(-) | ||
|
||
diff --git a/src/nvc_info.c b/src/nvc_info.c | ||
index cf4b1905fd2127c28ee16649501be122d3be5261..a238fba3f4ff7786cd1a84b80b1f623553e2d377 100644 | ||
index cf4b1905fd2127c28ee16649501be122d3be5261..cdfa19721bc913d8e2adb96d106cd65ee6111623 100644 | ||
--- a/src/nvc_info.c | ||
+++ b/src/nvc_info.c | ||
@@ -243,16 +243,28 @@ static int | ||
find_binary_paths(struct error *err, struct dxcore_context* dxcore, struct nvc_driver_info* info, | ||
const char *root, const char * const bins[], size_t size) | ||
{ | ||
- char *env, *ptr; | ||
+ char *env, *ptr, *os_path; | ||
const char *dir; | ||
char tmp[PATH_MAX]; | ||
@@ -249,10 +249,13 @@ find_binary_paths(struct error *err, struct dxcore_context* dxcore, struct nvc_d | ||
char path[PATH_MAX]; | ||
int rv = -1; | ||
|
||
- if ((env = secure_getenv("PATH")) == NULL) { | ||
+ if ((os_path = secure_getenv("PATH")) == NULL) { | ||
+ // TODO: Remove this patch once `virtualisation.docker.enableNvidia` is removed from NixOS. | ||
+ // It only exists to maintain compatibility with the old nvidia-docker package. | ||
+ if ((env = "/run/nvidia-docker/bin:/run/nvidia-docker/extras/bin:@driverLink@/bin") == NULL) { | ||
error_setx(err, "environment variable PATH not found"); | ||
return (-1); | ||
} | ||
+ | ||
+ // TODO: Remove this patch once `virtualisation.docker.enableNvidia` is removed from NixOS. | ||
+ // It only exists to maintain compatibility with the old nvidia-docker package. | ||
+ int p_rv = snprintf(env, PATH_MAX, "/run/nvidia-docker/bin:/run/nvidia-docker/extras/bin:@driverLink@/bin:%s", os_path); | ||
+ if (p_rv >= PATH_MAX) { | ||
+ error_setx(err, "PATH environment variable too long"); | ||
+ return (-1); | ||
+ } else if (p_rv < 0) { | ||
+ error_setx(err, "error setting PATH environment variable"); | ||
+ return (-1); | ||
+ } | ||
+ | ||
if ((env = ptr = xstrdup(err, env)) == NULL) | ||
return (-1); | ||
|