Skip to content

Commit 9856182

Browse files
committed
Merge pull request godotengine#90295 from sambler/sysctl_adjust
Make sysctl calls on FreeBSD
2 parents 15b9e7c + 97e95e1 commit 9856182

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

platform/linuxbsd/os_linuxbsd.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@
6262
#include <mntent.h>
6363
#endif
6464

65+
#if defined(__FreeBSD__)
66+
#include <sys/sysctl.h>
67+
#endif
68+
6569
void OS_LinuxBSD::alert(const String &p_alert, const String &p_title) {
6670
const char *message_programs[] = { "zenity", "kdialog", "Xdialog", "xmessage" };
6771

@@ -145,17 +149,36 @@ void OS_LinuxBSD::initialize_joypads() {
145149
String OS_LinuxBSD::get_unique_id() const {
146150
static String machine_id;
147151
if (machine_id.is_empty()) {
152+
#if defined(__FreeBSD__)
153+
const int mib[2] = { CTL_KERN, KERN_HOSTUUID };
154+
char buf[4096];
155+
memset(buf, 0, sizeof(buf));
156+
size_t len = sizeof(buf) - 1;
157+
if (sysctl(mib, 2, buf, &len, 0x0, 0) != -1) {
158+
machine_id = String::utf8(buf).replace("-", "");
159+
}
160+
#else
148161
Ref<FileAccess> f = FileAccess::open("/etc/machine-id", FileAccess::READ);
149162
if (f.is_valid()) {
150163
while (machine_id.is_empty() && !f->eof_reached()) {
151164
machine_id = f->get_line().strip_edges();
152165
}
153166
}
167+
#endif
154168
}
155169
return machine_id;
156170
}
157171

158172
String OS_LinuxBSD::get_processor_name() const {
173+
#if defined(__FreeBSD__)
174+
const int mib[2] = { CTL_HW, HW_MODEL };
175+
char buf[4096];
176+
memset(buf, 0, sizeof(buf));
177+
size_t len = sizeof(buf) - 1;
178+
if (sysctl(mib, 2, buf, &len, 0x0, 0) != -1) {
179+
return String::utf8(buf);
180+
}
181+
#else
159182
Ref<FileAccess> f = FileAccess::open("/proc/cpuinfo", FileAccess::READ);
160183
ERR_FAIL_COND_V_MSG(f.is_null(), "", String("Couldn't open `/proc/cpuinfo` to get the CPU model name. Returning an empty string."));
161184

@@ -165,8 +188,9 @@ String OS_LinuxBSD::get_processor_name() const {
165188
return line.split(":")[1].strip_edges();
166189
}
167190
}
191+
#endif
168192

169-
ERR_FAIL_V_MSG("", String("Couldn't get the CPU model name from `/proc/cpuinfo`. Returning an empty string."));
193+
ERR_FAIL_V_MSG("", String("Couldn't get the CPU model. Returning an empty string."));
170194
}
171195

172196
bool OS_LinuxBSD::is_sandboxed() const {

0 commit comments

Comments
 (0)