mkroot.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <venti.h>
  4. #include <thread.h>
  5. char *host;
  6. void
  7. usage(void)
  8. {
  9. fprint(2, "usage: mkroot [-h host] name type score blocksize prev\n");
  10. threadexitsall("usage");
  11. }
  12. void
  13. threadmain(int argc, char *argv[])
  14. {
  15. uchar score[VtScoreSize];
  16. uchar buf[VtRootSize];
  17. VtConn *z;
  18. VtRoot root;
  19. ARGBEGIN{
  20. case 'h':
  21. host = EARGF(usage());
  22. break;
  23. default:
  24. usage();
  25. break;
  26. }ARGEND
  27. if(argc != 5)
  28. usage();
  29. fmtinstall('V', vtscorefmt);
  30. fmtinstall('F', vtfcallfmt);
  31. strecpy(root.name, root.name+sizeof root.name, argv[0]);
  32. strecpy(root.type, root.type+sizeof root.type, argv[1]);
  33. if(vtparsescore(argv[2], nil, root.score) < 0)
  34. sysfatal("bad score '%s'", argv[2]);
  35. root.blocksize = atoi(argv[3]);
  36. if(vtparsescore(argv[4], nil, root.prev) < 0)
  37. sysfatal("bad score '%s'", argv[4]);
  38. vtrootpack(&root, buf);
  39. z = vtdial(host);
  40. if(z == nil)
  41. sysfatal("could not connect to server: %r");
  42. if(vtconnect(z) < 0)
  43. sysfatal("vtconnect: %r");
  44. if(vtwrite(z, score, VtRootType, buf, VtRootSize) < 0)
  45. sysfatal("vtwrite: %r");
  46. if(vtsync(z) < 0)
  47. sysfatal("vtsync: %r");
  48. vthangup(z);
  49. print("%V\n", score);
  50. threadexitsall(0);
  51. }