perp-patches 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. diff --git a/lasagna/cdb/cdb_dynread.c b/lasagna/cdb/cdb_dynread.c
  2. index b7135c5..f5e7ab8 100644
  3. --- a/lasagna/cdb/cdb_dynread.c
  4. +++ b/lasagna/cdb/cdb_dynread.c
  5. @@ -23,7 +23,7 @@ cdb_dynread(struct cdb *C, struct dynbuf *B, size_t len, uint32_t offset)
  6. if(dynbuf_grow(B, len) == -1)
  7. return -1;
  8. - if(cdb_read(C, dynbuf_BUF(B) + dynbuf_LEN(B), len, offset) == -1)
  9. + if(cdb_read(C, (uchar_t *)dynbuf_BUF(B) + dynbuf_LEN(B), len, offset) == -1)
  10. return -1;
  11. dynbuf_LEN(B) += len;
  12. diff --git a/lasagna/dynbuf/dynbuf_pack.c b/lasagna/dynbuf/dynbuf_pack.c
  13. index 84727cb..4543a0a 100644
  14. --- a/lasagna/dynbuf/dynbuf_pack.c
  15. +++ b/lasagna/dynbuf/dynbuf_pack.c
  16. @@ -46,7 +46,7 @@ dynbuf_pack(struct dynbuf *D, const char *fmt, ...)
  17. }
  18. /* with need satisfied, append directly into buf: */
  19. - b = (D->buf + D->p);
  20. + b = (uchar_t *)D->buf + D->p;
  21. va_start(args, fmt);
  22. w = upak_vpack(b, fmt, args);
  23. diff --git a/lasagna/dynbuf/dynbuf_put.c b/lasagna/dynbuf/dynbuf_put.c
  24. index 6ff7bdb..46989c4 100644
  25. --- a/lasagna/dynbuf/dynbuf_put.c
  26. +++ b/lasagna/dynbuf/dynbuf_put.c
  27. @@ -19,10 +19,11 @@ dynbuf_putbuf(struct dynbuf *d, const void *buf, size_t len)
  28. if(dynbuf_grow(d, (len + 1)) != 0)
  29. return -1; /* error! */
  30. - buf_copy((d->buf + d->p), buf, len);
  31. + b = d->buf;
  32. + buf_copy(b + d->p, buf, len);
  33. d->p += len;
  34. - b = d->buf; b[d->p] = 'Q'; /* "offensive programming" */
  35. + b[d->p] = 'Q'; /* "offensive programming" */
  36. return 0; /* no error */
  37. }
  38. diff --git a/lasagna/hdb/hdb_dynread.c b/lasagna/hdb/hdb_dynread.c
  39. index cd818bc..82d20d2 100644
  40. --- a/lasagna/hdb/hdb_dynread.c
  41. +++ b/lasagna/hdb/hdb_dynread.c
  42. @@ -23,7 +23,7 @@ hdb_dynread(struct hdb *H, struct dynbuf *B, size_t len, uint32_t offset)
  43. if(dynbuf_grow(B, len) == -1)
  44. return -1;
  45. - if(hdb_read(H, dynbuf_BUF(B) + dynbuf_LEN(B), len, offset) == -1)
  46. + if(hdb_read(H, (uchar_t *)dynbuf_BUF(B) + dynbuf_LEN(B), len, offset) == -1)
  47. return -1;
  48. dynbuf_LEN(B) += len;
  49. diff --git a/lasagna/ioq/iobuf_getnets.c b/lasagna/ioq/iobuf_getnets.c
  50. deleted file mode 100644
  51. index 55447ee..0000000
  52. --- a/lasagna/ioq/iobuf_getnets.c
  53. +++ /dev/null
  54. @@ -1,104 +0,0 @@
  55. -/*
  56. -** iobuf_getnets.c
  57. -** wcm, 2004.04.28 - 2004.04.29
  58. -** ===
  59. -*/
  60. -#include "iobuf.h"
  61. -
  62. -#include "buf.h"
  63. -#include "dynbuf.h"
  64. -
  65. -
  66. -static
  67. -int
  68. -get_netslen(iobuf *ibuf, size_t *len, size_t max)
  69. -{
  70. - char c;
  71. - size_t n = 0;
  72. - int digits = 0;
  73. -
  74. -/*
  75. -** returns length in len and:
  76. -** -3, netstring format error
  77. -** -1, io error
  78. -** 0, EOF
  79. -** 1, ok
  80. -*/
  81. -
  82. - for(;;){
  83. - switch(iobuf_GETC(ibuf, &c)){
  84. - case -1: return -1; /* io error */
  85. - case 0: return 0; /* EOF */
  86. - default: break; /* ok */
  87. - }
  88. - if(c == ':'){
  89. - if(digits){
  90. - *len = n;
  91. - return 1;
  92. - }
  93. - else break;
  94. - }
  95. - if((c < '0') || (c > '9')) break;
  96. - n = 10 * n + (c - '0');
  97. - if((digits && (n == 0)) || (n > max)) break;
  98. - ++digits;
  99. - }
  100. -
  101. - /* netstring format error: */
  102. - return -3;
  103. -}
  104. -
  105. -
  106. -int iobuf_getnets(iobuf *ibuf, dynbuf *b, size_t max)
  107. -{
  108. - int r;
  109. - size_t len = 0;
  110. - char *buf;
  111. - char c;
  112. -
  113. -/*
  114. -** returns netstring in dynbuf:
  115. -** -3, netstring format error
  116. -** -1, error (io or malloc)
  117. -** 0, EOF
  118. -** 1, ok
  119. -*/
  120. -
  121. - switch(get_netslen(ibuf, &len, max)){
  122. - case -3: return -3;
  123. - case -1: return -1;
  124. - case 0: return 0;
  125. - default: break;
  126. - }
  127. -
  128. - if(dynbuf_grow(b, len) != 0)
  129. - return -1; /* malloc error */
  130. -
  131. - buf = dynbuf_BUF(b);
  132. - while(len){
  133. - r = iobuf_get(ibuf, buf, len);
  134. - switch(r){
  135. - case -1: return -1; /* io error */
  136. - case 0: return -3; /* eof before complete */
  137. - default: break;
  138. - }
  139. - dynbuf_LEN(b) += r;
  140. - if(r == len) break;
  141. - /* else: */
  142. - buf += r;
  143. - len -= r;
  144. - }
  145. -
  146. - /* so far, so good; now comma? */
  147. - switch(iobuf_GETC(ibuf, &c)){
  148. - case -1: return -1; /* io error */
  149. - case 0: return -3; /* eof before comma */
  150. - default: break;
  151. - }
  152. - if(c != ',') return -3;
  153. -
  154. - /* success: */
  155. - return 1;
  156. -}
  157. -
  158. -/* that's all, folks! */
  159. diff --git a/lasagna/ioq/iobuf_getrec.c b/lasagna/ioq/iobuf_getrec.c
  160. deleted file mode 100644
  161. index 6462452..0000000
  162. --- a/lasagna/ioq/iobuf_getrec.c
  163. +++ /dev/null
  164. @@ -1,50 +0,0 @@
  165. -/*
  166. -** iobuf_getrec.c
  167. -** wcm, 2004.04.28 - 2004.04.29
  168. -** ===
  169. -*/
  170. -#include "iobuf.h"
  171. -
  172. -#include "buf.h"
  173. -#include "dynbuf.h"
  174. -
  175. -int iobuf_getrec(iobuf *ibuf, dynbuf *b, int sep)
  176. -{
  177. - int r;
  178. - int n;
  179. - char *x;
  180. -
  181. -/*
  182. -** returns:
  183. -** -1, error (io or malloc)
  184. -** 0, EOF
  185. -** 1, ok
  186. -*/
  187. -
  188. - for(;;){
  189. - r = iobuf_feed(ibuf);
  190. - if(r <= 0) return r; /* EOF (0) or io error (-1) */
  191. -
  192. - x = (char *)iobuf_PEEK(ibuf);
  193. - n = buf_ndx(x, r, sep);
  194. - if(n < r){ /* sep found */
  195. - if(dynbuf_putbuf(b, x, n) == 0) { /* ok */
  196. - /* strip contents out of ibuf */
  197. - iobuf_SEEK(ibuf, (n+1));
  198. - /* success: */
  199. - return 1;
  200. - }
  201. - else /* dynbuf malloc failure: */
  202. - return -1;
  203. - }
  204. - /* else: */
  205. - if(dynbuf_grow(b, r) != 0)
  206. - return -1;
  207. - dynbuf_LEN(b) += iobuf_get(ibuf, dynbuf_BUF(b)+dynbuf_LEN(b), r);
  208. - }
  209. -
  210. - /* not here: */
  211. - return -1;
  212. -}
  213. -
  214. -/* that's all, folks! */
  215. diff --git a/lasagna/ioq/ioq_put.c b/lasagna/ioq/ioq_put.c
  216. index 47f4897..20737a6 100644
  217. --- a/lasagna/ioq/ioq_put.c
  218. +++ b/lasagna/ioq/ioq_put.c
  219. @@ -44,7 +44,7 @@
  220. /* internal declarations: */
  221. -static int write_all(int fd, void *buf, size_t to_write, ssize_t (*op)());
  222. +static int write_all(int fd, uchar_t *buf, size_t to_write, ssize_t (*op)());
  223. /*
  224. @@ -63,13 +63,13 @@ static int write_all(int fd, void *buf, size_t to_write, ssize_t (*op)());
  225. */
  226. static
  227. int
  228. -write_all(int fd, void *buf, size_t to_write, ssize_t (*op)())
  229. +write_all(int fd, uchar_t *buf, size_t to_write, ssize_t (*op)())
  230. {
  231. ssize_t w = 0;
  232. while(to_write){
  233. do{
  234. - w = op(fd, buf, to_write);
  235. + w = op(fd, (void *)buf, to_write);
  236. }while((w == -1) && (errno == EINTR));
  237. if(w == -1) return -1; /* error! */
  238. @@ -137,7 +137,7 @@ ioq_put(ioq_t *ioq, const uchar_t *data, size_t len)
  239. while(len > ioq->n){
  240. /* don't write more than len! */
  241. if(len < n) n = len;
  242. - if(write_all(ioq->fd, (void *)data, n, ioq->op) == -1){
  243. + if(write_all(ioq->fd, (uchar_t *)data, n, ioq->op) == -1){
  244. /* write() error: */
  245. return -1;
  246. }
  247. @@ -178,7 +178,7 @@ ioq_putflush(ioq_t *ioq, const uchar_t *data, size_t len)
  248. if(ioq_flush(ioq) == -1) return -1;
  249. /* write() the rest */
  250. - return write_all(ioq->fd, (void *)data, len, ioq->op);
  251. + return write_all(ioq->fd, (uchar_t *)data, len, ioq->op);
  252. }
  253. diff --git a/lasagna/packet/packet_write.c b/lasagna/packet/packet_write.c
  254. index 66c5f8c..6af6a94 100644
  255. --- a/lasagna/packet/packet_write.c
  256. +++ b/lasagna/packet/packet_write.c
  257. @@ -50,11 +50,12 @@ packet_write(int fd, const void *packet, size_t n)
  258. {
  259. ssize_t w = 0;
  260. size_t to_write = n;
  261. + const char *b = packet;
  262. while(to_write > 0){
  263. do{
  264. - w = write(fd, packet, to_write);
  265. + w = write(fd, b, to_write);
  266. }while((w == -1) && (errno == EINTR));
  267. if(w == -1)
  268. @@ -63,7 +64,7 @@ packet_write(int fd, const void *packet, size_t n)
  269. if(w == 0)
  270. continue;
  271. - packet += w;
  272. + b += w;
  273. to_write -= w;
  274. }
  275. diff --git a/lasagna/tain/tain_now.c b/lasagna/tain/tain_now.c
  276. index 3c790be..ba53864 100644
  277. --- a/lasagna/tain/tain_now.c
  278. +++ b/lasagna/tain/tain_now.c
  279. @@ -6,18 +6,17 @@
  280. #include <stdlib.h>
  281. #include <time.h>
  282. -#include <sys/time.h>
  283. #include "tain.h"
  284. struct tain *
  285. tain_now(struct tain *t)
  286. {
  287. - struct timeval now;
  288. + struct timespec now;
  289. - gettimeofday(&now, NULL);
  290. + clock_gettime(CLOCK_REALTIME, &now);
  291. tain_load_utc(t, now.tv_sec);
  292. - t->nsec = (1000 * now.tv_usec) + 500;
  293. + t->nsec = now.tv_nsec;
  294. return t;
  295. }
  296. diff --git a/perp/perpd.c b/perp/perpd.c
  297. index 2bf5553..1b29577 100644
  298. --- a/perp/perpd.c
  299. +++ b/perp/perpd.c
  300. @@ -217,8 +217,9 @@ static
  301. void
  302. perpd_control_init(void)
  303. {
  304. - int fdbase;
  305. - int fd = -1;
  306. + int fdbase;
  307. + int fd = -1;
  308. + mode_t umask_orig;
  309. /* setup for return to base directory: */
  310. if((fdbase = open(".", O_RDONLY)) == -1){
  311. @@ -226,7 +227,7 @@ perpd_control_init(void)
  312. }
  313. /* setup umask for intentional mode on file creation: */
  314. - umask(0);
  315. + umask_orig = umask(0);
  316. /* initialize .control directory: */
  317. if(mkdir(PERP_CONTROL, 0700) == -1){
  318. @@ -286,6 +287,9 @@ perpd_control_init(void)
  319. }
  320. close(fdbase);
  321. + /* restore umask: */
  322. + umask(umask_orig);
  323. +
  324. return;
  325. }
  326. diff --git a/perp/perpd_svdef.c b/perp/perpd_svdef.c
  327. index 82fb0a0..7b5e87f 100644
  328. --- a/perp/perpd_svdef.c
  329. +++ b/perp/perpd_svdef.c
  330. @@ -186,7 +186,7 @@ void
  331. perpd_svdef_checkfail(struct svdef *svdef)
  332. {
  333. struct subsv *subsv;
  334. - int target, r = 0;
  335. + int target;
  336. /* insanity? */
  337. if(!(svdef->bitflags & SVDEF_FLAG_ACTIVE))
  338. @@ -201,7 +201,7 @@ perpd_svdef_checkfail(struct svdef *svdef)
  339. subsv = (svdef->bitflags & SVDEF_FLAG_HASLOG) ? &svdef->svpair[SUBSV_LOG] : NULL;
  340. if((subsv != NULL) && (subsv->bitflags & SUBSV_FLAG_FAILING)){
  341. target = (subsv->bitflags & SUBSV_FLAG_ISRESET) ? SVRUN_RESET : SVRUN_START;
  342. - r = perpd_svdef_run(svdef, SUBSV_LOG, target);
  343. + perpd_svdef_run(svdef, SUBSV_LOG, target);
  344. }
  345. /* XXX, bail here if log is failing? */
  346. diff --git a/perp/tinylog.c b/perp/tinylog.c
  347. index 8df6283..a593a66 100644
  348. --- a/perp/tinylog.c
  349. +++ b/perp/tinylog.c
  350. @@ -124,7 +124,7 @@ const char *gzip_path = NULL;
  351. /*
  352. ** declarations in scope:
  353. */
  354. -static void write_all(int fd, void *buf, size_t len);
  355. +static void write_all(int fd, char *buf, size_t len);
  356. static void stamp8601_make(char *stamp_buf);
  357. static void init_logdir(struct tinylog *tinylog);
  358. static void init_current(struct tinylog *tinylog, int resume);
  359. @@ -182,7 +182,7 @@ ssize_t read_op(int fd, void *buf, size_t len)
  360. */
  361. static
  362. void
  363. -write_all(int fd, void *buf, size_t len)
  364. +write_all(int fd, char *buf, size_t len)
  365. {
  366. ssize_t w = 0;
  367. tain_t epause = tain_INIT(0, EPAUSE);
  368. diff --git a/runtools/runchoom.c b/runtools/runchoom.c
  369. index e318e2a..0682ad3 100644
  370. --- a/runtools/runchoom.c
  371. +++ b/runtools/runchoom.c
  372. @@ -59,7 +59,7 @@ static char setbuf[256];
  373. static char pidfmt[NFMT_SIZE];
  374. /* functions in scope: */
  375. -static int write_all(int fd, void *buf, size_t to_write);
  376. +static int write_all(int fd, char *buf, size_t to_write);
  377. static void do_choom(void);
  378. /* syserr_warn() macro: */
  379. @@ -77,7 +77,7 @@ static void do_choom(void);
  380. static
  381. int
  382. -write_all(int fd, void *buf, size_t to_write)
  383. +write_all(int fd, char *buf, size_t to_write)
  384. {
  385. ssize_t w = 0;