-
Notifications
You must be signed in to change notification settings - Fork 1
/
sender.c
730 lines (674 loc) · 24.4 KB
/
sender.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* (C) 2015, 2016 Michael Andersen <[email protected]>
* (C) 2015, 2016 Sam Kumar <[email protected]>
* (C) 2015, 2016 Regents of the University of California
*/
#define EVENT_BUF_LEN 128 * ( sizeof (struct inotify_event) )
#define EVENT_SIZE ( sizeof (struct inotify_event) )
#define FULLPATHLEN 96 // the maximum length of a full file path
#define FILENAMELEN 48 // the maximum length of a file or directory name (within the root directory)
#define TIMEDELAY 10 // the number of seconds to wait between subsequent tries to reconnect
#define NUMFAILURES 360 // the number of failed connection attempts that will be tolerated before the program exits
#define MAXDEPTH 4 // the root directory is at depth 0
#define CHUNK_SIZE 31560 // the size of the portions into which each file is broken up
#define LASTFILEWAIT 240 // the number of seconds to wait before sending the last file when processing existing files
#define SOCKETTIMEOUT 600 // the number of seconds to wait for a send or receive operation on a socket before timing out
#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <libgen.h>
#include <unistd.h>
#include <sys/inotify.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <arpa/inet.h>
/* When my comments refer to the "root directory", they mean the directory the program is watching */
int ADDRESSP = 1883;
typedef struct
{
int fd;
char path[FULLPATHLEN];
} watched_entry_t;
watched_entry_t children[MAXDEPTH + 1];
fd_set set;
// information about the root directory
int rootdirOpen = 0; // 1 if open (i.e., root directory needs to be closed)
char rootpath[FULLPATHLEN];
// when processing directories upon initialization, store the watched directories in an array
int num_watched_dirs = 0;
int size_watched_arr = 0;
// the socket descriptor
int socket_des = -1;
// the serial number of this uPMU
char* serialNum;
uint32_t size_serial;
uint32_t size_serial_word;
// 1 if connected (i.e., socket connection needs to be closed), 0 otherwise
int connected = 0;
// pointer to the server address
struct sockaddr* server_addr;
// the id of the next message sent to the server
uint32_t sendid = 1;
// the timeout for the socket
struct timeval socket_timeout;
/* Deletes a directory if possible, printing messages as necessary. */
void remove_dir(const char* dirpath)
{
errno = 0;
if (rmdir(dirpath) != 0)
{
if (errno == ENOTEMPTY || errno == EEXIST)
{
printf("Directory %s not removed: still contains files\n", dirpath);
}
else
{
printf("Directory %s not removed: no permissions OR directory in use\n", dirpath);
}
}
}
/* Finds the smallest int larger than the input that's a multiple of 4. */
uint32_t roundUp4(uint32_t input)
{
return (input + 3) & 0xFFFFFFFCu;
}
/* Close the socket connection. */
void close_connection(int socket_descriptor)
{
shutdown(socket_descriptor, SHUT_RDWR);
close(socket_descriptor);
}
/* Exit, closing the socket connection if necessary. */
void safe_exit(int arg)
{
printf("Exiting...\n");
if (connected)
{
close_connection(socket_des);
}
fflush(stdout);
exit(arg);
}
/* Attempts to connect to the server_addr and returns the socket descriptor
* if successful. If not successful, return -1.
*/
int make_socket()
{
printf("Attempting to connect...\n");
int socket_descriptor = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (socket_descriptor < 0)
{
perror("could not create socket");
safe_exit(1);
}
if (connect(socket_descriptor, server_addr, sizeof(*server_addr)) < 0)
{
perror("could not connect");
close(socket_descriptor);
return -1;
}
errno = 0;
setsockopt(socket_descriptor, SOL_SOCKET, SO_RCVTIMEO, &socket_timeout, sizeof(struct timeval));
setsockopt(socket_descriptor, SOL_SOCKET, SO_SNDTIMEO, &socket_timeout, sizeof(struct timeval));
if (errno != 0) {
perror("could not set socket timeout");
close(socket_descriptor);
return -1;
}
printf("Successfully connected\n");
return socket_descriptor;
}
/* Sends the contents of the file at FILEPATH over TCP using SOCKET_DESCRIPTOR, if it
* is a .dat file.
* The total data sent is: 1. an id number, 2. the length of the filepath, 3.
* the filepath, 4. the length of the contents of the file, and 5. the contents
* of the file.
* The filepath sent includes the filename itself, and contains the parent directory
* if INROOTDIR is 1.
* Returns 0 if the transmission was successful or if the file did not have to be sent.
* Returns 1 if there was an error reading the file.
* Returns -1 if the file was read properly but could not be sent.
*/
int send_file(int socket_descriptor, const char* filepath)
{
// Ignore files that are not .dat
const char* substr = filepath + strlen(filepath) - 4;
if (strcmp(substr, ".dat") != 0)
{
printf("Skipping file %s (not \".dat\")\n", filepath);
return 0;
}
uint32_t size = strlen(filepath);
// Open file
FILE *input;
input = fopen(filepath, "rb");
if (input == NULL)
{
printf("Error: cannot read file %s.\n", filepath);
perror("Details");
return 1;
}
// Get the length of the file
fseek(input, 0, SEEK_END);
uint32_t length = ftell(input);
// Store file number (sendid), length of serial number, length of filename, length of data, and filename in data array
// The null terminator may be overwritten; the length of the filename does not
// include the null terminator.
// Space is added to the end of filename so it is word-aligned.
uint32_t size_word = roundUp4(size); // size with extra bytes so it's word-aligned
uint8_t data[16 + size_word + size_serial_word] __attribute__((aligned(4)));
memset(data, 0, 16 + size_word + size_serial_word);
*((uint32_t*) data) = sendid;
*((uint32_t*) (data + 4)) = size;
*((uint32_t*) (data + 8)) = size_serial;
*((uint32_t*) (data + 12)) = length;
strcpy((char*) (data + 16), filepath);
strcpy((char*) (data + 16 + size_word), serialNum);
rewind(input);
// Send info
int32_t dataleft = 16 + size_word + size_serial_word;
int32_t datawritten;
uint8_t* dest = data;
while (dataleft > 0)
{
errno = 0;
datawritten = write(socket_descriptor, dest, dataleft);
if (datawritten < 0 || errno != 0)
{
printf("Could not send file %s\n", filepath);
fclose(input);
return -1;
}
dataleft -= datawritten;
dest += datawritten;
}
// Send data
uint8_t* tosend = malloc(CHUNK_SIZE);
if (tosend == NULL) {
printf("Could not allocate memory to store part of data file; try reducing CHUNK_SIZE.");
safe_exit(1);
}
uint32_t totalread = 0;
int32_t dataread;
while (totalread != length)
{
dataread = fread(tosend, 1, CHUNK_SIZE, input);
totalread += dataread;
dataleft = dataread;
dest = tosend;
if (dataread != CHUNK_SIZE && totalread != length)
{
printf("Error: could not finish reading file %s (read %d out of %d bytes)\n", filepath, totalread, length);
free(tosend);
fclose(input);
return 1;
}
while (dataleft > 0)
{
errno = 0;
datawritten = write(socket_descriptor, dest, dataleft);
if (datawritten < 0 || errno != 0)
{
printf("Could not send file %s\n", filepath);
free(tosend);
fclose(input);
return -1;
}
dataleft -= datawritten;
dest += datawritten;
}
}
free(tosend);
fclose(input);
uint32_t response;
// Get confirmation of receipt
dataleft = 4;
while (dataleft > 0)
{
errno = 0;
dataread = read(socket_descriptor, ((uint8_t*) &response) + 4 - dataleft, 4);
if (dataread < 0 || errno != 0)
{
printf("Could not receive confirmation of receipt of %s\n", filepath);
return -1;
}
else if (dataread == 0)
{
printf("Connection was closed before confirmation was received for %s\n", filepath);
return -1;
}
dataleft -= dataread;
}
if (response != sendid++)
{
printf("Received improper confirmation of receipt of %s (will not be deleted)\n", filepath);
}
else
{
// Delete the file
if (unlink(filepath) != 0)
{
printf("File %s was successfully sent and confirmation was received, but could not be deleted\n", filepath);
}
}
if (sendid == 0xFFFFFFFFu)
{
sendid = 1;
}
sleep(1); // So that we don't use too much CPU time
return 0;
}
/* Same as send_file(), except that it takes a pointer to the socket_descriptor instead
* of the value itself, and that it will repeatedly try to send the file (waiting
* TIMEDELAY seconds between attempts) if the file could be read but could not be sent
* over TCP. It returns the value of the successful attempt (so it will never return -1,
* just 0 or 1).
*/
int send_until_success(int* socket_descriptor, const char* filepath)
{
int result;
int numreconnects = -1;
while ((result = send_file(*socket_descriptor, filepath)) == -1)
{
if (++numreconnects >= NUMFAILURES) {
printf("Connection lost; failed to reconnect %d times. Exiting program.\n", numreconnects);
safe_exit(1);
}
if (connected)
{
close_connection(*socket_descriptor);
connected = 0;
}
sleep(TIMEDELAY);
printf("Connection appears to be lost\n");
*socket_descriptor = make_socket();
}
connected = 1;
return result;
}
/* Used to compare two file entries so they can be sorted. */
int file_entry_comparator(const void* f1, const void* f2)
{
return strcmp((const char*) f1, (const char*) f2);
}
/* Processes directory, sending files and adding watches (uses information in global variables) */
int processdir(const char* dirpath, int* socket_descriptor, int inotify_fd, int depth, int addwatchtosubs)
{
if (strlen(dirpath) >= FULLPATHLEN - 5)
{
printf("%s too large: all filepaths must be less than %d characters long\n", dirpath, FULLPATHLEN);
return -1;
}
DIR* rootdir = opendir(dirpath);
if (rootdir == NULL)
{
printf("%s is not a valid directory\n", dirpath);
return -1;
}
struct dirent* subdir;
struct stat pathStats;
int pathlen;
char fullpath[FULLPATHLEN];
int numsubdirs = 8; // Length of array in FILENAMELEN units
int numfiles = 8; // Length of array in FILENAMELEN units
char* filearr = malloc(numfiles * FILENAMELEN);
unsigned int fileIndex = 0; // The number of strings actually in the array
char* subdirarr = malloc(numsubdirs * FILENAMELEN);
unsigned int subdirIndex = 0; // The number of strings actually in the array
if (filearr == NULL || subdirarr == NULL)
{
printf("Not enough memory to store filenames or subdirectories to sort.\n");
safe_exit(1);
}
// Add watch for root directory
// Add files and directories to arrays
while ((subdir = readdir(rootdir)) != NULL)
{
if (strcmp(subdir->d_name, ".") != 0 && strcmp(subdir->d_name, "..") != 0)
{
pathlen = strlen(dirpath) + strlen(subdir->d_name) + 2;
if (pathlen > FULLPATHLEN)
{
printf("Filepath of length %d found; max allowed is %d\n", pathlen, FULLPATHLEN);
free(filearr);
free(subdirarr);
return -1;
}
strcpy(fullpath, dirpath);
strcat(fullpath, subdir->d_name);
if (stat(fullpath, &pathStats) != 0)
{
printf("Could not read file %s\n", fullpath);
continue;
}
if (S_ISDIR(pathStats.st_mode))
{
if (strlen(subdir->d_name) >= FILENAMELEN - 1)
{
printf("Directory %s has name length of %d; max allowed is %d\n", subdir->d_name, (int) strlen(subdir->d_name), FILENAMELEN - 2);
free(filearr);
free(subdirarr);
return -1;
}
strcpy(subdirarr + (subdirIndex * FILENAMELEN), subdir->d_name);
strcat(subdirarr + (subdirIndex * FILENAMELEN), "/");
subdirIndex++;
if (subdirIndex == numsubdirs)
{
numsubdirs *= 2;
subdirarr = realloc(subdirarr, numsubdirs * FILENAMELEN);
if (subdirarr == NULL)
{
printf("Could not allocate memory to store subdirectory names to sort.\n");
safe_exit(1);
}
}
}
else if (S_ISREG(pathStats.st_mode))
{
if (strlen(subdir->d_name) >= FILENAMELEN)
{
printf("File %s has name length of %d; max allowed is %d\n", subdir->d_name, (int) strlen(subdir->d_name), FILENAMELEN - 1);
free(filearr);
free(subdirarr);
return -1;
}
strcpy(filearr + (fileIndex * FILENAMELEN), subdir->d_name);
fileIndex++;
if (fileIndex == numfiles)
{
numfiles *= 2;
filearr = realloc(filearr, numfiles * FILENAMELEN);
if (filearr == NULL)
{
printf("Could not allocate memory to store filenames to sort.\n");
safe_exit(1);
}
}
}
}
}
closedir(rootdir);
numfiles = fileIndex; // The actual number of files (so fileIndex can be changed)
numsubdirs = subdirIndex; // The actual number of files (so subdirIndex can be changed)
// Sort files and subdirectories in numerical order
qsort(filearr, numfiles, FILENAMELEN, file_entry_comparator);
qsort(subdirarr, numsubdirs, FILENAMELEN, file_entry_comparator);
for (fileIndex = 0; fileIndex < numfiles; fileIndex++)
{
strcpy(fullpath, dirpath);
strcat(fullpath, filearr + (fileIndex * FILENAMELEN));
if (addwatchtosubs && (fileIndex == numfiles - 1))
{
printf("Waiting %d seconds for last file...\n", LASTFILEWAIT);
sleep(LASTFILEWAIT);
}
send_until_success(socket_descriptor, fullpath);
}
free(filearr);
int result;
int addedwatch;
// Process directories, adding watches
for (subdirIndex = 0; subdirIndex < numsubdirs; subdirIndex++)
{
addedwatch = 0;
strcpy(fullpath, dirpath);
strcat(fullpath, subdirarr + (subdirIndex * FILENAMELEN));
if (addwatchtosubs && (subdirIndex == (numsubdirs - 1)))
{
children[depth].fd = inotify_add_watch(inotify_fd, fullpath, IN_CREATE | IN_CLOSE_WRITE);
strcpy(children[depth].path, fullpath);
addedwatch = 1;
}
result = processdir(fullpath, socket_descriptor, inotify_fd, depth + 1, addwatchtosubs && (subdirIndex == (numsubdirs - 1)));
if (result < 0)
{
free(subdirarr);
return -1;
}
if (!addedwatch)
{
remove_dir(fullpath);
}
}
free(subdirarr);
return 0;
}
void interrupt_handler(int sig)
{
safe_exit(0);
}
int main(int argc, char* argv[])
{
struct rlimit memlimit;
setbuf(stdout, NULL);
setbuf(stderr, NULL);
getrlimit(RLIMIT_AS, &memlimit);
memlimit.rlim_cur = (long) 400000000; // 4 MB
memlimit.rlim_max = (long) 419430400; // 4 MiB
setrlimit(RLIMIT_AS, &memlimit);
if (argc != 4 && argc != 5)
{
printf("Usage: %s <directorytowatch> <targetserver> <uPMU serial number> [<port number>]\n", argv[0]);
safe_exit(1);
}
socket_timeout.tv_sec = SOCKETTIMEOUT;
socket_timeout.tv_usec = 0;
int i, j;
for (i = 0; i < MAXDEPTH; i++)
{
children[i].fd = -1;
}
serialNum = argv[3];
size_serial = strlen(serialNum);
size_serial_word = roundUp4(size_serial);
if (argc == 5)
{
errno = 0;
unsigned long port = strtoul(argv[4], NULL, 0);
if (port > 65535 || port == 0 || errno != 0)
{
printf("Invalid port %s\n", argv[4]);
safe_exit(1);
}
ADDRESSP = (int) port;
}
// Set up signal to handle Ctrl-C (close socket connection before terminating)
struct sigaction interrupt_action;
interrupt_action.sa_handler = interrupt_handler;
interrupt_action.sa_flags = 0;
sigemptyset(&interrupt_action.sa_mask);
if (-1 == sigaction(SIGINT, &interrupt_action, NULL))
{
printf("Could not set up signal to handle keyboard interrupt\n");
exit(1);
}
struct sigaction socket_action;
socket_action.sa_handler = SIG_IGN;
socket_action.sa_flags = 0;
sigemptyset(&socket_action.sa_mask);
if (-1 == sigaction(SIGPIPE, &socket_action, NULL))
{
printf("Could not set up signal to handle writing to broken socket\n");
exit(1);
}
// Create the socket address
struct sockaddr_in server;
memset(&server, 0, sizeof(server));
server.sin_family = AF_INET;
server.sin_port = htons(ADDRESSP);
int result = inet_pton(AF_INET, argv[2], &server.sin_addr);
if (result < 0)
{
perror("invalid address family in \"inet_pton\"");
safe_exit(1);
}
else if (result == 0)
{
perror("invalid ip address in \"inet_pton\"");
safe_exit(1);
}
server_addr = (struct sockaddr*) &server;
connected = 0;
socket_des = make_socket();
int numreconnects = 0;
while (socket_des == -1)
{
if (++numreconnects >= NUMFAILURES) {
printf("Failed to connect %d times. Exiting program.\n", numreconnects);
safe_exit(1);
}
sleep(TIMEDELAY);
socket_des = make_socket();
}
connected = 1;
// Look for file/directory additions
int fd = inotify_init();
if (fd < 0)
{
perror("inotify_init");
safe_exit(1);
}
// This watch will notice any new files or subdirectories in the directory we are watching
children[0].fd = inotify_add_watch(fd, argv[1], IN_CREATE | IN_CLOSE_WRITE);
strcpy(children[0].path, argv[1]);
if (argv[1][strlen(argv[1]) - 1] != '/')
{
strcat(children[0].path, "/");
}
if (processdir(children[0].path, &socket_des, fd, 1, 1) < 0)
{
printf("Could not finish processing existing files.\n");
safe_exit(1);
}
printf("Finished processing existing files.\n");
char buffer[EVENT_BUF_LEN];
struct timeval timeout;
int rlen;
char fullname[FULLPATHLEN];
int index;
while (1)
{
//Select changes the timeout and the set
FD_ZERO(&set);
FD_SET(fd, &set);
timeout.tv_sec = 2; //Do a wavelet keepalive every 3 seconds
timeout.tv_usec = 0;
rlen = select(fd + 1, &set, NULL, NULL, &timeout);
if (rlen == 0)
{
// no activity
continue;
}
rlen = read(fd, buffer, EVENT_BUF_LEN);
index = 0;
if (rlen == -1)
{
printf("Error (possibly caused by filepath that is too long)\n");
}
while (index < rlen)
{
result = 0;
struct inotify_event* ev = (struct inotify_event*) &buffer[index];
if (ev->len)
{
/* Check for a new directory */
if ((IN_CREATE & ev->mask) && (IN_ISDIR & ev->mask))
{
// Find the correct depth, store it in i
for (i = MAXDEPTH; i >= 0; i--)
{
if (children[i].fd == ev->wd)
{
break;
}
}
i++;
if (i > MAXDEPTH)
{
printf("WARNING: unexpected new directory past maximum depth (will be ignored)\n");
}
char* parentname = children[i - 1].path;
strcpy(fullname, parentname);
strcat(fullname, ev->name);
strcat(fullname, "/");
if (strcmp(fullname, children[i].path) != 0) // check if we're already watching this (in case it was detected twice); if not, don't proceed
{
// remove watches from depth i and deeper and delete directories if possible
printf("Found new directory %s (depth %d)\n", fullname, i);
for (j = MAXDEPTH; j >= i; j--)
{
if (children[j].fd != -1) // if it has already been deleted or there's no watch, don't do anything
{
printf("Unwatching %s\n", children[j].path);
if (inotify_rm_watch(fd, children[j].fd))
{
perror("RM watch");
}
else
{
children[j].fd = -1; // mark it as deleted
}
remove_dir(children[j].path);
}
}
strcpy(children[i].path, fullname);
printf("Watching %s\n", children[i].path);
children[i].fd = inotify_add_watch(fd, children[i].path, IN_CREATE | IN_CLOSE_WRITE);
// Ok great, but we may have missed some files, so let's check for them:
printf("Processing existing files in %s\n", fullname);
if (processdir(fullname, &socket_des, fd, i + 1, 1) < 0)
{
printf("WARNING: could not process existing files in newly created directory %s", fullname);
}
else
{
printf("Finished processing existing files in %s\n", fullname);
}
}
else
{
printf("Directory %s already found\n", fullname);
}
}
/* Check for a new file */
else if (((IN_CLOSE_WRITE) & ev->mask) && !(IN_ISDIR & ev->mask))
{
if (children[MAXDEPTH].fd == ev->wd)
{
strcpy(fullname, children[MAXDEPTH].path);
strcat(fullname, ev->name);
result = send_until_success(&socket_des, fullname);
}
else
{
printf("Warning: file %s appeared outside hour directory (not sent)\n", ev->name);
}
}
if (result == 1)
{
printf("Could not read %s (file already sent, deleted concurrently, or not fully written)\n", ev->name);
}
}
index += EVENT_SIZE + ev->len;
}
}
}