about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2020-05-10 14:27:11 -0400
committerBen Morrison <ben@gbmor.dev>2020-05-10 14:27:11 -0400
commitf7d867ef146d776a8f1361e83019d9e2c437670b (patch)
tree427c399d091ca51465fd6eae443e19e6065aabbe
parent037d58e2b92faca8eaec6f06ae4249f334f3b9aa (diff)
downloadapi-f7d867ef146d776a8f1361e83019d9e2c437670b.tar.gz
fixed bug in userCountQuery
was only returning a single user when there were multiple users.
moved to absolute path for ls and strings.Fields().
-rw-r--r--usercount.go4
1 files changed, 2 insertions, 2 deletions
diff --git a/usercount.go b/usercount.go
index ff35463..a7084f1 100644
--- a/usercount.go
+++ b/usercount.go
@@ -9,12 +9,12 @@ import (
 // Just returns the number of directories in /home
 // The assumption being, it's the number of human users.
 func userCountQuery(format string) ([]byte, error) {
-	ls, err := exec.Command("ls", "/home").Output()
+	ls, err := exec.Command("/bin/ls", "/home").Output()
 	if err != nil {
 		return nil, fmt.Errorf("Couldn't execute ls: %w", err)
 	}
 
-	split := strings.Split(string(ls), " ")
+	split := strings.Fields(string(ls))
 
 	if format == "plain" {
 		return []byte(fmt.Sprintf("%v users", len(split))), nil