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.
This commit is contained in:
		| @@ -55,6 +55,4 @@ void vwarnx(const char *fmt, __va_list); | |||||||
| __DEAD void verr(int exitcode, 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); | __DEAD void verrx(int exitcode, const char *fmt, __va_list); | ||||||
|  |  | ||||||
| void crash_prog(void); |  | ||||||
|  |  | ||||||
| #endif /* _ERR_H_ */ | #endif /* _ERR_H_ */ | ||||||
|   | |||||||
| @@ -140,7 +140,6 @@ verr(int exitcode, const char *fmt, va_list ap) | |||||||
| 	__printerr(1, fmt, ap); | 	__printerr(1, fmt, ap); | ||||||
| 	exit(exitcode); | 	exit(exitcode); | ||||||
| 	// exit() didn't work. | 	// exit() didn't work. | ||||||
| 	crash_prog(); |  | ||||||
| } | } | ||||||
|  |  | ||||||
| /* errx/verrx: don't use errno, but do then exit */ | /* 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); | 	__printerr(0, fmt, ap); | ||||||
| 	exit(exitcode); | 	exit(exitcode); | ||||||
| 	// exit() didn't work. | 	// exit() didn't work. | ||||||
| 	crash_prog(); |  | ||||||
| } | } | ||||||
|  |  | ||||||
| /* | /* | ||||||
| @@ -193,12 +191,3 @@ errx(int exitcode, const char *fmt, ...) | |||||||
| 	verrx(exitcode, fmt, ap); | 	verrx(exitcode, fmt, ap); | ||||||
| 	va_end(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)); |  | ||||||
| } |  | ||||||
|   | |||||||
| @@ -75,7 +75,5 @@ main(int argc, char **argv) | |||||||
|  |  | ||||||
|  |  | ||||||
| 	success(TEST161_SUCCESS, SECRET, "/testbin/closetest"); | 	success(TEST161_SUCCESS, SECRET, "/testbin/closetest"); | ||||||
| 	// Exit may not be implemented. So crash. |  | ||||||
| 	crash_prog(); |  | ||||||
| 	return 0; | 	return 0; | ||||||
| } | } | ||||||
|   | |||||||
| @@ -54,11 +54,5 @@ main(int argc, char **argv) | |||||||
| 	(void) argv; | 	(void) argv; | ||||||
|  |  | ||||||
| 	secprintf(SECRET, "Able was i ere i saw elbA", "/testbin/consoletest"); | 	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; | 	return 0; | ||||||
| } | } | ||||||
|   | |||||||
| @@ -162,7 +162,5 @@ main(int argc, char **argv) | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	success(TEST161_SUCCESS, SECRET, "/testbin/fileonlytest"); | 	success(TEST161_SUCCESS, SECRET, "/testbin/fileonlytest"); | ||||||
| 	// Exit may not be implemented. So crash. |  | ||||||
| 	crash_prog(); |  | ||||||
| 	return 0; | 	return 0; | ||||||
| } | } | ||||||
|   | |||||||
| @@ -75,8 +75,5 @@ main(int argc, char **argv) | |||||||
|  |  | ||||||
|  |  | ||||||
| 	success(TEST161_SUCCESS, SECRET, "/testbin/opentest"); | 	success(TEST161_SUCCESS, SECRET, "/testbin/opentest"); | ||||||
|  |  | ||||||
| 	// Exit may not be implemented. So crash. |  | ||||||
| 	crash_prog(); |  | ||||||
| 	return 0; | 	return 0; | ||||||
| } | } | ||||||
|   | |||||||
| @@ -100,7 +100,5 @@ main(int argc, char **argv) | |||||||
| 	nprintf("\n"); | 	nprintf("\n"); | ||||||
|  |  | ||||||
| 	secprintf(SECRET, MAGIC, "/testbin/readwritetest"); | 	secprintf(SECRET, MAGIC, "/testbin/readwritetest"); | ||||||
| 	// Exit may not be implemented. So crash. |  | ||||||
| 	crash_prog(); |  | ||||||
| 	return 0; | 	return 0; | ||||||
| } | } | ||||||
|   | |||||||
| @@ -60,7 +60,6 @@ doopen(const char *path, int openflags) | |||||||
| 	fd = open(path, openflags, 0664); | 	fd = open(path, openflags, 0664); | ||||||
| 	if (fd < 0) { | 	if (fd < 0) { | ||||||
| 		err(1, "%s", path); | 		err(1, "%s", path); | ||||||
| 		crash_prog(); |  | ||||||
| 	} | 	} | ||||||
| 	return fd; | 	return fd; | ||||||
| } | } | ||||||
| @@ -77,7 +76,6 @@ dodup2(int ofd, int nfd, const char *file) | |||||||
| 	} | 	} | ||||||
| 	if (r != nfd) { | 	if (r != nfd) { | ||||||
| 		errx(1, "%s: dup2: Expected %d, got %d", nfd, r); | 		errx(1, "%s: dup2: Expected %d, got %d", nfd, r); | ||||||
| 		crash_prog(); |  | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -102,12 +100,10 @@ mkfile(void) | |||||||
| 	r = write(fd, slogan, strlen(slogan)); | 	r = write(fd, slogan, strlen(slogan)); | ||||||
| 	if (r < 0) { | 	if (r < 0) { | ||||||
| 		err(1, "%s: write", INFILE); | 		err(1, "%s: write", INFILE); | ||||||
| 		crash_prog(); |  | ||||||
| 	} | 	} | ||||||
| 	if ((size_t)r != strlen(slogan)) { | 	if ((size_t)r != strlen(slogan)) { | ||||||
| 		errx(1, "%s: write: Short count (got %zd, expected %zu)", | 		errx(1, "%s: write: Short count (got %zd, expected %zu)", | ||||||
| 		     INFILE, r, strlen(slogan)); | 		     INFILE, r, strlen(slogan)); | ||||||
| 		crash_prog(); |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	doclose(fd, INFILE); | 	doclose(fd, INFILE); | ||||||
| @@ -126,16 +122,13 @@ chkfile(void) | |||||||
| 	r = read(fd, buf, sizeof(buf)); | 	r = read(fd, buf, sizeof(buf)); | ||||||
| 	if (r < 0) { | 	if (r < 0) { | ||||||
| 		err(1, "%s: read", OUTFILE); | 		err(1, "%s: read", OUTFILE); | ||||||
| 		crash_prog(); |  | ||||||
| 	} | 	} | ||||||
| 	if (r == 0) { | 	if (r == 0) { | ||||||
| 		errx(1, "%s: read: Unexpected EOF", OUTFILE); | 		errx(1, "%s: read: Unexpected EOF", OUTFILE); | ||||||
| 		crash_prog(); |  | ||||||
| 	} | 	} | ||||||
| 	if ((size_t)r != strlen(slogan)) { | 	if ((size_t)r != strlen(slogan)) { | ||||||
| 		errx(1, "%s: read: Short count (got %zd, expected %zu)", | 		errx(1, "%s: read: Short count (got %zd, expected %zu)", | ||||||
| 		     OUTFILE, r, strlen(slogan)); | 		     OUTFILE, r, strlen(slogan)); | ||||||
| 		crash_prog(); |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	doclose(fd, OUTFILE); | 	doclose(fd, OUTFILE); | ||||||
| @@ -155,7 +148,6 @@ cat(void) | |||||||
| 	pid = fork(); | 	pid = fork(); | ||||||
| 	if (pid < 0) { | 	if (pid < 0) { | ||||||
| 		err(1, "fork"); | 		err(1, "fork"); | ||||||
| 		crash_prog(); |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if (pid == 0) { | 	if (pid == 0) { | ||||||
| @@ -178,15 +170,12 @@ cat(void) | |||||||
| 	result = waitpid(pid, &status, 0); | 	result = waitpid(pid, &status, 0); | ||||||
| 	if (result == -1) { | 	if (result == -1) { | ||||||
| 		err(1, "waitpid"); | 		err(1, "waitpid"); | ||||||
| 		crash_prog(); |  | ||||||
| 	} | 	} | ||||||
| 	if (WIFSIGNALED(status)) { | 	if (WIFSIGNALED(status)) { | ||||||
| 		errx(1, "pid %d: Signal %d", (int)pid, WTERMSIG(status)); | 		errx(1, "pid %d: Signal %d", (int)pid, WTERMSIG(status)); | ||||||
| 		crash_prog(); |  | ||||||
| 	} | 	} | ||||||
| 	if (WIFEXITED(status) && WEXITSTATUS(status) != 0) { | 	if (WIFEXITED(status) && WEXITSTATUS(status) != 0) { | ||||||
| 		errx(1, "pid %d: Exit %d", (int)pid, WEXITSTATUS(status)); | 		errx(1, "pid %d: Exit %d", (int)pid, WEXITSTATUS(status)); | ||||||
| 		crash_prog(); |  | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -109,7 +109,5 @@ main(int argc, char *argv[]) | |||||||
|  |  | ||||||
| 	nprintf("\n"); | 	nprintf("\n"); | ||||||
| 	success(TEST161_SUCCESS, SECRET, "/testbin/sparsefile"); | 	success(TEST161_SUCCESS, SECRET, "/testbin/sparsefile"); | ||||||
| 	// Exit may not be implemented. So crash. |  | ||||||
| 	crash_prog(); |  | ||||||
| 	return 0; | 	return 0; | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user