Skip to content

Commit 8b4856b

Browse files
authored
Merge pull request #6655 from BOINC/mac_get_podman_path_in_client
Mac: Don't search for podman path in installer or Mac_SA_Secure.sh script
2 parents a7e9c0e + 05cd898 commit 8b4856b

File tree

5 files changed

+56
-92
lines changed

5 files changed

+56
-92
lines changed

client/Run_Podman.cpp

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ int main(int argc, char *argv[])
4343
int argsCount = 0;
4444
int argvCount;
4545
char buf [2048];
46-
char Podman_Path[1024];
47-
FILE *f;
48-
struct stat sbuf;
4946
int status = 0;
5047

5148
if (geteuid() != 0) {
@@ -78,65 +75,6 @@ int main(int argc, char *argv[])
7875
fflush(stdout);
7976
#endif
8077

81-
// While the official Podman installer puts the Podman executable at
82-
// "/opt/podman/bin/podman", other installation methods (e.g. brew) might not
83-
84-
// The Mac installer wrote path to podman executable in Path_to_podman.txt
85-
Podman_Path[0] = 0;
86-
f = fopen("/Library/Application Support/BOINC Data/Path_to_podman.txt", "r");
87-
if (f) {
88-
fgets(Podman_Path, sizeof(Podman_Path), f);
89-
fclose(f);
90-
char * p=strstr(Podman_Path, "\n");
91-
if (p) *p = '\0'; // Remove the newline character
92-
}
93-
if (stat((const char*)Podman_Path, &sbuf)!= 0) {
94-
Podman_Path[0] = 0;
95-
}
96-
97-
if (Podman_Path[0] == 0) {
98-
// If we couldn't get it from that file, use default if installed using Podman installer
99-
strlcpy(Podman_Path, "/opt/podman/bin/podman", sizeof(Podman_Path));
100-
if (stat((const char*)Podman_Path, &sbuf) != 0) {
101-
Podman_Path[0] = 0;
102-
}
103-
}
104-
105-
if (Podman_Path[0] == 0) {
106-
// If we couldn't get it from that file, use default if installed by Homebrew
107-
#ifdef __arm64__
108-
strlcpy(Podman_Path, "/opt/homebrew/bin/podman", sizeof(Podman_Path));
109-
#else
110-
strlcpy(Podman_Path, "/usr/local/bin/podman", sizeof(Podman_Path));
111-
#endif
112-
if (stat(Podman_Path, &sbuf) != 0) {
113-
Podman_Path[0] = 0;
114-
}
115-
}
116-
117-
if (Podman_Path[0] == 0) {
118-
// Get the path to the podman executable dynamically
119-
// Mac executables get a very limited PATH environment variable, so we must get the
120-
// PATH variable used by Terminal and search there for the path to podman
121-
f = popen("a=`/usr/libexec/path_helper`;b=${a%\\\"*}\\\";env ${b} which podman", "r");
122-
if (f) {
123-
fgets(Podman_Path, sizeof(Podman_Path), f);
124-
pclose(f);
125-
char * p=strstr(Podman_Path, "\n");
126-
if (p) *p = '\0'; // Remove the newline character
127-
#if VERBOSE
128-
fprintf(debug_file, "popen returned podman path = \"%s\"\n", Podman_Path);
129-
#endif
130-
}
131-
}
132-
if (Podman_Path[0] == 0) {
133-
#if VERBOSE
134-
fprintf(debug_file, "Can't get path to Podman\n");
135-
fflush(debug_file);
136-
fclose(debug_file);
137-
#endif
138-
exit(1);
139-
}
14078

14179
#if VERBOSE
14280
dup2(saved_stdout_fd, fileno(stdout));
@@ -149,7 +87,7 @@ int main(int argc, char *argv[])
14987
// mostly in that user's home directory. To get around this, we
15088
// simulate a login by user boinc_project and set environment
15189
// variables for Podman to use our BOINC podman" directory instead
152-
snprintf(buf, sizeof(buf), "env XDG_CONFIG_HOME=\"/Library/Application Support/BOINC podman\" XDG_DATA_HOME=\"/Library/Application Support/BOINC podman\" HOME=\"/Library/Application Support/BOINC podman\" %s", Podman_Path);
90+
strlcpy(buf, "env XDG_CONFIG_HOME=\"/Library/Application Support/BOINC podman\" XDG_DATA_HOME=\"/Library/Application Support/BOINC podman\" HOME=\"/Library/Application Support/BOINC podman\" ", sizeof(buf));
15391

15492
argvCount = 1; // arguments to be passed to Podman
15593
while (argv[argvCount]) {

client/hostinfo_unix.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,9 @@ bool HOST_INFO::is_podman_VM_running() {
12511251
bool HOST_INFO::get_docker_version_aux(DOCKER_TYPE type){
12521252
char cmd[1024], buf[256];
12531253

1254+
#ifdef __APPLE__
1255+
if (docker_cli_prog(type)[0] == '\0') return false;
1256+
#endif
12541257
snprintf(cmd, sizeof(cmd), "%s --version 2>/dev/null",
12551258
docker_cli_prog(type)
12561259
);

lib/hostinfo.cpp

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "parse.h"
3636
#include "util.h"
3737
#include "str_replace.h"
38+
#include "filesys.h"
3839

3940
#include "hostinfo.h"
4041

@@ -345,13 +346,63 @@ int HOST_INFO::write_cpu_benchmarks(FILE* out) {
345346
return 0;
346347
}
347348

349+
#ifdef __APPLE__
350+
// While the official Podman installer puts the Podman executable at
351+
// "/opt/podman/bin/podman", other installation methods (e.g. brew) might not
352+
static void find_podman_path(char *path, size_t len) {
353+
// Mac executables get a very limited PATH environment variable, so we must get the
354+
// PATH variable used by Terminal and search there for the path to podman
355+
FILE *f = popen("a=`/usr/libexec/path_helper`;b=${a%\\\"*}\\\";env ${b} which podman", "r");
356+
if (f) {
357+
fgets(path, len, f);
358+
pclose(f);
359+
char* p = strstr(path, "\n");
360+
if (p) *p = '\0'; // Remove the newline character
361+
}
362+
if (boinc_file_exists(path)) return;
363+
364+
// If we couldn't get it from that file, use default when installed using Podman installer
365+
strlcpy(path, "/opt/podman/bin/podman", len);
366+
if (boinc_file_exists(path)) return;
367+
368+
// If we couldn't get it from that file, use default when installed by Homebrew
369+
#ifdef __arm64__
370+
strlcpy(path, "/opt/homebrew/bin/podman", len);
371+
#else
372+
strlcpy(path, "/usr/local/bin/podman", len);
373+
#endif
374+
if (boinc_file_exists(path)) return;
375+
path[0] = '\0'; // Failed to find path to Podman
376+
return;
377+
}
378+
#endif
379+
348380
// name of CLI program
349381
//
350382
const char* docker_cli_prog(DOCKER_TYPE type) {
351383
switch (type) {
352384
case DOCKER: return "docker";
353385
#ifdef __APPLE__
354-
case PODMAN: return "\"/Library/Application Support/BOINC Data/Run_Podman\" ";
386+
case PODMAN:
387+
static char docker_cli_string[MAXPATHLEN];
388+
static bool docker_cli_inited = false;
389+
char path[MAXPATHLEN];
390+
if (docker_cli_inited) return docker_cli_string;
391+
docker_cli_string[0] = '\0';
392+
find_podman_path(path, sizeof(path));
393+
if (path[0]) {
394+
strlcpy(docker_cli_string,
395+
"\"/Library/Application Support/BOINC Data/Run_Podman\" ",
396+
sizeof(docker_cli_string)
397+
);
398+
strlcat(docker_cli_string,
399+
path,
400+
sizeof(docker_cli_string)
401+
);
402+
strlcat(docker_cli_string, " ", sizeof(docker_cli_string));
403+
}
404+
docker_cli_inited = true;
405+
return docker_cli_string;
355406
#else
356407
case PODMAN: return "podman";
357408
#endif

mac_build/Mac_SA_Secure.sh

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@
7474
# Updated 8/24/25 to add Run_Podman and BOINC podman directory
7575
# Updated 8/27/25 to allow podman to stat items under BOINC Data directory
7676
# Updated 11/9/25 to create "BOINC podman" directory if not present (for bare client)
77-
# Updated 11/9/25 to create Path_to_podman.txt if not present (for bare client)
7877
#
7978
# WARNING: do not use this script with versions of BOINC older
8079
# than 7.20.4
@@ -232,13 +231,6 @@ dscl . -merge /groups/boinc_master GroupMembership "$(LOGNAME)"
232231
dscl . -merge /groups/boinc_project GroupMembership "$(LOGNAME)"
233232
#fi
234233

235-
if [ ! -f "Path_to_podman.txt" ]; then
236-
a=`/usr/libexec/path_helper`;b=${a%\"*}\";env ${b} which podman > /tmp/pathToPodman.txt
237-
exec 6</tmp/pathToPodman.txt
238-
read pathToPodman <&6
239-
printf "%s" "$pathToPodman" > Path_to_podman.txt # Strips off trailing newline
240-
fi
241-
242234
# Set permissions of BOINC Data directory's contents:
243235
# ss_config.xml is world-readable so screensaver coordinator can read it
244236
# all other *.xml are not world-readable to keep authenticators private

mac_installer/PostInstall.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -259,26 +259,6 @@ int main(int argc, char *argv[])
259259
if (coreClientPID)
260260
kill(coreClientPID, SIGTERM); // boinc catches SIGTERM & exits gracefully
261261

262-
// While the official Podman installer puts the podman executable at
263-
// "/opt/podman/bin/podman", other installation methods (e.g. brew) might not.
264-
// Mac executables get a very limited PATH environment variable, so we must get the
265-
// PATH variable used by Terminal and search ther of the path to podman
266-
f = popen("a=`/usr/libexec/path_helper`;b=${a%\\\"*}\\\";env ${b} which podman", "r");
267-
s[0] = '\0';
268-
if (f) {
269-
fgets(s, sizeof(s), f);
270-
pclose(f);
271-
char * p=strstr(s, "\n");
272-
if (p) *p='\0'; // Remove the newline character
273-
printf("popen returned podman path = \"%s\"\n", s);
274-
// Write path to podman executable to a file for our Run_Podman utility to use
275-
f = fopen("/Library/Application Support/BOINC Data/Path_to_podman.txt", "w");
276-
if (f) {
277-
fprintf(f, "%s", s);
278-
fclose(f);
279-
}
280-
}
281-
282262
// Create the new BOINC Podman directory if it does not yet exist
283263
snprintf(s, sizeof(s), "/Library/Application Support/" PODMAN_DIR);
284264
if (stat(s, &sbuf) != 0) {

0 commit comments

Comments
 (0)