Skip to content

Commit b1186a6

Browse files
authored
Merge pull request #1191 from shirou/feature/update_mac_cgo
[disk][host][mac] fix deprecated code in macOS Monterey
2 parents 69ea4bf + 4c3edcf commit b1186a6

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

disk/iostat_darwin.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ gopsutil_v3_readdrivestat(DriveStats a[], int n)
2525
kern_return_t status;
2626
int na, rv;
2727

28-
IOMasterPort(bootstrap_port, &port);
28+
IOMainPort(bootstrap_port, &port);
2929
match = IOServiceMatching("IOMedia");
3030
CFDictionaryAddValue(match, CFSTR(kIOMediaWholeKey), kCFBooleanTrue);
3131
status = IOServiceGetMatchingServices(port, match, &drives);

disk/iostat_darwin.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@ struct CPUStats {
3030
};
3131

3232
extern int gopsutil_v3_readdrivestat(DriveStats a[], int n);
33+
34+
#if (MAC_OS_X_VERSION_MIN_REQUIRED < 120000) // Before macOS 12 Monterey
35+
#define IOMainPort IOMasterPort
36+
#endif

host/smc_darwin.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ kern_return_t gopsutil_v3_open_smc(void) {
7272
kern_return_t result;
7373
io_service_t service;
7474

75-
service = IOServiceGetMatchingService(kIOMasterPortDefault,
75+
service = IOServiceGetMatchingService(kIOMainPortDefault,
7676
IOServiceMatching(IOSERVICE_SMC));
7777
if (service == 0) {
7878
// Note: IOServiceMatching documents 0 on failure

host/smc_darwin.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,9 @@ kern_return_t gopsutil_v3_open_smc(void);
2929
kern_return_t gopsutil_v3_close_smc(void);
3030
double gopsutil_v3_get_temperature(char *);
3131

32+
#if (MAC_OS_X_VERSION_MIN_REQUIRED < 120000) // Before macOS 12 Monterey
33+
#define kIOMainPortDefault kIOMasterPortDefault
34+
#endif
35+
36+
3237
#endif // __SMC_H__

0 commit comments

Comments
 (0)