append-only.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/bin/sh
  2. # Ensure that tail -f works on an append-only file
  3. # Requires root access to do chattr +a, as well as an ext[23] or xfs file system
  4. # Copyright (C) 2006-2018 Free Software Foundation, Inc.
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
  16. print_ver_ tail
  17. require_root_
  18. # Terminate any background tail process
  19. cleanup_() { kill $pid 2>/dev/null && wait $pid; }
  20. chattr_a_works=1
  21. touch f
  22. chattr +a f 2>/dev/null || chattr_a_works=0
  23. ( echo x > f ) 2>/dev/null && chattr_a_works=0
  24. echo x >> f || chattr_a_works=0
  25. if test $chattr_a_works = 0; then
  26. skip_ "chattr +a doesn't work on this file system"
  27. fi
  28. for mode in '' '---disable-inotify'; do
  29. sleep 1 & pid=$!
  30. tail --pid=$pid -f $mode f || fail=1
  31. cleanup_
  32. done
  33. chattr -a f 2>/dev/null
  34. Exit $fail