Преглед на файлове

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

Adam Heath преди 25 години
родител
ревизия
9d1b8a959f
променени са 4 файла, в които са добавени 24 реда и са изтрити 1 реда
  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>
 Sat Dec 23 22:56:16 CST 2000 Adam Heath <doogie@debian.org>
 
 
   * main/dpkg.8: Document that --largemem is the default, and that
   * 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
 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
   * Document that --largemem is the default, and that the test point is
     24 megs.  Closes: #65607.
     24 megs.  Closes: #65607.
   * Document that --set-selections does not actually install any
   * 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
 make no sense forking on their own, or where it's not feasible to add the
 code for it to do this itself.
 code for it to do this itself.
 .TP
 .TP
+-BR -N | --nicelevel
+This alters the prority of the process before starting it.
+.TP
 .BR -m | --make-pidfile
 .BR -m | --make-pidfile
 Used when starting a program that does not create its own pid file. This
 Used when starting a program that does not create its own pid file. This
 option will make
 option will make

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

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