better grind error messages
This commit is contained in:
parent
b418a34537
commit
8c67f96b72
38
user/grind.c
38
user/grind.c
|
@ -57,7 +57,7 @@ go(int which_child)
|
|||
|
||||
mkdir("grindir");
|
||||
if(chdir("grindir") != 0){
|
||||
printf("chdir grindir failed\n");
|
||||
printf("grind: chdir grindir failed\n");
|
||||
exit(1);
|
||||
}
|
||||
chdir("/");
|
||||
|
@ -75,7 +75,7 @@ go(int which_child)
|
|||
unlink("grindir/../a");
|
||||
} else if(what == 4){
|
||||
if(chdir("grindir") != 0){
|
||||
printf("chdir grindir failed\n");
|
||||
printf("grind: chdir grindir failed\n");
|
||||
exit(1);
|
||||
}
|
||||
unlink("../b");
|
||||
|
@ -139,7 +139,7 @@ go(int which_child)
|
|||
exit(1);
|
||||
}
|
||||
if(chdir("../grindir/..") != 0){
|
||||
printf("chdir failed\n");
|
||||
printf("grind: chdir failed\n");
|
||||
exit(1);
|
||||
}
|
||||
kill(pid);
|
||||
|
@ -188,7 +188,7 @@ go(int which_child)
|
|||
unlink("x");
|
||||
exit(0);
|
||||
} else if(pid < 0){
|
||||
printf("fork failed\n");
|
||||
printf("grind: fork failed\n");
|
||||
exit(1);
|
||||
}
|
||||
wait(0);
|
||||
|
@ -198,24 +198,24 @@ go(int which_child)
|
|||
// file descriptors, blocks.
|
||||
int fd1 = open("c", O_CREATE|O_RDWR);
|
||||
if(fd1 < 0){
|
||||
printf("create c failed\n");
|
||||
printf("grind: create c failed\n");
|
||||
exit(1);
|
||||
}
|
||||
if(write(fd1, "x", 1) != 1){
|
||||
printf("write c failed\n");
|
||||
printf("grind: write c failed\n");
|
||||
exit(1);
|
||||
}
|
||||
struct stat st;
|
||||
if(fstat(fd1, &st) != 0){
|
||||
printf("fstat failed\n");
|
||||
printf("grind: fstat failed\n");
|
||||
exit(1);
|
||||
}
|
||||
if(st.size != 1){
|
||||
printf("fstat reports wrong size %d\n", (int)st.size);
|
||||
printf("grind: fstat reports wrong size %d\n", (int)st.size);
|
||||
exit(1);
|
||||
}
|
||||
if(st.ino > 200){
|
||||
printf("fstat reports crazy i-number %d\n", st.ino);
|
||||
printf("grind: fstat reports crazy i-number %d\n", st.ino);
|
||||
exit(1);
|
||||
}
|
||||
close(fd1);
|
||||
|
@ -224,11 +224,11 @@ go(int which_child)
|
|||
// echo hi | cat
|
||||
int aa[2], bb[2];
|
||||
if(pipe(aa) < 0){
|
||||
fprintf(2, "pipe failed\n");
|
||||
fprintf(2, "grind: pipe failed\n");
|
||||
exit(1);
|
||||
}
|
||||
if(pipe(bb) < 0){
|
||||
fprintf(2, "pipe failed\n");
|
||||
fprintf(2, "grind: pipe failed\n");
|
||||
exit(1);
|
||||
}
|
||||
int pid1 = fork();
|
||||
|
@ -238,16 +238,16 @@ go(int which_child)
|
|||
close(aa[0]);
|
||||
close(1);
|
||||
if(dup(aa[1]) != 1){
|
||||
fprintf(2, "dup failed\n");
|
||||
fprintf(2, "grind: dup failed\n");
|
||||
exit(1);
|
||||
}
|
||||
close(aa[1]);
|
||||
char *args[3] = { "echo", "hi", 0 };
|
||||
exec("grindir/../echo", args);
|
||||
fprintf(2, "echo: not found\n");
|
||||
fprintf(2, "grind: echo: not found\n");
|
||||
exit(2);
|
||||
} else if(pid1 < 0){
|
||||
fprintf(2, "fork failed\n");
|
||||
fprintf(2, "grind: fork failed\n");
|
||||
exit(3);
|
||||
}
|
||||
int pid2 = fork();
|
||||
|
@ -256,22 +256,22 @@ go(int which_child)
|
|||
close(bb[0]);
|
||||
close(0);
|
||||
if(dup(aa[0]) != 0){
|
||||
fprintf(2, "dup failed\n");
|
||||
fprintf(2, "grind: dup failed\n");
|
||||
exit(4);
|
||||
}
|
||||
close(aa[0]);
|
||||
close(1);
|
||||
if(dup(bb[1]) != 1){
|
||||
fprintf(2, "dup failed\n");
|
||||
fprintf(2, "grind: dup failed\n");
|
||||
exit(5);
|
||||
}
|
||||
close(bb[1]);
|
||||
char *args[2] = { "cat", 0 };
|
||||
exec("/cat", args);
|
||||
fprintf(2, "cat: not found\n");
|
||||
fprintf(2, "grind: cat: not found\n");
|
||||
exit(6);
|
||||
} else if(pid2 < 0){
|
||||
fprintf(2, "fork failed\n");
|
||||
fprintf(2, "grind: fork failed\n");
|
||||
exit(7);
|
||||
}
|
||||
close(aa[0]);
|
||||
|
@ -285,7 +285,7 @@ go(int which_child)
|
|||
wait(&st1);
|
||||
wait(&st2);
|
||||
if(st1 != 0 || st2 != 0 || strcmp(buf, "hi") != 0){
|
||||
printf("exec pipeline failed %d %d \"%s\"\n", st1, st2, buf);
|
||||
printf("grind: exec pipeline failed %d %d \"%s\"\n", st1, st2, buf);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue