Mac bookにログインできなくなった

OS X 10.9.4 でフリーズ後再起動するとログイン出来なくなった。ユーザー選択して、パスワード入力画面まではいけるのだがパスワード入力後、虹色のぐるぐるが延々終わらずにフリーズしている模様。

セーフモード起動試してみるも同じ。ディスクユーティリティ起動してディスクのチェックしても問題なし。
シングルユーザーモードで起動後、ログを確認してみると以下のようなエラーが記録されていた。
どうもsystemkeychainがhangしていて認証途中で止まっている模様

# less /var/log/system.log  
Apr 12 00:00:22 --- last message repeated 5 times ---
Apr 12 00:00:22  systemkeychain[324]: Could not run security-checksystem failure Resource temporarily unavailable
Apr 12 00:00:22 host com.apple.launchd[1] (com.apple.systemkeychain[324]): Exited with code: 71
Apr 12 00:00:22 host.local ReportCrash[313]: Saved crash report for bash[325] version ??? to /Library/Logs/DiagnosticReports/bash_2018-04-12-000022_host.crash
Apr 12 00:00:22 host com.apple.launchd[1] (com.apple.systemkeychain): Throttling respawn: Will start in 10 seconds
Apr 12 00:00:22 host.local ReportCrash[313]: Removing excessive log: file:///Library/Logs/DiagnosticReports/bash_2018-04-11-235700_host.crash
Apr 12 00:00:32 host.local ReportCrash[328]: Attempt to read info_array in pid 327 failed, address was ...

crash ログを見てみるとlibreadline.6.dylibが無いとかでエラーを吐いている。

# less  /Library/Logs/DiagnosticReports/bash_2018-04-11-235700_host.crash
Dyld Error Message:
  Library not loaded: /usr/local/opt/readline/lib/libreadline.6.dylib
  Referenced from: /bin/bash
  Reason: image not found

確認してみると確かにlibreadline.6.dylibは存在しない。消した記憶はないのだけど、どうもbrew経由でなにかをinstallしたときに7に勝手に揚げられていた模様。

ls /usr/local/opt/readline/lib/ 
libhistory.7.dylib    libhistory.dylib      libreadline.7.0.dylib libreadline.a
libhistory.7.0.dylib  libhistory.a           libreadline.7.dylib   libreadline.dylib

ためしに/をwritableに再マウントしてsymbolic link貼ってやると起動できた。

mount -uw / 
cd /usr/local/opt/readline/lib/ 
ln -s libreadline.dylib libreadline.6.dylib
ln -s libhistory.dylib  libhistory.6.dylib 
reboot