From 2cb47cb4c80f66416f01d5e2349b3ba5cf8a082b Mon Sep 17 00:00:00 2001 From: Guru Prasad Srinivasa Date: Mon, 7 Mar 2016 10:55:20 -0500 Subject: [PATCH] Removed all instances of crash_prog() crash_prog was introduced to force-crash a userspace program since _exit may not yet be implemented. However, the new versions of OS161 already have the exact same logic as crash_prog in stdlib/exit. --- userland/include/err.h | 2 -- userland/lib/libc/unix/err.c | 11 ----------- userland/testbin/closetest/closetest.c | 2 -- userland/testbin/consoletest/consoletest.c | 6 ------ userland/testbin/fileonlytest/fileonlytest.c | 2 -- userland/testbin/opentest/opentest.c | 3 --- userland/testbin/readwritetest/readwritetest.c | 2 -- userland/testbin/redirect/redirect.c | 11 ----------- userland/testbin/sparsefile/sparsefile.c | 2 -- 9 files changed, 41 deletions(-) diff --git a/userland/include/err.h b/userland/include/err.h index 6caab13..8d3f9cb 100644 --- a/userland/include/err.h +++ b/userland/include/err.h @@ -55,6 +55,4 @@ void vwarnx(const char *fmt, __va_list); __DEAD void verr(int exitcode, const char *fmt, __va_list); __DEAD void verrx(int exitcode, const char *fmt, __va_list); -void crash_prog(void); - #endif /* _ERR_H_ */ diff --git a/userland/lib/libc/unix/err.c b/userland/lib/libc/unix/err.c index 85107be..214f89d 100644 --- a/userland/lib/libc/unix/err.c +++ b/userland/lib/libc/unix/err.c @@ -140,7 +140,6 @@ verr(int exitcode, const char *fmt, va_list ap) __printerr(1, fmt, ap); exit(exitcode); // exit() didn't work. - crash_prog(); } /* errx/verrx: don't use errno, but do then exit */ @@ -150,7 +149,6 @@ verrx(int exitcode, const char *fmt, va_list ap) __printerr(0, fmt, ap); exit(exitcode); // exit() didn't work. - crash_prog(); } /* @@ -193,12 +191,3 @@ errx(int exitcode, const char *fmt, ...) verrx(exitcode, fmt, ap); va_end(ap); } - -void -crash_prog(void) -{ - // Guru: Since exit() may not yet be implemented, just trigger a - // failure so things don't fall through to a success print - nprintf("Accessing invalid memory location to trigger failure\n"); - tprintf("%d", *((int *) 0xd34db33f)); -} diff --git a/userland/testbin/closetest/closetest.c b/userland/testbin/closetest/closetest.c index 2a217ca..53b0ea1 100644 --- a/userland/testbin/closetest/closetest.c +++ b/userland/testbin/closetest/closetest.c @@ -75,7 +75,5 @@ main(int argc, char **argv) success(TEST161_SUCCESS, SECRET, "/testbin/closetest"); - // Exit may not be implemented. So crash. - crash_prog(); return 0; } diff --git a/userland/testbin/consoletest/consoletest.c b/userland/testbin/consoletest/consoletest.c index d7093ce..6f91155 100644 --- a/userland/testbin/consoletest/consoletest.c +++ b/userland/testbin/consoletest/consoletest.c @@ -54,11 +54,5 @@ main(int argc, char **argv) (void) argv; secprintf(SECRET, "Able was i ere i saw elbA", "/testbin/consoletest"); - - // Guru: Since exit() may not yet be implemented, just trigger a - // failure that the grading scripts expect to see. - tprintf("Accessing invalid memory location to trigger failure\n"); - tprintf("%d", *((int *) 0xd34db33f)); - return 0; } diff --git a/userland/testbin/fileonlytest/fileonlytest.c b/userland/testbin/fileonlytest/fileonlytest.c index bdf73cb..3b3b230 100644 --- a/userland/testbin/fileonlytest/fileonlytest.c +++ b/userland/testbin/fileonlytest/fileonlytest.c @@ -162,7 +162,5 @@ main(int argc, char **argv) } success(TEST161_SUCCESS, SECRET, "/testbin/fileonlytest"); - // Exit may not be implemented. So crash. - crash_prog(); return 0; } diff --git a/userland/testbin/opentest/opentest.c b/userland/testbin/opentest/opentest.c index 0859b91..79b0eac 100644 --- a/userland/testbin/opentest/opentest.c +++ b/userland/testbin/opentest/opentest.c @@ -75,8 +75,5 @@ main(int argc, char **argv) success(TEST161_SUCCESS, SECRET, "/testbin/opentest"); - - // Exit may not be implemented. So crash. - crash_prog(); return 0; } diff --git a/userland/testbin/readwritetest/readwritetest.c b/userland/testbin/readwritetest/readwritetest.c index e187c24..e693100 100644 --- a/userland/testbin/readwritetest/readwritetest.c +++ b/userland/testbin/readwritetest/readwritetest.c @@ -100,7 +100,5 @@ main(int argc, char **argv) nprintf("\n"); secprintf(SECRET, MAGIC, "/testbin/readwritetest"); - // Exit may not be implemented. So crash. - crash_prog(); return 0; } diff --git a/userland/testbin/redirect/redirect.c b/userland/testbin/redirect/redirect.c index 809c576..544308b 100644 --- a/userland/testbin/redirect/redirect.c +++ b/userland/testbin/redirect/redirect.c @@ -60,7 +60,6 @@ doopen(const char *path, int openflags) fd = open(path, openflags, 0664); if (fd < 0) { err(1, "%s", path); - crash_prog(); } return fd; } @@ -77,7 +76,6 @@ dodup2(int ofd, int nfd, const char *file) } if (r != nfd) { errx(1, "%s: dup2: Expected %d, got %d", nfd, r); - crash_prog(); } } @@ -102,12 +100,10 @@ mkfile(void) r = write(fd, slogan, strlen(slogan)); if (r < 0) { err(1, "%s: write", INFILE); - crash_prog(); } if ((size_t)r != strlen(slogan)) { errx(1, "%s: write: Short count (got %zd, expected %zu)", INFILE, r, strlen(slogan)); - crash_prog(); } doclose(fd, INFILE); @@ -126,16 +122,13 @@ chkfile(void) r = read(fd, buf, sizeof(buf)); if (r < 0) { err(1, "%s: read", OUTFILE); - crash_prog(); } if (r == 0) { errx(1, "%s: read: Unexpected EOF", OUTFILE); - crash_prog(); } if ((size_t)r != strlen(slogan)) { errx(1, "%s: read: Short count (got %zd, expected %zu)", OUTFILE, r, strlen(slogan)); - crash_prog(); } doclose(fd, OUTFILE); @@ -155,7 +148,6 @@ cat(void) pid = fork(); if (pid < 0) { err(1, "fork"); - crash_prog(); } if (pid == 0) { @@ -178,15 +170,12 @@ cat(void) result = waitpid(pid, &status, 0); if (result == -1) { err(1, "waitpid"); - crash_prog(); } if (WIFSIGNALED(status)) { errx(1, "pid %d: Signal %d", (int)pid, WTERMSIG(status)); - crash_prog(); } if (WIFEXITED(status) && WEXITSTATUS(status) != 0) { errx(1, "pid %d: Exit %d", (int)pid, WEXITSTATUS(status)); - crash_prog(); } } diff --git a/userland/testbin/sparsefile/sparsefile.c b/userland/testbin/sparsefile/sparsefile.c index ea3cb3c..a719f91 100644 --- a/userland/testbin/sparsefile/sparsefile.c +++ b/userland/testbin/sparsefile/sparsefile.c @@ -109,7 +109,5 @@ main(int argc, char *argv[]) nprintf("\n"); success(TEST161_SUCCESS, SECRET, "/testbin/sparsefile"); - // Exit may not be implemented. So crash. - crash_prog(); return 0; }