Macchina-CLI / libmacchina

A library providing access to all sorts of system information.
https://crates.io/crates/libmacchina
MIT License
66 stars 20 forks source link

Add FreeBSD uptime detection #137

Closed Gobidev closed 1 year ago

Gobidev commented 1 year ago

This PR adds uptime detection on FreeBSD by spawning a sysctl system command. This is sadly pretty much the fastest option on FreeBSD, as getting the uptime requires a syscall and cannot be read directly from /proc.

CarterLi commented 1 year ago

So starting a process is faster than emitting a syscall.

What?

Gobidev commented 1 year ago

@CarterLi you're right, I somehow did not think of making the syscall directly😅 I will look into how that could be done

Gobidev commented 1 year ago

It looks like the sysinfo crate already has such an implementation already that uses the libc crate to interact with sysctl directly. The question is if the plan for this project is to have its own implementation or not. If not, we could just add sysinfo as a FreeBSD dependency and use that.

grtcdr commented 1 year ago

sysinfo and libmacchina essentially do the same thing. If we were to depend on sysinfo, we would do that in macchina. At that point, maintaining libmacchina would be pointless, except it does what sysinfo doesn't currently do, and that is to provide support for NetBSD.

Gobidev commented 1 year ago

Ok, in that case I will work on a proper implementation without spawning a process, closing this for now.

grtcdr commented 1 year ago

Thank you @Gobidev! I'm eager to see the FreeBSD implementation improve.