Browse Source

When using '-m' on linux, send the forked process a SIGTERM on exit

Kano 14 years ago
parent
commit
f9af5acf13
1 changed files with 18 additions and 3 deletions
  1. 18 3
      cgminer.c

+ 18 - 3
cgminer.c

@@ -221,6 +221,7 @@ static int include_count = 0;
 
 #if defined(unix)
 	static char *opt_stderr_cmd = NULL;
+	static int forkpid = 0;
 #endif // defined(unix)
 
 bool ping = true;
@@ -4121,6 +4122,13 @@ void quit(int status, const char *format, ...)
 	fprintf(stderr, "\n");
 	fflush(stderr);
 
+#if defined(unix)
+	if (forkpid > 0) {
+		kill(forkpid, SIGTERM);
+		forkpid = 0;
+	}
+#endif
+
 	exit(status);
 }
 
@@ -4265,14 +4273,14 @@ out:
 		}
 
 		// Fork a child process
-		r = fork();
-		if (r<0) {
+		forkpid = fork();
+		if (forkpid<0) {
 			perror("fork - failed to fork child process for --monitor");
 			exit(1);
 		}
 
 		// Child: launch monitor command
-		if (0==r) {
+		if (0==forkpid) {
 			// Make stdin read end of pipe
 			r = dup2(pfd[0], 0);
 			if (r<0) {
@@ -4839,5 +4847,12 @@ begin_bench:
 		free(block);
 	}
 
+#if defined(unix)
+	if (forkpid > 0) {
+		kill(forkpid, SIGTERM);
+		forkpid = 0;
+	}
+#endif
+
 	return 0;
 }