debian/0000755000000000000000000000000011373003320007156 5ustar debian/and.init.d0000644000000000000000000002011011373002115011022 0ustar #!/bin/sh ### BEGIN INIT INFO # Provides: and # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: AutoNice daemon ### END INIT INFO PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/usr/sbin/and # Introduce the server's location here NAME=and # Introduce the short server's name here DESC="autonice daemon" # Introduce a short description here LOGDIR=/var/log/and # Log directory to use PIDFILE=/var/run/$NAME.pid test -x $DAEMON || exit 0 . /lib/lsb/init-functions # Default options, these can be overriden by the information # at /etc/default/$NAME DAEMON_OPTS="" # Additional options given to the server DIETIME=2 # Time to wait for the server to die, in seconds # If this value is set too low you might not # let some servers to die gracefully and # 'restart' will not work #STARTTIME=2 # Time to wait for the server to start, in seconds # If this value is set each time the server is # started (on start or restart) the script will # stall to try to determine if it is running # If it is not set and the server takes time # to setup a pid file the log message might # be a false positive (says it did not start # when it actually did) LOGFILE=$LOGDIR/$NAME.log # Server logfile #DAEMONUSER=and # Users to run the daemons as. If this value # is set start-stop-daemon will chuid the server # Include defaults if available if [ -f /etc/default/$NAME ] ; then . /etc/default/$NAME fi # Use this if you want the user to explicitly set 'RUN' in # /etc/default/ #if [ "x$RUN" != "xyes" ] ; then # log_failure_msg "$NAME disabled, please adjust the configuration to your needs " # log_failure_msg "and then set RUN to 'yes' in /etc/default/$NAME to enable it." # exit 0 #fi # Check that the user exists (if we set a user) # Does the user exist? if [ -n "$DAEMONUSER" ] ; then if getent passwd | grep -q "^$DAEMONUSER:"; then # Obtain the uid and gid DAEMONUID=`getent passwd |grep "^$DAEMONUSER:" | awk -F : '{print $3}'` DAEMONGID=`getent passwd |grep "^$DAEMONUSER:" | awk -F : '{print $4}'` else log_failure_msg "The user $DAEMONUSER, required to run $NAME does not exist." exit 0 fi fi set -e running_pid() { # Check if a given process pid's cmdline matches a given name pid=$1 name=$2 [ -z "$pid" ] && return 1 [ ! -d /proc/$pid ] && return 1 cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1` # Is this the expected server [ "$cmd" != "$name" ] && return 1 return 0 } running() { # Check if the process is running looking at /proc # (works for all users) pid=$( /bin/pidof $DAEMON ) if [ "${pid}" = "" ] then return 1 else return 0 fi # No pidfile, probably no daemon present #[ ! -f "$PIDFILE" ] && return 1 #pid=`cat $PIDFILE` #running_pid $pid $DAEMON || return 1 #return 0 } start_server() { # Start the process using the wrapper if [ -z "$DAEMONUSER" ] ; then start-stop-daemon --start --make-pidfile --pidfile $PIDFILE --exec $DAEMON >/dev/null 2>&1 # Write correct pid into $PIDFILE pid=$( pidof $DAEMON ) echo "${pid}" > $PIDFILE errcode=$? fi return $errcode } stop_server() { # Stop the process using the wrapper if [ -z "$DAEMONUSER" ] ; then killproc -p $PIDFILE $DAEMON errcode=$? else # if we are using a daemonuser then look for process that match start-stop-daemon --stop --quiet --pidfile $PIDFILE \ --user $DAEMONUSER \ --exec $DAEMON errcode=$? fi return $errcode } reload_server() { [ ! -f "$PIDFILE" ] && return 1 pid=pidofproc $PIDFILE # This is the daemon's pid # Send a SIGHUP kill -1 $pid return $? } force_stop() { # Force the process to die killing it manually [ ! -e "$PIDFILE" ] && return if running ; then kill -15 $pid # Is it really dead? sleep "$DIETIME"s if running ; then kill -9 $pid sleep "$DIETIME"s if running ; then echo "Cannot kill $NAME (pid=$pid)!" exit 0 fi fi fi rm -f $PIDFILE } case "$1" in start) log_daemon_msg "Starting $DESC " "$NAME" # Check if it's running first if running ; then log_progress_msg "apparently already running" log_end_msg 0 exit 0 fi if start_server ; then # NOTE: Some servers might die some time after they start, # this code will detect this issue if STARTTIME is set # to a reasonable value [ -n "$STARTTIME" ] && sleep $STARTTIME # Wait some time if running ; then # It's ok, the server started and is running log_end_msg 0 else # It is not running after we did start log_end_msg 1 fi else # Either we could not start it log_end_msg 1 fi ;; stop) log_daemon_msg "Stopping $DESC" "$NAME" if running ; then # Only stop the server if we see it running errcode=0 stop_server || errcode=$? log_end_msg $errcode else # If it's not running don't do anything log_progress_msg "apparently not running" log_end_msg 0 exit 0 fi ;; force-stop) # First try to stop gracefully the program $0 stop if running; then # If it's still running try to kill it more forcefully log_daemon_msg "Stopping (force) $DESC" "$NAME" errcode=0 force_stop || errcode=$? log_end_msg $errcode fi ;; restart|force-reload) log_daemon_msg "Restarting $DESC" "$NAME" errcode=0 stop_server || errcode=$? # Wait some sensible amount, some server need this [ -n "$DIETIME" ] && sleep $DIETIME start_server || errcode=$? [ -n "$STARTTIME" ] && sleep $STARTTIME running || errcode=$? log_end_msg $errcode ;; status) log_daemon_msg "Checking status of $DESC" "$NAME" if running ; then log_progress_msg "running" log_end_msg 0 else log_progress_msg "apparently not running" log_end_msg 1 exit 0 fi ;; # Use this if the daemon cannot reload reload) log_warning_msg "Reloading $NAME daemon: not implemented, as the daemon" log_warning_msg "cannot re-read the config file (use restart)." ;; # And this if it cann #reload) # # If the daemon can reload its config files on the fly # for example by sending it SIGHUP, do it here. # # If the daemon responds to changes in its config file # directly anyway, make this a do-nothing entry. # # log_daemon_msg "Reloading $DESC configuration files" "$NAME" # if running ; then # reload_server # if ! running ; then # Process died after we tried to reload # log_progress_msg "died on reload" # log_end_msg 1 # exit 0 # fi # else # log_progress_msg "server is not running" # log_end_msg 1 # exit 0 # fi #;; *) N=/etc/init.d/$NAME echo "Usage: $N {start|stop|force-stop|restart|force-reload|status}" >&2 exit 1 ;; esac exit 0 debian/compat0000644000000000000000000000000211327116544010370 0ustar 5 debian/source/0000755000000000000000000000000011327124673010474 5ustar debian/source/format0000644000000000000000000000001411373001146011670 0ustar 3.0 (quilt) debian/rules0000755000000000000000000000041111327133027010241 0ustar #!/usr/bin/make -f #export DH_VERBOSE=1 %: dh $@ override_dh_installchangelogs: dh_installchangelogs CHANGELOG debian/patches/0000755000000000000000000000000011327141203010607 5ustar debian/patches/000_watch.diff0000644000000000000000000000062711327125545013146 0ustar --- and-1.2.2.orig/watch +++ and-1.2.2/watch @@ -0,0 +1,8 @@ +# Example watch control file for uscan +# Rename this file to "watch" and then you can run the "uscan" command +# to check for upstream updates and more. +version=2 + +# Site Directory Pattern Version Script +#http://and.sourceforge.net/and-(.*)\.tar\.gz debian uupdate +http://heanet.dl.sourceforge.net/and/and-(.*)\.tar\.gz debian uupdate debian/patches/000_and.8.man.diff0000644000000000000000000000252211327137230013510 0ustar # # Descripton: Fix manpages minus ("-") not escaped. (applied on version 1.2.2-1) # From: Jerome Warnier # --- and-1.2.2.orig/and.8.man +++ and-1.2.2/and.8.man @@ -5,7 +5,7 @@ .SH "SYNOPSIS" .B and -.RB [ \-htvsx ] +.RB [ \-htvsxf ] .RB [ \-i .IR interval ] .RB [ \-c @@ -42,12 +42,12 @@ A CPU server is dedicated to a certain group, but others may also use it when it's idle. Just define default nice levels of e.g. 18 and a lower -nice level for the privilegued group, say nice level 12. +nice level for the privileged group, say nice level 12. A certain web browser who shall remain unnamed tends to go berserk once in a while. You can configure .B and -to kill -9 it after e.g. 20 CPU minutes. +to kill \-9 it after e.g. 20 CPU minutes. .SH "COMMAND\-LINE OPTIONS" @@ -73,7 +73,7 @@ Sets the interval between nice level checks. This flag overrides the interval specified in the configuration file, if any. The default interval of .I 60 -seconds is used if neither -i nor an interval directive in the configuration +seconds is used if neither \-i nor an interval directive in the configuration file is given. .TP 0.5i @@ -101,6 +101,10 @@ Run in full operational mode, i.e. really renice or kill things. This is the default. +.TP 0.5i +.B \-f +Foreground mode. Don't daemonize. + .SH "SIGNALS" On debian/patches/000_and-GNU_kFreeBSD.c.diff0000644000000000000000000001205411327140523015105 0ustar # # Description: Fix for FTBFS on GNU/kFreeBSD # Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=562295 # From: Cyril Brulebois # Last-Update: 2010-01-24 # --- a/Makefile +++ b/Makefile @@ -89,13 +89,14 @@ MANPAGES=and.8 and.conf.5 and.priorities # # Determine architecture from uname(1) # -ARCH=$(shell uname) +ARCH=$(shell uname|sed 's,/,_,') # # Architecture-dependent settings: ANSI C compiler and linker # +DEBIAN_GCC = gcc -ansi -pedantic -Wall -g ifeq (${ARCH},Linux) - CC = gcc -ansi -pedantic -Wall -g + CC = $(DEBIAN_GCC) LD = gcc LIBS = else @@ -127,7 +128,12 @@ ifeq (${ARCH},IRIX64) LD = cc else ifeq (${ARCH},GNU) - CC = gcc -ansi -pedantic -Wall -g + CC = $(DEBIAN_GCC) + LD = gcc + LIBS = +else +ifeq (${ARCH},GNU_kFreeBSD) + CC = $(DEBIAN_GCC) LD = gcc LIBS = else @@ -143,6 +149,7 @@ endif endif endif endif +endif # @@ -189,6 +196,8 @@ and-SunOS.o: and.h and-OSF1.c and-GNU.o: and.h and-GNU.c $(CC) -c and-GNU.c +and-GNU_kFreeBSD.o: and.h and-GNU_kFreeBSD.c + $(CC) -c and-GNU_kFreeBSD.c # # Create script for SysV init --- /dev/null +++ b/and-GNU_kFreeBSD.c @@ -0,0 +1,136 @@ +/* + + AND auto nice daemon - renice programs according to their CPU usage. + Copyright (C) 1999-2003 Patrick Schemitz + http://and.sourceforge.net/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include /* kernel interrupt frequency: HZ */ + + +#include "and.h" + + +/* + + AND -- auto-nice daemon/GNU version. + + GNU-specific AND version. Makes excessive use of the GNU + /proc filesystem and is not portable. + + 1999-2003 Patrick Schemitz, + http://and.sourceforge.net/ + +*/ + + +static DIR *linux_procdir = 0; + + +static struct and_procent linux_proc; + + +int linux_readproc (char *fn) +{ + /* Scan /proc//stat file. Format described in proc(5). + l1: pid comm state ppid + l2: pgrp session tty tpgid + l3: flags minflt cminflt majflt cmajflt + l4: utime stime cutime cstime + l5: counter priority + */ + FILE* f; + int i; + long li; + long unsigned u, ujf, sjf; + char state; + char buffer [1024]; + if (!(f = fopen(fn,"rt"))) return 0; + fscanf(f,"%d %1023s %c %d",&(linux_proc.pid),buffer,&state,&(linux_proc.ppid)); + fscanf(f,"%d %d %d %d",&i,&i,&i,&i); + fscanf(f,"%lu %lu %lu %lu %lu",&u,&u,&u,&u,&u); + fscanf(f,"%lu %lu %ld %ld",&ujf,&sjf,&li,&li); + fscanf(f,"%ld %d",&li,&(linux_proc.nice)); + i = feof(f); + fclose(f); + if (i) return 0; + if (state == 'Z') return 0; /* ignore zombies */ + ujf += sjf; /* take into account both usr and sys time */ + ujf /= 60; /* convert jiffies to seconds */ + linux_proc.utime = ujf > INT_MAX ? INT_MAX: (int) ujf; + buffer[strlen(buffer)-1] = 0; /* remove () around command name */ + strncpy(linux_proc.command,&buffer[1],1023); + linux_proc.command[1023] = 0; + and_printf(3, "GNU: process %s pid: %d ppid: %d\n", + linux_proc.command, linux_proc.pid, linux_proc.ppid); + return 1; +} + + +struct and_procent *linux_getnext () +{ + char name [1024]; + struct dirent *entry; + struct stat dirstat; + if (!linux_procdir) return NULL; + while ((entry = readdir(linux_procdir)) != NULL) { /* omit . .. apm bus... */ + if (isdigit(entry->d_name[0])) break; + } + if (!entry) return NULL; + /* stat() /proc/ directory to get uid/gid */ + snprintf(name, 1024, "/proc/%s",entry->d_name); + if (stat(name,&dirstat)) return linux_getnext(); + /* read the job's stat "file" to get command, nice level, etc */ + snprintf(name, 1024, "/proc/%s/stat",entry->d_name); + if (!linux_readproc(name)) return linux_getnext(); + linux_proc.uid = dirstat.st_uid; + linux_proc.gid = dirstat.st_gid; + return &linux_proc; +} + + +struct and_procent *linux_getfirst () +{ + if (linux_procdir) { + rewinddir(linux_procdir); + } else { + linux_procdir = opendir("/proc"); + if (!linux_procdir) { + and_printf(0,"cannot open /proc, aborting.\n"); + abort(); + } + } + return linux_getnext(); +} + + +int main (int argc, char** argv) +{ + and_setprocreader(&linux_getfirst,&linux_getnext); + return and_main(argc,argv); +} debian/patches/000_Makefile.diff0000644000000000000000000000403511327136414013547 0ustar # # Description: Fix for FTBFS on Debian GNU/Hurd # Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=532698 # From: Barry deFreese # --- and-1.2.2.orig/Makefile +++ and-1.2.2/Makefile @@ -16,17 +16,17 @@ # (and.init.debian for Debian GNU/Linux or and.init for others; # leave empty for BSD!) # -INITSCRIPT=and.init +INITSCRIPT=and.init.debian # # Target directories. Examples for common configurations are # given below. # -PREFIX=/usr/local -INSTALL_ETC=$(PREFIX)/etc -INSTALL_INITD=/etc/init.d -INSTALL_SBIN=$(PREFIX)/sbin -INSTALL_MAN=$(PREFIX)/man +#PREFIX=/usr/local +#INSTALL_ETC=$(PREFIX)/etc +#INSTALL_INITD=/etc/init.d +#INSTALL_SBIN=$(PREFIX)/sbin +#INSTALL_MAN=$(PREFIX)/man # typical OpenBSD or FreeBSD configuration #PREFIX=/usr/local @@ -36,11 +36,11 @@ #INSTALL_MAN=$(PREFIX)/man # typical Debian or SuSE 7.x configuration -#PREFIX=/usr -#INSTALL_ETC=/etc -#INSTALL_INITD=/etc/init.d -#INSTALL_SBIN=$(PREFIX)/sbin -#INSTALL_MAN=$(PREFIX)/share/man +PREFIX=/usr +INSTALL_ETC=/etc +INSTALL_INITD=/etc/init.d +INSTALL_SBIN=$(PREFIX)/sbin +INSTALL_MAN=$(PREFIX)/share/man # typical SuSE 6.x configuration #PREFIX=/usr @@ -126,6 +126,11 @@ CC = cc LD = cc else +ifeq (${ARCH},GNU) + CC = gcc -ansi -pedantic -Wall -g + LD = gcc + LIBS = +else # unsupported architecture CC = false LD = false @@ -137,6 +142,7 @@ endif endif endif +endif # @@ -180,6 +186,8 @@ and-SunOS.o: and.h and-OSF1.c $(CC) -c and-OSF1.c -o and-SunOS.o +and-GNU.o: and.h and-GNU.c + $(CC) -c and-GNU.c # @@ -215,7 +223,6 @@ # Install and under $(PREFIX)/bin etc. # install: and $(INITSCRIPT) - strip and #-mkdir $(PREFIX) -mkdir -p $(DESTDIR)$(INSTALL_SBIN) -mkdir -p $(DESTDIR)$(INSTALL_ETC) @@ -243,7 +250,6 @@ $(INSTALL) -m 0644 and.priorities.5 $(DESTDIR)$(INSTALL_MAN)/man5 simpleinstall: and and.init - strip and mkdir -p $(DESTDIR)$(INSTALL_SBIN) $(DESTDIR)$(INSTALL_ETC) mkdir -p $(DESTDIR)$(INSTALL_INITD) mkdir -p $(DESTDIR)$(INSTALL_MAN)/man5 $(DESTDIR)$(INSTALL_MAN)/man8 debian/patches/000_and.priorities.5.man.diff0000644000000000000000000000216411327137243015703 0ustar # # Descripton: Fix manpages minus ("-") not escaped. (applied on version 1.2.2-1) # From: Jerome Warnier # --- and-1.2.2.orig/and.priorities.5.man +++ and-1.2.2/and.priorities.5.man @@ -104,7 +104,7 @@ The nice level after lv1time CPU time was used by the command. Positive numbers and 0 are interpreted as nice levels; negative numbers are interpreted as signals to be sent to the command. A "nice level" of -19 will almost stop the job, -9 will actually kill it. (Like in kill -9.) +19 will almost stop the job, \-9 will actually kill it. (Like in kill \-9.) lv1time can be set in .I /etc/and.conf @@ -140,7 +140,7 @@ # Netscape sometimes goes berserk, we must stop it .br -* * netscape * 4 -9 -9 +* * netscape * 4 \-9 \-9 .br # Most hosts are free for everyone but some are @@ -153,7 +153,7 @@ .br * * * * 8 12 16 .br -# ... or, more radical: * * * * -9 -9 -9 +# ... or, more radical: * * * * \-9 \-9 \-9 .br * foo * * 4 8 12 .br @@ -179,7 +179,7 @@ .br # (owned by grid) is left alone. .br -* * grid_master * -9 -9 -9 +* * grid_master * \-9 \-9 \-9 .br grid * grid_master * 0 0 0 .br debian/patches/000_highpriostart.c.diff0000644000000000000000000000540111327136602015137 0ustar # # Description: highpriostart wrapper # Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=363065 # From: Patrick Schemitz # --- and-1.2.2.orig/highpriostart.c +++ and-1.2.2/highpriostart.c @@ -0,0 +1,85 @@ +#include +#include +#include +#include +#include + + +/********************************************************************* + + High priority task starter. + + USE AT OWN RISK! THIS PROGRAM COMES WITHOUT *ANY* + WARRANTY WHATSOEVER! + + This program executes a program (as defined in PROGRAM) + at a given (usually higher than normal) priority (as + defined in PRIORITY). Edit PROGRAM and PRIORITY to meet + your needs. Sensible programs may be: cdrecord, MP3 or + DVD players, etc. Sensible priorities range from -1 to -5. + + The program itself is *not* started SUID root but as the + user invoking the task starter. Root privilegues are used + *only* to set the desired priority (aka. nice level). + + Compile and install as follows: + # gcc highpriostart.c -o startwhatever + # cp startwhatever /usr/local/bin + # chmod +s /usr/local/bin/startwhatever + + 2002, Patrick Schemitz + This program is released under the GNU Public License (GPL). + +*********************************************************************/ + + +/* The program to start with higher priority, with full path. */ +#define PROGRAM "/usr/X11R6/bin/xclock" + + +/* The desired priority, ranging from 19 (very low) to -20 (too + high). Sensible values from 0 (normal) to maybe -5 (pretty + high). + + WARNING: + + DO NOT SET THIS TO -20, OR YOU WILL SEVERELY AND PERMANENTLY + DAMAGE YOUR SYSTEM! Setting the priority too high causes your + program to interfere with very important system tasks (like + the swapper or the RAID daemons). Messing with the RAID + daemons is a *VERY* bad idea! +*/ +#define PRIORITY -1 + + +/* You can increase this if your program can sensibly handle a + very large number of parameters (like tar, ls, etc); normally + the default (1024) should be plenty. +*/ +#define MAX_ARGS 1024 + + +int main (int argc, char **argv) +{ + int i; + pid_t pid; + char* args [MAX_ARGS+1] = { PROGRAM, NULL }; + /* first thing to do: drop privilegues */ + seteuid(getuid()); + /* copy over arguments */ + for (i=1; i # --- and-1.2.2.orig/and.c +++ and-1.2.2/and.c @@ -156,6 +156,7 @@ struct { char hostname [512]; int test; + int foreground; char *program; char *config_file; char *database_file; @@ -179,6 +180,7 @@ void set_defaults (int argc, char **argv) { and_config.test = 0; + and_config.foreground = 0; and_config.verbose = 0; and_config.to_stdout = 0; and_config.program = argv[0]; @@ -884,7 +886,7 @@ void and_getopt (int argc, char** argv) { -#define OPTIONS "c:d:i:vstxh" +#define OPTIONS "c:d:i:vstxfh" int opt, value; opt = getopt(argc,argv,OPTIONS); while (opt != -1) { @@ -921,12 +923,16 @@ case 'x': and_config.test = 0; break; + case 'f': + and_config.foreground = 1; + break; case 'h': printf("auto nice daemon version %s (%s)\n" "%s [-v] [-s] [-t] [-x] [-c configfile] [-d databasefile] [-i interval]\n" "-v: verbosity -v, -vv, -vvv etc\n" "-s: log to stdout (default is syslog, or debug.and)\n" "-x: really execute renices and kills (default)\n" + "-f: don't daemonize, stay in foreground\n" "-t: test configuration (don't really renice)\n" "-i interval: loop interval in seconds (default %i)\n" "-c configfile: specify config file (default %s)\n" @@ -986,7 +992,11 @@ if (and_config.test) { and_worker(); } else { - if (fork() == 0) and_worker(); + if (and_config.foreground) { + and_worker(); + } else { + if (fork() == 0) and_worker(); + } } return 0; } debian/patches/000_and.conf.5.man.diff0000644000000000000000000000075411327134551014441 0ustar # # Description: Fix typo in '/usr/share/man/man5/and.conf.5.gz' # Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=310360 # From: A Costa # Forwarded: Patrick Schemitz # --- and-1.2.2.orig/and.conf.5.man +++ and-1.2.2/and.conf.5.man @@ -199,7 +199,7 @@ .br # Hosts bar, baz belong to group foo, which .br -# is privilegued on these hosts, so override +# is privileged on these hosts, so override .br # affinity. (Note regexp!) .br debian/patches/000_and-GNU_Hurd.c.diff0000644000000000000000000001020111327140177014417 0ustar # # Description: Fix for FTBFS on Debian GNU/Hurd # Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=532698 # From: Barry deFreese # --- and-1.2.2.orig/and-GNU.c +++ and-1.2.2/and-GNU.c @@ -0,0 +1,136 @@ +/* + + AND auto nice daemon - renice programs according to their CPU usage. + Copyright (C) 1999-2003 Patrick Schemitz + http://and.sourceforge.net/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include /* kernel interrupt frequency: HZ */ + + +#include "and.h" + + +/* + + AND -- auto-nice daemon/GNU version. + + GNU-specific AND version. Makes excessive use of the GNU + /proc filesystem and is not portable. + + 1999-2003 Patrick Schemitz, + http://and.sourceforge.net/ + +*/ + + +static DIR *linux_procdir = 0; + + +static struct and_procent linux_proc; + + +int linux_readproc (char *fn) +{ + /* Scan /proc//stat file. Format described in proc(5). + l1: pid comm state ppid + l2: pgrp session tty tpgid + l3: flags minflt cminflt majflt cmajflt + l4: utime stime cutime cstime + l5: counter priority + */ + FILE* f; + int i; + long li; + long unsigned u, ujf, sjf; + char state; + char buffer [1024]; + if (!(f = fopen(fn,"rt"))) return 0; + fscanf(f,"%d %1023s %c %d",&(linux_proc.pid),buffer,&state,&(linux_proc.ppid)); + fscanf(f,"%d %d %d %d",&i,&i,&i,&i); + fscanf(f,"%lu %lu %lu %lu %lu",&u,&u,&u,&u,&u); + fscanf(f,"%lu %lu %ld %ld",&ujf,&sjf,&li,&li); + fscanf(f,"%ld %d",&li,&(linux_proc.nice)); + i = feof(f); + fclose(f); + if (i) return 0; + if (state == 'Z') return 0; /* ignore zombies */ + ujf += sjf; /* take into account both usr and sys time */ + ujf /= 60; /* convert jiffies to seconds */ + linux_proc.utime = ujf > INT_MAX ? INT_MAX: (int) ujf; + buffer[strlen(buffer)-1] = 0; /* remove () around command name */ + strncpy(linux_proc.command,&buffer[1],1023); + linux_proc.command[1023] = 0; + and_printf(3, "GNU: process %s pid: %d ppid: %d\n", + linux_proc.command, linux_proc.pid, linux_proc.ppid); + return 1; +} + + +struct and_procent *linux_getnext () +{ + char name [1024]; + struct dirent *entry; + struct stat dirstat; + if (!linux_procdir) return NULL; + while ((entry = readdir(linux_procdir)) != NULL) { /* omit . .. apm bus... */ + if (isdigit(entry->d_name[0])) break; + } + if (!entry) return NULL; + /* stat() /proc/ directory to get uid/gid */ + snprintf(name, 1024, "/proc/%s",entry->d_name); + if (stat(name,&dirstat)) return linux_getnext(); + /* read the job's stat "file" to get command, nice level, etc */ + snprintf(name, 1024, "/proc/%s/stat",entry->d_name); + if (!linux_readproc(name)) return linux_getnext(); + linux_proc.uid = dirstat.st_uid; + linux_proc.gid = dirstat.st_gid; + return &linux_proc; +} + + +struct and_procent *linux_getfirst () +{ + if (linux_procdir) { + rewinddir(linux_procdir); + } else { + linux_procdir = opendir("/proc"); + if (!linux_procdir) { + and_printf(0,"cannot open /proc, aborting.\n"); + abort(); + } + } + return linux_getnext(); +} + + +int main (int argc, char** argv) +{ + and_setprocreader(&linux_getfirst,&linux_getnext); + return and_main(argc,argv); +} debian/patches/series0000644000000000000000000000026711327141203012031 0ustar 000_and.8.man.diff 000_and.c.diff 000_and.conf.5.man.diff 000_and.priorities.5.man.diff 000_highpriostart.c.diff 000_Makefile.diff 000_and-GNU_Hurd.c.diff 000_and-GNU_kFreeBSD.c.diff debian/copyright0000644000000000000000000000253611327132441011125 0ustar Format-Specification: http://svn.debian.org/wsvn/dep/web/deps/dep5.mdwn?op=file&rev=59 Upstream-Name: and Upstream-Maintainer: Patrick Schemitz Upstream-Source: http://sourceforge.net/projects/and/files/ Files: * Copyright: 1999-2004 Patrick Schemitz License: GPL-2 On Debian systems the full text of the GNU General Public License can be found in the `/usr/share/common-licenses/GPL-2' file. Files: and.init.debian Copyright: 2001, Miquel van Smoorenburg 2001, Ian Murdock 2001, Andras Bali License: GPL-2 On Debian systems the full text of the GNU General Public License can be found in the `/usr/share/common-licenses/GPL-2' file. Files: debian/* Copyright: 2001-2002, Andras Bali 2004-2007, Jerome Warnier 2008, Petter Reinholdtsen 2009, Barry deFreese 2010, Dario Minnucci License: GPL-2 On Debian systems the full text of the GNU General Public License can be found in the `/usr/share/common-licenses/GPL-2' file. debian/changelog0000644000000000000000000001117511373003276011047 0ustar and (1.2.2-4.1) unstable; urgency=low * Non-maintainer upload. * Fix bashism in init file (Closes: #580014). Thanks to Jon Daley for the patch. -- Serafeim Zanikolas Thu, 13 May 2010 15:53:26 +0200 and (1.2.2-4) unstable; urgency=low * Intend to adopt and. (Closes: #562220) * debian/control: - Maintainer address changed. - Added dependency on ${misc:Depends} - Debhelper upgraded to (>= 7.0.50~) to allow "override_dh_" in debian/rules * debian/rules: Replaced by the 'magic' rules file * Package migrated to 3.0 (quilt) format * Direct changes on upstream sources were extracted into patches. The extraction produced the following patches: + 000_and.8.man.diff + 000_and.c.diff + 000_and.conf.5.man.diff + 000_and-GNU.c.diff + 000_and.priorities.5.man.diff + 000_highpriostart.c.diff + 000_Makefile.diff + 000_watch.diff * Patch 000_watch.diff dropped. * Added headers to all extracted patches. * Added patch 000_and+kbsd.diff to fix FTBFS on GNU/kFreeBSD Thanks to Cyril Brulebois (Closes: #562295) * debian/copyright: Migrated to DEP-5 format. * debian/and.init.d: Written from scratch. (Closes: #367997) -- Dario Minnucci Mon, 25 Jan 2010 03:28:06 +0100 and (1.2.2-3) unstable; urgency=low * QA upload. + Set maintainer to Debian QA Group . * Acknowledge NMUs. * Add Homepage field. * Update watch file to use SF redirector. (Closes: #449941). * Add -f support to run in foreground (Closes: #372746). + Thanks to Andras Korn for the patch! * Add support to build on GNU/Hurd. (Closes: #532698). * Bump debhelper build-dep and compat to 5. * Bump Standards Version to 3.8.3. -- Barry deFreese Wed, 23 Dec 2009 16:47:24 -0500 and (1.2.2-2.1) unstable; urgency=low * Non-maintainer upload to solve release goal. * Add LSB dependency header to init.d scripts (Closes: #460052). * Really acknowledge NMU (Closes: #375163). -- Petter Reinholdtsen Tue, 25 Mar 2008 09:19:35 +0100 and (1.2.2-2) unstable; urgency=high * Acknowledge NMU (thanks to Steinar H. Gunderson) * Disable unconditional stripping of binaries to allow use of DEB_BUILD_OPTIONS=nostrip (Closes: #436457) * Some cleanup to make lintian happier -- Jerome Warnier Mon, 13 Aug 2007 20:45:27 +0200 and (1.2.2-1.1) unstable; urgency=high * Non-maintainer upload. * Add --oknodo to start-stop-daemon in the stop target in the init script; fixes error on package removal when the daemon is stopped. (Closes: #373651) -- Steinar H. Gunderson Fri, 23 Jun 2006 23:25:49 +0200 and (1.2.2-1) unstable; urgency=low * New upstream release * Fix watch file (I hate how SourceForge does it!) * Fix typo in manpages (Closes: #310360) * Add highpriostart.c as example (Closes: #363065) * Fix initscript to stop it using erroneous pid file (Closes: #360713) * Fix manpages minus ("-") not escaped. * Fixed the debian/copyright file. Many thanks to Guilherme de S. Pastore for this and more. -- Jerome Warnier Thu, 13 Oct 2005 19:11:27 +0200 and (1.2.1-2) unstable; urgency=low * Fix "defaultnice" in manpage (Closes: #272782). -- Jerome Warnier Mon, 25 Oct 2004 11:40:27 +0200 and (1.2.1-1) unstable; urgency=low * New upstream version (Closes: #197010). -- Jerome Warnier Fri, 10 Sep 2004 22:47:27 +0200 and (1.2.0-1) unstable; urgency=low * New upstream version. * Added watch file. * New maintainer with permission from Andras -- Jerome Warnier Mon, 19 Jul 2004 14:51:37 +0200 and (1.0.9-1) unstable; urgency=low * New upstream version (Closes: #154147, #230777). -- Jerome Warnier Sun, 02 Feb 2004 19:53:37 +0200 and (1.0.7-1) unstable; urgency=low * New upstream version. * Removed nicelevel setting from the init script. It seems to be broken and it's the only obstacle of using the package on potato out of the box (Closes: #142398). -- Andras Bali Sat, 13 Apr 2002 19:53:37 +0200 and (1.0.5-1) unstable; urgency=high * New upstream version (fixes format string vulnerability). * Added gtop to default config file (Closes: #111043). -- Andras Bali Sat, 24 Nov 2001 00:39:01 +0100 and (1.0.3-1) unstable; urgency=low * Initial release (Closes: #101343). -- Andras Bali Sun, 17 Jun 2001 20:41:40 +0200 Local variables: mode: debian-changelog End: debian/and.examples0000644000000000000000000000002011327116544011464 0ustar highpriostart.c debian/control0000644000000000000000000000212411327125047010572 0ustar Source: and Section: misc Priority: extra Maintainer: Dario Minnucci Build-Depends: debhelper (>= 7.0.50~) Standards-Version: 3.8.3 Homepage: http://and.sourceforge.net/ Package: and Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends} Description: Auto Nice Daemon The auto nice daemon activates itself in certain intervals and renices jobs according to their priority and CPU usage. Jobs owned by root are left alone. Jobs are never increased in their priority. . The renice intervals can be adjusted as well as the default nice level and the activation intervals. A priority database stores user/group/job tuples along with their renice values for three CPU usage time ranges. Negative nice levels are interpreted as signals to be sent to a process, triggered by CPU usage; this way, Netscapes going berserk can be killed automatically. The strategy for searching the priority database can be configured. . AND also provides network-wide configuration files with host-specific sections, as well as wildcard/regexp support for commands in the priority database. debian/and.docs0000644000000000000000000000000711327123111010567 0ustar README debian/watch0000644000000000000000000000006211327127766010231 0ustar version=3 http://sf.net/and/and-([\d.]+)\.tar\.gz debian/and.dirs0000644000000000000000000000012011327116544010610 0ustar etc etc/init.d usr/sbin usr/share/doc/and usr/share/man/man5 usr/share/man/man8