debug.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <auth.h>
  4. #include <bio.h>
  5. #include "imap4d.h"
  6. void
  7. debuglog(char *fmt, ...)
  8. {
  9. va_list arg;
  10. static int logfd;
  11. if(debug == 0)
  12. return;
  13. if(logfd == 0)
  14. logfd = open("/sys/log/imap4d", OWRITE);
  15. if(logfd > 0){
  16. va_start(arg, fmt);
  17. fprint(logfd, "%s: ", username);
  18. vfprint(logfd, fmt, arg);
  19. va_end(arg);
  20. }
  21. }
  22. void
  23. boxVerify(Box *box)
  24. {
  25. Msg *m;
  26. ulong seq, uid, recent;
  27. if(box == nil)
  28. return;
  29. recent = 0;
  30. seq = 0;
  31. uid = 0;
  32. for(m = box->msgs; m != nil; m = m->next){
  33. if(m->seq == 0)
  34. fprint(2, "m->seq == 0: m->seq=%lud\n", m->seq);
  35. else if(m->seq <= seq)
  36. fprint(2, "m->seq=%lud out of order: last=%lud\n", m->seq, seq);
  37. seq = m->seq;
  38. if(m->uid == 0)
  39. fprint(2, "m->uid == 0: m->seq=%lud\n", m->seq);
  40. else if(m->uid <= uid)
  41. fprint(2, "m->uid=%lud out of order: last=%lud\n", m->uid, uid);
  42. uid = m->uid;
  43. if(m->flags & MRecent)
  44. recent++;
  45. }
  46. if(seq != box->max)
  47. fprint(2, "max=%lud, should be %lud\n", box->max, seq);
  48. if(uid >= box->uidnext)
  49. fprint(2, "uidnext=%lud, maxuid=%lud\n", box->uidnext, uid);
  50. if(recent != box->recent)
  51. fprint(2, "recent=%lud, should be %lud\n", box->recent, recent);
  52. }
  53. void
  54. openfiles(void)
  55. {
  56. Dir *d;
  57. int i;
  58. for(i = 0; i < 20; i++){
  59. d = dirfstat(i);
  60. if(d != nil){
  61. fprint(2, "fd[%d]='%s' type=%c dev=%d user='%s group='%s'\n", i, d->name, d->type, d->dev, d->uid, d->gid);
  62. free(d);
  63. }
  64. }
  65. }
  66. void
  67. ls(char *file)
  68. {
  69. Dir *d;
  70. int fd, i, nd;
  71. fd = open(file, OREAD);
  72. if(fd < 0)
  73. return;
  74. /*
  75. * read box to find all messages
  76. * each one has a directory, and is in numerical order
  77. */
  78. d = dirfstat(fd);
  79. if(d == nil){
  80. close(fd);
  81. return;
  82. }
  83. if(!(d->mode & DMDIR)){
  84. fprint(2, "file %s\n", file);
  85. free(d);
  86. close(fd);
  87. return;
  88. }
  89. free(d);
  90. while((nd = dirread(fd, &d)) > 0){
  91. for(i = 0; i < nd; i++){
  92. fprint(2, "%s/%s %c\n", file, d[i].name, "-d"[(d[i].mode & DMDIR) == DMDIR]);
  93. }
  94. free(d);
  95. }
  96. close(fd);
  97. }