error exit status is 1

This commit is contained in:
Robert Morris 2019-09-11 10:04:40 -04:00
parent 7e6c37e67e
commit 35010f0d0f
11 changed files with 210 additions and 210 deletions

View file

@ -12,12 +12,12 @@ cat(int fd)
while((n = read(fd, buf, sizeof(buf))) > 0) {
if (write(1, buf, n) != n) {
printf("cat: write error\n");
exit(-1);
exit(1);
}
}
if(n < 0){
printf("cat: read error\n");
exit(-1);
exit(1);
}
}
@ -28,13 +28,13 @@ main(int argc, char *argv[])
if(argc <= 1){
cat(0);
exit(-1);
exit(1);
}
for(i = 1; i < argc; i++){
if((fd = open(argv[i], 0)) < 0){
printf("cat: cannot open %s\n", argv[i]);
exit(-1);
exit(1);
}
cat(fd);
close(fd);

View file

@ -30,19 +30,19 @@ forktest(void)
if(n == N){
print("fork claimed to work N times!\n");
exit(-1);
exit(1);
}
for(; n > 0; n--){
if(wait(0) < 0){
print("wait stopped early\n");
exit(-1);
exit(1);
}
}
if(wait(0) != -1){
print("wait got too many\n");
exit(-1);
exit(1);
}
print("fork test OK\n");

View file

@ -41,7 +41,7 @@ main(int argc, char *argv[])
if(argc <= 1){
fprintf(2, "usage: grep pattern [file ...]\n");
exit(-1);
exit(1);
}
pattern = argv[1];
@ -53,7 +53,7 @@ main(int argc, char *argv[])
for(i = 2; i < argc; i++){
if((fd = open(argv[i], 0)) < 0){
printf("grep: cannot open %s\n", argv[i]);
exit(-1);
exit(1);
}
grep(pattern, fd);
close(fd);

View file

@ -24,12 +24,12 @@ main(void)
pid = fork();
if(pid < 0){
printf("init: fork failed\n");
exit(-1);
exit(1);
}
if(pid == 0){
exec("sh", argv);
printf("init: exec sh failed\n");
exit(-1);
exit(1);
}
while((wpid=wait(0)) >= 0 && wpid != pid){
//printf("zombie!\n");

View file

@ -9,7 +9,7 @@ main(int argc, char **argv)
if(argc < 2){
fprintf(2, "usage: kill pid...\n");
exit(-1);
exit(1);
}
for(i=1; i<argc; i++)
kill(atoi(argv[i]));

View file

@ -7,7 +7,7 @@ main(int argc, char *argv[])
{
if(argc != 3){
fprintf(2, "Usage: ln old new\n");
exit(-1);
exit(1);
}
if(link(argv[1], argv[2]) < 0)
fprintf(2, "link %s %s: failed\n", argv[1], argv[2]);

View file

@ -9,7 +9,7 @@ main(int argc, char *argv[])
if(argc < 2){
fprintf(2, "Usage: mkdir files...\n");
exit(-1);
exit(1);
}
for(i = 1; i < argc; i++){

View file

@ -9,7 +9,7 @@ main(int argc, char *argv[])
if(argc < 2){
fprintf(2, "Usage: rm files...\n");
exit(-1);
exit(1);
}
for(i = 1; i < argc; i++){

View file

@ -65,7 +65,7 @@ runcmd(struct cmd *cmd)
struct redircmd *rcmd;
if(cmd == 0)
exit(-1);
exit(1);
switch(cmd->type){
default:
@ -74,7 +74,7 @@ runcmd(struct cmd *cmd)
case EXEC:
ecmd = (struct execcmd*)cmd;
if(ecmd->argv[0] == 0)
exit(-1);
exit(1);
exec(ecmd->argv[0], ecmd->argv);
fprintf(2, "exec %s failed\n", ecmd->argv[0]);
break;
@ -84,7 +84,7 @@ runcmd(struct cmd *cmd)
close(rcmd->fd);
if(open(rcmd->file, rcmd->mode) < 0){
fprintf(2, "open %s failed\n", rcmd->file);
exit(-1);
exit(1);
}
runcmd(rcmd->cmd);
break;
@ -175,7 +175,7 @@ void
panic(char *s)
{
fprintf(2, "%s\n", s);
exit(-1);
exit(1);
}
int

File diff suppressed because it is too large Load diff

View file

@ -27,7 +27,7 @@ wc(int fd, char *name)
}
if(n < 0){
printf("wc: read error\n");
exit(-1);
exit(1);
}
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++){
if((fd = open(argv[i], 0)) < 0){
printf("wc: cannot open %s\n", argv[i]);
exit(-1);
exit(1);
}
wc(fd, argv[i]);
close(fd);