Skip to content

Commit 1f8dfa3

Browse files
authored
Merge pull request #6263 from BOINC/dpa_docker16
client (linux): verify docker/podman detection by running hello world image
2 parents 0c6f8c1 + 250fea6 commit 1f8dfa3

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

client/hostinfo_unix.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,7 @@ int HOST_INFO::get_virtualbox_version() {
12331233
return 0;
12341234
}
12351235

1236-
// check if docker is installed on this host
1236+
// check if docker/podman is installed on this host
12371237
// populate docker_version on success
12381238
//
12391239
bool HOST_INFO::get_docker_version_aux(DOCKER_TYPE type){
@@ -1246,8 +1246,8 @@ bool HOST_INFO::get_docker_version_aux(DOCKER_TYPE type){
12461246
#endif
12471247
string cmd = string(docker_cli_prog(type)) + " --version 2>/dev/null";
12481248
FILE* f = popen(cmd.c_str(), "r");
1249+
char buf[256];
12491250
if (f) {
1250-
char buf[256];
12511251
// normally the version is on the first line,
12521252
// but it's on the 2nd line if using podman-docker
12531253
//
@@ -1262,6 +1262,32 @@ bool HOST_INFO::get_docker_version_aux(DOCKER_TYPE type){
12621262
}
12631263
pclose(f);
12641264
}
1265+
#ifdef __linux__
1266+
// if we're running as an unprivileged user, Docker/podman may not work.
1267+
// Check by running the Hello World image.
1268+
//
1269+
// Since we do this every time on startup, don't delete the image.
1270+
//
1271+
cmd = string(docker_cli_prog(type)) + " run hello-world 2>/dev/null";
1272+
bool found = false;
1273+
f = popen(cmd.c_str(), "r");
1274+
if (f) {
1275+
while (fgets(buf, 256, f)) {
1276+
if (strstr(buf, "Hello")) {
1277+
found = true;
1278+
break;
1279+
}
1280+
}
1281+
pclose(f);
1282+
}
1283+
if (!found) {
1284+
msg_printf(NULL, MSG_INFO,
1285+
"%s found but 'hello-world' test failed",
1286+
docker_type_str(type)
1287+
);
1288+
docker_version[0] = 0;
1289+
}
1290+
#endif
12651291
return ret;
12661292
}
12671293

0 commit comments

Comments
 (0)