15 char from[PATH_LENGTH];
24 int rename_errors = 0;
25 int unlink_errors = 0;
27 void handler(int sig) {
28 static long last_time;
31 signal(SIGINT, handler);
32 signal(SIGALRM, handler);
33 printf("%6ld sec %14d iterations errors %d/%d/%d - "
34 "Use SIGQUIT (^\\) to kill\n", now - start, loops,
35 creat_errors, rename_errors, unlink_errors);
39 else if (sig == SIGALRM)
41 else if (sig == SIGINT) {
42 if (last_time - now < 2)
48 int main(int argc, char *argv[])
54 names = malloc(sizeof(struct names) * count);
60 h2 = sprintf(names[0].from, "%x", count); /* just to figure length */
61 h1 = (PATH_LENGTH-h2-2)/4;
65 printf("h1 = %d, h2 = %d n = %lu\n", h1, h2, n);
70 signal(SIGQUIT, handler);
71 signal(SIGINT, handler);
72 signal(SIGALRM, handler);
78 if (mkdir("tmp", S_IRWXU) == -1) {
82 if (chdir("tmp") == -1) {
87 for (i = 0; i < count ; i++) {
88 j = random() & (n - 1);
89 k = random() & (n - 1);
90 l = random() & (n - 1);
91 m = random() & (n - 1);
92 sprintf(names[i].from, "%0*x%0*x%0*x%0*x0%0*x",
93 h1, j, h1, k, h1, l, h1, m, h2, i);
94 sprintf(names[i].to, "%0*x%0*x%0*x%0*x1%0*x",
95 h1, j, h1, k, h1, l, h1, m, h2, i);
99 for (i = 0; i < count; i++) {
101 if ((fd = creat(names[i].from, S_IRUSR|S_IWUSR)) == -1){
103 sprintf(msg, "creat %s", names[i].from);
107 if (close(fd) == -1) {
113 for (i = 0; i < count; i++) {
114 if (rename(names[i].from, names[i].to) == -1) {
116 sprintf(msg, "rename %s to %s",
117 names[i].from, names[i].to);
123 for (i = 0; i < count; i++) {
124 if (unlink(names[i].to) == -1) {
126 sprintf(msg, "unlink %s", names[i].to);
132 if (chdir("..") == -1) {
137 if (rmdir("tmp") == -1) {
138 if (chdir("tmp") == -1) {
142 for (i = 0; i < count; i++) {
143 if (unlink(names[i].from) != -1) {
144 fprintf(stderr, "Unexpected file %s\n",
149 if (chdir("..") == -1) {
153 if (rmdir("tmp") == -1) {