1f08c3bdfSopenharmony_ci/* 2f08c3bdfSopenharmony_ci * 3f08c3bdfSopenharmony_ci * Copyright (c) International Business Machines Corp., 2001 4f08c3bdfSopenharmony_ci * 5f08c3bdfSopenharmony_ci * This program is free software; you can redistribute it and/or modify 6f08c3bdfSopenharmony_ci * it under the terms of the GNU General Public License as published by 7f08c3bdfSopenharmony_ci * the Free Software Foundation; either version 2 of the License, or 8f08c3bdfSopenharmony_ci * (at your option) any later version. 9f08c3bdfSopenharmony_ci * 10f08c3bdfSopenharmony_ci * This program is distributed in the hope that it will be useful, 11f08c3bdfSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of 12f08c3bdfSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13f08c3bdfSopenharmony_ci * the GNU General Public License for more details. 14f08c3bdfSopenharmony_ci * 15f08c3bdfSopenharmony_ci * You should have received a copy of the GNU General Public License 16f08c3bdfSopenharmony_ci * along with this program; if not, write to the Free Software 17f08c3bdfSopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18f08c3bdfSopenharmony_ci */ 19f08c3bdfSopenharmony_ci 20f08c3bdfSopenharmony_ci/* 21f08c3bdfSopenharmony_ci * NAME 22f08c3bdfSopenharmony_ci * fcntl16.c 23f08c3bdfSopenharmony_ci * 24f08c3bdfSopenharmony_ci * DESCRIPTION 25f08c3bdfSopenharmony_ci * Additional file locking test cases for checking proper notifictaion 26f08c3bdfSopenharmony_ci * of processes on lock change 27f08c3bdfSopenharmony_ci * 28f08c3bdfSopenharmony_ci * ALGORITHM 29f08c3bdfSopenharmony_ci * Various test cases are used to lock a file opened without mandatory 30f08c3bdfSopenharmony_ci * locking, with madatory locking and mandatory locking with NOBLOCK. 31f08c3bdfSopenharmony_ci * Checking that processes waiting on lock boundaries are notified 32f08c3bdfSopenharmony_ci * properly when boundaries change 33f08c3bdfSopenharmony_ci * 34f08c3bdfSopenharmony_ci * USAGE 35f08c3bdfSopenharmony_ci * fcntl16 36f08c3bdfSopenharmony_ci * 37f08c3bdfSopenharmony_ci * HISTORY 38f08c3bdfSopenharmony_ci * 07/2001 Ported by Wayne Boyer 39f08c3bdfSopenharmony_ci * 04/2002 wjhuie sigset cleanups 40f08c3bdfSopenharmony_ci * 41f08c3bdfSopenharmony_ci * RESTRICTIONS 42f08c3bdfSopenharmony_ci * None 43f08c3bdfSopenharmony_ci */ 44f08c3bdfSopenharmony_ci 45f08c3bdfSopenharmony_ci#include <fcntl.h> 46f08c3bdfSopenharmony_ci#include <signal.h> 47f08c3bdfSopenharmony_ci#include <errno.h> 48f08c3bdfSopenharmony_ci#include "test.h" 49f08c3bdfSopenharmony_ci#include "safe_macros.h" 50f08c3bdfSopenharmony_ci#include <sys/stat.h> 51f08c3bdfSopenharmony_ci#include <sys/types.h> 52f08c3bdfSopenharmony_ci#include <sys/wait.h> 53f08c3bdfSopenharmony_ci 54f08c3bdfSopenharmony_ci 55f08c3bdfSopenharmony_ci#define SKIPVAL 0x0f00 56f08c3bdfSopenharmony_ci//#define SKIP SKIPVAL, 0, 0L, 0L, IGNORED 57f08c3bdfSopenharmony_ci#define SKIP 0,0,0L,0L,0 58f08c3bdfSopenharmony_ci#if (SKIPVAL == F_RDLCK) || (SKIPVAL == F_WRLCK) 59f08c3bdfSopenharmony_ci#error invalid SKIP, must not be F_RDLCK or F_WRLCK 60f08c3bdfSopenharmony_ci#endif 61f08c3bdfSopenharmony_ci 62f08c3bdfSopenharmony_ci#define IGNORED 0 63f08c3bdfSopenharmony_ci#define NOBLOCK 2 /* immediate success */ 64f08c3bdfSopenharmony_ci#define WILLBLOCK 3 /* blocks, succeeds, parent unlocks records */ 65f08c3bdfSopenharmony_ci#define TIME_OUT 10 66f08c3bdfSopenharmony_ciint NO_NFS = 1; /* Test on NFS or not */ 67f08c3bdfSopenharmony_ci 68f08c3bdfSopenharmony_citypedef struct { 69f08c3bdfSopenharmony_ci struct flock parent_a; 70f08c3bdfSopenharmony_ci struct flock parent_b; 71f08c3bdfSopenharmony_ci struct flock child_a; 72f08c3bdfSopenharmony_ci struct flock child_b; 73f08c3bdfSopenharmony_ci struct flock parent_c; 74f08c3bdfSopenharmony_ci struct flock parent_d; 75f08c3bdfSopenharmony_ci} testcase; 76f08c3bdfSopenharmony_ci 77f08c3bdfSopenharmony_cistatic testcase testcases[] = { 78f08c3bdfSopenharmony_ci /* #1 Parent_a making a write lock on entire file */ 79f08c3bdfSopenharmony_ci {{F_WRLCK, 0, 0L, 0L, IGNORED}, 80f08c3bdfSopenharmony_ci /* Parent_b skipped */ 81f08c3bdfSopenharmony_ci {SKIP}, 82f08c3bdfSopenharmony_ci /* Child_a read lock on byte 1 to byte 5 */ 83f08c3bdfSopenharmony_ci {F_RDLCK, 0, 0L, 5L, NOBLOCK}, 84f08c3bdfSopenharmony_ci /* Child_b read lock on byte 6 to byte 10 */ 85f08c3bdfSopenharmony_ci {F_RDLCK, 0, 6L, 5L, NOBLOCK}, 86f08c3bdfSopenharmony_ci /* 87f08c3bdfSopenharmony_ci * Parent_c read lock on entire file 88f08c3bdfSopenharmony_ci */ 89f08c3bdfSopenharmony_ci {F_RDLCK, 0, 0L, 0L, IGNORED}, 90f08c3bdfSopenharmony_ci /* Parent_d skipped */ 91f08c3bdfSopenharmony_ci {SKIP},}, 92f08c3bdfSopenharmony_ci 93f08c3bdfSopenharmony_ci /* #2 Parent_a making a write lock on entire file */ 94f08c3bdfSopenharmony_ci {{F_WRLCK, 0, 0L, 0L, IGNORED}, 95f08c3bdfSopenharmony_ci /* Parent_b skipped */ 96f08c3bdfSopenharmony_ci {SKIP}, 97f08c3bdfSopenharmony_ci /* Child_a read lock on byte 1 to byte 5 */ 98f08c3bdfSopenharmony_ci {F_RDLCK, 0, 0L, 5L, WILLBLOCK}, 99f08c3bdfSopenharmony_ci /* Child_b read lock on byte 6 to byte 10 */ 100f08c3bdfSopenharmony_ci {F_RDLCK, 0, 6L, 5L, WILLBLOCK}, 101f08c3bdfSopenharmony_ci /* 102f08c3bdfSopenharmony_ci * Parent_c write lock on entire 103f08c3bdfSopenharmony_ci * file 104f08c3bdfSopenharmony_ci */ 105f08c3bdfSopenharmony_ci {F_WRLCK, 0, 0L, 0L, IGNORED}, 106f08c3bdfSopenharmony_ci /* Parent_d skipped */ 107f08c3bdfSopenharmony_ci {SKIP},}, 108f08c3bdfSopenharmony_ci 109f08c3bdfSopenharmony_ci /* #3 Parent_a making a write lock on entire file */ 110f08c3bdfSopenharmony_ci {{F_WRLCK, 0, 0L, 0L, IGNORED}, 111f08c3bdfSopenharmony_ci /* Parent_b skipped */ 112f08c3bdfSopenharmony_ci {SKIP}, 113f08c3bdfSopenharmony_ci /* Child_a read lock on byte 2 to byte 4 */ 114f08c3bdfSopenharmony_ci {F_RDLCK, 0, 2L, 3L, WILLBLOCK}, 115f08c3bdfSopenharmony_ci /* Child_b read lock on byte 6 to byte 8 */ 116f08c3bdfSopenharmony_ci {F_RDLCK, 0, 6L, 3L, WILLBLOCK}, 117f08c3bdfSopenharmony_ci /* 118f08c3bdfSopenharmony_ci * Parent_c read lock on byte 3 to 119f08c3bdfSopenharmony_ci * byte 7 120f08c3bdfSopenharmony_ci */ 121f08c3bdfSopenharmony_ci {F_RDLCK, 0, 3L, 5L, IGNORED}, 122f08c3bdfSopenharmony_ci /* Parent_d skipped */ 123f08c3bdfSopenharmony_ci {SKIP},}, 124f08c3bdfSopenharmony_ci 125f08c3bdfSopenharmony_ci /* #4 Parent_a making a write lock on entire file */ 126f08c3bdfSopenharmony_ci {{F_WRLCK, 0, 0L, 0L, IGNORED}, 127f08c3bdfSopenharmony_ci /* Parent_b skipped */ 128f08c3bdfSopenharmony_ci {SKIP}, 129f08c3bdfSopenharmony_ci /* Child_a read lock on byte 2 to byte 4 */ 130f08c3bdfSopenharmony_ci {F_RDLCK, 0, 2L, 3L, WILLBLOCK}, 131f08c3bdfSopenharmony_ci /* Child_b read lock on byte 6 to byte 8 */ 132f08c3bdfSopenharmony_ci {F_RDLCK, 0, 6L, 3L, NOBLOCK}, 133f08c3bdfSopenharmony_ci /* 134f08c3bdfSopenharmony_ci * Parent_c read lock on byte 5 to 135f08c3bdfSopenharmony_ci * byte 9 136f08c3bdfSopenharmony_ci */ 137f08c3bdfSopenharmony_ci {F_RDLCK, 0, 5L, 5L, IGNORED}, 138f08c3bdfSopenharmony_ci /* Parent_d skipped */ 139f08c3bdfSopenharmony_ci {SKIP},}, 140f08c3bdfSopenharmony_ci 141f08c3bdfSopenharmony_ci /* #5 Parent_a making a write lock on entire file */ 142f08c3bdfSopenharmony_ci {{F_WRLCK, 0, 0L, 0L, IGNORED}, 143f08c3bdfSopenharmony_ci /* Parent_b skipped */ 144f08c3bdfSopenharmony_ci {SKIP}, 145f08c3bdfSopenharmony_ci /* Child_a read lock on byte 3 to byte 7 */ 146f08c3bdfSopenharmony_ci {F_RDLCK, 0, 3L, 5L, NOBLOCK}, 147f08c3bdfSopenharmony_ci /* Child_b read lock on byte 5 to byte 10 */ 148f08c3bdfSopenharmony_ci {F_RDLCK, 0, 5L, 6L, WILLBLOCK}, 149f08c3bdfSopenharmony_ci /* 150f08c3bdfSopenharmony_ci * Parent_c read lock on byte 2 to 151f08c3bdfSopenharmony_ci * byte 8 152f08c3bdfSopenharmony_ci */ 153f08c3bdfSopenharmony_ci {F_RDLCK, 0, 2L, 7L, IGNORED}, 154f08c3bdfSopenharmony_ci /* Parent_d skipped */ 155f08c3bdfSopenharmony_ci {SKIP},}, 156f08c3bdfSopenharmony_ci 157f08c3bdfSopenharmony_ci /* #6 Parent_a making a write lock on entire file */ 158f08c3bdfSopenharmony_ci {{F_WRLCK, 0, 0L, 0L, IGNORED}, 159f08c3bdfSopenharmony_ci /* Parent_b skipped */ 160f08c3bdfSopenharmony_ci {SKIP}, 161f08c3bdfSopenharmony_ci /* Child_a read lock on byte 2 to byte 4 */ 162f08c3bdfSopenharmony_ci {F_RDLCK, 0, 2L, 3L, WILLBLOCK}, 163f08c3bdfSopenharmony_ci /* Child_b write lock on byte 6 to byte 8 */ 164f08c3bdfSopenharmony_ci {F_RDLCK, 0, 6L, 3L, NOBLOCK}, 165f08c3bdfSopenharmony_ci /* Parent_c no lock on byte 3 to 9 */ 166f08c3bdfSopenharmony_ci {F_UNLCK, 0, 3L, 7L, IGNORED}, 167f08c3bdfSopenharmony_ci /* Parent_d skipped */ 168f08c3bdfSopenharmony_ci {SKIP},}, 169f08c3bdfSopenharmony_ci 170f08c3bdfSopenharmony_ci /* #7 Parent_a making a write lock on entire file */ 171f08c3bdfSopenharmony_ci {{F_WRLCK, 0, 0L, 0L, IGNORED}, 172f08c3bdfSopenharmony_ci /* Parent_b read lock on byte 3 to byte 7 */ 173f08c3bdfSopenharmony_ci {F_RDLCK, 0, 3L, 5L, IGNORED}, 174f08c3bdfSopenharmony_ci /* Child_a read lock on byte 2 to byte 4 */ 175f08c3bdfSopenharmony_ci {F_RDLCK, 0, 2L, 3L, NOBLOCK}, 176f08c3bdfSopenharmony_ci /* Child_b read lock on byte 6 to byte 8 */ 177f08c3bdfSopenharmony_ci {F_RDLCK, 0, 6L, 3L, NOBLOCK}, 178f08c3bdfSopenharmony_ci /* 179f08c3bdfSopenharmony_ci * Parent_c read lock on byte 1 to 180f08c3bdfSopenharmony_ci * byte 9 181f08c3bdfSopenharmony_ci */ 182f08c3bdfSopenharmony_ci {F_RDLCK, 0, 1L, 9L, IGNORED}, 183f08c3bdfSopenharmony_ci /* Parent_d skipped */ 184f08c3bdfSopenharmony_ci {SKIP},}, 185f08c3bdfSopenharmony_ci 186f08c3bdfSopenharmony_ci /* #8 Parent_a making a write lock on byte 2 to byte 4 */ 187f08c3bdfSopenharmony_ci {{F_WRLCK, 0, 2L, 3L, IGNORED}, 188f08c3bdfSopenharmony_ci /* Parent_b write lock on byte 6 to byte 8 */ 189f08c3bdfSopenharmony_ci {F_WRLCK, 0, 6L, 3L, IGNORED}, 190f08c3bdfSopenharmony_ci /* Child_a read lock on byte 3 to byte 7 */ 191f08c3bdfSopenharmony_ci {F_RDLCK, 0, 3L, 5L, NOBLOCK}, 192f08c3bdfSopenharmony_ci /* Child_b skipped */ 193f08c3bdfSopenharmony_ci {SKIP}, 194f08c3bdfSopenharmony_ci /* 195f08c3bdfSopenharmony_ci * Parent_c read lock on byte 1 to 196f08c3bdfSopenharmony_ci * byte 5 197f08c3bdfSopenharmony_ci */ 198f08c3bdfSopenharmony_ci {F_RDLCK, 0, 1L, 5L, IGNORED}, 199f08c3bdfSopenharmony_ci /* 200f08c3bdfSopenharmony_ci * Parent_d read lock on 201f08c3bdfSopenharmony_ci * byte 5 to byte 9 202f08c3bdfSopenharmony_ci */ 203f08c3bdfSopenharmony_ci {F_RDLCK, 0, 5L, 5L, 204f08c3bdfSopenharmony_ci IGNORED},}, 205f08c3bdfSopenharmony_ci 206f08c3bdfSopenharmony_ci /* #9 Parent_a making a write lock on entire file */ 207f08c3bdfSopenharmony_ci {{F_WRLCK, 0, 0L, 0L, IGNORED}, 208f08c3bdfSopenharmony_ci /* Parent_b read lock on byte 3 to byte 7 */ 209f08c3bdfSopenharmony_ci {F_RDLCK, 0, 3L, 5L, IGNORED}, 210f08c3bdfSopenharmony_ci /* Child_a read lock on byte 2 to byte 4 */ 211f08c3bdfSopenharmony_ci {F_RDLCK, 0, 2L, 3L, NOBLOCK}, 212f08c3bdfSopenharmony_ci /* Child_b read lock on byte 6 to byte 8 */ 213f08c3bdfSopenharmony_ci {F_RDLCK, 0, 6L, 3L, NOBLOCK}, 214f08c3bdfSopenharmony_ci /* 215f08c3bdfSopenharmony_ci * Parent_c read lock on byte 1 to 216f08c3bdfSopenharmony_ci * byte 3 217f08c3bdfSopenharmony_ci */ 218f08c3bdfSopenharmony_ci {F_RDLCK, 0, 1L, 3L, IGNORED}, 219f08c3bdfSopenharmony_ci /* 220f08c3bdfSopenharmony_ci * Parent_d read lock on 221f08c3bdfSopenharmony_ci * byte 7 to byte 9 222f08c3bdfSopenharmony_ci */ 223f08c3bdfSopenharmony_ci {F_RDLCK, 0, 7L, 3L, 224f08c3bdfSopenharmony_ci IGNORED},}, 225f08c3bdfSopenharmony_ci 226f08c3bdfSopenharmony_ci /* #10 Parent_a making a write lock on entire file */ 227f08c3bdfSopenharmony_ci {{F_WRLCK, 0, 0L, 0L, IGNORED}, 228f08c3bdfSopenharmony_ci /* Parent_b skipped */ 229f08c3bdfSopenharmony_ci {SKIP}, 230f08c3bdfSopenharmony_ci /* Child_a read lock on byte 2 to byte 4 */ 231f08c3bdfSopenharmony_ci {F_RDLCK, 0, 2L, 3L, NOBLOCK}, 232f08c3bdfSopenharmony_ci /* Child_b read lock on byte 6 to byte 8 */ 233f08c3bdfSopenharmony_ci {F_RDLCK, 0, 6L, 3L, NOBLOCK}, 234f08c3bdfSopenharmony_ci /* 235f08c3bdfSopenharmony_ci * Parent_c read lock on byte 1 to 236f08c3bdfSopenharmony_ci * byte 7 237f08c3bdfSopenharmony_ci */ 238f08c3bdfSopenharmony_ci {F_RDLCK, 0, 1L, 7L, IGNORED}, 239f08c3bdfSopenharmony_ci /* 240f08c3bdfSopenharmony_ci * Parent_d read lock on 241f08c3bdfSopenharmony_ci * byte 3 to byte 9 242f08c3bdfSopenharmony_ci */ 243f08c3bdfSopenharmony_ci {F_RDLCK, 0, 3L, 7L, 244f08c3bdfSopenharmony_ci IGNORED},}, 245f08c3bdfSopenharmony_ci 246f08c3bdfSopenharmony_ci /* #11 Parent_a making a write lock on entire file */ 247f08c3bdfSopenharmony_ci {{F_WRLCK, 0, 0L, 0L, IGNORED}, 248f08c3bdfSopenharmony_ci /* Parent_b skipped */ 249f08c3bdfSopenharmony_ci {SKIP}, 250f08c3bdfSopenharmony_ci /* Child_a read lock on byte 3 to byte 7 */ 251f08c3bdfSopenharmony_ci {F_RDLCK, 0, 3L, 5L, NOBLOCK}, 252f08c3bdfSopenharmony_ci /* Child_b read lock on byte 3 to byte 7 */ 253f08c3bdfSopenharmony_ci {F_RDLCK, 0, 3L, 5L, NOBLOCK}, 254f08c3bdfSopenharmony_ci /* 255f08c3bdfSopenharmony_ci * Parent_c read lock on byte 3 to 256f08c3bdfSopenharmony_ci * byte 7 257f08c3bdfSopenharmony_ci */ 258f08c3bdfSopenharmony_ci {F_RDLCK, 0, 3L, 5L, IGNORED}, 259f08c3bdfSopenharmony_ci /* Parent_d skipped */ 260f08c3bdfSopenharmony_ci {SKIP},}, 261f08c3bdfSopenharmony_ci}; 262f08c3bdfSopenharmony_ci 263f08c3bdfSopenharmony_cistatic testcase *thiscase; 264f08c3bdfSopenharmony_cistatic struct flock *thislock; 265f08c3bdfSopenharmony_cistatic int parent; 266f08c3bdfSopenharmony_cistatic int child_flag1 = 0; 267f08c3bdfSopenharmony_cistatic int child_flag2 = 0; 268f08c3bdfSopenharmony_cistatic int parent_flag = 0; 269f08c3bdfSopenharmony_cistatic int alarm_flag = 0; 270f08c3bdfSopenharmony_cistatic int child_pid[2], flag[2]; 271f08c3bdfSopenharmony_cistatic int fd; 272f08c3bdfSopenharmony_cistatic int test; 273f08c3bdfSopenharmony_cistatic char tmpname[40]; 274f08c3bdfSopenharmony_ci 275f08c3bdfSopenharmony_ci#define FILEDATA "tenbytes!" 276f08c3bdfSopenharmony_ci 277f08c3bdfSopenharmony_ciextern void catch_int(int sig); /* signal catching subroutine */ 278f08c3bdfSopenharmony_ci 279f08c3bdfSopenharmony_cichar *TCID = "fcntl16"; 280f08c3bdfSopenharmony_ciint TST_TOTAL = 1; 281f08c3bdfSopenharmony_ci 282f08c3bdfSopenharmony_ci#ifdef UCLINUX 283f08c3bdfSopenharmony_cistatic char *argv0; 284f08c3bdfSopenharmony_ci#endif 285f08c3bdfSopenharmony_ci 286f08c3bdfSopenharmony_ci/* 287f08c3bdfSopenharmony_ci * cleanup - performs all the ONE TIME cleanup for this test at completion or 288f08c3bdfSopenharmony_ci * premature exit 289f08c3bdfSopenharmony_ci */ 290f08c3bdfSopenharmony_civoid cleanup(void) 291f08c3bdfSopenharmony_ci{ 292f08c3bdfSopenharmony_ci tst_rmdir(); 293f08c3bdfSopenharmony_ci 294f08c3bdfSopenharmony_ci} 295f08c3bdfSopenharmony_ci 296f08c3bdfSopenharmony_civoid dochild(int kid) 297f08c3bdfSopenharmony_ci{ 298f08c3bdfSopenharmony_ci /* child process */ 299f08c3bdfSopenharmony_ci struct sigaction sact; 300f08c3bdfSopenharmony_ci sact.sa_flags = 0; 301f08c3bdfSopenharmony_ci sact.sa_handler = catch_int; 302f08c3bdfSopenharmony_ci sigemptyset(&sact.sa_mask); 303f08c3bdfSopenharmony_ci (void)sigaction(SIGUSR1, &sact, NULL); 304f08c3bdfSopenharmony_ci 305f08c3bdfSopenharmony_ci /* Lock should succeed after blocking and parent releases lock */ 306f08c3bdfSopenharmony_ci if (kid) { 307f08c3bdfSopenharmony_ci if ((kill(parent, SIGUSR2)) < 0) { 308f08c3bdfSopenharmony_ci tst_resm(TFAIL, "Attempt to send signal to parent " 309f08c3bdfSopenharmony_ci "failed"); 310f08c3bdfSopenharmony_ci tst_resm(TFAIL, "Test case %d, child %d, errno = %d", 311f08c3bdfSopenharmony_ci test + 1, kid, errno); 312f08c3bdfSopenharmony_ci exit(1); 313f08c3bdfSopenharmony_ci } 314f08c3bdfSopenharmony_ci } else { 315f08c3bdfSopenharmony_ci if ((kill(parent, SIGUSR1)) < 0) { 316f08c3bdfSopenharmony_ci tst_resm(TFAIL, "Attempt to send signal to parent " 317f08c3bdfSopenharmony_ci "failed"); 318f08c3bdfSopenharmony_ci tst_resm(TFAIL, "Test case %d, child %d, errno = %d", 319f08c3bdfSopenharmony_ci test + 1, kid, errno); 320f08c3bdfSopenharmony_ci exit(1); 321f08c3bdfSopenharmony_ci } 322f08c3bdfSopenharmony_ci } 323f08c3bdfSopenharmony_ci 324f08c3bdfSopenharmony_ci if ((fcntl(fd, F_SETLKW, thislock)) < 0) { 325f08c3bdfSopenharmony_ci if (errno == EINTR && parent_flag) { 326f08c3bdfSopenharmony_ci /* 327f08c3bdfSopenharmony_ci * signal received is waiting for lock to clear, 328f08c3bdfSopenharmony_ci * this is expected if flag = WILLBLOCK 329f08c3bdfSopenharmony_ci */ 330f08c3bdfSopenharmony_ci exit(1); 331f08c3bdfSopenharmony_ci } else { 332f08c3bdfSopenharmony_ci tst_resm(TFAIL, "Attempt to set child BLOCKING lock " 333f08c3bdfSopenharmony_ci "failed"); 334f08c3bdfSopenharmony_ci tst_resm(TFAIL, "Test case %d, errno = %d", test + 1, 335f08c3bdfSopenharmony_ci errno); 336f08c3bdfSopenharmony_ci exit(2); 337f08c3bdfSopenharmony_ci } 338f08c3bdfSopenharmony_ci } 339f08c3bdfSopenharmony_ci exit(0); 340f08c3bdfSopenharmony_ci} /* end of child process */ 341f08c3bdfSopenharmony_ci 342f08c3bdfSopenharmony_ci#ifdef UCLINUX 343f08c3bdfSopenharmony_cistatic int kid_uc; 344f08c3bdfSopenharmony_ci 345f08c3bdfSopenharmony_civoid dochild_uc(void) 346f08c3bdfSopenharmony_ci{ 347f08c3bdfSopenharmony_ci dochild(kid_uc); 348f08c3bdfSopenharmony_ci} 349f08c3bdfSopenharmony_ci#endif 350f08c3bdfSopenharmony_ci 351f08c3bdfSopenharmony_civoid catch_alarm(int sig) 352f08c3bdfSopenharmony_ci{ 353f08c3bdfSopenharmony_ci alarm_flag = 1; 354f08c3bdfSopenharmony_ci} 355f08c3bdfSopenharmony_ci 356f08c3bdfSopenharmony_civoid catch_usr1(int sig) 357f08c3bdfSopenharmony_ci{ /* invoked on catching SIGUSR1 */ 358f08c3bdfSopenharmony_ci /* 359f08c3bdfSopenharmony_ci * Set flag to let parent know that child #1 is ready to have the 360f08c3bdfSopenharmony_ci * lock removed 361f08c3bdfSopenharmony_ci */ 362f08c3bdfSopenharmony_ci child_flag1 = 1; 363f08c3bdfSopenharmony_ci} 364f08c3bdfSopenharmony_ci 365f08c3bdfSopenharmony_civoid catch_usr2(int sig) 366f08c3bdfSopenharmony_ci{ /* invoked on catching SIGUSR2 */ 367f08c3bdfSopenharmony_ci /* 368f08c3bdfSopenharmony_ci * Set flag to let parent know that child #2 is ready to have the 369f08c3bdfSopenharmony_ci * lock removed 370f08c3bdfSopenharmony_ci */ 371f08c3bdfSopenharmony_ci child_flag2 = 1; 372f08c3bdfSopenharmony_ci} 373f08c3bdfSopenharmony_ci 374f08c3bdfSopenharmony_civoid catch_int(int sig) 375f08c3bdfSopenharmony_ci{ /* invoked on child catching SIGUSR1 */ 376f08c3bdfSopenharmony_ci /* 377f08c3bdfSopenharmony_ci * Set flag to interrupt fcntl call in child and force a controlled 378f08c3bdfSopenharmony_ci * exit 379f08c3bdfSopenharmony_ci */ 380f08c3bdfSopenharmony_ci parent_flag = 1; 381f08c3bdfSopenharmony_ci} 382f08c3bdfSopenharmony_ci 383f08c3bdfSopenharmony_civoid child_sig(int sig, int nkids) 384f08c3bdfSopenharmony_ci{ 385f08c3bdfSopenharmony_ci int i; 386f08c3bdfSopenharmony_ci 387f08c3bdfSopenharmony_ci for (i = 0; i < nkids; i++) { 388f08c3bdfSopenharmony_ci if (kill(child_pid[i], 0) == 0) { 389f08c3bdfSopenharmony_ci if ((kill(child_pid[i], sig)) < 0) { 390f08c3bdfSopenharmony_ci tst_resm(TFAIL, "Attempt to signal child %d, " 391f08c3bdfSopenharmony_ci "failed", i + 1); 392f08c3bdfSopenharmony_ci } 393f08c3bdfSopenharmony_ci } 394f08c3bdfSopenharmony_ci } 395f08c3bdfSopenharmony_ci} 396f08c3bdfSopenharmony_ci 397f08c3bdfSopenharmony_ci/* 398f08c3bdfSopenharmony_ci * setup - performs all ONE TIME steup for this test 399f08c3bdfSopenharmony_ci */ 400f08c3bdfSopenharmony_civoid setup(void) 401f08c3bdfSopenharmony_ci{ 402f08c3bdfSopenharmony_ci struct sigaction sact; 403f08c3bdfSopenharmony_ci 404f08c3bdfSopenharmony_ci tst_sig(FORK, DEF_HANDLER, cleanup); 405f08c3bdfSopenharmony_ci 406f08c3bdfSopenharmony_ci umask(0); 407f08c3bdfSopenharmony_ci 408f08c3bdfSopenharmony_ci /* Pause if option was specified */ 409f08c3bdfSopenharmony_ci TEST_PAUSE; 410f08c3bdfSopenharmony_ci 411f08c3bdfSopenharmony_ci parent = getpid(); 412f08c3bdfSopenharmony_ci 413f08c3bdfSopenharmony_ci tst_tmpdir(); 414f08c3bdfSopenharmony_ci 415f08c3bdfSopenharmony_ci /* On NFS or not */ 416f08c3bdfSopenharmony_ci if (tst_fs_type(cleanup, ".") == TST_NFS_MAGIC) 417f08c3bdfSopenharmony_ci NO_NFS = 0; 418f08c3bdfSopenharmony_ci 419f08c3bdfSopenharmony_ci /* set up temp filename */ 420f08c3bdfSopenharmony_ci sprintf(tmpname, "fcntl4.%d", parent); 421f08c3bdfSopenharmony_ci 422f08c3bdfSopenharmony_ci /* 423f08c3bdfSopenharmony_ci * Set up signal handling functions 424f08c3bdfSopenharmony_ci */ 425f08c3bdfSopenharmony_ci memset(&sact, 0, sizeof(sact)); 426f08c3bdfSopenharmony_ci sact.sa_handler = catch_usr1; 427f08c3bdfSopenharmony_ci sigemptyset(&sact.sa_mask); 428f08c3bdfSopenharmony_ci sigaddset(&sact.sa_mask, SIGUSR1); 429f08c3bdfSopenharmony_ci sigaction(SIGUSR1, &sact, NULL); 430f08c3bdfSopenharmony_ci 431f08c3bdfSopenharmony_ci memset(&sact, 0, sizeof(sact)); 432f08c3bdfSopenharmony_ci sact.sa_handler = catch_usr2; 433f08c3bdfSopenharmony_ci sigemptyset(&sact.sa_mask); 434f08c3bdfSopenharmony_ci sigaddset(&sact.sa_mask, SIGUSR2); 435f08c3bdfSopenharmony_ci sigaction(SIGUSR2, &sact, NULL); 436f08c3bdfSopenharmony_ci 437f08c3bdfSopenharmony_ci memset(&sact, 0, sizeof(sact)); 438f08c3bdfSopenharmony_ci sact.sa_handler = catch_alarm; 439f08c3bdfSopenharmony_ci sigemptyset(&sact.sa_mask); 440f08c3bdfSopenharmony_ci sigaddset(&sact.sa_mask, SIGALRM); 441f08c3bdfSopenharmony_ci sigaction(SIGALRM, &sact, NULL); 442f08c3bdfSopenharmony_ci} 443f08c3bdfSopenharmony_ci 444f08c3bdfSopenharmony_ciint run_test(int file_flag, int file_mode, int start, int end) 445f08c3bdfSopenharmony_ci{ 446f08c3bdfSopenharmony_ci int child_count; 447f08c3bdfSopenharmony_ci int child; 448f08c3bdfSopenharmony_ci int nexited; 449f08c3bdfSopenharmony_ci int status, expect_stat; 450f08c3bdfSopenharmony_ci int i, fail = 0; 451f08c3bdfSopenharmony_ci 452f08c3bdfSopenharmony_ci /* loop through all test cases */ 453f08c3bdfSopenharmony_ci for (test = start; test < end; test++) { 454f08c3bdfSopenharmony_ci /* open a temp file to lock */ 455f08c3bdfSopenharmony_ci fd = SAFE_OPEN(cleanup, tmpname, file_flag, file_mode); 456f08c3bdfSopenharmony_ci 457f08c3bdfSopenharmony_ci /* write some dummy data to the file */ 458f08c3bdfSopenharmony_ci (void)write(fd, FILEDATA, 10); 459f08c3bdfSopenharmony_ci 460f08c3bdfSopenharmony_ci /* Initialize first parent lock structure */ 461f08c3bdfSopenharmony_ci thiscase = &testcases[test]; 462f08c3bdfSopenharmony_ci thislock = &thiscase->parent_a; 463f08c3bdfSopenharmony_ci 464f08c3bdfSopenharmony_ci /* set the initial parent lock on the file */ 465f08c3bdfSopenharmony_ci if ((fcntl(fd, F_SETLK, thislock)) < 0) { 466f08c3bdfSopenharmony_ci tst_resm(TFAIL, "First parent lock failed"); 467f08c3bdfSopenharmony_ci tst_resm(TFAIL, "Test case %d, errno = %d", test + 1, 468f08c3bdfSopenharmony_ci errno); 469f08c3bdfSopenharmony_ci close(fd); 470f08c3bdfSopenharmony_ci unlink(tmpname); 471f08c3bdfSopenharmony_ci return 1; 472f08c3bdfSopenharmony_ci } 473f08c3bdfSopenharmony_ci 474f08c3bdfSopenharmony_ci /* Initialize second parent lock structure */ 475f08c3bdfSopenharmony_ci thislock = &thiscase->parent_b; 476f08c3bdfSopenharmony_ci 477f08c3bdfSopenharmony_ci if ((thislock->l_type) != IGNORED) { /*SKIPVAL */ 478f08c3bdfSopenharmony_ci /* set the second parent lock */ 479f08c3bdfSopenharmony_ci if ((fcntl(fd, F_SETLK, thislock)) < 0) { 480f08c3bdfSopenharmony_ci tst_resm(TFAIL, "Second parent lock failed"); 481f08c3bdfSopenharmony_ci tst_resm(TFAIL, "Test case %d, errno = %d", 482f08c3bdfSopenharmony_ci test + 1, errno); 483f08c3bdfSopenharmony_ci close(fd); 484f08c3bdfSopenharmony_ci unlink(tmpname); 485f08c3bdfSopenharmony_ci return 1; 486f08c3bdfSopenharmony_ci } 487f08c3bdfSopenharmony_ci } 488f08c3bdfSopenharmony_ci 489f08c3bdfSopenharmony_ci /* Initialize first child lock structure */ 490f08c3bdfSopenharmony_ci thislock = &thiscase->child_a; 491f08c3bdfSopenharmony_ci 492f08c3bdfSopenharmony_ci /* Initialize child counter and flags */ 493f08c3bdfSopenharmony_ci alarm_flag = parent_flag = 0; 494f08c3bdfSopenharmony_ci child_flag1 = child_flag2 = 0; 495f08c3bdfSopenharmony_ci child_count = 0; 496f08c3bdfSopenharmony_ci 497f08c3bdfSopenharmony_ci /* spawn child processes */ 498f08c3bdfSopenharmony_ci for (i = 0; i < 2; i++) { 499f08c3bdfSopenharmony_ci if (thislock->l_type != IGNORED) { 500f08c3bdfSopenharmony_ci if ((child = FORK_OR_VFORK()) == 0) { 501f08c3bdfSopenharmony_ci#ifdef UCLINUX 502f08c3bdfSopenharmony_ci if (self_exec(argv0, "ddddd", i, parent, 503f08c3bdfSopenharmony_ci test, thislock, fd) < 0) { 504f08c3bdfSopenharmony_ci perror("self_exec failed"); 505f08c3bdfSopenharmony_ci return 1; 506f08c3bdfSopenharmony_ci } 507f08c3bdfSopenharmony_ci#else 508f08c3bdfSopenharmony_ci dochild(i); 509f08c3bdfSopenharmony_ci#endif 510f08c3bdfSopenharmony_ci } 511f08c3bdfSopenharmony_ci if (child < 0) { 512f08c3bdfSopenharmony_ci perror("Fork failed"); 513f08c3bdfSopenharmony_ci return 1; 514f08c3bdfSopenharmony_ci } 515f08c3bdfSopenharmony_ci child_count++; 516f08c3bdfSopenharmony_ci child_pid[i] = child; 517f08c3bdfSopenharmony_ci flag[i] = thislock->l_pid; 518f08c3bdfSopenharmony_ci } 519f08c3bdfSopenharmony_ci /* Initialize second child lock structure */ 520f08c3bdfSopenharmony_ci thislock = &thiscase->child_b; 521f08c3bdfSopenharmony_ci } 522f08c3bdfSopenharmony_ci /* parent process */ 523f08c3bdfSopenharmony_ci 524f08c3bdfSopenharmony_ci /* 525f08c3bdfSopenharmony_ci * Wait for children to signal they are ready. Set a timeout 526f08c3bdfSopenharmony_ci * just in case they don't signal at all. 527f08c3bdfSopenharmony_ci */ 528f08c3bdfSopenharmony_ci alarm(TIME_OUT); 529f08c3bdfSopenharmony_ci 530f08c3bdfSopenharmony_ci while (!alarm_flag 531f08c3bdfSopenharmony_ci && (child_flag1 + child_flag2 != child_count)) { 532f08c3bdfSopenharmony_ci pause(); 533f08c3bdfSopenharmony_ci } 534f08c3bdfSopenharmony_ci 535f08c3bdfSopenharmony_ci /* 536f08c3bdfSopenharmony_ci * Turn off alarm and unmask signals 537f08c3bdfSopenharmony_ci */ 538f08c3bdfSopenharmony_ci alarm((unsigned)0); 539f08c3bdfSopenharmony_ci 540f08c3bdfSopenharmony_ci if (child_flag1 + child_flag2 != child_count) { 541f08c3bdfSopenharmony_ci tst_resm(TFAIL, "Test case %d: kids didn't signal", 542f08c3bdfSopenharmony_ci test + 1); 543f08c3bdfSopenharmony_ci fail = 1; 544f08c3bdfSopenharmony_ci } 545f08c3bdfSopenharmony_ci child_flag1 = child_flag2 = alarm_flag = 0; 546f08c3bdfSopenharmony_ci 547f08c3bdfSopenharmony_ci thislock = &thiscase->parent_c; 548f08c3bdfSopenharmony_ci 549f08c3bdfSopenharmony_ci /* set the third parent lock on the file */ 550f08c3bdfSopenharmony_ci if ((fcntl(fd, F_SETLK, thislock)) < 0) { 551f08c3bdfSopenharmony_ci tst_resm(TFAIL, "Third parent lock failed"); 552f08c3bdfSopenharmony_ci tst_resm(TFAIL, "Test case %d, errno = %d", 553f08c3bdfSopenharmony_ci test + 1, errno); 554f08c3bdfSopenharmony_ci close(fd); 555f08c3bdfSopenharmony_ci unlink(tmpname); 556f08c3bdfSopenharmony_ci return 1; 557f08c3bdfSopenharmony_ci } 558f08c3bdfSopenharmony_ci 559f08c3bdfSopenharmony_ci /* Initialize fourth parent lock structure */ 560f08c3bdfSopenharmony_ci thislock = &thiscase->parent_d; 561f08c3bdfSopenharmony_ci 562f08c3bdfSopenharmony_ci if ((thislock->l_type) != IGNORED) { /*SKIPVAL */ 563f08c3bdfSopenharmony_ci /* set the fourth parent lock */ 564f08c3bdfSopenharmony_ci if ((fcntl(fd, F_SETLK, thislock)) < 0) { 565f08c3bdfSopenharmony_ci tst_resm(TINFO, "Fourth parent lock failed"); 566f08c3bdfSopenharmony_ci tst_resm(TINFO, "Test case %d, errno = %d", 567f08c3bdfSopenharmony_ci test + 1, errno); 568f08c3bdfSopenharmony_ci close(fd); 569f08c3bdfSopenharmony_ci unlink(tmpname); 570f08c3bdfSopenharmony_ci return 1; 571f08c3bdfSopenharmony_ci } 572f08c3bdfSopenharmony_ci } 573f08c3bdfSopenharmony_ci 574f08c3bdfSopenharmony_ci /* 575f08c3bdfSopenharmony_ci * Wait for children to exit, or for timeout to occur. 576f08c3bdfSopenharmony_ci * Timeouts are expected for testcases where kids are 577f08c3bdfSopenharmony_ci * 'WILLBLOCK', In that case, send kids a wakeup interrupt 578f08c3bdfSopenharmony_ci * and wait again for them. If a second timeout occurs, then 579f08c3bdfSopenharmony_ci * something is wrong. 580f08c3bdfSopenharmony_ci */ 581f08c3bdfSopenharmony_ci alarm_flag = nexited = 0; 582f08c3bdfSopenharmony_ci while (nexited < child_count) { 583f08c3bdfSopenharmony_ci alarm(TIME_OUT); 584f08c3bdfSopenharmony_ci child = wait(&status); 585f08c3bdfSopenharmony_ci alarm(0); 586f08c3bdfSopenharmony_ci 587f08c3bdfSopenharmony_ci if (child == -1) { 588f08c3bdfSopenharmony_ci if (errno != EINTR || alarm_flag != 1) { 589f08c3bdfSopenharmony_ci /* 590f08c3bdfSopenharmony_ci * Some error other than a timeout, 591f08c3bdfSopenharmony_ci * or else this is the second 592f08c3bdfSopenharmony_ci * timeout. Both cases are errors. 593f08c3bdfSopenharmony_ci */ 594f08c3bdfSopenharmony_ci break; 595f08c3bdfSopenharmony_ci } 596f08c3bdfSopenharmony_ci 597f08c3bdfSopenharmony_ci /* 598f08c3bdfSopenharmony_ci * Expected timeout case. Signal kids then 599f08c3bdfSopenharmony_ci * go back and wait again 600f08c3bdfSopenharmony_ci */ 601f08c3bdfSopenharmony_ci child_sig(SIGUSR1, child_count); 602f08c3bdfSopenharmony_ci continue; 603f08c3bdfSopenharmony_ci } 604f08c3bdfSopenharmony_ci 605f08c3bdfSopenharmony_ci for (i = 0; i < child_count; i++) 606f08c3bdfSopenharmony_ci if (child == child_pid[i]) 607f08c3bdfSopenharmony_ci break; 608f08c3bdfSopenharmony_ci if (i == child_count) { 609f08c3bdfSopenharmony_ci /* 610f08c3bdfSopenharmony_ci * Ignore unexpected kid, it could be a 611f08c3bdfSopenharmony_ci * leftover from a previous iteration that 612f08c3bdfSopenharmony_ci * timed out. 613f08c3bdfSopenharmony_ci */ 614f08c3bdfSopenharmony_ci continue; 615f08c3bdfSopenharmony_ci } 616f08c3bdfSopenharmony_ci 617f08c3bdfSopenharmony_ci /* Found the right kid, check his status */ 618f08c3bdfSopenharmony_ci nexited++; 619f08c3bdfSopenharmony_ci 620f08c3bdfSopenharmony_ci expect_stat = (flag[i] == NOBLOCK) ? 0 : 1; 621f08c3bdfSopenharmony_ci 622f08c3bdfSopenharmony_ci if (!WIFEXITED(status) 623f08c3bdfSopenharmony_ci || WEXITSTATUS(status) != expect_stat) { 624f08c3bdfSopenharmony_ci /* got unexpected exit status from kid */ 625f08c3bdfSopenharmony_ci tst_resm(TFAIL, "Test case %d: child %d %s " 626f08c3bdfSopenharmony_ci "or got bad status (x%x)", test + 1, 627f08c3bdfSopenharmony_ci i, (flag[i] == NOBLOCK) ? 628f08c3bdfSopenharmony_ci "BLOCKED unexpectedly" : 629f08c3bdfSopenharmony_ci "failed to BLOCK", status); 630f08c3bdfSopenharmony_ci fail = 1; 631f08c3bdfSopenharmony_ci } 632f08c3bdfSopenharmony_ci } 633f08c3bdfSopenharmony_ci 634f08c3bdfSopenharmony_ci if (nexited != child_count) { 635f08c3bdfSopenharmony_ci tst_resm(TFAIL, "Test case %d, caught %d expected %d " 636f08c3bdfSopenharmony_ci "children", test + 1, nexited, child_count); 637f08c3bdfSopenharmony_ci child_sig(SIGKILL, nexited); 638f08c3bdfSopenharmony_ci fail = 1; 639f08c3bdfSopenharmony_ci } 640f08c3bdfSopenharmony_ci close(fd); 641f08c3bdfSopenharmony_ci } 642f08c3bdfSopenharmony_ci unlink(tmpname); 643f08c3bdfSopenharmony_ci if (fail) { 644f08c3bdfSopenharmony_ci return 1; 645f08c3bdfSopenharmony_ci } else { 646f08c3bdfSopenharmony_ci return 0; 647f08c3bdfSopenharmony_ci } 648f08c3bdfSopenharmony_ci return 0; 649f08c3bdfSopenharmony_ci} 650f08c3bdfSopenharmony_ci 651f08c3bdfSopenharmony_ciint main(int ac, char **av) 652f08c3bdfSopenharmony_ci{ 653f08c3bdfSopenharmony_ci 654f08c3bdfSopenharmony_ci int lc; 655f08c3bdfSopenharmony_ci 656f08c3bdfSopenharmony_ci tst_parse_opts(ac, av, NULL, NULL); 657f08c3bdfSopenharmony_ci#ifdef UCLINUX 658f08c3bdfSopenharmony_ci maybe_run_child(dochild_uc, "ddddd", &kid_uc, &parent, &test, 659f08c3bdfSopenharmony_ci &thislock, &fd); 660f08c3bdfSopenharmony_ci argv0 = av[0]; 661f08c3bdfSopenharmony_ci#endif 662f08c3bdfSopenharmony_ci 663f08c3bdfSopenharmony_ci setup(); /* global setup */ 664f08c3bdfSopenharmony_ci 665f08c3bdfSopenharmony_ci for (lc = 0; TEST_LOOPING(lc); lc++) { 666f08c3bdfSopenharmony_ci /* reset tst_count in case we are looping */ 667f08c3bdfSopenharmony_ci tst_count = 0; 668f08c3bdfSopenharmony_ci 669f08c3bdfSopenharmony_ci/* //block1: */ 670f08c3bdfSopenharmony_ci /* 671f08c3bdfSopenharmony_ci * Check file locks on an ordinary file without 672f08c3bdfSopenharmony_ci * mandatory locking 673f08c3bdfSopenharmony_ci */ 674f08c3bdfSopenharmony_ci tst_resm(TINFO, "Entering block 1"); 675f08c3bdfSopenharmony_ci if (run_test(O_CREAT | O_RDWR | O_TRUNC, 0777, 0, 11)) { 676f08c3bdfSopenharmony_ci tst_resm(TINFO, "Test case 1: without mandatory " 677f08c3bdfSopenharmony_ci "locking FAILED"); 678f08c3bdfSopenharmony_ci } else { 679f08c3bdfSopenharmony_ci tst_resm(TINFO, "Test case 1: without manadatory " 680f08c3bdfSopenharmony_ci "locking PASSED"); 681f08c3bdfSopenharmony_ci } 682f08c3bdfSopenharmony_ci tst_resm(TINFO, "Exiting block 1"); 683f08c3bdfSopenharmony_ci 684f08c3bdfSopenharmony_ci/* //block2: */ 685f08c3bdfSopenharmony_ci /* 686f08c3bdfSopenharmony_ci * Check the file locks on a file with mandatory record 687f08c3bdfSopenharmony_ci * locking 688f08c3bdfSopenharmony_ci */ 689f08c3bdfSopenharmony_ci tst_resm(TINFO, "Entering block 2"); 690f08c3bdfSopenharmony_ci if (NO_NFS && run_test(O_CREAT | O_RDWR | O_TRUNC, S_ISGID | 691f08c3bdfSopenharmony_ci S_IRUSR | S_IWUSR, 0, 11)) { 692f08c3bdfSopenharmony_ci tst_resm(TINFO, "Test case 2: with mandatory record " 693f08c3bdfSopenharmony_ci "locking FAILED"); 694f08c3bdfSopenharmony_ci } else { 695f08c3bdfSopenharmony_ci if (NO_NFS) 696f08c3bdfSopenharmony_ci tst_resm(TINFO, "Test case 2: with mandatory" 697f08c3bdfSopenharmony_ci " record locking PASSED"); 698f08c3bdfSopenharmony_ci else 699f08c3bdfSopenharmony_ci tst_resm(TCONF, "Test case 2: NFS does not" 700f08c3bdfSopenharmony_ci " support mandatory locking"); 701f08c3bdfSopenharmony_ci } 702f08c3bdfSopenharmony_ci tst_resm(TINFO, "Exiting block 2"); 703f08c3bdfSopenharmony_ci 704f08c3bdfSopenharmony_ci/* //block3: */ 705f08c3bdfSopenharmony_ci /* 706f08c3bdfSopenharmony_ci * Check file locks on a file with mandatory record locking 707f08c3bdfSopenharmony_ci * and no delay 708f08c3bdfSopenharmony_ci */ 709f08c3bdfSopenharmony_ci tst_resm(TINFO, "Entering block 3"); 710f08c3bdfSopenharmony_ci if (NO_NFS && run_test(O_CREAT | O_RDWR | O_TRUNC | O_NDELAY, 711f08c3bdfSopenharmony_ci S_ISGID | S_IRUSR | S_IWUSR, 0, 11)) { 712f08c3bdfSopenharmony_ci tst_resm(TINFO, "Test case 3: mandatory locking with " 713f08c3bdfSopenharmony_ci "NODELAY FAILED"); 714f08c3bdfSopenharmony_ci } else { 715f08c3bdfSopenharmony_ci if (NO_NFS) 716f08c3bdfSopenharmony_ci tst_resm(TINFO, "Test case 3: mandatory" 717f08c3bdfSopenharmony_ci " locking with NODELAY PASSED"); 718f08c3bdfSopenharmony_ci else 719f08c3bdfSopenharmony_ci tst_resm(TCONF, "Test case 3: NFS does not" 720f08c3bdfSopenharmony_ci " support mandatory locking"); 721f08c3bdfSopenharmony_ci } 722f08c3bdfSopenharmony_ci tst_resm(TINFO, "Exiting block 3"); 723f08c3bdfSopenharmony_ci } 724f08c3bdfSopenharmony_ci cleanup(); 725f08c3bdfSopenharmony_ci tst_exit(); 726f08c3bdfSopenharmony_ci} 727