fixes and alert improvements
[distro-setup] / system-status
index c11024bc5ba2c125615beb78c285f6193755c201..3ccde7c023e1fb06017a24b5a9c3d7a627d4cc6a 100755 (executable)
@@ -143,7 +143,7 @@ write-status() {
     if (( ${#files[@]} )); then
       snaps=($(ls -1avdr "${files[@]}" 2>/dev/null |head -n1 || : ))
     fi
-    now=$(date +%s)
+    now=$EPOCHSECONDS
     maxtime=0
     for s in ${snaps[@]}; do
       file=${s##*/}
@@ -194,14 +194,21 @@ write-status() {
     esac
   fi
 
-
-  if pgrep -G iank -u iank -f 'emacs --daemon' &>/dev/null; then
-    emacsfiles="$(emacsclient --eval "$(cat /usr/local/bin/unsaved-buffers.el)"| sed '/^"nil"$/d;s/^"(/E: /;s/)"$//')"
-    if [[ $emacsfiles ]]; then
-      chars+=("$emacsfiles")
+  # We do this once every 5 minutes, since this is not a grave problem.
+  # For formatted elisp, see /b/ds/unsaved-buffers.el
+  elisp='(format "%s" (-reduce-from (lambda (acc buf) (let ((bpath (buffer-file-name buf))) (if (and bpath (buffer-modified-p buf)) (cons bpath acc ) acc))) nil (buffer-list)))'
+  if [[ ! $last_emacs_check || $emacsfiles ]] || (( last_emacs_check < EPOCHSECONDS - 300 )); then
+    if pgrep -G iank -u iank -f 'emacs --daemon' &>/dev/null; then
+      # i dun care if this fails
+      emacsfiles="$(timeout 1 emacsclient --eval "$elisp"| sed '/^"nil"$/d;s/^"(/E: /;s/)"$//' ||:)"
+      if [[ $emacsfiles ]]; then
+        chars+=("$emacsfiles")
+      fi
     fi
+    last_emacs_check=$EPOCHSECONDS
   fi
 
+
   glob=(/nocow/btrfs-stale/*)
   if [[ -e ${glob[0]} ]]; then
     chars+=(STALE)
@@ -212,16 +219,6 @@ write-status() {
   fi
   p $var_mail_msg | loday -1 var_mail
 
-
-  tmp=(/var/local/cron-errors/mailtest-check*)
-  if (( ${#tmp[@]} )); then
-    chars+=(MAILPING)
-  fi
-  tmp=(/var/local/cron-errors/mailtest-slow*)
-  if (( ${#tmp[@]} )); then
-    chars+=(SPAMD)
-  fi
-
   # early in install process, we dont have permission yet for exiqgrep.
   # 1100 helps allow for system restarts
   qlen=$(/usr/sbin/exiqgrep -o 1100 -c -b | awk '{print $1}') ||:
@@ -261,7 +258,7 @@ write-status() {
     # shellcheck disable=SC2043
     for _ in 1; do
       if [[ -e $f ]]; then
-        now=$(date +%s)
+        now=$EPOCHSECONDS
         fsec=$(stat -c%Y $f)
         # the / 60 makes it 0-59 seconds less strict, +1 to help make sure we
         # dont have any false positives.