plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (c) International Business Machines Corp., 2001 |
| 4 | * |
| 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 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 13 | * the GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | /* |
| 21 | * NAME |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 22 | * fcntl11.c |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 23 | * |
| 24 | * DESCRIPTION |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 25 | * Testcase to check locking of regions of a file |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 26 | * |
| 27 | * ALGORITHM |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 28 | * Test changing lock sections around a write lock |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 29 | * |
| 30 | * USAGE |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 31 | * fcntl11 |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 32 | * |
| 33 | * HISTORY |
| 34 | * 07/2001 Ported by Wayne Boyer |
| 35 | * |
| 36 | * RESTRICTIONS |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 37 | * None |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 38 | */ |
| 39 | |
| 40 | #include <fcntl.h> |
| 41 | #include <errno.h> |
| 42 | #include <signal.h> |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 43 | #include <sys/types.h> |
| 44 | #include <sys/stat.h> |
mridge | db63921 | 2005-01-04 21:04:11 +0000 | [diff] [blame] | 45 | #include <sys/wait.h> |
subrata_modak | 923b23f | 2009-11-02 13:57:16 +0000 | [diff] [blame] | 46 | #include <inttypes.h> |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 47 | #include "test.h" |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 48 | #include "safe_macros.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 49 | |
| 50 | #define STRINGSIZE 27 |
| 51 | #define STRING "abcdefghijklmnopqrstuvwxyz\n" |
| 52 | #define STOP 0xFFF0 |
| 53 | |
| 54 | int parent_pipe[2]; |
| 55 | int child_pipe[2]; |
| 56 | int fd; |
plars | a1e518d | 2002-09-09 18:23:52 +0000 | [diff] [blame] | 57 | pid_t parent_pid, child_pid; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 58 | |
| 59 | void parent_put(); |
| 60 | void parent_get(); |
| 61 | void child_put(); |
| 62 | void child_get(); |
| 63 | void stop_child(); |
plars | a1e518d | 2002-09-09 18:23:52 +0000 | [diff] [blame] | 64 | void compare_lock(struct flock *, short, short, int, int, pid_t); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 65 | void unlock_file(); |
| 66 | void do_test(struct flock *, short, short, int, int); |
| 67 | void catch_child(); |
| 68 | char *str_type(); |
| 69 | int do_lock(int, short, short, int, int); |
| 70 | |
| 71 | char *TCID = "fcntl11"; |
| 72 | int TST_TOTAL = 1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 73 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 74 | int fail; |
| 75 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 76 | void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 77 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 78 | tst_rmdir(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 79 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 80 | } |
| 81 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 82 | void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 83 | { |
| 84 | char *buf = STRING; |
robbiew | 83f259b | 2003-04-16 18:58:09 +0000 | [diff] [blame] | 85 | char template[PATH_MAX]; |
robbiew | 1e4cf0c | 2005-02-24 17:03:42 +0000 | [diff] [blame] | 86 | struct sigaction act; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 87 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 88 | tst_sig(FORK, DEF_HANDLER, cleanup); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 89 | tst_tmpdir(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 90 | |
| 91 | umask(0); |
| 92 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 93 | TEST_PAUSE; |
| 94 | |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 95 | SAFE_PIPE(cleanup, parent_pipe); |
| 96 | SAFE_PIPE(cleanup, child_pipe); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 97 | parent_pid = getpid(); |
robbiew | 83f259b | 2003-04-16 18:58:09 +0000 | [diff] [blame] | 98 | snprintf(template, PATH_MAX, "fcntl11XXXXXX"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 99 | |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 100 | if ((fd = mkstemp(template)) < 0) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 101 | tst_resm(TFAIL, "Couldn't open temp file! errno = %d", errno); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 102 | |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 103 | SAFE_WRITE(cleanup, 0, fd, buf, STRINGSIZE); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 104 | |
robbiew | 1e4cf0c | 2005-02-24 17:03:42 +0000 | [diff] [blame] | 105 | memset(&act, 0, sizeof(act)); |
| 106 | act.sa_handler = catch_child; |
| 107 | sigemptyset(&act.sa_mask); |
| 108 | sigaddset(&act.sa_mask, SIGCLD); |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 109 | if ((sigaction(SIGCLD, &act, NULL)) < 0) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 110 | tst_brkm(TBROK | TERRNO, cleanup, |
| 111 | "sigaction(SIGCLD, ..) failed"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 112 | } |
| 113 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 114 | void do_child(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 115 | { |
| 116 | struct flock fl; |
| 117 | |
| 118 | close(parent_pipe[1]); |
| 119 | close(child_pipe[0]); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 120 | while (1) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 121 | child_get(&fl); |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 122 | if (fcntl(fd, F_GETLK, &fl) < 0) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 123 | tst_resm(TFAIL | TERRNO, "fcntl on file failed"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 124 | child_put(&fl); |
| 125 | } |
| 126 | } |
| 127 | |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 128 | int do_lock(int cmd, short type, short whence, int start, int len) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 129 | { |
| 130 | struct flock fl; |
| 131 | |
| 132 | fl.l_type = type; |
| 133 | fl.l_whence = whence; |
| 134 | fl.l_start = start; |
| 135 | fl.l_len = len; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 136 | return (fcntl(fd, cmd, &fl)); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 137 | } |
| 138 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 139 | void do_test(struct flock *fl, short type, short whence, int start, int len) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 140 | { |
| 141 | fl->l_type = type; |
| 142 | fl->l_whence = whence; |
| 143 | fl->l_start = start; |
| 144 | fl->l_len = len; |
| 145 | fl->l_pid = (short)0; |
| 146 | |
| 147 | parent_put(fl); |
| 148 | parent_get(fl); |
| 149 | } |
| 150 | |
| 151 | void |
| 152 | compare_lock(struct flock *fl, short type, short whence, int start, int len, |
plars | a1e518d | 2002-09-09 18:23:52 +0000 | [diff] [blame] | 153 | pid_t pid) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 154 | { |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 155 | if (fl->l_type != type) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 156 | tst_resm(TFAIL, "lock type is wrong should be %s is %s", |
| 157 | str_type(type), str_type(fl->l_type)); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 158 | |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 159 | if (fl->l_whence != whence) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 160 | tst_resm(TFAIL, "lock whence is wrong should be %d is %d", |
| 161 | whence, fl->l_whence); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 162 | |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 163 | if (fl->l_start != start) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 164 | tst_resm(TFAIL, "region starts in wrong place, should be " |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 165 | "%d is %" PRId64, start, (int64_t) fl->l_start); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 166 | |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 167 | if (fl->l_len != len) |
| 168 | tst_resm(TFAIL, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 169 | "region length is wrong, should be %d is %" PRId64, |
| 170 | len, (int64_t) fl->l_len); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 171 | |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 172 | if (fl->l_pid != pid) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 173 | tst_resm(TFAIL, "locking pid is wrong, should be %d is %d", |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 174 | pid, fl->l_pid); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 175 | } |
| 176 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 177 | void unlock_file(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 178 | { |
| 179 | struct flock fl; |
| 180 | |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 181 | if (do_lock(F_SETLK, (short)F_UNLCK, (short)0, 0, 0) < 0) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 182 | tst_resm(TFAIL | TERRNO, "fcntl on file failed"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 183 | do_test(&fl, F_WRLCK, 0, 0, 0); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 184 | compare_lock(&fl, (short)F_UNLCK, (short)0, 0, 0, (pid_t) 0); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 185 | } |
| 186 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 187 | char *str_type(int type) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 188 | { |
| 189 | static char buf[20]; |
| 190 | |
| 191 | switch (type) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 192 | case 0: |
| 193 | return ("F_RDLCK"); |
| 194 | case 1: |
| 195 | return ("F_WRLCK"); |
| 196 | case 2: |
| 197 | return ("F_UNLCK"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 198 | default: |
| 199 | sprintf(buf, "BAD VALUE: %d", type); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 200 | return (buf); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 201 | } |
| 202 | } |
| 203 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 204 | void parent_put(struct flock *l) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 205 | { |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 206 | SAFE_WRITE(cleanup, 1, parent_pipe[1], l, sizeof(*l)); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 207 | } |
| 208 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 209 | void parent_get(struct flock *l) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 210 | { |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 211 | SAFE_READ(cleanup, 1, child_pipe[0], l, sizeof(*l)); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 212 | } |
| 213 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 214 | void child_put(struct flock *l) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 215 | { |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 216 | SAFE_WRITE(NULL, 1, child_pipe[1], l, sizeof(*l)); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 217 | } |
| 218 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 219 | void child_get(struct flock *l) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 220 | { |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 221 | SAFE_READ(NULL, 1, parent_pipe[0], l, sizeof(*l)); |
| 222 | if (l->l_type == (short)STOP) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 223 | exit(0); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 224 | } |
| 225 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 226 | void stop_child(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 227 | { |
| 228 | struct flock fl; |
| 229 | |
Mike Frysinger | e61ddba | 2014-04-09 23:24:32 -0400 | [diff] [blame] | 230 | signal(SIGCLD, SIG_DFL); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 231 | fl.l_type = STOP; |
| 232 | parent_put(&fl); |
| 233 | wait(0); |
| 234 | } |
| 235 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 236 | void catch_child(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 237 | { |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 238 | tst_brkm(TFAIL, cleanup, "Unexpected death of child process"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 239 | } |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 240 | |
| 241 | int main(int ac, char **av) |
| 242 | { |
| 243 | struct flock tl; |
| 244 | |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 245 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 246 | const char *msg; |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 247 | |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 248 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 249 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 250 | #ifdef UCLINUX |
| 251 | maybe_run_child(&do_child, "ddddd", &parent_pipe[0], |
| 252 | &parent_pipe[1], &child_pipe[0], &child_pipe[1], &fd); |
| 253 | #endif |
| 254 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 255 | setup(); /* global setup */ |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 256 | |
| 257 | /* Check for looping state if -i option is given */ |
| 258 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 259 | /* reset tst_count in case we are looping */ |
| 260 | tst_count = 0; |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 261 | |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 262 | if ((child_pid = FORK_OR_VFORK()) == 0) { /* parent */ |
| 263 | #ifdef UCLINUX |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 264 | if (self_exec(av[0], "ddddd", parent_pipe[0], |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 265 | parent_pipe[1], child_pipe[0], |
| 266 | child_pipe[1], fd) < 0) |
| 267 | tst_brkm(TBROK | TERRNO, cleanup, |
| 268 | "self_exec failed"); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 269 | #else |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 270 | do_child(); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 271 | #endif |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 272 | } else if (child_pid == -1) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 273 | tst_brkm(TBROK | TERRNO, cleanup, "fork failed"); |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 274 | |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 275 | SAFE_CLOSE(cleanup, parent_pipe[0]); |
| 276 | SAFE_CLOSE(cleanup, child_pipe[1]); |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 277 | |
mridge | db63921 | 2005-01-04 21:04:11 +0000 | [diff] [blame] | 278 | /* //block1: */ |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 279 | tst_resm(TINFO, "Enter block 1"); |
| 280 | |
| 281 | /* |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 282 | * Add a write lock to the middle of the file and a read |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 283 | * at the begining |
| 284 | */ |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 285 | if (do_lock(F_SETLK, (short)F_WRLCK, (short)0, 10, 5) < 0) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 286 | tst_resm(TFAIL | TERRNO, "fcntl on file failed"); |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 287 | |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 288 | if (do_lock(F_SETLK, (short)F_RDLCK, (short)0, 1, 5) < 0) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 289 | tst_resm(TFAIL | TERRNO, "fcntl on file failed"); |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 290 | |
| 291 | /* |
| 292 | * Test read lock |
| 293 | */ |
| 294 | do_test(&tl, F_WRLCK, 0, 0, 0); |
| 295 | compare_lock(&tl, (short)F_RDLCK, (short)0, 1, 5, parent_pid); |
| 296 | |
| 297 | /* |
| 298 | * Test write lock |
| 299 | */ |
| 300 | do_test(&tl, F_WRLCK, 0, 6, 0); |
| 301 | compare_lock(&tl, (short)F_WRLCK, (short)0, 10, 5, parent_pid); |
| 302 | |
| 303 | /* |
| 304 | * Test that the rest of the file is unlocked |
| 305 | */ |
| 306 | do_test(&tl, F_WRLCK, 0, 15, 0); |
| 307 | compare_lock(&tl, (short)F_UNLCK, (short)0, 15, 0, 0); |
| 308 | |
| 309 | /* |
| 310 | * remove all the locks set above |
| 311 | */ |
| 312 | unlock_file(); |
| 313 | |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 314 | tst_resm(TINFO, "Exit block 1"); |
| 315 | |
mridge | db63921 | 2005-01-04 21:04:11 +0000 | [diff] [blame] | 316 | /* //block2: */ |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 317 | tst_resm(TINFO, "Enter block 2"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 318 | |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 319 | /* |
| 320 | * Set a write lock at the middle of the file and a |
| 321 | * read lock just before |
| 322 | */ |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 323 | if (do_lock(F_SETLK, (short)F_WRLCK, (short)0, 10, 5) < 0) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 324 | tst_resm(TFAIL | TERRNO, "fcntl on file failed"); |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 325 | |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 326 | if (do_lock(F_SETLK, (short)F_RDLCK, (short)0, 5, 5) < 0) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 327 | tst_resm(TFAIL | TERRNO, "fcntl on file failed"); |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 328 | |
| 329 | /* |
| 330 | * Test the read lock |
| 331 | */ |
| 332 | do_test(&tl, (short)F_WRLCK, (short)0, 0, 0); |
| 333 | compare_lock(&tl, (short)F_RDLCK, (short)0, 5, 5, parent_pid); |
| 334 | |
| 335 | /* |
| 336 | * Test the write lock. |
| 337 | */ |
| 338 | do_test(&tl, (short)F_WRLCK, (short)0, 10, 0); |
| 339 | compare_lock(&tl, (short)F_WRLCK, (short)0, 10, 5, parent_pid); |
| 340 | |
| 341 | /* |
| 342 | * Test to make sure the rest of the file is unlocked. |
| 343 | */ |
| 344 | do_test(&tl, (short)F_WRLCK, (short)0, 15, 0); |
| 345 | compare_lock(&tl, (short)F_UNLCK, (short)0, 15, 0, 0); |
| 346 | |
| 347 | /* |
| 348 | * remove all the locks set above |
| 349 | */ |
| 350 | unlock_file(); |
| 351 | |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 352 | tst_resm(TINFO, "Exit block 2"); |
| 353 | |
mridge | db63921 | 2005-01-04 21:04:11 +0000 | [diff] [blame] | 354 | /* //block3: */ |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 355 | tst_resm(TINFO, "Enter block 3"); |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 356 | |
| 357 | /* |
| 358 | * Set a write lock in the middle and a read lock that |
| 359 | * ends at the first byte of the write lock |
| 360 | */ |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 361 | if (do_lock(F_SETLK, (short)F_WRLCK, (short)0, 10, 5) < 0) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 362 | tst_resm(TFAIL | TERRNO, "fcntl on file failed"); |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 363 | |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 364 | if (do_lock(F_SETLK, (short)F_RDLCK, (short)0, 5, 6) < 0) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 365 | tst_resm(TFAIL | TERRNO, "fcntl on file failed"); |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 366 | |
| 367 | /* |
| 368 | * Test read lock |
| 369 | */ |
| 370 | do_test(&tl, (short)F_WRLCK, (short)0, 0, 0); |
| 371 | compare_lock(&tl, (short)F_RDLCK, (short)0, 5, 6, parent_pid); |
| 372 | |
| 373 | /* |
| 374 | * Test write lock |
| 375 | */ |
| 376 | do_test(&tl, (short)F_WRLCK, (short)0, 11, 0); |
| 377 | compare_lock(&tl, (short)F_WRLCK, (short)0, 11, 4, parent_pid); |
| 378 | |
| 379 | /* |
| 380 | * Test to make sure the rest of the file is unlocked. |
| 381 | */ |
| 382 | do_test(&tl, (short)F_WRLCK, (short)0, 15, 0); |
| 383 | compare_lock(&tl, (short)F_UNLCK, (short)0, 15, 0, 0); |
| 384 | |
| 385 | /* |
| 386 | * remove all the locks set above |
| 387 | */ |
| 388 | unlock_file(); |
| 389 | |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 390 | tst_resm(TINFO, "Exit block 3"); |
| 391 | |
mridge | db63921 | 2005-01-04 21:04:11 +0000 | [diff] [blame] | 392 | /* //block4: */ |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 393 | tst_resm(TINFO, "Enter block 4"); |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 394 | |
| 395 | /* |
| 396 | * Set a write lock on the middle of the file and a read |
| 397 | * lock that overlaps the front of the write. |
| 398 | */ |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 399 | if (do_lock(F_SETLK, (short)F_WRLCK, (short)0, 10, 5) < 0) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 400 | tst_resm(TFAIL | TERRNO, "fcntl on file failed"); |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 401 | |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 402 | if (do_lock(F_SETLK, (short)F_RDLCK, (short)0, 5, 8) < 0) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 403 | tst_resm(TFAIL | TERRNO, "fcntl on file failed"); |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 404 | |
| 405 | /* |
| 406 | * Test the read lock |
| 407 | */ |
| 408 | do_test(&tl, (short)F_WRLCK, (short)0, 5, 0); |
| 409 | compare_lock(&tl, (short)F_RDLCK, (short)0, 5, 8, parent_pid); |
| 410 | |
| 411 | /* |
| 412 | * Test the write lock |
| 413 | */ |
| 414 | do_test(&tl, (short)F_WRLCK, (short)0, 13, 0); |
| 415 | compare_lock(&tl, (short)F_WRLCK, (short)0, 13, 2, parent_pid); |
| 416 | |
| 417 | /* |
| 418 | * Test to make sure the rest of the file is unlocked. |
| 419 | */ |
| 420 | do_test(&tl, (short)F_WRLCK, (short)0, 15, 0); |
| 421 | compare_lock(&tl, (short)F_UNLCK, (short)0, 15, 0, 0); |
| 422 | |
| 423 | /* |
| 424 | * remove all the locks set above |
| 425 | */ |
| 426 | unlock_file(); |
| 427 | |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 428 | tst_resm(TINFO, "Exit block 4"); |
| 429 | |
mridge | db63921 | 2005-01-04 21:04:11 +0000 | [diff] [blame] | 430 | /* //block5: */ |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 431 | tst_resm(TINFO, "Enter block 5"); |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 432 | |
| 433 | /* |
| 434 | * Set a write lock in the middle of a file and a read |
| 435 | * lock in the middle of it |
| 436 | */ |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 437 | if (do_lock(F_SETLK, (short)F_WRLCK, (short)0, 10, 10) < 0) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 438 | tst_resm(TFAIL | TERRNO, "fcntl on file failed"); |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 439 | |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 440 | if (do_lock(F_SETLK, (short)F_RDLCK, (short)0, 13, 5) < 0) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 441 | tst_resm(TFAIL | TERRNO, "fcntl on file failed"); |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 442 | |
| 443 | /* |
| 444 | * Test the first write lock |
| 445 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 446 | do_test(&tl, (short)F_WRLCK, (short)0, 0, 0); |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 447 | compare_lock(&tl, (short)F_WRLCK, (short)0, 10, 3, parent_pid); |
| 448 | |
| 449 | /* |
| 450 | * Test the read lock |
| 451 | */ |
| 452 | do_test(&tl, (short)F_WRLCK, (short)0, 13, 0); |
| 453 | compare_lock(&tl, (short)F_RDLCK, (short)0, 13, 5, parent_pid); |
| 454 | |
| 455 | /* |
| 456 | * Test the second write lock |
| 457 | */ |
| 458 | do_test(&tl, (short)F_WRLCK, (short)0, 18, 0); |
| 459 | compare_lock(&tl, (short)F_WRLCK, (short)0, 18, 2, parent_pid); |
| 460 | |
| 461 | /* |
| 462 | * Test to make sure the rest of the file is unlocked |
| 463 | */ |
| 464 | do_test(&tl, (short)F_WRLCK, (short)0, 20, 0); |
| 465 | compare_lock(&tl, (short)F_UNLCK, (short)0, 20, 0, 0); |
| 466 | |
| 467 | /* |
| 468 | * remove all the locks set above. |
| 469 | */ |
| 470 | unlock_file(); |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 471 | tst_resm(TINFO, "Exit block 5"); |
| 472 | |
mridge | db63921 | 2005-01-04 21:04:11 +0000 | [diff] [blame] | 473 | /* //block6: */ |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 474 | tst_resm(TINFO, "Enter block 6"); |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 475 | /* |
| 476 | * Set a write lock in the middle of the file and a read |
| 477 | * lock that overlaps the end |
| 478 | */ |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 479 | if (do_lock(F_SETLK, (short)F_WRLCK, (short)0, 10, 5) < 0) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 480 | tst_resm(TFAIL | TERRNO, "fcntl on file failed"); |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 481 | |
| 482 | /* |
| 483 | * Set a read lock on the whole file |
| 484 | */ |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 485 | if (do_lock(F_SETLK, (short)F_RDLCK, (short)0, 13, 5) < 0) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 486 | tst_resm(TFAIL | TERRNO, "fcntl on file failed"); |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 487 | |
| 488 | /* |
| 489 | * Test the write lock |
| 490 | */ |
| 491 | do_test(&tl, (short)F_WRLCK, (short)0, 0, 0); |
| 492 | compare_lock(&tl, (short)F_WRLCK, (short)0, 10, 3, parent_pid); |
| 493 | |
| 494 | /* |
| 495 | * Test the read lock |
| 496 | */ |
| 497 | do_test(&tl, (short)F_WRLCK, (short)0, 13, 0); |
| 498 | compare_lock(&tl, (short)F_RDLCK, (short)0, 13, 5, parent_pid); |
| 499 | |
| 500 | /* |
| 501 | * Test to make sure the rest of the file is unlocked |
| 502 | */ |
| 503 | do_test(&tl, (short)F_WRLCK, (short)0, 18, 0); |
| 504 | compare_lock(&tl, (short)F_UNLCK, (short)0, 18, 0, 0); |
| 505 | |
| 506 | /* |
| 507 | * remove all the locks set above |
| 508 | */ |
| 509 | unlock_file(); |
| 510 | |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 511 | tst_resm(TINFO, "Exit block 6"); |
| 512 | |
mridge | db63921 | 2005-01-04 21:04:11 +0000 | [diff] [blame] | 513 | /* //block7: */ |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 514 | tst_resm(TINFO, "Enter block 7"); |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 515 | |
| 516 | /* |
| 517 | * Set a write lock in the middle of the file and a read |
| 518 | * lock starting at the last byte of the write lock |
| 519 | */ |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 520 | if (do_lock(F_SETLK, (short)F_WRLCK, (short)0, 10, 5) < 0) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 521 | tst_resm(TFAIL | TERRNO, "fcntl on file failed"); |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 522 | |
| 523 | /* |
| 524 | * Set a read lock on the whole file. |
| 525 | */ |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 526 | if (do_lock(F_SETLK, (short)F_RDLCK, (short)0, 14, 5) < 0) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 527 | tst_resm(TFAIL | TERRNO, "fcntl on file failed"); |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 528 | |
| 529 | /* |
| 530 | * Test write lock |
| 531 | */ |
| 532 | do_test(&tl, (short)F_WRLCK, (short)0, 0, 0); |
| 533 | compare_lock(&tl, (short)F_WRLCK, (short)0, 10, 4, parent_pid); |
| 534 | |
| 535 | /* |
| 536 | * Test the read lock |
| 537 | */ |
| 538 | do_test(&tl, (short)F_WRLCK, (short)0, 14, 0); |
| 539 | compare_lock(&tl, (short)F_RDLCK, (short)0, 14, 5, parent_pid); |
| 540 | |
| 541 | /* |
| 542 | * Test to make sure the end of the file is unlocked |
| 543 | */ |
| 544 | do_test(&tl, (short)F_WRLCK, (short)0, 19, 0); |
| 545 | compare_lock(&tl, (short)F_UNLCK, (short)0, 19, 0, 0); |
| 546 | |
| 547 | /* |
| 548 | * remove all the locks set above |
| 549 | */ |
| 550 | unlock_file(); |
| 551 | |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 552 | tst_resm(TINFO, "Exit block 7"); |
| 553 | |
mridge | db63921 | 2005-01-04 21:04:11 +0000 | [diff] [blame] | 554 | /* //block8: */ |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 555 | tst_resm(TINFO, "Enter block 8"); |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 556 | |
| 557 | /* |
| 558 | * Set a write lock in the middle of the file and a read |
| 559 | * lock that starts just after the last byte of the |
| 560 | * write lock. |
| 561 | */ |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 562 | if (do_lock(F_SETLK, (short)F_WRLCK, (short)0, 10, 5) < 0) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 563 | tst_resm(TFAIL | TERRNO, "fcntl on file failed"); |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 564 | |
| 565 | /* |
| 566 | * Set a read lock on the whole file |
| 567 | */ |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 568 | if (do_lock(F_SETLK, (short)F_RDLCK, (short)0, 15, 5) < 0) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 569 | tst_resm(TFAIL | TERRNO, "fcntl on file failed"); |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 570 | |
| 571 | /* |
| 572 | * Test the write lock |
| 573 | */ |
| 574 | do_test(&tl, (short)F_WRLCK, (short)0, 0, 0); |
| 575 | compare_lock(&tl, (short)F_WRLCK, (short)0, 10, 5, parent_pid); |
| 576 | |
| 577 | /* |
| 578 | * Test the read lock |
| 579 | */ |
| 580 | do_test(&tl, (short)F_WRLCK, (short)0, 15, 0); |
| 581 | compare_lock(&tl, (short)F_RDLCK, (short)0, 15, 5, parent_pid); |
| 582 | |
| 583 | /* |
| 584 | * Test to make sure the rest of the file is unlocked |
| 585 | */ |
| 586 | do_test(&tl, (short)F_WRLCK, (short)0, 20, 0); |
| 587 | compare_lock(&tl, (short)F_UNLCK, (short)0, 20, 0, 0); |
| 588 | |
| 589 | /* |
| 590 | * remove all the locks set above |
| 591 | */ |
| 592 | unlock_file(); |
| 593 | |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 594 | tst_resm(TINFO, "Exit block 8"); |
| 595 | |
mridge | db63921 | 2005-01-04 21:04:11 +0000 | [diff] [blame] | 596 | /* //block9: */ |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 597 | tst_resm(TINFO, "Enter block 9"); |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 598 | |
| 599 | /* |
| 600 | * Set a write lock at the middle of the file and a read |
| 601 | * lock that starts past the end of the write lock. |
| 602 | */ |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 603 | if (do_lock(F_SETLK, (short)F_WRLCK, (short)0, 10, 5) < 0) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 604 | tst_resm(TFAIL | TERRNO, "fcntl on file failed"); |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 605 | |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 606 | if (do_lock(F_SETLK, (short)F_RDLCK, (short)0, 16, 5) < 0) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 607 | tst_resm(TFAIL | TERRNO, "fcntl on file failed"); |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 608 | |
| 609 | /* |
| 610 | * Test the write lock |
| 611 | */ |
| 612 | do_test(&tl, (short)F_WRLCK, (short)0, 0, 0); |
| 613 | compare_lock(&tl, (short)F_WRLCK, (short)0, 10, 5, parent_pid); |
| 614 | |
| 615 | /* |
| 616 | * Test that byte in between is unlocked |
| 617 | */ |
| 618 | do_test(&tl, (short)F_WRLCK, (short)0, 15, 1); |
| 619 | compare_lock(&tl, (short)F_UNLCK, (short)0, 15, 1, 0); |
| 620 | |
| 621 | /* |
| 622 | * Test the read lock |
| 623 | */ |
| 624 | do_test(&tl, (short)F_WRLCK, (short)0, 16, 0); |
| 625 | compare_lock(&tl, (short)F_RDLCK, (short)0, 16, 5, parent_pid); |
| 626 | |
| 627 | /* |
| 628 | * Test to make sure the rest of the file is unlocked |
| 629 | */ |
| 630 | do_test(&tl, (short)F_WRLCK, (short)0, 21, 0); |
| 631 | compare_lock(&tl, (short)F_UNLCK, (short)0, 21, 0, 0); |
| 632 | |
| 633 | /* |
| 634 | * remove all the locks set above |
| 635 | */ |
| 636 | unlock_file(); |
| 637 | |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 638 | tst_resm(TINFO, "Exit block 9"); |
| 639 | |
| 640 | stop_child(); |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 641 | SAFE_CLOSE(cleanup, fd); |
robbiew | 4cf8096 | 2003-03-25 21:53:41 +0000 | [diff] [blame] | 642 | } |
| 643 | cleanup(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 644 | tst_exit(); |
Garrett Cooper | 0a643cb | 2010-12-21 11:21:19 -0800 | [diff] [blame] | 645 | } |