Index: trunk/tools/trickle/trickle.c |
— | — | @@ -137,12 +137,12 @@ |
138 | 138 | |
139 | 139 | if (Zflag) { |
140 | 140 | if (isatty(0)) |
141 | | - fatal("-Z should not be used directly"); |
| 141 | + fatal("m1", "-Z should not be used directly"); |
142 | 142 | discuss_files(); |
143 | 143 | } |
144 | 144 | |
145 | 145 | if ((rflag || uflag) && archive) { |
146 | | - fprintf(stderr, "%s: -u/-r and -t may not be specified together\n", progname); |
| 146 | + fatal("m2", "-u/-r and -t may not be specified together"); |
147 | 147 | usage(); |
148 | 148 | } |
149 | 149 | |
— | — | @@ -188,13 +188,13 @@ |
189 | 189 | if (!strcmp(dest, "-")) |
190 | 190 | archfile = stdout; |
191 | 191 | else if ((archfile = fopen(dest, "w")) == NULL) { |
192 | | - perror(dest); |
| 192 | + pfatal("m3", dest); |
193 | 193 | exit(8); |
194 | 194 | } |
195 | 195 | } |
196 | 196 | |
197 | 197 | if (stat(src, &sb) < 0) { |
198 | | - perror(src); |
| 198 | + pfatal("m4", dest); |
199 | 199 | exit(8); |
200 | 200 | } |
201 | 201 | |
— | — | @@ -209,7 +209,7 @@ |
210 | 210 | |
211 | 211 | errno = 0; |
212 | 212 | if (stat(dest, &sd) < 0 && errno != ENOENT) { |
213 | | - perror(dest); |
| 213 | + pfatal("m5", dest); |
214 | 214 | exit(8); |
215 | 215 | } |
216 | 216 | |
— | — | @@ -227,7 +227,7 @@ |
228 | 228 | } ok: |
229 | 229 | if ((c = fgetc(stdin)) != '\n') ungetc(c, stdin); |
230 | 230 | if (unlink(dest) < 0) { |
231 | | - perror(dest); |
| 231 | + pfatal("m6", dest); |
232 | 232 | exit(8); |
233 | 233 | } |
234 | 234 | } |
— | — | @@ -241,7 +241,7 @@ |
242 | 242 | } |
243 | 243 | |
244 | 244 | if (chdir(src) < 0) { |
245 | | - perror(src); |
| 245 | + pfatal("m7", src); |
246 | 246 | exit(8); |
247 | 247 | } |
248 | 248 | |
— | — | @@ -272,7 +272,7 @@ |
273 | 273 | char *oldcur; |
274 | 274 | |
275 | 275 | if (chdir(dir) < 0) { |
276 | | - perror("chdir"); |
| 276 | + pfatal("cd1", dir); |
277 | 277 | exit(8); |
278 | 278 | } |
279 | 279 | |
— | — | @@ -280,7 +280,7 @@ |
281 | 281 | curdir = allocf("%s%s/", oldcur, dir); |
282 | 282 | |
283 | 283 | if ((dirp = opendir(".")) == NULL) { |
284 | | - perror(dir); |
| 284 | + pfatal("cd2", dir); |
285 | 285 | exit(8); |
286 | 286 | } |
287 | 287 | |
— | — | @@ -289,11 +289,16 @@ |
290 | 290 | continue; |
291 | 291 | |
292 | 292 | if (lstat(dp->d_name, &sb) < 0) { |
293 | | - perror(dp->d_name); |
| 293 | + pfatal("cd3", dp->d_name); |
294 | 294 | exit(8); |
295 | 295 | } |
296 | 296 | |
297 | | - if (sb.st_mode & S_IFDIR) { |
| 297 | + if ((sb.st_mode & S_IFLNK) == S_IFLNK) { |
| 298 | + if (!qflag) |
| 299 | + fprintf(stderr, "fs %s%s\n", curdir, dp->d_name); |
| 300 | + /* XXX should be possible to include symlinks in the output */ |
| 301 | + continue; |
| 302 | + } else if (sb.st_mode & S_IFDIR) { |
298 | 303 | char *dpath; |
299 | 304 | if (exclude(dp->d_name)) { |
300 | 305 | if (!qflag) |
— | — | @@ -312,7 +317,7 @@ |
313 | 318 | * exists, just leave it. |
314 | 319 | */ |
315 | 320 | if (mkdir(dpath, sb.st_mode) < 0 && errno != EEXIST) { |
316 | | - perror(dpath); |
| 321 | + pfatal("cd4", dpath); |
317 | 322 | exit(8); |
318 | 323 | } |
319 | 324 | free(dpath); |
— | — | @@ -323,7 +328,11 @@ |
324 | 329 | } |
325 | 330 | copy_directory(dp->d_name, cf); |
326 | 331 | } else if (sb.st_mode & S_IFREG) { |
327 | | - char *outname = allocf("%s/%s%s", dest, curdir, dp->d_name); |
| 332 | + char *outname; |
| 333 | + if (archive) |
| 334 | + outname = allocf("%s%s", curdir, dp->d_name); |
| 335 | + else |
| 336 | + outname = allocf("%s/%s%s", dest, curdir, dp->d_name); |
328 | 337 | cf(dp->d_name, outname); |
329 | 338 | free(outname); |
330 | 339 | usleep(filesleep); |
— | — | @@ -353,7 +362,7 @@ |
354 | 363 | struct utimbuf ut; |
355 | 364 | |
356 | 365 | if (lstat(name, &sb) < 0) { |
357 | | - perror(name); |
| 366 | + pfatal("cf1", name); |
358 | 367 | exit(8); |
359 | 368 | } |
360 | 369 | |
— | — | @@ -379,28 +388,27 @@ |
380 | 389 | fprintf(stderr, "%s: %s exists and I didn't expect it to\n", |
381 | 390 | progname, outname); |
382 | 391 | } |
383 | | - perror(outname); |
| 392 | + pfatal("cf2", outname); |
384 | 393 | exit(8); |
385 | 394 | } |
386 | 395 | } |
387 | 396 | if ((in = open(name, O_RDONLY)) == -1) { |
388 | | - perror(name); |
| 397 | + pfatal("cf3", name); |
389 | 398 | exit(8); |
390 | 399 | } |
391 | 400 | copy_from_to(in, out, outname); |
392 | 401 | |
393 | | - ut.actime = sb.st_atime; |
394 | | - ut.modtime = sb.st_mtime; |
395 | | - if (utime(outname, &ut) < 0) { |
396 | | - perror(outname); |
397 | | - } |
| 402 | + if (!archive) { |
| 403 | + ut.actime = sb.st_atime; |
| 404 | + ut.modtime = sb.st_mtime; |
| 405 | + if (utime(outname, &ut) < 0) |
| 406 | + fprintf(stderr, "%s: %s: %s (cf4)\n", progname, outname, strerror(errno)); |
398 | 407 | |
399 | | - if (Pflag) { |
400 | | - if (fchown(out, sb.st_uid, sb.st_gid) < 0) { |
401 | | - perror(outname); |
| 408 | + if (Pflag) { |
| 409 | + if (fchown(out, sb.st_uid, sb.st_gid) < 0) |
| 410 | + fprintf(stderr, "%s: %s: %s (cf5)\n", progname, outname, strerror(errno)); |
402 | 411 | } |
403 | 412 | } |
404 | | - |
405 | 413 | } |
406 | 414 | |
407 | 415 | void |
— | — | @@ -409,19 +417,20 @@ |
410 | 418 | const char *destname; |
411 | 419 | { |
412 | 420 | static char *buf; |
413 | | - int bytes, blocks, bsize; |
| 421 | + int bytes = 0, blocks = 0, bsize; |
| 422 | + |
414 | 423 | if (buf == NULL) |
415 | 424 | buf = malloc(blocksize); |
416 | 425 | |
417 | | - while ((bsize = read(from, buf, blocksize)) != -1) { |
| 426 | + while ((bsize = read(from, buf, blocksize)) > 0) { |
418 | 427 | if (tflag) { |
419 | 428 | if (write_blocked(buf, bsize, archfile) < 1) { |
420 | | - perror(dest); |
| 429 | + pfatal("ct1", destname); |
421 | 430 | exit(8); |
422 | 431 | } |
423 | 432 | } else { |
424 | 433 | if (write(to, buf, bsize) < 1) { |
425 | | - perror(destname); |
| 434 | + pfatal("ct2", destname); |
426 | 435 | exit(8); |
427 | 436 | } |
428 | 437 | } |
— | — | @@ -456,7 +465,7 @@ |
457 | 466 | char *p = buf; |
458 | 467 | size_t ret = 0, tow; |
459 | 468 | |
460 | | - while (size) { |
| 469 | + do { |
461 | 470 | tow = min(size, sizeof(block)); |
462 | 471 | |
463 | 472 | memset(block, 0, sizeof block); |
— | — | @@ -465,7 +474,8 @@ |
466 | 475 | return ret; |
467 | 476 | p += tow; |
468 | 477 | size -= tow; |
469 | | - } |
| 478 | + ++records; |
| 479 | + } while (size > 0); |
470 | 480 | return ret; |
471 | 481 | } |
472 | 482 | |
— | — | @@ -478,7 +488,7 @@ |
479 | 489 | if (lstat(name, &sa) < 0) { |
480 | 490 | if (errno == ENOENT) |
481 | 491 | return 1; |
482 | | - perror(name); |
| 492 | + pfatal("co1", name); |
483 | 493 | exit(8); |
484 | 494 | } |
485 | 495 | |
— | — | @@ -493,14 +503,14 @@ |
494 | 504 | if (lstat(fa, &sa) < 0) { |
495 | 505 | if (errno == ENOENT) |
496 | 506 | return 0; |
497 | | - perror(fa); |
| 507 | + pfatal("sf1", fa); |
498 | 508 | exit(8); |
499 | 509 | } |
500 | 510 | |
501 | 511 | if (lstat(fb, &sb) < 0) { |
502 | 512 | if (errno == ENOENT) |
503 | 513 | return 0; |
504 | | - perror(fb); |
| 514 | + pfatal("sf2", fb); |
505 | 515 | exit(8); |
506 | 516 | } |
507 | 517 | |
— | — | @@ -595,7 +605,7 @@ |
596 | 606 | sock = proto_rsh(remote, rsh); |
597 | 607 | proto_neg(sock); |
598 | 608 | if (chdir(src) < 0) { |
599 | | - perror(src); |
| 609 | + pfatal("sf1", src); |
600 | 610 | exit(8); |
601 | 611 | } |
602 | 612 | frame.rf_buf = dest; |
— | — | @@ -617,11 +627,11 @@ |
618 | 628 | if (buf == NULL) |
619 | 629 | buf = malloc(blocksize); |
620 | 630 | if ((in = open(from, O_RDONLY)) == -1) { |
621 | | - perror(from); |
| 631 | + pfatal("cn1", from); |
622 | 632 | exit(8); |
623 | 633 | } |
624 | 634 | if (fstat(in, &sb) < 0) { |
625 | | - perror(from); |
| 635 | + pfatal("cn2", from); |
626 | 636 | exit(8); |
627 | 637 | } |
628 | 638 | if (!proto_offer(from, &sb)) { |
Index: trunk/tools/trickle/util.c |
— | — | @@ -10,6 +10,8 @@ |
11 | 11 | #include <unistd.h> |
12 | 12 | #include <varargs.h> |
13 | 13 | #include <stdlib.h> |
| 14 | +#include <errno.h> |
| 15 | +#include <string.h> |
14 | 16 | |
15 | 17 | #include "trickle.h" |
16 | 18 | |
— | — | @@ -50,3 +52,11 @@ |
51 | 53 | fputs("\n", stderr); |
52 | 54 | exit(8); |
53 | 55 | } |
| 56 | + |
| 57 | +void |
| 58 | +pfatal(c, e) |
| 59 | + const char *c, *e; |
| 60 | +{ |
| 61 | + fprintf(stderr, "%s: %s (%s)\n", e, strerror(errno), c); |
| 62 | + exit(8); |
| 63 | +} |
Index: trunk/tools/trickle/trickle.h |
— | — | @@ -16,14 +16,21 @@ |
17 | 17 | #define min(x,y) ((x) < (y) ? (x) : (y)) |
18 | 18 | #define max(x,y) ((x) < (y) ? (y) : (x)) |
19 | 19 | |
| 20 | +#define RECORD_SIZE 20 /* one record = RECORD_SIZE blocks */ |
| 21 | + |
20 | 22 | extern int pflag; |
21 | 23 | extern char *dest; /* destination name */ |
22 | 24 | extern const char *progname; /* argv[0] */ |
23 | 25 | extern char *curdir; /* cwd name */ |
24 | 26 | extern char *trickle; |
| 27 | +extern int records; |
25 | 28 | |
26 | 29 | size_t write_blocked(void *buf, size_t size, FILE *file); |
| 30 | +char *allocf(); |
| 31 | +void fatal(); |
| 32 | +void pfatal(const char *, const char *); |
27 | 33 | |
| 34 | +/** Protocol support */ |
28 | 35 | #define PROTO_VERS 1 |
29 | 36 | #define P_ACCEPT 1 |
30 | 37 | #define P_DECLINE 2 |
— | — | @@ -41,19 +48,19 @@ |
42 | 49 | struct rdcp_frame; |
43 | 50 | struct stat; |
44 | 51 | |
45 | | -int proto_neg(int); |
46 | | -int proto_rsh(const char *, const char *); |
47 | | -struct pfile *proto_getfile(void); |
48 | | -void proto_decline(void); |
49 | | -void proto_accept(void); |
50 | | -int proto_read(struct rdcp_frame *); |
51 | | -void proto_write(struct rdcp_frame *); |
52 | | -int proto_offer(const char *file, struct stat *); |
53 | | -void proto_eof(void); |
54 | | -void proto_writeblock(void *, size_t); |
55 | | -char *proto_readdir(); |
56 | | -char *allocf(); |
57 | | -void fatal(); |
| 52 | +int proto_neg (int); |
| 53 | +int proto_rsh (const char *, const char *); |
| 54 | +struct pfile *proto_getfile (void); |
| 55 | +void proto_decline (void); |
| 56 | +void proto_accept (void); |
| 57 | +int proto_read (struct rdcp_frame *); |
| 58 | +void proto_write (struct rdcp_frame *); |
| 59 | +int proto_offer (const char *file, struct stat *); |
| 60 | +void proto_eof (void); |
| 61 | +void proto_writeblock (void *, size_t); |
| 62 | +char *proto_readdir (void); |
| 63 | +void proto_ack (void); |
| 64 | +void proto_nack (const char *error); |
58 | 65 | |
59 | 66 | /** Tar support */ |
60 | 67 | |
Index: trunk/tools/trickle/tar.c |
— | — | @@ -16,6 +16,8 @@ |
17 | 17 | |
18 | 18 | #include "trickle.h" |
19 | 19 | |
| 20 | +int records; |
| 21 | + |
20 | 22 | void |
21 | 23 | tar_writeheader(file, name) |
22 | 24 | FILE *file; |
— | — | @@ -27,10 +29,8 @@ |
28 | 30 | int sum = 0, i; |
29 | 31 | int truncate = 0; |
30 | 32 | |
31 | | - if (lstat(name, &sb) < 0) { |
32 | | - perror(name); |
33 | | - exit(8); |
34 | | - } |
| 33 | + if (lstat(name, &sb) < 0) |
| 34 | + pfatal("tw1", name); |
35 | 35 | |
36 | 36 | /* |
37 | 37 | * This is a very lax tar header. It's accepted by Solaris tar |
— | — | @@ -86,14 +86,10 @@ |
87 | 87 | sum += *buf++; |
88 | 88 | snprintf(hdr.tr_chksum, 8, "%06o", sum); |
89 | 89 | |
90 | | - if (write_blocked(&hdr, sizeof(hdr), file) < 1) { |
91 | | - perror(dest); |
92 | | - exit(8); |
93 | | - } |
94 | | - if (write_blocked(tardata, strlen(tardata), file) < 1) { |
95 | | - perror(dest); |
96 | | - exit(8); |
97 | | - } |
| 90 | + if (write_blocked(&hdr, sizeof(hdr), file) < 1) |
| 91 | + pfatal("tw2", dest); |
| 92 | + if (write_blocked(tardata, strlen(tardata), file) < 1) |
| 93 | + pfatal("tw3", dest); |
98 | 94 | } |
99 | 95 | |
100 | 96 | memset(&hdr, 0, sizeof(hdr)); |
— | — | @@ -121,10 +117,8 @@ |
122 | 118 | sum += *buf++; |
123 | 119 | snprintf(hdr.tr_chksum, 8, "%06o", sum); |
124 | 120 | |
125 | | - if (write_blocked(&hdr, sizeof(hdr), file) < 1) { |
126 | | - perror(dest); |
127 | | - exit(8); |
128 | | - } |
| 121 | + if (write_blocked(&hdr, sizeof(hdr), file) < 1) |
| 122 | + pfatal("tw4", dest); |
129 | 123 | } |
130 | 124 | |
131 | 125 | void |
— | — | @@ -138,4 +132,6 @@ |
139 | 133 | */ |
140 | 134 | write_blocked(zbuf, 1, file); |
141 | 135 | write_blocked(zbuf, 1, file); |
| 136 | + while (records % 20) |
| 137 | + write_blocked(zbuf, 1, file); |
142 | 138 | } |
Index: trunk/tools/trickle/Makefile |
— | — | @@ -2,8 +2,8 @@ |
3 | 3 | |
4 | 4 | trickle: trickle.o tar.o proto.o util.o rdcp.o |
5 | 5 | cc -g trickle.o tar.o proto.o util.o rdcp.o -o $@ -lsocket -lnsl |
6 | | -.c.o: Makefile |
7 | | - cc -g -O -D_FILE_OFFSET_BITS=64 -c $< |
| 6 | +.c.o: Makefile $< |
| 7 | + cc -g -D_FILE_OFFSET_BITS=64 -c $< |
8 | 8 | clean: |
9 | | - rm -f trickle trickle.o tar.o |
| 9 | + rm -f trickle trickle.o tar.o util.o rdcp.o proto.o |
10 | 10 | .KEEP_STATE: |