Home | History | Annotate | Line # | Download | only in ckckp
ckckp.c revision 1.2
      1  1.1  perseant #include <err.h>
      2  1.1  perseant #include <fcntl.h>
      3  1.1  perseant #include <stdio.h>
      4  1.1  perseant #include <stdlib.h>
      5  1.1  perseant #include <sys/param.h>
      6  1.1  perseant #include <sys/mount.h>
      7  1.1  perseant #include <ufs/ufs/dinode.h>
      8  1.1  perseant #include <ufs/lfs/lfs.h>
      9  1.1  perseant 
     10  1.1  perseant int main(int argc, char **argv)
     11  1.1  perseant {
     12  1.1  perseant 	int fd, e, sno;
     13  1.1  perseant 	char cmd[BUFSIZ], s[BUFSIZ];
     14  1.1  perseant 	FILE *pp;
     15  1.1  perseant 
     16  1.2  perseant 	if (argc < 5)
     17  1.2  perseant 		errx(1, "usage: %s <fs-root> <raw-dev> <save-filename> "
     18  1.2  perseant 		     "<work-filename>\n", argv[0]);
     19  1.1  perseant 
     20  1.1  perseant 	fd = open(argv[1], 0, 0);
     21  1.1  perseant 	if (fd < 0)
     22  1.1  perseant 		err(1, argv[1]);
     23  1.1  perseant 
     24  1.1  perseant 	fcntl(fd, LFCNWRAPGO, NULL);
     25  1.1  perseant 	sleep(5);
     26  1.1  perseant 
     27  1.1  perseant 	/* Loop forever calling LFCNWRAP{STOP,GO} */
     28  1.1  perseant 	sno = 0;
     29  1.1  perseant 	while(1) {
     30  1.1  perseant 		printf("Waiting until fs wraps\n");
     31  1.1  perseant 		fcntl(fd, LFCNWRAPSTOP, NULL);
     32  1.1  perseant 
     33  1.1  perseant 		/*
     34  1.1  perseant 		 * When the fcntl exits, the wrap is about to occur (but
     35  1.1  perseant 		 * is waiting for the signal to go).  Call our mass-check
     36  1.1  perseant 		 * script, and if all is well, continue.  The output
     37  1.1  perseant 		 * of the script should end with a line that begins with a
     38  1.1  perseant 		 * numeric code: zero for okay, nonzero for a failure.
     39  1.1  perseant 		 */
     40  1.1  perseant 		printf("Verifying all checkpoints from s/n %d\n", sno);
     41  1.2  perseant 		sprintf(cmd, "./check-all %s %s %s %d", argv[2], argv[3],
     42  1.2  perseant 			argv[4], sno);
     43  1.1  perseant 		pp = popen(cmd, "r");
     44  1.1  perseant 		s[0] = '\0';
     45  1.1  perseant 		while(fgets(s, BUFSIZ, pp) != NULL)
     46  1.1  perseant 			printf("  %s", s);
     47  1.1  perseant 		if (s[0] == '\0') {
     48  1.1  perseant 			printf("No checkpoints found or script exited\n");
     49  1.1  perseant 			return 0;
     50  1.1  perseant 		}
     51  1.1  perseant 		sscanf(s, "%d %d", &e, &sno);
     52  1.1  perseant 		if (e) {
     53  1.1  perseant 			return 0;
     54  1.1  perseant 		}
     55  1.1  perseant 		pclose(pp);
     56  1.1  perseant 
     57  1.1  perseant 		++sno;
     58  1.1  perseant 		printf("Waiting until fs continues\n");
     59  1.1  perseant 		fcntl(fd, LFCNWRAPGO, NULL);
     60  1.1  perseant 	}
     61  1.1  perseant 
     62  1.1  perseant 	return 0;
     63  1.1  perseant }
     64