Mon Apr 25 04:30:59 2011 UTC ()
- fix warnings
- try to handle ENOBUFS in a nicer way
- use errx() for usage message, not err(), as we do not waht strerror(errno)


(manu)
diff -r1.9 -r1.10 src/usr.sbin/perfused/msg.c
diff -r1.11 -r1.12 src/usr.sbin/perfused/perfused.c

cvs diff -r1.9 -r1.10 src/usr.sbin/perfused/msg.c (expand / switch to unified diff)

--- src/usr.sbin/perfused/msg.c 2010/10/11 05:37:58 1.9
+++ src/usr.sbin/perfused/msg.c 2011/04/25 04:30:59 1.10
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: msg.c,v 1.9 2010/10/11 05:37:58 manu Exp $ */ 1/* $NetBSD: msg.c,v 1.10 2011/04/25 04:30:59 manu Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved. 4 * Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
5 *  5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 *  14 *
@@ -488,42 +488,42 @@ perfuse_readframe(pu, pufbuf, fd, done) @@ -488,42 +488,42 @@ perfuse_readframe(pu, pufbuf, fd, done)
488 break; 488 break;
489 case -1: 489 case -1:
490 if (errno == EAGAIN) 490 if (errno == EAGAIN)
491 return 0; 491 return 0;
492 DWARN("%s: recv retunred -1", __func__); 492 DWARN("%s: recv retunred -1", __func__);
493 return errno; 493 return errno;
494 /* NOTREACHED */ 494 /* NOTREACHED */
495 break; 495 break;
496 default: 496 default:
497 break; 497 break;
498 } 498 }
499 499
500#ifdef PERFUSE_DEBUG 500#ifdef PERFUSE_DEBUG
501 if (readen != len) 501 if (readen != (ssize_t)len)
502 DERRX(EX_SOFTWARE, "%s: short recv %zd/%zd", 502 DERRX(EX_SOFTWARE, "%s: short recv %zd/%zd",
503 __func__, readen, len); 503 __func__, readen, len);
504#endif 504#endif
505 505
506 /* 506 /*
507 * We have a header, get remaing length to read 507 * We have a header, get remaing length to read
508 */ 508 */
509 if (puffs_framebuf_getdata_atoff(pufbuf, 0, &foh, sizeof(foh)) != 0) 509 if (puffs_framebuf_getdata_atoff(pufbuf, 0, &foh, sizeof(foh)) != 0)
510 DERR(EX_SOFTWARE, "puffs_framebuf_getdata_atoff failed"); 510 DERR(EX_SOFTWARE, "puffs_framebuf_getdata_atoff failed");
511 511
512 len = foh.len; 512 len = foh.len;
513 513
514#ifdef PERFUSE_DEBUG 514#ifdef PERFUSE_DEBUG
515 if (len > FUSE_BUFSIZE) 515 if (len > FUSE_BUFSIZE)
516 DERRX(EX_SOFTWARE, "%s: foh.len = %d", __func__, len); 516 DERRX(EX_SOFTWARE, "%s: foh.len = %zu", __func__, len);
517#endif 517#endif
518 518
519 /* 519 /*
520 * This is time to reserve space. 520 * This is time to reserve space.
521 */ 521 */
522 if (puffs_framebuf_reserve_space(pufbuf, len) == -1) 522 if (puffs_framebuf_reserve_space(pufbuf, len) == -1)
523 DERR(EX_OSERR, "puffs_framebuf_reserve_space failed"); 523 DERR(EX_OSERR, "puffs_framebuf_reserve_space failed");
524 524
525 /* 525 /*
526 * And read the remaining data 526 * And read the remaining data
527 */  527 */
528 PUFFS_FRAMEBUF_GETWINDOW(pufbuf, 0, &data, &len); 528 PUFFS_FRAMEBUF_GETWINDOW(pufbuf, 0, &data, &len);
529 529
@@ -535,27 +535,27 @@ perfuse_readframe(pu, pufbuf, fd, done) @@ -535,27 +535,27 @@ perfuse_readframe(pu, pufbuf, fd, done)
535 break; 535 break;
536 case -1: 536 case -1:
537 if (errno == EAGAIN) 537 if (errno == EAGAIN)
538 return 0; 538 return 0;
539 DWARN("%s: recv retunred -1", __func__); 539 DWARN("%s: recv retunred -1", __func__);
540 return errno; 540 return errno;
541 /* NOTREACHED */ 541 /* NOTREACHED */
542 break; 542 break;
543 default: 543 default:
544 break; 544 break;
545 } 545 }
546 546
547#ifdef PERFUSE_DEBUG 547#ifdef PERFUSE_DEBUG
548 if (readen != len) 548 if (readen != (ssize_t)len)
549 DERRX(EX_SOFTWARE, "%s: short recv %zd/%zd", 549 DERRX(EX_SOFTWARE, "%s: short recv %zd/%zd",
550 __func__, readen, len); 550 __func__, readen, len);
551#endif 551#endif
552 552
553 *done = 1; 553 *done = 1;
554 return 0; 554 return 0;
555} 555}
556 556
557/* ARGSUSED0 */ 557/* ARGSUSED0 */
558int 558int
559perfuse_writeframe(pu, pufbuf, fd, done) 559perfuse_writeframe(pu, pufbuf, fd, done)
560 struct puffs_usermount *pu; 560 struct puffs_usermount *pu;
561 struct puffs_framebuf *pufbuf; 561 struct puffs_framebuf *pufbuf;
@@ -566,38 +566,44 @@ perfuse_writeframe(pu, pufbuf, fd, done) @@ -566,38 +566,44 @@ perfuse_writeframe(pu, pufbuf, fd, done)
566 ssize_t written; 566 ssize_t written;
567 void *data; 567 void *data;
568 568
569 len = puffs_framebuf_tellsize(pufbuf); 569 len = puffs_framebuf_tellsize(pufbuf);
570 PUFFS_FRAMEBUF_GETWINDOW(pufbuf, 0, &data, &len); 570 PUFFS_FRAMEBUF_GETWINDOW(pufbuf, 0, &data, &len);
571 571
572 switch (written = send(fd, data, len, MSG_NOSIGNAL)) { 572 switch (written = send(fd, data, len, MSG_NOSIGNAL)) {
573 case 0: 573 case 0:
574 DWARNX("%s: send retunred 0", __func__); 574 DWARNX("%s: send retunred 0", __func__);
575 return ECONNRESET; 575 return ECONNRESET;
576 /* NOTREACHED */ 576 /* NOTREACHED */
577 break; 577 break;
578 case -1: 578 case -1:
579 if (errno == EAGAIN) 579 DWARN("%s: send retunred -1, errno = %d", __func__, errno);
 580 switch(errno) {
 581 case EAGAIN:
 582 case ENOBUFS:
580 return 0; 583 return 0;
581 DWARN("%s: send retunred -1", __func__); 584 break;
582 return errno; 585 default:
 586 return errno;
 587 break;
 588 }
583 /* NOTREACHED */ 589 /* NOTREACHED */
584 break; 590 break;
585 default: 591 default:
586 break; 592 break;
587 } 593 }
588 594
589#ifdef PERFUSE_DEBUG 595#ifdef PERFUSE_DEBUG
590 if (written != len) 596 if (written != (ssize_t)len)
591 DERRX(EX_SOFTWARE, "%s: short send %zd/%zd", 597 DERRX(EX_SOFTWARE, "%s: short send %zd/%zd",
592 __func__, written, len); 598 __func__, written, len);
593#endif 599#endif
594 600
595 *done = 1; 601 *done = 1;
596 return 0; 602 return 0;
597} 603}
598 604
599/* ARGSUSED0 */ 605/* ARGSUSED0 */
600int 606int
601perfuse_cmpframe(pu, pb1, pb2, match) 607perfuse_cmpframe(pu, pb1, pb2, match)
602 struct puffs_usermount *pu; 608 struct puffs_usermount *pu;
603 struct puffs_framebuf *pb1; 609 struct puffs_framebuf *pb1;

cvs diff -r1.11 -r1.12 src/usr.sbin/perfused/perfused.c (expand / switch to unified diff)

--- src/usr.sbin/perfused/perfused.c 2010/10/11 05:37:58 1.11
+++ src/usr.sbin/perfused/perfused.c 2011/04/25 04:30:59 1.12
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: perfused.c,v 1.11 2010/10/11 05:37:58 manu Exp $ */ 1/* $NetBSD: perfused.c,v 1.12 2011/04/25 04:30:59 manu Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved. 4 * Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
5 *  5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 *  14 *
@@ -355,27 +355,27 @@ parse_options(argc, argv) @@ -355,27 +355,27 @@ parse_options(argc, argv)
355 case 's': 355 case 's':
356 if (signal(SIGINFO, siginfo_handler) != 0) 356 if (signal(SIGINFO, siginfo_handler) != 0)
357 DERR(EX_OSERR, "signal failed"); 357 DERR(EX_OSERR, "signal failed");
358 break; 358 break;
359 case 'f': 359 case 'f':
360 foreground = 1; 360 foreground = 1;
361 perfuse_diagflags |= PDF_MISC; 361 perfuse_diagflags |= PDF_MISC;
362 break; 362 break;
363 case 'i': 363 case 'i':
364 retval = atoi(optarg); 364 retval = atoi(optarg);
365 foreground = 1; 365 foreground = 1;
366 break; 366 break;
367 default: 367 default:
368 DERR(EX_USAGE, "%s [-fs] [-d level] [-i fd]", argv[0]); 368 DERRX(EX_USAGE, "%s [-fs] [-d classes] [-i fd]", argv[0]);
369 break; 369 break;
370 } 370 }
371 } 371 }
372  372
373 if (!foreground) 373 if (!foreground)
374 perfuse_diagflags &= ~PDF_FOREGROUND; 374 perfuse_diagflags &= ~PDF_FOREGROUND;
375 375
376 return retval;  376 return retval;
377} 377}
378 378
379int 379int
380main(argc, argv) 380main(argc, argv)
381 int argc; 381 int argc;