david@ukma.UUCP (David Herron, NPR Lover) (10/21/85)
Sigh... No sooner than I post it then I find problems... First I find that if its run under crontab then it will renice almost everything. Second I find that csh has 'limit' as a builtin. Oh well. Change its name to 'cplim' then. Third is, its a pain to use by hand because it doesn't search for the file to exec. So fix it to use execvp(). Fixes follow: ------------------------> Cut Here <------------------------------- *** limit.c.orig Fri Oct 18 20:35:22 1985 --- limit.c Mon Oct 21 15:25:21 1985 *************** *** 65,70 } loadav(avg); lastpr = 200; if((pid=fork()) == 0) { strcpy(buf, argv[1]); s = rindex(argv[1], '/'); --- 65,74 ----- } loadav(avg); lastpr = 200; + setpgrp(0, getpid()); /* For running from cron, + * otherwise EVERYTHING will + * be reniced. + */ if((pid=fork()) == 0) { strcpy(buf, argv[1]); s = rindex(argv[1], '/'); *************** *** 71,77 argv[1] = ++s; setuid(getuid()); setgid(getgid()); ! execve(buf, &argv[1], environ); sprintf(buf, "Unknown program: %s\n", argv[1]); perror(buf); exit(1); --- 75,81 ----- argv[1] = ++s; setuid(getuid()); setgid(getgid()); ! execvp(buf, &argv[1]); sprintf(buf, "Unknown program: %s\n", argv[1]); perror(buf); exit(1); *************** *** 78,83 } setuid(0); setgid(0); signal(SIGCHLD, leave); signal(SIGINT, SIG_IGN); signal(SIGQUIT, SIG_IGN); --- 82,91 ----- } setuid(0); setgid(0); + /* + * The intent is for SIGINT or SIGQUIT to cause our children + * to exit, and that exit causing a SIGCHLD to be sent here. + */ signal(SIGCHLD, leave); signal(SIGINT, SIG_IGN); signal(SIGQUIT, SIG_IGN); ------------------> Cut Again <----------------------------------------- *** limit.1.orig Fri Oct 18 20:35:20 1985 --- limit.1 Mon Oct 21 15:27:09 1985 *************** *** 1,6 .TH LIMIT 1L "University of Kentucky" "4.2BSD" .SH NAME ! limit \- limit processor usage of a program by renicing .SH USAGE limit .I file --- 1,6 ----- .TH LIMIT 1L "University of Kentucky" "4.2BSD" .SH NAME ! cplim \- limit processor usage of a program by renicing .SH USAGE cplim .I file *************** *** 2,8 .SH NAME limit \- limit processor usage of a program by renicing .SH USAGE ! limit .I file [ .I args --- 2,8 ----- .SH NAME cplim \- limit processor usage of a program by renicing .SH USAGE ! cplim .I file [ .I args *************** *** 9,15 ] .SH DESCRIPTION .LP ! Limit(1) is meant to limit processor usage by background processes. It fork()'s and exec()'s .I file with --- 9,15 ----- ] .SH DESCRIPTION .LP ! Cplim(1) is meant to limit processor usage by background processes. It fork()'s and exec()'s .I file with *************** *** 29,35 .ft L #! /bin/sh ! exec /usr/local/limit /usr/lib/news/rnews .ft P .RE --- 29,35 ----- .ft L #! /bin/sh ! exec /usr/local/cplim /usr/lib/news/rnews .ft P .RE