Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FreeBSD support for common widgets #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

theconnstruct
Copy link

No description provided.

Copy link

@kai-burghardt kai-burghardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your pull request. I would love to have a more sophisticated support of the FreeBSD operating system.

@@ -26,6 +26,8 @@ __load_average_detail() {
__load_average() {
if [ -r "/proc/loadavg" ]; then
read one five fifteen other < /proc/loadavg
elif [ $(uname) = "FreeBSD" ]; then
one=$(uptime | sed -En 's:.*averages\: ([[:digit:]]+\.[[:digit:]]+),.*:\1:p')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To some people regular expressions may be witchcraft. Maybe we can instead write this as:

sysctl -n vm.loadavg | read brace_left one five fifteen brace_right

Comment on lines +44 to +48
mem_phys=$(sysctl -n hw.physmem)
page_size=$(sysctl -n hw.pagesize)
mem_inactive=$(($(sysctl -n vm.stats.vm.v_inactive_count)*$page_size))
mem_cache=$(($(sysctl -n vm.stats.vm.v_cache_count)*$page_size))
mem_free=$(($(sysctl -n vm.stats.vm.v_free_count)*$page_size))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you do not perform error checking of any kind, these can be grouped into one sysctl command:

sysctl -n hw.physmem hw.pagesize vm.stats.vm.v_inactive_count vm.stats.vm.v_cache_count vm.stats.vm.v_free_count | \
    read mem_phys page_size mem_inactive mem_cache mem_free

The factor is applied subsequently:

mem_inactive=$(($mem_inactive*$page_size))
mem_cache=$(($mem_cache*$page_size))
mem_free=$(($mem_free*$page_size))

c=$(getconf _NPROCESSORS_ONLN 2>/dev/null || grep -ci "^processor" /proc/cpuinfo)
c=$(getconf _NPROCESSORS_ONLN 2>/dev/null || \
grep -ci "^processor" /proc/cpuinfo || \
sysctl -n hw.ncpu)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently getconf _NPROCESSORS_ONLN succeeds on a FreeBSD system, hence the sysctl is never invoked (via || list-operator).

Comment on lines +45 to +46
fpdiv $hz "1000000000" 1
freq="$_RET"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unnecessary duplication of code. The same can be achieved via:

elif hz=$(sysctl -n hw.cpufrequency 2>/dev/null || sysctl -n machdep.tsc_freq 2>/dev/null); then

Ideally insert a comment saying which OID is available on which system.

Comment on lines -23 to +27
df -h -P
if [ $(uname) = "FreeBSD" ]; then
df -h
else
df -h -P
fi

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Granted ‑P has a different meaning in the FreeBSD version of df, it does not matter since ‑h renders the effects of ‑P irrelevant. There is no column indicating the size in blocks.

df -Ph  # order matters: with FreeBSD's version of df the -P option must be overridden by -h

@dustinkirkland
Copy link
Owner

Hi all! I'm actually keen to get this merged in. I don't have any Mac / FreeBSD systems, but if someone could update this branch with a clean, working set, I'll ensure that it doesn't regress anything on non-Mac/BSD systems and get it merged...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants