1 #include <ccan/tdb/tdb.h>
2 #include <ccan/grab_file/grab_file.h>
3 #include <ccan/hash/hash.h>
4 #include <ccan/talloc/talloc.h>
5 #include <ccan/str_talloc/str_talloc.h>
6 #include <ccan/str/str.h>
7 #include <ccan/list/list.h>
12 #include <sys/types.h>
16 #define STRINGIFY2(x) #x
17 #define STRINGIFY(x) STRINGIFY2(x)
19 /* Avoid mod by zero */
20 static unsigned int total_keys = 1;
22 /* #define DEBUG_DEPS 1 */
27 static struct pipe *pipes;
29 static void __attribute__((noreturn)) fail(const char *filename,
36 fprintf(stderr, "%s:%u: FAIL: ", filename, line);
37 vfprintf(stderr, fmt, ap);
38 fprintf(stderr, "\n");
44 #define try(expr, expect) \
47 if (ret != (expect)) \
48 fail(filename, i+1, STRINGIFY(expr) "= %i", ret); \
51 /* Try or imitate results. */
52 #define unreliable(expr, expect, force, undo) \
55 if (ret != expect) { \
56 fprintf(stderr, "%s:%u: %s gave %i not %i", \
57 filename, i+1, STRINGIFY(expr), ret, expect); \
65 static bool key_eq(TDB_DATA a, TDB_DATA b)
67 if (a.dsize != b.dsize)
69 return memcmp(a.dptr, b.dptr, a.dsize) == 0;
72 /* This is based on the hash algorithm from gdbm */
73 static unsigned int hash_key(TDB_DATA *key)
75 uint32_t value; /* Used to compute the hash value. */
76 uint32_t i; /* Used to cycle through random values. */
78 /* Set the initial value from the key size. */
79 for (value = 0x238F13AF ^ key->dsize, i=0; i < key->dsize; i++)
80 value = (value + (key->dptr[i] << (i*5 % 24)));
82 return (1103515243 * value + 12345);
88 OP_TDB_LOCKALL_UNMARK,
89 OP_TDB_LOCKALL_NONBLOCK,
92 OP_TDB_LOCKALL_READ_NONBLOCK,
93 OP_TDB_UNLOCKALL_READ,
95 OP_TDB_CHAINLOCK_NONBLOCK,
96 OP_TDB_CHAINLOCK_MARK,
97 OP_TDB_CHAINLOCK_UNMARK,
99 OP_TDB_CHAINLOCK_READ,
100 OP_TDB_CHAINUNLOCK_READ,
107 OP_TDB_TRANSACTION_START,
108 OP_TDB_TRANSACTION_CANCEL,
109 OP_TDB_TRANSACTION_COMMIT,
110 OP_TDB_TRAVERSE_READ_START,
111 OP_TDB_TRAVERSE_START,
126 /* Who is waiting for us? */
127 struct list_head post;
128 /* How many are we waiting for? */
132 int flag; /* open and store */
133 struct traverse *trav; /* traverse start */
134 TDB_DATA post_append; /* append */
138 static unsigned char hex_char(const char *filename, unsigned int line, char c)
141 if (c >= 'A' && c <= 'F')
143 if (c >= '0' && c <= '9')
145 fail(filename, line, "invalid hex character '%c'", c);
148 /* TDB data is <size>:<%02x>* */
149 static TDB_DATA make_tdb_data(const void *ctx,
150 const char *filename, unsigned int line,
157 if (streq(word, "NULL"))
160 data.dsize = atoi(word);
161 data.dptr = talloc_array(ctx, unsigned char, data.dsize);
162 p = strchr(word, ':');
164 fail(filename, line, "invalid tdb data '%s'", word);
166 for (i = 0; i < data.dsize; i++)
167 data.dptr[i] = hex_char(filename, line, p[i*2])*16
168 + hex_char(filename, line, p[i*2+1]);
173 static void add_op(const char *filename, struct op **op, unsigned int i,
174 unsigned int serial, enum op_type type)
177 *op = talloc_realloc(NULL, *op, struct op, i+1);
180 new->serial = serial;
185 static void op_add_nothing(const char *filename,
186 struct op op[], unsigned int op_num, char *words[])
189 fail(filename, op_num+1, "Expected no arguments");
190 op[op_num].key = tdb_null;
193 static void op_add_key(const char *filename,
194 struct op op[], unsigned int op_num, char *words[])
196 if (words[2] == NULL || words[3])
197 fail(filename, op_num+1, "Expected just a key");
199 op[op_num].key = make_tdb_data(op, filename, op_num+1, words[2]);
200 if (op[op_num].op != OP_TDB_TRAVERSE)
204 static void op_add_key_ret(const char *filename,
205 struct op op[], unsigned int op_num, char *words[])
207 if (!words[2] || !words[3] || !words[4] || words[5]
208 || !streq(words[3], "="))
209 fail(filename, op_num+1, "Expected <key> = <ret>");
210 op[op_num].ret = atoi(words[4]);
211 op[op_num].key = make_tdb_data(op, filename, op_num+1, words[2]);
212 /* May only be a unique key if it fails */
213 if (op[op_num].ret != 0)
217 static void op_add_key_data(const char *filename,
218 struct op op[], unsigned int op_num, char *words[])
220 if (!words[2] || !words[3] || !words[4] || words[5]
221 || !streq(words[3], "="))
222 fail(filename, op_num+1, "Expected <key> = <data>");
223 op[op_num].key = make_tdb_data(op, filename, op_num+1, words[2]);
224 op[op_num].data = make_tdb_data(op, filename, op_num+1, words[4]);
225 /* May only be a unique key if it fails */
226 if (!op[op_num].data.dptr)
230 /* <serial> tdb_store <rec> <rec> <flag> = <ret> */
231 static void op_add_store(const char *filename,
232 struct op op[], unsigned int op_num, char *words[])
234 if (!words[2] || !words[3] || !words[4] || !words[5] || !words[6]
235 || words[7] || !streq(words[5], "="))
236 fail(filename, op_num+1, "Expect <key> <data> <flag> = <ret>");
238 op[op_num].flag = strtoul(words[4], NULL, 0);
239 op[op_num].ret = atoi(words[6]);
240 op[op_num].key = make_tdb_data(op, filename, op_num+1, words[2]);
241 op[op_num].data = make_tdb_data(op, filename, op_num+1, words[3]);
245 /* <serial> tdb_append <rec> <rec> = <rec> */
246 static void op_add_append(const char *filename,
247 struct op op[], unsigned int op_num, char *words[])
249 if (!words[2] || !words[3] || !words[4] || !words[5] || words[6]
250 || !streq(words[4], "="))
251 fail(filename, op_num+1, "Expect <key> <data> = <rec>");
253 op[op_num].key = make_tdb_data(op, filename, op_num+1, words[2]);
254 op[op_num].data = make_tdb_data(op, filename, op_num+1, words[3]);
255 op[op_num].post_append
256 = make_tdb_data(op, filename, op_num+1, words[5]);
260 /* <serial> tdb_get_seqnum = <ret> */
261 static void op_add_seqnum(const char *filename,
262 struct op op[], unsigned int op_num, char *words[])
264 if (!words[2] || !words[3] || words[4] || !streq(words[2], "="))
265 fail(filename, op_num+1, "Expect = <ret>");
267 op[op_num].key = tdb_null;
268 op[op_num].ret = atoi(words[3]);
271 static void op_add_traverse(const char *filename,
272 struct op op[], unsigned int op_num, char *words[])
275 fail(filename, op_num+1, "Expect no arguments");
277 op[op_num].key = tdb_null;
278 op[op_num].trav = NULL;
281 struct traverse_hash {
286 /* A traverse is a hash of keys, each one associated with ops. */
288 /* How many traversal callouts should I do? */
291 /* Where is traversal end op? */
294 /* For trivial traversals. */
295 struct traverse_hash *hash;
298 /* A trivial traversal is one which doesn't terminate early and only
299 * plays with its own record. We can reliably replay these even if
300 * traverse order changes. */
301 static bool is_trivial_traverse(struct op op[], unsigned int end)
305 TDB_DATA cur = tdb_null;
307 if (op[end].ret != 0)
310 for (i = 0; i < end; i++) {
313 if (op[i].op == OP_TDB_TRAVERSE)
315 if (!key_eq(cur, op[i].key))
320 /* With multiple things happening at once, no traverse is trivial. */
324 static void op_analyze_traverse(const char *filename,
325 struct op op[], unsigned int op_num,
329 struct traverse *trav = talloc(op, struct traverse);
331 /* = %u means traverse function terminated. */
333 if (!streq(words[2], "=") || !words[3] || words[4])
334 fail(filename, op_num+1, "expect = <num>");
335 op[op_num].ret = atoi(words[3]);
341 for (i = op_num-1; i >= 0; i--) {
342 if (op[i].op == OP_TDB_TRAVERSE)
344 if (op[i].op != OP_TDB_TRAVERSE_READ_START
345 && op[i].op != OP_TDB_TRAVERSE_START)
353 fail(filename, op_num+1, "no traversal start found");
357 if (is_trivial_traverse(op+i, op_num-i)) {
358 /* Fill in a plentiful hash table. */
359 op[i].trav->hash = talloc_zero_array(op[i].trav,
360 struct traverse_hash,
362 for (; i < op_num; i++) {
364 if (op[i].op != OP_TDB_TRAVERSE)
366 h = hash_key(&op[i].key) % (trav->num * 2);
367 while (trav->hash[h].index)
368 h = (h + 1) % (trav->num * 2);
369 trav->hash[h].index = i+1;
370 trav->hash[h].key = op[i].key;
376 /* Keep -Wmissing-declarations happy: */
377 const struct op_table *
378 find_keyword (register const char *str, register unsigned int len);
380 #include "keywords.c"
382 static int get_len(TDB_DATA key, TDB_DATA data, void *private_data)
387 static unsigned run_ops(struct tdb_context *tdb,
389 const char *filename,
391 unsigned int start, unsigned int stop);
393 struct traverse_info {
395 const char *filename;
401 /* Trivial case: do whatever they did for this key. */
402 static int trivial_traverse(struct tdb_context *tdb,
403 TDB_DATA key, TDB_DATA data,
406 struct traverse_info *tinfo = _tinfo;
407 struct traverse *trav = tinfo->op[tinfo->start].trav;
408 unsigned int h = hash_key(&key) % (trav->num * 2);
410 while (trav->hash[h].index) {
411 if (key_eq(trav->hash[h].key, key)) {
412 run_ops(tdb, tinfo->pre_fd, tinfo->filename, tinfo->op,
413 trav->hash[h].index, trav->end);
417 h = (h + 1) % (trav->num * 2);
419 fail(tinfo->filename, tinfo->start + 1, "unexpected traverse key");
422 /* More complex. Just do whatever's they did at the n'th entry. */
423 static int nontrivial_traverse(struct tdb_context *tdb,
424 TDB_DATA key, TDB_DATA data,
427 struct traverse_info *tinfo = _tinfo;
428 struct traverse *trav = tinfo->op[tinfo->start].trav;
430 if (tinfo->i == trav->end) {
431 /* This can happen if traverse expects to be empty. */
432 if (tinfo->start + 1 == trav->end)
434 fail(tinfo->filename, tinfo->start + 1,
435 "traverse did not terminate");
438 if (tinfo->op[tinfo->i].op != OP_TDB_TRAVERSE)
439 fail(tinfo->filename, tinfo->start + 1,
440 "%s:%u:traverse terminated early");
442 /* Run any normal ops. */
443 tinfo->i = run_ops(tdb, tinfo->pre_fd, tinfo->filename, tinfo->op,
444 tinfo->i+1, trav->end);
446 if (tinfo->i == trav->end)
452 static unsigned op_traverse(struct tdb_context *tdb,
454 const char *filename,
455 int (*traversefn)(struct tdb_context *,
456 tdb_traverse_func, void *),
460 struct traverse *trav = op[start].trav;
461 struct traverse_info tinfo = { op, filename, pre_fd, start, start+1 };
465 int ret = traversefn(tdb, trivial_traverse, &tinfo);
466 if (ret != trav->num)
467 fail(filename, start+1, "short traversal %i", ret);
471 traversefn(tdb, nontrivial_traverse, &tinfo);
473 /* Traversing in wrong order can have strange effects: eg. if
474 * original traverse went A (delete A), B, we might do B
475 * (delete A). So if we have ops left over, we do it now. */
476 while (tinfo.i != trav->end) {
477 if (op[tinfo.i].op == OP_TDB_TRAVERSE)
480 tinfo.i = run_ops(tdb, pre_fd, filename, op,
487 /* We can have more than one */
488 struct list_node list;
493 static void do_pre(const char *filename, int pre_fd,
494 struct op op[], unsigned int i)
496 while (op[i].pre != 0) {
500 printf("%s:%u:waiting for pre\n", filename, i+1);
502 if (read(pre_fd, &opnum, sizeof(opnum)) != sizeof(opnum))
503 errx(1, "Reading from pipe");
506 printf("%s:%u:got pre %u\n",
507 filename, i+1, opnum);
509 /* This could be any op, not just this one. */
510 if (op[opnum].pre == 0)
511 errx(1, "Got unexpected notification for op line %u",
517 static void do_post(const char *filename, const struct op op[], unsigned int i)
521 list_for_each(&op[i].post, dep, list) {
523 printf("%s:%u:sending %u to file %u\n", filename, i+1,
526 if (write(pipes[dep->file].fd[1], &dep->op, sizeof(dep->op))
528 err(1, "Failed to tell file %u", dep->file);
532 static __attribute__((noinline))
533 unsigned run_ops(struct tdb_context *tdb,
535 const char *filename,
536 struct op op[], unsigned int start, unsigned int stop)
540 for (i = start; i < stop; i++) {
541 do_pre(filename, pre_fd, op, i);
545 try(tdb_lockall(tdb), op[i].ret);
547 case OP_TDB_LOCKALL_MARK:
548 try(tdb_lockall_mark(tdb), op[i].ret);
550 case OP_TDB_LOCKALL_UNMARK:
551 try(tdb_lockall_unmark(tdb), op[i].ret);
553 case OP_TDB_LOCKALL_NONBLOCK:
554 unreliable(tdb_lockall_nonblock(tdb), op[i].ret,
555 tdb_lockall(tdb), tdb_unlockall(tdb));
557 case OP_TDB_UNLOCKALL:
558 try(tdb_unlockall(tdb), op[i].ret);
560 case OP_TDB_LOCKALL_READ:
561 try(tdb_lockall_read(tdb), op[i].ret);
563 case OP_TDB_LOCKALL_READ_NONBLOCK:
564 unreliable(tdb_lockall_read_nonblock(tdb), op[i].ret,
565 tdb_lockall_read(tdb),
566 tdb_unlockall_read(tdb));
568 case OP_TDB_UNLOCKALL_READ:
569 try(tdb_unlockall_read(tdb), op[i].ret);
571 case OP_TDB_CHAINLOCK:
572 try(tdb_chainlock(tdb, op[i].key), op[i].ret);
574 case OP_TDB_CHAINLOCK_NONBLOCK:
575 unreliable(tdb_chainlock_nonblock(tdb, op[i].key),
577 tdb_chainlock(tdb, op[i].key),
578 tdb_chainunlock(tdb, op[i].key));
580 case OP_TDB_CHAINLOCK_MARK:
581 try(tdb_chainlock_mark(tdb, op[i].key), op[i].ret);
583 case OP_TDB_CHAINLOCK_UNMARK:
584 try(tdb_chainlock_unmark(tdb, op[i].key), op[i].ret);
586 case OP_TDB_CHAINUNLOCK:
587 try(tdb_chainunlock(tdb, op[i].key), op[i].ret);
589 case OP_TDB_CHAINLOCK_READ:
590 try(tdb_chainlock_read(tdb, op[i].key), op[i].ret);
592 case OP_TDB_CHAINUNLOCK_READ:
593 try(tdb_chainunlock_read(tdb, op[i].key), op[i].ret);
595 case OP_TDB_PARSE_RECORD:
596 try(tdb_parse_record(tdb, op[i].key, get_len, NULL),
600 try(tdb_exists(tdb, op[i].key), op[i].ret);
603 try(tdb_store(tdb, op[i].key, op[i].data, op[i].flag),
604 op[i].ret < 0 ? op[i].ret : 0);
607 try(tdb_append(tdb, op[i].key, op[i].data),
608 op[i].ret < 0 ? op[i].ret : 0);
610 case OP_TDB_GET_SEQNUM:
611 try(tdb_get_seqnum(tdb), op[i].ret);
613 case OP_TDB_WIPE_ALL:
614 try(tdb_wipe_all(tdb), op[i].ret);
616 case OP_TDB_TRANSACTION_START:
617 try(tdb_transaction_start(tdb), op[i].ret);
619 case OP_TDB_TRANSACTION_CANCEL:
620 try(tdb_transaction_cancel(tdb), op[i].ret);
622 case OP_TDB_TRANSACTION_COMMIT:
623 try(tdb_transaction_commit(tdb), op[i].ret);
625 case OP_TDB_TRAVERSE_READ_START:
626 i = op_traverse(tdb, pre_fd, filename,
627 tdb_traverse_read, op, i);
629 case OP_TDB_TRAVERSE_START:
630 i = op_traverse(tdb, pre_fd, filename,
631 tdb_traverse, op, i);
633 case OP_TDB_TRAVERSE:
634 /* Terminate: we're in a traverse, and we've
637 case OP_TDB_TRAVERSE_END:
638 fail(filename, i+1, "unepxected end traverse");
639 /* FIXME: These must be treated like traverse. */
640 case OP_TDB_FIRSTKEY:
641 if (!key_eq(tdb_firstkey(tdb), op[i].data))
642 fail(filename, i+1, "bad firstkey");
645 if (!key_eq(tdb_nextkey(tdb, op[i].key), op[i].data))
646 fail(filename, i+1, "bad nextkey");
649 TDB_DATA f = tdb_fetch(tdb, op[i].key);
650 if (!key_eq(f, op[i].data))
651 fail(filename, i+1, "bad fetch %u", f.dsize);
655 try(tdb_delete(tdb, op[i].key), op[i].ret);
658 do_post(filename, op, i);
663 static struct op *load_tracefile(const char *filename, unsigned int *num,
664 unsigned int *hashsize,
665 unsigned int *tdb_flags,
666 unsigned int *open_flags)
669 struct op *op = talloc_array(NULL, struct op, 1);
674 file = grab_file(NULL, filename, NULL);
676 err(1, "Reading %s", filename);
678 lines = strsplit(file, file, "\n", NULL);
680 errx(1, "%s is empty", filename);
682 words = strsplit(lines, lines[0], " ", NULL);
683 if (!streq(words[1], "tdb_open"))
684 fail(filename, 1, "does not start with tdb_open");
686 *hashsize = atoi(words[2]);
687 *tdb_flags = strtoul(words[3], NULL, 0);
688 *open_flags = strtoul(words[4], NULL, 0);
690 for (i = 1; lines[i]; i++) {
691 const struct op_table *opt;
693 words = strsplit(lines, lines[i], " ", NULL);
694 if (!words[0] || !words[1])
695 fail(filename, i+1, "Expected serial number and op");
697 opt = find_keyword(words[1], strlen(words[1]));
699 if (streq(words[1], "tdb_close")) {
702 "lines after tdb_close");
707 fail(filename, i+1, "Unknown operation '%s'", words[1]);
710 add_op(filename, &op, i, atoi(words[0]), opt->type);
711 opt->enhance_op(filename, op, i, words);
714 fprintf(stderr, "%s:%u:last operation is not tdb_close: incomplete?",
721 /* We remember all the keys we've ever seen, and who has them. */
729 unsigned int num_users;
730 struct key_user *user;
733 static bool changes_db(const struct op *op)
738 return op->op == OP_TDB_STORE
739 || op->op == OP_TDB_APPEND
740 || op->op == OP_TDB_WIPE_ALL
741 || op->op == OP_TDB_TRANSACTION_COMMIT
742 || op->op == OP_TDB_DELETE;
745 static struct keyinfo *hash_ops(struct op *op[], unsigned int num_ops[],
748 unsigned int i, j, h;
749 struct keyinfo *hash;
751 /* Gcc nexted function extension. How cool is this? */
752 int compare_user_serial(const void *_a, const void *_b)
754 const struct key_user *a = _a, *b = _b;
755 int ret = op[a->file][a->op_num].serial
756 - op[b->file][b->op_num].serial;
758 /* Fetches don't inc serial, so we put changes first. */
760 if (changes_db(&op[a->file][a->op_num])
761 && !changes_db(&op[b->file][b->op_num]))
763 if (changes_db(&op[b->file][b->op_num])
764 && !changes_db(&op[a->file][a->op_num]))
770 hash = talloc_zero_array(op[0], struct keyinfo, total_keys*2);
771 for (i = 0; i < num; i++) {
772 for (j = 1; j < num_ops[i]; j++) {
773 /* We can't do this on allocation, due to realloc. */
774 list_head_init(&op[i][j].post);
776 if (!op[i][j].key.dptr)
779 /* We don't wait for traverse keys */
780 /* FIXME: We should, for trivial traversals. */
781 if (op[i][j].op == OP_TDB_TRAVERSE)
784 h = hash_key(&op[i][j].key) % (total_keys * 2);
785 while (!key_eq(hash[h].key, op[i][j].key)) {
786 if (!hash[h].key.dptr) {
787 hash[h].key = op[i][j].key;
790 h = (h + 1) % (total_keys * 2);
792 /* Might as well save some memory if we can. */
793 if (op[i][j].key.dptr != hash[h].key.dptr) {
794 talloc_free(op[i][j].key.dptr);
795 op[i][j].key.dptr = hash[h].key.dptr;
797 hash[h].user = talloc_realloc(hash, hash[h].user,
799 hash[h].num_users+1);
800 hash[h].user[hash[h].num_users].op_num = j;
801 hash[h].user[hash[h].num_users].file = i;
806 /* Now sort into seqnum order. */
807 for (h = 0; h < total_keys * 2; h++)
808 qsort(hash[h].user, hash[h].num_users, sizeof(hash[h].user[0]),
809 compare_user_serial);
814 static void add_dependency(void *ctx,
816 unsigned int needs_file,
817 unsigned int needs_opnum,
818 unsigned int satisfies_file,
819 unsigned int satisfies_opnum)
823 post = talloc(ctx, struct depend);
824 post->file = needs_file;
825 post->op = needs_opnum;
826 list_add(&op[satisfies_file][satisfies_opnum].post, &post->list);
828 op[needs_file][needs_opnum].pre++;
831 static void derive_dependencies(char *filename[],
832 struct op *op[], unsigned int num_ops[],
835 struct keyinfo *hash;
838 /* Create hash table for faster key lookup. */
839 hash = hash_ops(op, num_ops, num);
841 /* We make the naive assumption that two ops on the same key
842 * have to be ordered; it's overkill. */
843 for (i = 0; i < total_keys * 2; i++) {
846 for (j = 1; j < hash[i].num_users; j++) {
847 /* We don't depend on ourselves. */
848 if (hash[i].user[j].file == hash[i].user[j-1].file)
851 printf("%s:%u: depends on %s:%u\n",
852 filename[hash[i].user[j].file],
853 hash[i].user[j].op_num+1,
854 filename[hash[i].user[j-1].file],
855 hash[i].user[j-1].op_num+1);
857 add_dependency(hash, op,
858 hash[i].user[j].file,
859 hash[i].user[j].op_num,
860 hash[i].user[j-1].file,
861 hash[i].user[j-1].op_num);
866 int main(int argc, char *argv[])
868 struct timeval start, end;
869 unsigned int i, num_ops[argc], hashsize[argc], tdb_flags[argc], open_flags[argc];
875 errx(1, "Usage: %s <tdbfile> <tracefile>...", argv[0]);
877 pipes = talloc_array(NULL, struct pipe, argc - 2);
878 for (i = 0; i < argc - 2; i++) {
879 op[i] = load_tracefile(argv[2+i], &num_ops[i], &hashsize[i],
880 &tdb_flags[i], &open_flags[i]);
881 if (pipe(pipes[i].fd) != 0)
882 err(1, "creating pipe");
885 derive_dependencies(argv+2, op, num_ops, i);
887 /* Don't fork for single arg case: simple debugging. */
889 struct tdb_context *tdb;
890 tdb = tdb_open_ex(argv[1], hashsize[0], tdb_flags[0],
893 run_ops(tdb, pipes[0].fd[0], argv[2],
894 op[0], 1, num_ops[0]);
899 err(1, "creating pipe");
901 for (i = 0; i < argc - 2; i++) {
902 struct tdb_context *tdb;
906 err(1, "fork failed");
909 tdb = tdb_open_ex(argv[1], hashsize[i], tdb_flags[i],
913 err(1, "Opening tdb %s", argv[1]);
915 /* This catches parent exiting. */
916 if (read(fds[0], &c, 1) != 1)
918 run_ops(tdb, pipes[i].fd[0], argv[2+i],
919 op[i], 1, num_ops[i]);
926 /* Let everything settle. */
929 gettimeofday(&start, NULL);
930 /* Tell them all to go! Any write of sufficient length will do. */
931 if (write(fds[1], hashsize, i) != i)
932 err(1, "Writing to wakeup pipe");
934 for (i = 0; i < argc - 2; i++) {
937 if (!WIFEXITED(status))
938 errx(1, "Child died with signal");
939 if (WEXITSTATUS(status) != 0)
940 errx(1, "Child died with error code");
942 gettimeofday(&end, NULL);
944 end.tv_sec -= start.tv_sec;
945 printf("Time replaying: %lu usec\n",
946 end.tv_sec * 1000000UL + (end.tv_usec - start.tv_usec));