1.1 --- a/sync.cc Sat Mar 28 00:31:00 2020 +0100
1.2 +++ b/sync.cc Sat Mar 28 23:07:28 2020 +0100
1.3 @@ -1,7 +1,7 @@
1.4 /*
1.5 * Access a filesystem.
1.6 *
1.7 - * Copyright (C) 2018, 2019 Paul Boddie <paul@boddie.org.uk>
1.8 + * Copyright (C) 2018, 2019, 2020 Paul Boddie <paul@boddie.org.uk>
1.9 *
1.10 * This program is free software; you can redistribute it and/or
1.11 * modify it under the terms of the GNU General Public License as
1.12 @@ -22,6 +22,7 @@
1.13 #include <stdlib.h>
1.14 #include <stdio.h>
1.15 #include <string.h>
1.16 +#include <unistd.h>
1.17
1.18 #include <fsclient/client.h>
1.19 #include <systypes/fcntl.h>
1.20 @@ -82,6 +83,12 @@
1.21
1.22 printf("Waiting to create a file in %s...\n", dir);
1.23
1.24 + /* NOTE: Useful for testing race conditions. */
1.25 +
1.26 + //sleep(2);
1.27 +
1.28 + /* Wait for control over the directory. */
1.29 +
1.30 client_begin(descD);
1.31
1.32 printf("Open file...\n");
1.33 @@ -94,7 +101,9 @@
1.34 return 1;
1.35 }
1.36
1.37 - client_yield(descD);
1.38 + /* Give the observer control over the directory and proceed. */
1.39 +
1.40 + client_end(descD);
1.41
1.42 printf("Wait for another client...\n");
1.43
1.44 @@ -167,6 +176,8 @@
1.45
1.46 printf("Waiting for the file to be created in %s...\n", dir);
1.47
1.48 + /* Wait for control over the directory. */
1.49 +
1.50 client_begin(descD);
1.51
1.52 while (desc1 == NULL)
1.53 @@ -175,7 +186,12 @@
1.54
1.55 desc1 = client_open(argv[2], O_RDONLY, 0);
1.56
1.57 - client_yield(descD);
1.58 + /* Give the file creator control over the directory. */
1.59 +
1.60 + if (desc1 == NULL)
1.61 + client_yield(descD);
1.62 + else
1.63 + client_end(descD);
1.64 }
1.65
1.66 printf("Wait for the other client...\n");