error exit status is 1
This commit is contained in:
parent
7e6c37e67e
commit
35010f0d0f
|
@ -12,12 +12,12 @@ cat(int fd)
|
||||||
while((n = read(fd, buf, sizeof(buf))) > 0) {
|
while((n = read(fd, buf, sizeof(buf))) > 0) {
|
||||||
if (write(1, buf, n) != n) {
|
if (write(1, buf, n) != n) {
|
||||||
printf("cat: write error\n");
|
printf("cat: write error\n");
|
||||||
exit(-1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(n < 0){
|
if(n < 0){
|
||||||
printf("cat: read error\n");
|
printf("cat: read error\n");
|
||||||
exit(-1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,13 +28,13 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
if(argc <= 1){
|
if(argc <= 1){
|
||||||
cat(0);
|
cat(0);
|
||||||
exit(-1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 1; i < argc; i++){
|
for(i = 1; i < argc; i++){
|
||||||
if((fd = open(argv[i], 0)) < 0){
|
if((fd = open(argv[i], 0)) < 0){
|
||||||
printf("cat: cannot open %s\n", argv[i]);
|
printf("cat: cannot open %s\n", argv[i]);
|
||||||
exit(-1);
|
exit(1);
|
||||||
}
|
}
|
||||||
cat(fd);
|
cat(fd);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
|
@ -30,19 +30,19 @@ forktest(void)
|
||||||
|
|
||||||
if(n == N){
|
if(n == N){
|
||||||
print("fork claimed to work N times!\n");
|
print("fork claimed to work N times!\n");
|
||||||
exit(-1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(; n > 0; n--){
|
for(; n > 0; n--){
|
||||||
if(wait(0) < 0){
|
if(wait(0) < 0){
|
||||||
print("wait stopped early\n");
|
print("wait stopped early\n");
|
||||||
exit(-1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(wait(0) != -1){
|
if(wait(0) != -1){
|
||||||
print("wait got too many\n");
|
print("wait got too many\n");
|
||||||
exit(-1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
print("fork test OK\n");
|
print("fork test OK\n");
|
||||||
|
|
|
@ -41,7 +41,7 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
if(argc <= 1){
|
if(argc <= 1){
|
||||||
fprintf(2, "usage: grep pattern [file ...]\n");
|
fprintf(2, "usage: grep pattern [file ...]\n");
|
||||||
exit(-1);
|
exit(1);
|
||||||
}
|
}
|
||||||
pattern = argv[1];
|
pattern = argv[1];
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ main(int argc, char *argv[])
|
||||||
for(i = 2; i < argc; i++){
|
for(i = 2; i < argc; i++){
|
||||||
if((fd = open(argv[i], 0)) < 0){
|
if((fd = open(argv[i], 0)) < 0){
|
||||||
printf("grep: cannot open %s\n", argv[i]);
|
printf("grep: cannot open %s\n", argv[i]);
|
||||||
exit(-1);
|
exit(1);
|
||||||
}
|
}
|
||||||
grep(pattern, fd);
|
grep(pattern, fd);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
|
@ -24,12 +24,12 @@ main(void)
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if(pid < 0){
|
if(pid < 0){
|
||||||
printf("init: fork failed\n");
|
printf("init: fork failed\n");
|
||||||
exit(-1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if(pid == 0){
|
if(pid == 0){
|
||||||
exec("sh", argv);
|
exec("sh", argv);
|
||||||
printf("init: exec sh failed\n");
|
printf("init: exec sh failed\n");
|
||||||
exit(-1);
|
exit(1);
|
||||||
}
|
}
|
||||||
while((wpid=wait(0)) >= 0 && wpid != pid){
|
while((wpid=wait(0)) >= 0 && wpid != pid){
|
||||||
//printf("zombie!\n");
|
//printf("zombie!\n");
|
||||||
|
|
|
@ -9,7 +9,7 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
if(argc < 2){
|
if(argc < 2){
|
||||||
fprintf(2, "usage: kill pid...\n");
|
fprintf(2, "usage: kill pid...\n");
|
||||||
exit(-1);
|
exit(1);
|
||||||
}
|
}
|
||||||
for(i=1; i<argc; i++)
|
for(i=1; i<argc; i++)
|
||||||
kill(atoi(argv[i]));
|
kill(atoi(argv[i]));
|
||||||
|
|
|
@ -7,7 +7,7 @@ main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
if(argc != 3){
|
if(argc != 3){
|
||||||
fprintf(2, "Usage: ln old new\n");
|
fprintf(2, "Usage: ln old new\n");
|
||||||
exit(-1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if(link(argv[1], argv[2]) < 0)
|
if(link(argv[1], argv[2]) < 0)
|
||||||
fprintf(2, "link %s %s: failed\n", argv[1], argv[2]);
|
fprintf(2, "link %s %s: failed\n", argv[1], argv[2]);
|
||||||
|
|
|
@ -9,7 +9,7 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
if(argc < 2){
|
if(argc < 2){
|
||||||
fprintf(2, "Usage: mkdir files...\n");
|
fprintf(2, "Usage: mkdir files...\n");
|
||||||
exit(-1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 1; i < argc; i++){
|
for(i = 1; i < argc; i++){
|
||||||
|
|
|
@ -9,7 +9,7 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
if(argc < 2){
|
if(argc < 2){
|
||||||
fprintf(2, "Usage: rm files...\n");
|
fprintf(2, "Usage: rm files...\n");
|
||||||
exit(-1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 1; i < argc; i++){
|
for(i = 1; i < argc; i++){
|
||||||
|
|
|
@ -65,7 +65,7 @@ runcmd(struct cmd *cmd)
|
||||||
struct redircmd *rcmd;
|
struct redircmd *rcmd;
|
||||||
|
|
||||||
if(cmd == 0)
|
if(cmd == 0)
|
||||||
exit(-1);
|
exit(1);
|
||||||
|
|
||||||
switch(cmd->type){
|
switch(cmd->type){
|
||||||
default:
|
default:
|
||||||
|
@ -74,7 +74,7 @@ runcmd(struct cmd *cmd)
|
||||||
case EXEC:
|
case EXEC:
|
||||||
ecmd = (struct execcmd*)cmd;
|
ecmd = (struct execcmd*)cmd;
|
||||||
if(ecmd->argv[0] == 0)
|
if(ecmd->argv[0] == 0)
|
||||||
exit(-1);
|
exit(1);
|
||||||
exec(ecmd->argv[0], ecmd->argv);
|
exec(ecmd->argv[0], ecmd->argv);
|
||||||
fprintf(2, "exec %s failed\n", ecmd->argv[0]);
|
fprintf(2, "exec %s failed\n", ecmd->argv[0]);
|
||||||
break;
|
break;
|
||||||
|
@ -84,7 +84,7 @@ runcmd(struct cmd *cmd)
|
||||||
close(rcmd->fd);
|
close(rcmd->fd);
|
||||||
if(open(rcmd->file, rcmd->mode) < 0){
|
if(open(rcmd->file, rcmd->mode) < 0){
|
||||||
fprintf(2, "open %s failed\n", rcmd->file);
|
fprintf(2, "open %s failed\n", rcmd->file);
|
||||||
exit(-1);
|
exit(1);
|
||||||
}
|
}
|
||||||
runcmd(rcmd->cmd);
|
runcmd(rcmd->cmd);
|
||||||
break;
|
break;
|
||||||
|
@ -175,7 +175,7 @@ void
|
||||||
panic(char *s)
|
panic(char *s)
|
||||||
{
|
{
|
||||||
fprintf(2, "%s\n", s);
|
fprintf(2, "%s\n", s);
|
||||||
exit(-1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
378
user/usertests.c
378
user/usertests.c
File diff suppressed because it is too large
Load diff
|
@ -27,7 +27,7 @@ wc(int fd, char *name)
|
||||||
}
|
}
|
||||||
if(n < 0){
|
if(n < 0){
|
||||||
printf("wc: read error\n");
|
printf("wc: read error\n");
|
||||||
exit(-1);
|
exit(1);
|
||||||
}
|
}
|
||||||
printf("%d %d %d %s\n", l, w, c, name);
|
printf("%d %d %d %s\n", l, w, c, name);
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ main(int argc, char *argv[])
|
||||||
for(i = 1; i < argc; i++){
|
for(i = 1; i < argc; i++){
|
||||||
if((fd = open(argv[i], 0)) < 0){
|
if((fd = open(argv[i], 0)) < 0){
|
||||||
printf("wc: cannot open %s\n", argv[i]);
|
printf("wc: cannot open %s\n", argv[i]);
|
||||||
exit(-1);
|
exit(1);
|
||||||
}
|
}
|
||||||
wc(fd, argv[i]);
|
wc(fd, argv[i]);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
Loading…
Reference in a new issue