1#!/bin/sh
2# Test various sync(1) operations
3
4# Copyright (C) 2015-2023 Free Software Foundation, Inc.
5
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15
16# You should have received a copy of the GNU General Public License
17# along with this program.  If not, see <https://www.gnu.org/licenses/>.
18
19. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20print_ver_ sync
21
22touch file || framework_failure_
23
24# fdatasync+syncfs is nonsensical
25returns_ 1 sync --data --file-system || fail=1
26
27# fdatasync needs an operand
28returns_ 1 sync -d || fail=1
29
30# Test syncing of file (fsync) (little side effects)
31sync file || fail=1
32
33# Test syncing of write-only file - which failed since adding argument
34# support to sync in coreutils-8.24.
35chmod 0200 file || framework_failure_
36sync file || fail=1
37
38# Ensure multiple args are processed and diagnosed
39returns_ 1 sync file nofile || fail=1
40
41# Ensure inaccessible dirs give an appropriate error
42mkdir norw || framework_failure_
43chmod 0 norw || framework_failure_
44if ! test -r norw; then
45  returns_ 1 sync norw 2>errt || fail=1
46  # AIX gives "Is a directory"
47  sed 's/Is a directory/Permission denied/' <errt >err || framework_failure_
48  printf "sync: error opening 'norw': Permission denied\n" >exp
49  compare exp err || fail=1
50fi
51
52if test "$fail" != '1'; then
53  # Ensure a fifo doesn't block
54  mkfifo_or_skip_ fifo
55  returns_ 124 timeout 10 sync fifo && fail=1
56fi
57
58Exit $fail
59