Skip to content

Commit

Permalink
[mac] fix deprecated code in macOS Monterey
Browse files Browse the repository at this point in the history
  • Loading branch information
shirou committed Dec 4, 2021
1 parent 1ec4629 commit 4c3edcf
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion disk/iostat_darwin.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ gopsutil_v3_readdrivestat(DriveStats a[], int n)
kern_return_t status;
int na, rv;

IOMasterPort(bootstrap_port, &port);
IOMainPort(bootstrap_port, &port);
match = IOServiceMatching("IOMedia");
CFDictionaryAddValue(match, CFSTR(kIOMediaWholeKey), kCFBooleanTrue);
status = IOServiceGetMatchingServices(port, match, &drives);
Expand Down
4 changes: 4 additions & 0 deletions disk/iostat_darwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ struct CPUStats {
};

extern int gopsutil_v3_readdrivestat(DriveStats a[], int n);

#if (MAC_OS_X_VERSION_MIN_REQUIRED < 120000) // Before macOS 12 Monterey
#define IOMainPort IOMasterPort
#endif
2 changes: 1 addition & 1 deletion host/smc_darwin.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ kern_return_t gopsutil_v3_open_smc(void) {
kern_return_t result;
io_service_t service;

service = IOServiceGetMatchingService(kIOMasterPortDefault,
service = IOServiceGetMatchingService(kIOMainPortDefault,
IOServiceMatching(IOSERVICE_SMC));
if (service == 0) {
// Note: IOServiceMatching documents 0 on failure
Expand Down
5 changes: 5 additions & 0 deletions host/smc_darwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ kern_return_t gopsutil_v3_open_smc(void);
kern_return_t gopsutil_v3_close_smc(void);
double gopsutil_v3_get_temperature(char *);

#if (MAC_OS_X_VERSION_MIN_REQUIRED < 120000) // Before macOS 12 Monterey
#define kIOMainPortDefault kIOMasterPortDefault
#endif


#endif // __SMC_H__

0 comments on commit 4c3edcf

Please sign in to comment.