Kaynağa Gözat

Add --nicelevel, to alter a programs priority before starting.

Adam Heath 25 yıl önce
ebeveyn
işleme
9d1b8a959f
4 değiştirilmiş dosya ile 24 ekleme ve 1 silme
  1. 5 0
      ChangeLog
  2. 2 0
      debian/changelog
  3. 3 0
      utils/start-stop-daemon.8
  4. 14 1
      utils/start-stop-daemon.c

+ 5 - 0
ChangeLog

@@ -1,3 +1,8 @@
+Sat Dec 23 23:28:52 CST 2000 Adam Heath <doogie@debian.org>
+
+  * utils/start-stop-daemon.c: Add --nicelevel, to alter a
+    programs priority before starting.
+
 Sat Dec 23 22:56:16 CST 2000 Adam Heath <doogie@debian.org>
 
   * main/dpkg.8: Document that --largemem is the default, and that

+ 2 - 0
debian/changelog

@@ -1,5 +1,7 @@
 dpkg (1.8.0) unstable; urgency=low
 
+  * Add --nicelevel to start-stop-daemon, to alter a programs priority
+    before starting.  Closes: #65191.
   * Document that --largemem is the default, and that the test point is
     24 megs.  Closes: #65607.
   * Document that --set-selections does not actually install any

+ 3 - 0
utils/start-stop-daemon.8

@@ -148,6 +148,9 @@ reason. This is a last resort, and is only meant for programs that either
 make no sense forking on their own, or where it's not feasible to add the
 code for it to do this itself.
 .TP
+-BR -N | --nicelevel
+This alters the prority of the process before starting it.
+.TP
 .BR -m | --make-pidfile
 Used when starting a program that does not create its own pid file. This
 option will make

+ 14 - 1
utils/start-stop-daemon.c

@@ -77,6 +77,7 @@ static char *execname = NULL;
 static char *startas = NULL;
 static const char *pidfile = NULL;
 static const char *progname = "";
+static int nicelevel = 0;
 
 static struct stat exec_stat;
 #if defined(OSHURD)
@@ -177,6 +178,7 @@ Options (at least one of --exec|--pidfile|--user is required):
   -n|--name <process-name>      stop processes with this name\n\
   -s|--signal <signal>          signal to send (default TERM)\n\
   -a|--startas <pathname>       program to start (default is <executable>)\n\
+  -N|--nicelevel <incr>         add incr to the process's nice level\n\
   -b|--background               force the process to detach\n\
   -m|--make-pidfile             create the pidfile before starting\n\
   -t|--test                     test mode, don't do anything\n\
@@ -256,6 +258,7 @@ parse_options(int argc, char * const *argv)
 		{ "verbose",	  0, NULL, 'v'},
 		{ "exec",	  1, NULL, 'x'},
 		{ "chuid",	  1, NULL, 'c'},
+		{ "nicelevel",	  1, NULL, 'N'},
 		{ "background",   0, NULL, 'b'},
 		{ "make-pidfile", 0, NULL, 'm'},
 		{ NULL,		0, NULL, 0}
@@ -263,7 +266,7 @@ parse_options(int argc, char * const *argv)
 	int c;
 
 	for (;;) {
-		c = getopt_long(argc, argv, "HKSVa:n:op:qr:s:tu:vx:c:bm",
+		c = getopt_long(argc, argv, "HKSVa:n:op:qr:s:tu:vx:c:N:bm",
 				longopts, (int *) 0);
 		if (c == -1)
 			break;
@@ -320,6 +323,9 @@ parse_options(int argc, char * const *argv)
 		case 'r':  /* --chroot /new/root */
 			changeroot = optarg;
 			break;
+		case 'N':  /* --nice */
+			nicelevel = atoi(optarg);
+			break;
 		case 'b':  /* --background */
 			background = 1;
 			break;
@@ -657,6 +663,8 @@ main(int argc, char **argv)
 		}
 		if (changeroot != NULL)
 			printf(" in directory %s", changeroot);
+		if (nicelevel)
+			printf(", and add %i to the priority", nicelevel);
 		printf(".\n");
 		exit(0);
 	}
@@ -705,6 +713,11 @@ main(int argc, char **argv)
 		dup(fd); /* stdout */
 		dup(fd); /* stderr */
 	}
+	if (nicelevel) {
+		if (nice(nicelevel))
+			fatal("Unable to alter nice level by %i: %s", nicelevel,
+				strerror(errno));
+	}
 	if (mpidfile && pidfile != NULL) { /* user wants _us_ to make the pidfile :) */
 		FILE *pidf = fopen(pidfile, "w");
 		pid_t pidt = getpid();