summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile16
-rw-r--r--conf.d/localinit3
-rw-r--r--functions.sh131
-rw-r--r--init.d/Makefile21
-rwxr-xr-xinit.d/alpinecfg.sh44
-rwxr-xr-xinit.d/bootmisc.sh5
-rwxr-xr-xinit.d/checkfs56
-rwxr-xr-xinit.d/networking23
-rw-r--r--inittab7
-rw-r--r--rc-services.sh26
-rwxr-xr-xrc_add78
-rwxr-xr-xrc_delete68
-rwxr-xr-xrc_status57
-rwxr-xr-xrunscript-alpine.sh110
-rwxr-xr-xsend-pr581
-rw-r--r--send-pr.conf5
-rw-r--r--send-pr.template41
-rw-r--r--sendbug.conf2
-rw-r--r--src/Makefile10
-rw-r--r--src/cttyhack.c83
-rw-r--r--src/readahead.c56
-rw-r--r--src/runscript.c25
-rw-r--r--src/splashbard.c215
-rw-r--r--src/start-stop-daemon.c1375
24 files changed, 9 insertions, 3029 deletions
diff --git a/Makefile b/Makefile
index 4ca1b3f..d265aa7 100644
--- a/Makefile
+++ b/Makefile
@@ -24,16 +24,13 @@ ETC_FILES = TZ \
shells \
sysctl.conf \
-CONFD_FILES = $(addprefix conf.d/, cron hwclock localinit rdate syslog tuntap vlan watchdog)
-SBIN_FILES =runscript-alpine.sh functions.sh rc_add rc_delete rc_status
-RC_SH_FILES =rc-services.sh
+CONFD_FILES = $(addprefix conf.d/, cron hwclock rdate syslog tuntap vlan watchdog)
UDHCPC_FILES =default.script
LIB_MDEV_FILES =ide_links usbdisk_link subdir_dev usbdev dvbdev
MODPROBED_FILES =aliases blacklist i386
-SENDBUG_FILES =sendbug.conf
CRONTABS =crontab
-DISTFILES =$(ETC_FILES) $(SBIN_FILES) $(UDHCPC_FILES) $(RC_SH_FILES)\
- $(LIB_MDEV_FILES) $(SENDBUG_FILES) $(MODPROBED_FILES) Makefile
+DISTFILES =$(ETC_FILES) $(UDHCPC_FILES) $(LIB_MDEV_FILES)\
+ $(MODPROBED_FILES) Makefile
all: $(GENERATED_FILES)
for i in $(SUBDIRS) ; do \
@@ -73,13 +70,9 @@ install: $(GENERATED_FILES)
etc/periodic/hourly \
etc/periodic/monthly \
etc/periodic/weekly \
- etc/rcK.d \
- etc/rcL.d \
- etc/sendbug \
home \
lib/firmware \
lib/mdev \
- lib/rcscripts/sh \
media/cdrom \
media/floppy \
media/usb \
@@ -105,12 +98,9 @@ install: $(GENERATED_FILES)
cd $$i && make install && cd .. ;\
done
install -m 0644 $(ETC_FILES) $(GENERATED_FILES) $(DESTDIR)/etc
- install -m 0644 $(SENDBUG_FILES) $(DESTDIR)/etc/sendbug
chmod 600 $(DESTDIR)/etc/shadow
install -m 0644 $(CONFD_FILES) $(DESTDIR)/etc/conf.d
- install -m 0755 $(SBIN_FILES) $(DESTDIR)/sbin
install -m 0755 $(UDHCPC_FILES) $(DESTDIR)/usr/share/udhcpc
- install -m 0755 $(RC_SH_FILES) $(DESTDIR)/lib/rcscripts/sh
install -m 0755 $(LIB_MDEV_FILES) $(DESTDIR)/lib/mdev
install -m 0755 $(MODPROBED_FILES) $(DESTDIR)/etc/modprobe.d
mv $(DESTDIR)/etc/crontab $(DESTDIR)/etc/crontabs/root
diff --git a/conf.d/localinit b/conf.d/localinit
deleted file mode 100644
index 5cf879b..0000000
--- a/conf.d/localinit
+++ /dev/null
@@ -1,3 +0,0 @@
-# look only for localinit in those dirs.
-# set to "" to disable localinit
-MOUNTS="usb floppy cdrom"
diff --git a/functions.sh b/functions.sh
deleted file mode 100644
index 335bc09..0000000
--- a/functions.sh
+++ /dev/null
@@ -1,131 +0,0 @@
-# Copyright 2007-2008 Natanael Copa <natanael.copa@gmail.com>
-# Copyright 2007-2008 Roy Marples <roy@marples.name>
-# All rights reserved. Released under the 2-clause BSD license.
-
-RC_GOT_FUNCTIONS="yes"
-
-# load user settings
-[ -r /etc/conf.d/rc ] && . /etc/conf.d/rc
-
-
-
-svclib="/lib/rcscripts"
-svcdir="${svcdir:-/var/lib/init.d}"
-
-# void import_addon(char *Addon)
-import_addon() {
- local addon="$svclib/addons/$1"
- [ -r "$addon" ] && . "$addon"
-}
-
-echon () {
- if [ -z "$ECHON" ]; then
- # Determine how to "echo" without newline: "echo -n"
- # or "echo ...\c"
- if [ "X`echo -n`" = "X-n" ]; then
- ECHON=echo
- NNL="\c"
- # "
- else
- ECHON="echo -n"
- NNL=""
- fi
- fi
- $ECHON "$*$NNL"
-}
-
-
-eerror() {
- echo $* >&2
-}
-
-einfo() {
- echo $* >&2
-}
-
-einfon() {
- echon $* >&2
-}
-
-ewarn() {
- echo $* >&2
-}
-
-ebegin() {
- echon " * $*: "
-}
-
-eend() {
- local msg
- if [ "$1" = 0 ] || [ $# -lt 1 ] ; then
- msg="ok."
- else
- shift
- msg=" failed. $*"
- fi
- echo "$msg"
-}
-
-eindent() {
- true
-}
-
-eoutdent() {
- true
-}
-
-start_addon() {
- (import_addon "$1-start.sh")
- return 0
-}
-
-stop_addon() {
- (import_addon "$1-stop.sh")
- return 0
-}
-
-save_options() {
- local myopts="$1"
- mkdir -p -m 0755 "$svcdir/options/$SVCNAME"
- shift
- echo "$*" > "$svcdir/options/$SVCNAME/$myopts"
-}
-
-get_options() {
- local svc="$SVCNAME"
- [ "$2" ] && svc="$2"
- cat "$svcdir/options/$svc/$1" 2>/dev/null
-}
-
-die() {
- eerror "$1"
- exit 1
-}
-
-yesno() {
- [ -z "$1" ] && return 1
-
- case "$1" in
- [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) return 0;;
- [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) return 1;;
- esac
-
- local value=
- eval value=\$${1}
- case "${value}" in
- [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) return 0;;
- [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) return 1;;
- *) ewarn "\$${1} is not set properly"; return 1;;
- esac
-}
-
-# print a cute \ | / - animation
-roller() {
- awk 'BEGIN {
- i=0; split("\\ | / -", a, " ");
- printf " ";
- }
- { printf "\b" a[and(i++,3)+1] }
- END { printf "\b" }'
-}
-
diff --git a/init.d/Makefile b/init.d/Makefile
index 21e756c..6ac6cfe 100644
--- a/init.d/Makefile
+++ b/init.d/Makefile
@@ -1,28 +1,9 @@
-SCRIPTS = alpinecfg.sh \
- bootmisc.sh \
- checkfs \
- checkroot.sh \
- cron \
+SCRIPTS = cron \
dnsd \
- hostname \
httpd \
- hwclock \
hwdrivers \
inetd \
- keymap \
- localinit \
- localmount \
mdev \
- modutils \
- networking \
- procps \
- rc.local \
- rcK \
- rcL \
- rcS \
- rdate\
- runtimes \
- swap\
syslog \
tuntap \
vlan \
diff --git a/init.d/alpinecfg.sh b/init.d/alpinecfg.sh
deleted file mode 100755
index 180b6e8..0000000
--- a/init.d/alpinecfg.sh
+++ /dev/null
@@ -1,44 +0,0 @@
-#!/bin/busybox sh
-
-# the purpose of this script is to find and import the alpine config.
-# load it or set default values.
-
-#depracated
-echo "remeber to remove this $0 file..."
-exit
-
-get_boot_var () {
- # Look for CFG_MEDIA in cmdline
- for i in `cat /proc/cmdline` ; do
-# if echo $i | grep $ > /dev/null ; then
-# echo $i | sed 's/'$1'=//'
-# fi
- case $i in
- $1=*) echo $i | sed 's|'$1'=||' ;;
- esac
- done
-}
-
-
-import_config() {
- if mount $1 ; then
- echo "Using Alpine config from $1"
- cp $1/$2 /etc/alpine.conf
- sleep 1
- umount $1
- fi
-}
-
-CFG="alpine.conf"
-CFG_MEDIA=`get_boot_var cfg_media`
-#if [ -z "$CFG_MEDIA" ] ; then
- # cfg_media was not set in cmdline. We use the defaults...
- echo "looking for alpine.conf on default locations"
- for i in /media/* ; do
- import_config $i $CFG
- done
-#else
- # Only import for specified location
-# import_config "/media/$CFG_MEDIA" $CFG
-#fi
-
diff --git a/init.d/bootmisc.sh b/init.d/bootmisc.sh
deleted file mode 100755
index be2a035..0000000
--- a/init.d/bootmisc.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/sh
-
-mkdir -p /var/log
-dmesg -s 65536 > /var/log/dmesg
-
diff --git a/init.d/checkfs b/init.d/checkfs
deleted file mode 100755
index 5beff0a..0000000
--- a/init.d/checkfs
+++ /dev/null
@@ -1,56 +0,0 @@
-#!/sbin/runscript
-# Copyright 1999-2007 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-
-get_bootparam() {
- # todo
- return 1
-}
-
-start() {
- local rc=0 mode="-p" opts="-A -C0 -R -T" parts=
-
- ebegin "Checking all filesystems"
-
- if [ -e /forcefsck ] || get_bootparam "forcefsck" ; then
- ewarn "A full fsck has been forced"
- mode="-f -n"
- fi
-
- fsck ${opts} ${mode} ${parts}
- rc=$?
-
- if [ ${rc} -eq 0 ] ; then
- eend 0
- elif [ ${rc} -eq 1 ] ; then
- ewend 1 "Filesystem errors corrected."
- rc=0
- elif [ ${rc} -eq 2 ] ; then
- ewend 1 "System should be rebooted"
- elif [ ${rc} -eq 8 ] ; then
- ewend 1 "Operational error, continuing"
- rc=0
- else
- if [ "${RC_FORCE_AUTO}" = "yes" ] ; then
- eend 2 "Fsck could not correct all errors, rerunning"
- fsck ${opts} -y ${parts}
- retval=$?
- eend ${retval}
- fi
-
- if [ ${retval} -gt 3 ] ; then
- eend 2 "Fsck could not correct all errors, manual repair needed"
-# exec rc-abort || exit 1
- fi
- fi
-
- [ ${rc} = 0 -a -e /forcefsck ] && rm /forcefsck
-
- return ${rc}
-}
-
-stop() {
- return 0
-}
-
-# vim: set ts=4 :
diff --git a/init.d/networking b/init.d/networking
deleted file mode 100755
index 11cb8e7..0000000
--- a/init.d/networking
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/sbin/runscript
-
-# note that the spoofprotect, syncoockies and ip_forward options are set in
-# /etc/sysctl.conf
-
-start() {
- ebegin "Configuring network interfaces"
- ifup -a >/dev/null 2>&1
- eend $?
-}
-
-stop() {
- ebegin "Deconfiguring network interfaces"
- ifdown -a >/dev/null 2>&1
- eend $?
-}
-
-restart() {
- ebegin "Reconfiguring network interfaces"
- ifdown -a >/dev/null 2>&1 && ifup -a >/dev/null 2>&1
- eend $?
-}
-
diff --git a/inittab b/inittab
index f170b8b..592c7c3 100644
--- a/inittab
+++ b/inittab
@@ -1,7 +1,8 @@
# /etc/inittab
-::sysinit:/etc/init.d/rcS
-::wait:/etc/init.d/rcL
+::sysinit:/sbin/rc sysinit
+::wait:/sbin/rc boot
+::wait:/sbin/rc default
# Set up a couple of getty's
tty1::respawn:/sbin/getty 38400 tty1
@@ -17,7 +18,7 @@ tty4::respawn:/sbin/getty 38400 tty4
::ctrlaltdel:/sbin/reboot
# Stuff to do before rebooting
-::shutdown:/etc/init.d/rcK
+::shutdown:/sbin/rc shutdown
null::shutdown:/bin/umount -a -r 2>/dev/null
null::shutdown:/sbin/swapoff -a 2>/dev/null
diff --git a/rc-services.sh b/rc-services.sh
deleted file mode 100644
index 4a3686d..0000000
--- a/rc-services.sh
+++ /dev/null
@@ -1,26 +0,0 @@
-
-RC_GOT_SERVICES="yes"
-
-[ "$RC_GOT_FUNCTIONS" ] || . /sbin/functions.sh
-
-# void save_options(char *option, char *optstring)
-save_options() {
- local myopts="$1"
-
- shift
- if [ ! -d "${svcdir}/options/${SVCNAME}" ] ; then
- mkdir -p -m 0755 "${svcdir}/options/${SVCNAME}"
- fi
-
- echo "$*" > "${svcdir}/options/${SVCNAME}/${myopts}"
-}
-
-# char *get_options(char *option)
-get_options() {
- local svc="${SVCNAME}"
- [ -n $2 ] && svc="$2"
-
- if [ -f "${svcdir}/options/${svc}/$1" ] ; then
- echo "$(< ${svcdir}/options/${svc}/$1)"
- fi
-}
diff --git a/rc_add b/rc_add
deleted file mode 100755
index de0b8c3..0000000
--- a/rc_add
+++ /dev/null
@@ -1,78 +0,0 @@
-#!/bin/sh
-#
-# rc_add - add an init script to a runlevel
-#
-# Copyright (c) 2005 Natanael Copa
-#
-# Distributed under GPL-2
-#
-
-PROGRAM=`basename $0`
-
-#load the libraries
-. /sbin/functions.sh
-
-STARTNUM=50
-RCDIR="$ROOT/etc/rcL.d"
-
-die() {
- echo "$1" >&2
- exit 1
-}
-
-# print usage and die
-usage() {
- echo "$PROGRAM $VERSION"
- echo "usage: $PROGRAM [-hv] [-s number] script"
- echo ""
- echo " -h Show help and exit."
- echo " -k Also add a corresponding kill link for shutdown/reboot."
- echo " -s Set two-digit start number (00-99). Default is $STARTNUM."
- echo " -S Add service as a system init service (rcS.d)."
- echo " -v Turn on verbose output."
- echo ""
- exit 1
-}
-
-#parse args
-unset vflag
-while getopts "hks:Sv" opt ; do
- case "$opt" in
- h) usage;;
- k) KILL="-k";;
- s) STARTNUM="$OPTARG";;
- S) RCDIR="ROOT/rcS.d";;
- v) vflag="-v"; VERBOSE=1 ;;
- \?) usage;;
- esac
-done
-shift `expr $OPTIND - 1`
-
-# check if script is specified
-[ $# -lt 1 ] && usage
-
-while [ $# -gt 0 ] ; do
- SCRIPT="$1"
-
- # validate the start number
- echo "$STARTNUM" | grep '^[0-9][0-9]$' > /dev/null || die "Start number needs to be a 2 digit number. (00-99)"
-
- mkdir -p "$ROOT/$RCDIR"
- cd "$ROOT/$RCDIR"
-
- LINKTARGET="../init.d/$SCRIPT"
- [ -f "$LINKTARGET" ] || die "Could not find init script $LINKTARGET"
- SLINK="S$LEVEL$STARTNUM$SCRIPT"
- [ "$VERBOSE" ] && echo "Creating $ROOT/$RCDIR/$SLINK."
- ln -sf $LINKTARGET "$ROOT/$RCDIR/$SLINK" || exit $?
-
- if [ "$KILL" ] ; then
- KLINK="K$LEVEL$STARTNUM$SCRIPT"
- [ "$VERBOSE" ] && echo "Creating $ROOT/etc/rcK.d/$KLINK."
- mkdir -p "$ROOT/etc/rcK.d"
- ln -sf $LINKTARGET "$ROOT/etc/rcK.d/$KLINK" || exit $?
- fi
-
- shift
-done
-exit 0
diff --git a/rc_delete b/rc_delete
deleted file mode 100755
index 319d44b..0000000
--- a/rc_delete
+++ /dev/null
@@ -1,68 +0,0 @@
-#!/bin/sh
-#
-# rc_delete - delete an init script from a runlevel
-#
-# Copyright (c) 2005 Natanael Copa
-#
-# Distributed under GPL-2
-#
-
-PROGRAM=`basename $0`
-
-#load the libraries
-. /sbin/functions.sh
-
-LEVEL=4
-
-die() {
- echo "$1" >&2
- exit 1
-}
-
-# print usage and die
-usage() {
- echo "$PROGRAM $VERSION"
- echo "usage: $PROGRAM [-hv] [-l level] script..."
- echo ""
- echo " -h Show help and exit."
- echo " -l Only remove from specified level. Default is all levels."
- echo " -v Turn on verbose output."
- echo ""
- exit 1
-}
-
-#parse args
-unset vflag
-while getopts "hl:v" opt ; do
- case "$opt" in
- h) usage;;
- l) LEVEL="$OPTARG";;
- v) vflag="-v"; VERBOSE=1 ;;
- \?) usage;;
- esac
-done
-shift `expr $OPTIND - 1`
-
-# check if script is specified
-[ $# -lt 1 ] && usage
-while [ $# -gt 0 ] ; do
- SCRIPT="$1"
-
- rclinks=""
- for rcl in $ROOT/etc/rcS.d/[S][0-9][0-9]$SCRIPT \
- $ROOT/etc/rcL.d/[SK][0-9][0-9]$SCRIPT \
- $ROOT/etc/rcK.d/[SK][0-9][0-9]$SCRIPT ; do
- [ -e "$rcl" -o -L "$rcl" ] || continue
- echo "$rcl"
- rclinks="$rclinks $rcl"
- done
-
- for rclink in $rclinks ; do
- [ "$VERBOSE" ] && echo "Removing $rclink."
- rm -f $rclink
- done
- shift
-done
-
-exit 0
-
diff --git a/rc_status b/rc_status
deleted file mode 100755
index d547555..0000000
--- a/rc_status
+++ /dev/null
@@ -1,57 +0,0 @@
-#!/bin/sh
-#
-# rc_status - show status of boot scripts
-#
-# Copyright (c) 2005 Natanael Copa
-#
-# Distributed under GPL-2
-#
-
-PROGRAM=`basename $0`
-
-#load the libraries
-. /sbin/functions.sh
-
-die() {
- echo "$1" >&2
- exit 1
-}
-
-# print usage and die
-usage() {
- echo "$PROGRAM $VERSION"
- echo "usage: $PROGRAM [-hv] [-l level] [script]"
- echo ""
- echo " -h Show help and exit."
- echo " -l Show only specified level."
- echo " -v Turn on verbose output."
- echo ""
- exit 1
-}
-
-#parse args
-while getopts "hl:v" opt ; do
- case "$opt" in
- h) usage;;
- l) case "$OPTARG" in
- S|L|K) LEVELS="$LEVELS $OPTARG";;
- *) die "Valid levels are: all, S, K and L";;
- esac
- ;;
- v) VERBOSE="-v" ;;
- \?) usage;;
- esac
-done
-shift `expr $OPTIND - 1`
-
-cd "$ROOT/etc"
-
-[ -z "$LEVELS" ] && LEVELS="S L K"
-
-for i in $LEVELS ; do
- echo "rc$i.d:"
- ls -1 $VERBOSE rc$i.d 2>/dev/null
- echo ""
-done
-
-exit
diff --git a/runscript-alpine.sh b/runscript-alpine.sh
deleted file mode 100755
index 104cc17..0000000
--- a/runscript-alpine.sh
+++ /dev/null
@@ -1,110 +0,0 @@
-#!/bin/sh
-
-myscript="$1"
-if [ -L $1 ] && [ ! -L "/etc/init.d/${1##*/}" ]; then
- myservice=$(readlink "$1")
-else
- myservice=$1
-fi
-
-myservice=`basename ${myservice}`
-export SVCNAME=${myservice}
-
-[ "$RC_GOT_FUNCTIONS" ] || . /sbin/functions.sh
-
-# wrapper for busybox killall
-killall() {
- local flags ka
- ka=`which killall`
- while [ $# -gt 0 ] ; do
- case "$1" in
- -*) flags="$flags $1";;
- *) flags="$flags `basename $1`"
- esac
- shift
- done
- $ka $flags
-}
-
-svc_start() {
- start
-}
-
-svc_stop() {
- stop
-}
-
-svc_status() {
- status
-}
-
-restart() {
- svc_stop
- sleep 1
- svc_start
-}
-
-usage() {
- local i uopts
- for i in $opts; do
- uopts="$uopts|$i"
- done
- echo "usage: $myscript start|stop|status|restart$uopts"
- exit $1
-}
-
-# imported from gentoo
-get_bootparam() {
- local match="$1"
- [ -z "${match}" -o ! -r /proc/cmdline ] && return 1
-
- set -- $(cat /proc/cmdline)
- while [ -n "$1" ] ; do
- case "$1" in
- gentoo=*)
- local params="${1##*=}"
- local IFS=, x=
- for x in ${params} ; do
- [ "${x}" = "${match}" ] && return 0
- done
- ;;
- esac
- shift
- done
-
- return 1
-}
-
-
-[ -f "/etc/conf.d/$myservice" ] && . "/etc/conf.d/$myservice"
-. "$myscript"
-
-shift
-if [[ $# -lt 1 ]] ; then
- usage 1
-fi
-
-for arg in $* ; do
- case "${arg}" in
- start)
- svc_start
- ;;
- stop)
- svc_stop
- ;;
- status)
- svc_status
- ;;
- restart)
- restart
- ;;
- *)
- for opt in $opts ; do
- if [ "$arg" = "$opt" ]; then
- $arg
- fi
- done
- ;;
- esac
-done
-
diff --git a/send-pr b/send-pr
deleted file mode 100755
index 9f479bf..0000000
--- a/send-pr
+++ /dev/null
@@ -1,581 +0,0 @@
-#!/bin/sh
-# send-pr. Generated from send-pr.sh by configure.
-#
-# Submit a problem report to a GNATS site.
-# Copyright (C) 2001, 2002 Milan Zamazal
-# Copyright (C) 1993, 2001 Free Software Foundation, Inc.
-# Contributed by Brendan Kehoe (brendan@cygnus.com), based on a
-# version written by Heinz G. Seidl (hgs@cygnus.com).
-# Further edited by Milan Zamazal (pdm@zamazal.org).
-# mktemp support by Yngve Svendsen (yngve.svendsen@clustra.com).
-#
-# This file is part of GNU GNATS.
-#
-# GNU GNATS 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, or (at your option)
-# any later version.
-#
-# GNU GNATS 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 GNU GNATS; see the file COPYING. If not, write to
-# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
-
-################################################################################
-# Default values -- You may override these in your configuration file
-################################################################################
-# The version of this send-pr.
-VERSION="4.1.0-alpine"
-
-# The submitter-id for your site.
-SUBMITTER="unknown"
-
-# The place where our usual binaries live.
-prefix="/usr"
-exec_prefix="${prefix}"
-bindir="${exec_prefix}/bin"
-sbindir="${exec_prefix}/bin"
-sysconfdir="/etc"
-libexecdir="${exec_prefix}/libexec/gnats"
-
-# The default release for this host.
-DEFAULT_RELEASE="gnats-4.1.0"
-
-# The default organization.
-DEFAULT_ORGANIZATION="unknown"
-
-# How to read the passwd database.
-PASSWD="cat /etc/passwd"
-
-# Is the mktemp command available?
-MKTEMP="yes"
-
-ECHON=bsd
-
-# By default send-pr connects directly to the database. However, it
-# can be configured to use an existing template file by setting the
-# TEMPLATE variable below to point to a PR template generated from
-# "send-pr -P".
-TEMPLATE=""
-
-# send-pr can use mail to submit PRs, instead of connecting to the
-# database directly. MAILPROG needs to point to a compatible mailer
-# (sendmail will work). If MAILPROG needs to have the address that
-# the mail is being sent to specified on the command line, it should
-# be specified here as well (for example, the command
-# MAILPROG="mail bugs@foo.bar.com"
-# should work). If sendmail is used, this should be set to
-# MAILPROG="/usr/sbin/sendmail -oi -t"
-MAILPROG=""
-
-# The address that PRs are sent to. Normally this can be left as "bugs";
-# however, if using mail to submit PRs, this should be set to the address
-# where PRs should be sent.
-MAILADDR="bugs"
-
-# Configuration file to be read. It must be a shell script that can redefine
-# the variables above to fit a local configuration. It reads the system config
-# file first, then the personal config file.
-CONFIGFILES="/etc/gnats/send-pr.conf ${HOME}/.send-pr.conf"
-for CONFIGFILE in ${CONFIGFILES}; do
- if [ -r ${CONFIGFILE} ]; then
- . ${CONFIGFILE}
- fi
-done
-
-#
-# check hf sendmail exist
-if ! which sendmail > /dev/null ; then
- echo "sendmail not found. Please run 'setup-mta'"
- exit 1;
-fi
-
-if [ -z "$TMPDIR" ]; then
- TMPDIR=/tmp
-else
- if [ "`echo $TMPDIR | grep '/$'`" != "" ]; then
- TMPDIR="`echo $TMPDIR | sed -e 's,/$,,'`"
- fi
-fi
-
-# TEMP: Temporary copy of the PR, to be edited by the user.
-# BAD: The PR will end up here if the user aborts.
-# REF: The 'reference' copy of the PR template, used to verify that the user
-# actually did edit the template.
-# FIXFIL: A sed script used to remove comments from the template before
-# processing.
-if [ $MKTEMP = yes ]; then
- TEMP=`mktemp $TMPDIR/pXXXXXX` || exit 1
- BAD=`mktemp $TMPDIR/pbadXXXXXX` || exit 1
- REF=`mktemp $TMPDIR/pfXXXXXX` || exit 1
- FIXFIL=`mktemp $TMPDIR/fixXXXXXX` || exit 1
-else
- TEMP=$TMPDIR/p$$
- BAD=$TMPDIR/pbad$$
- REF=$TMPDIR/pf$$
- FIXFIL=$TMPDIR/fix$$
- bad_temp=0
- : > $TEMP || bad_temp=1
- : > $BAD || bad_temp=1
- : > $REF || bad_temp=1
- : > $FIXFIL || bad_temp=1
- if [ $bad_temp = 1 ]; then
- rm -f $TEMP $BAD $REF $FIXFIL
- exit 1;
- fi
-fi
-REMOVE_TEMP="rm -f $TEMP $BAD $REF"
-
-# find a user name
-if [ "$LOGNAME" = "" ]; then
- if [ "$USER" != "" ]; then
- LOGNAME="$USER"
- else
- LOGNAME="UNKNOWN"
- fi
-fi
-
-[ -z "$FROM" ] && FROM="$LOGNAME"
-REPLYTO="${REPLY_TO:-${REPLYTO:-$FROM}}"
-if [ "x$MAILPROG" != "x" ]
-then
- RESP_ALIAS="`query-pr --adm-field responsible --adm-key $LOGNAME --adm-subfield alias 2>/dev/null`"
-else
- RESP_ALIAS=""
-fi
-
-# Find out the name of the originator of this PR.
-if [ -n "$NAME" ]; then
- DEFAULT_ORIGINATOR="$NAME"
-elif [ -f $HOME/.fullname ]; then
- DEFAULT_ORIGINATOR="`sed -e '1q' $HOME/.fullname`"
-else
- # Must use temp file due to incompatibilities in quoting behavior
- # and to protect shell metacharacters in the expansion of $LOGNAME
- $PASSWD | grep "^$LOGNAME:" | awk -F: '{print $5}' | sed -e 's/,.*//' > $TEMP
- if [ "x$RESP_ALIAS" != "x" ]
- then
- DEFAULT_ORIGINATOR="$RESP_ALIAS (`cat $TEMP`)"
- else
- DEFAULT_ORIGINATOR="$FROM (`cat $TEMP`)"
- fi
- rm -f $TEMP
-fi
-
-if [ -z "$ORGANIZATION" ]
-then
- ORGANIZATION="$DEFAULT_ORGANIZATION";
-fi
-
-if [ -n "$ORGANIZATION" -a "x$ORGANIZATION" != "unknown" ]; then
- if [ `echo $ORGANIZATION | fgrep -c /` -gt 0 -a -f "$ORGANIZATION" ]; then
- ORGANIZATION="`cat $ORGANIZATION`"
- fi
-elif [ -f $HOME/.organization ]; then
- ORGANIZATION="`cat $HOME/.organization`"
-fi
-
-if [ "x$ORGANIZATION" = "unknown" ]; then
- cat <<__EOF__
-It seems that send-pr is not installed with your organization set to a useful
-value. To fix this, you need to edit the configuration file
-$CONFIGFILE
-and fill in the organization with the correct value.
-
-__EOF__
- ORGANIZATION="";
-else
- DEFAULT_ORGANIZATION="$ORGANIZATION"
-fi 1>&2
-
-# If they don't have a preferred editor set, then use
-if [ -z "$VISUAL" ]; then
- if [ -z "$EDITOR" ]; then
- EDIT=vi
- else
- EDIT="$EDITOR"
- fi
-else
- EDIT="$VISUAL"
-fi
-
-# Find out some information.
-SYSTEM=`( [ -f /bin/uname ] && /bin/uname -a ) || \
- ( [ -f /usr/bin/uname ] && /usr/bin/uname -a ) || echo ""`
-
-# alpine specific addition
-ALPINE_RELEASE=`cat /etc/alpine-release || echo ""`
-
-# Our base command name.
-COMMAND=`echo $0 | sed -e 's,.*/,,'`
-USAGE="Usage: $COMMAND [OPTION]...
-
- -b --batch run without printing most messages
- -d --database DATABASE submit PR to DATABASE
- -f --file FILE read the PR template from FILE (\`-' for stdin)
- -p --print just print the template and exit
- --request-id send a request for a user id
- -s --severity SEVERITY PR severity
-
- -h --help display this help and exit
- -V --version output version information and exit
-"
-REMOVE=
-BATCH=
-DEFAULT_SEVERITY=
-
-if [ "$SYSTEM" != "" ]
-then
- DEFAULT_ENVIRONMENT="System: $SYSTEM
-"
-fi
-
-while [ $# -gt 0 ]; do
- case "$1" in
- -r) ;; # Ignore for backward compat.
- -f | --file) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
- shift ; IN_FILE="$1"
- if [ "$IN_FILE" != "-" -a ! -r "$IN_FILE" ]; then
- echo "$COMMAND: cannot read $IN_FILE"
- exit 1
- fi
- ;;
- -b | --batch) BATCH=true ;;
- -d | --database) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
- shift; GNATSDB="$1"; export GNATSDB
- ;;
- -s | --severity) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
- shift ; DEFAULT_SEVERITY="$1"
- ;;
- -p | -P | --print) PRINT=true ;;
- --request-id) REQUEST_ID=true ;;
- -h | --help) echo "$USAGE"; exit 0 ;;
- -V | --version) echo "$VERSION"; exit 0 ;;
- -*) echo "$USAGE" ; exit 1 ;;
- *) echo "$USAGE" ; exit 1 ;;
- esac
- shift
-done
-
-if [ "x$SUBMITTER" = "x" ]
-then
- SUBMITTER="unknown"
-fi
-
-if [ "x$SUBMITTER" = "xunknown" -a -z "$REQUEST_ID" -a -z "$IN_FILE" ]; then
- cat << '__EOF__'
-It seems that send-pr is not installed with your unique submitter-id, or that
-"unknown" has been specified. You need to run:
-
- install-sid YOUR-SID
-
-where YOUR-SID is the identification code you received with `send-pr'.
-`send-pr' will automatically insert this value into the template field
-`>Submitter-Id'. If you've downloaded `send-pr' from the Net, use `net'
-for this value. If you do not know your id, run `send-pr --request-id' to
-get one from your support site.
-__EOF__
- exit 1
-fi
-
-# So the template generation code finds it.
-DEFAULT_SUBMITTERID=${SUBMITTER}
-
-# Catch some signals. ($xs kludge needed by Sun /bin/sh)
-xs=0
-trap 'rm -f $REF $TEMP $FIXFIL; exit $xs' 0
-trap 'echo "$COMMAND: Aborting ..."; rm -f $REF $TEMP $FIXFIL; xs=1; exit' 1 3 13 15
-
-if [ "x$PRINT" = "xtrue" ]; then
- FROM="<FROM>"
- REPLYTO="<REPLYTO>"
- DEFAULT_ORIGINATOR="<DEFAULT_ORIGINATOR>"
- DEFAULT_SUBMITTERID="<SUBMITTER>"
-fi
-
-# If they told us to use a specific file, then do so.
-if [ -n "$IN_FILE" ]; then
- if [ "$IN_FILE" = "-" ]; then
- # The PR is coming from the standard input.
- cat > $TEMP
- else
- # Use the file they named.
- cat $IN_FILE > $TEMP
- fi
-else
- if [ -n "$TEMPLATE" -a -z "$PRINT_INTERN" ]; then
- # If their TEMPLATE points to a bogus entry, then bail.
- if [ ! -f "$TEMPLATE" -o ! -r "$TEMPLATE" -o ! -s "$TEMPLATE" ]; then
- echo "$COMMAND: can't seem to read your template file (\`$TEMPLATE'), ignoring TEMPLATE"
- sleep 1
- PRINT_INTERN=bad_prform
- fi
- fi
-
- if [ -n "$TEMPLATE" -a -z "$PRINT_INTERN" ]; then
- sed "s/<FROM>/$FROM/;s/<REPLYTO>/$REPLYTO/;s/<DEFAULT_ORIGINATOR>/$DEFAULT_ORIGINATOR/;s/<SUBMITTER>/$DEFAULT_SUBMITTERID/;s/<SYSTEM>/$SYSTEM/;s/<ALPINE_RELEASE>/$ALPINE_RELEASE/" < $TEMPLATE > $TEMP ||
- ( echo "$COMMAND: could not copy $TEMPLATE" ; xs=1; exit )
- else
- # Which genius thought of iterating through this loop twice, when the
- # cp command would suffice?
- for file in $TEMP ; do
- cat > $file << '__EOF__'
-SEND-PR: -*- send-pr -*-
-SEND-PR: Lines starting with `SEND-PR' will be removed automatically, as
-SEND-PR: will all comments (text enclosed in `<' and `>').
-SEND-PR:
-SEND-PR: Please consult the send-pr man page `send-pr(1)' or the Texinfo
-SEND-PR: manual if you are not sure how to fill out a problem report.
-SEND-PR: Note that the Synopsis field is mandatory. The Subject (for
-SEND-PR: the mail) will be made the same as Synopsis unless explicitly
-SEND-PR: changed.
-SEND-PR:
-SEND-PR: Choose from the following categories:
-SEND-PR:
-__EOF__
-
- # Format the categories so they fit onto lines.
- CATEGORIES=`${bindir}/query-pr --valid-values Category`;
- l=`echo "$CATEGORIES" | \
- awk 'BEGIN {max = 0; } { if (length($0) > max) { max = length($0); } }
- END {print max + 1;}'`
- c=`expr 61 / $l`
- if [ $c -eq 0 ]; then c=1; fi
- echo "$CATEGORIES" | \
- awk 'BEGIN {printf "SEND-PR: "; i = 0 }
- { printf ("%-'$l'.'$l's", $0);
- if ((++i % '$c') == 0) { printf "\nSEND-PR: " } }
- END { printf "\nSEND-PR:\n"; }' >> $file
-
- cat >> $file << __EOF__
-To: $MAILADDR
-Subject:
-From: $FROM
-Reply-To: $REPLYTO
-X-send-pr-version: $VERSION
-
-
-__EOF__
-
- #
- # Iterate through the list of input fields. fieldname is the
- # name of the field. fmtname is the formatted name of the field,
- # with >, : and extra spaces to cause the field contents to be
- # aligned.
- #
- ${bindir}/query-pr --list-input-fields | awk '{a[NR]=$1""; mnr = NR+1; len = length($1) + 2; if (mlen < len) mlen = len; } END { for (x = 1; x < mnr; x++) { b = ">"a[x]":"; printf ("%s %-"mlen"s&\n", a[x], b); } }' | while read fieldname fmtname
- do
- fmtname="`echo "$fmtname" | sed 's/[&]$//;'`"
- upname="`echo $fieldname | sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/;s/-//g;'`"
- # Grab the default value for this field.
- eval 'default_val="$DEFAULT_'${upname}'"'
- # What's stored in the field?
- type=`${bindir}/query-pr --field-type $fieldname | sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
- case $type in
- enum)
- if [ "$default_val" != "" ]
- then
- desc=$default_val;
- else
- if [ "$fieldname" != "Category" ]
- then
- values=`${bindir}/query-pr --valid-values $fieldname | tr '\n' ' ' | sed 's/ *$//g; s/ / | /g;s/^/[ /;s/$/ ]/;'`
- valslen=`echo "$values" | wc -c`
- else
- values="choose from a category listed above"
- valslen=1;
- fi
- if [ "$valslen" -gt 160 ]
- then
- desc="<`${bindir}/query-pr --field-description $fieldname` (one line)>";
- else
- desc="<${values} (one line)>";
- fi
- dpat=`echo "$desc" | tr '\]\[*+^$|\()&/' '............'`
- echo "/^>${fieldname}:/ s/${dpat}//" >> $FIXFIL
- fi
- echo "${fmtname}${desc}" >> $file
- ;;
- multitext)
- if [ "$default_val" != "" ]
- then
- desc=" $default_val";
- else
- desc=" <`${bindir}/query-pr --field-description $fieldname` (multiple lines)>";
- dpat=`echo "$desc" | tr '\]\[*+^$|\()&/' '............'`
- echo "s/^${dpat}//" >> $FIXFIL
- fi
- echo "${fmtname}" >> $file;
- echo "$desc" >> $file;
- ;;
- *)
- if [ "$default_val" != "" ]
- then
- desc="${default_val}"
- else
- desc="<`${bindir}/query-pr --field-description $fieldname` (one line)>"
- dpat=`echo "$desc" | tr '\]\[*+^$|\()&/' '............'`
- echo "/^>${fieldname}:/ s/${dpat}//" >> $FIXFIL
- fi
- echo "${fmtname}${desc}" >> $file
- ;;
- esac
- done
- done
- fi
-
- if [ "$PRINT" = true -o "$PRINT_INTERN" = true ]; then
- cat $TEMP
- xs=0; exit
- fi
-
- cp $TEMP $REF
-
- chmod u+w $TEMP
- if [ -z "$REQUEST_ID" ]; then
- eval $EDIT $TEMP
- else
- ed -s $TEMP << '__EOF__'
-/^Subject/s/^Subject:.*/Subject: request for a customer id/
-/^>Category/s/^>Category:.*/>Category: send-pr/
-w
-q
-__EOF__
- fi
-
- if cmp -s $REF $TEMP ; then
- echo "$COMMAND: problem report not filled out, therefore not sent"
- xs=1; exit
- fi
-fi
-
-# TEMP is the PR that we are editing. When we're done, REF will contain
-# the final PR to be sent.
-
-while [ -z "$REQUEST_ID" ]; do
- CNT=0
-
- #
- # Remove comments.
- #
- echo '/^SEND-PR:/d' >> $FIXFIL
- echo 's/<.*>//' >> $FIXFIL
- sed -f $FIXFIL $TEMP > $REF
-
- # REF now has the actual PR that we want to send.
-
- #
- # Check that synopsis is not empty.
- #
- if grep "^>Synopsis:[ ]*$" $REF > /dev/null
- then
- echo "$COMMAND: Synopsis must not be empty."
- CNT=`expr $CNT + 1`
- fi
-
- if [ "x$MAILPROG" = "x" ]
- then
- # Since we're not using mail, use pr-edit to check the PR. We can't
- # do much checking otherwise, sorry.
- $libexecdir/pr-edit --check-initial < $REF || CNT=`expr $CNT + 1`
- fi
-
- [ $CNT -gt 0 -a -z "$BATCH" ] &&
- echo "Errors were found with the problem report."
-
- while true; do
- if [ -z "$BATCH" ]; then
- echo -n "a)bort, e)dit or s)end? "
- read input
- else
- if [ $CNT -eq 0 ]; then
- input=s
- else
- input=a
- fi
- fi
- case "$input" in
- a*)
- if [ -z "$BATCH" ]; then
- echo "$COMMAND: the problem report remains in $BAD and is not sent."
- mv $TEMP $BAD
- else
- echo "$COMMAND: the problem report is not sent."
- fi
- xs=1; exit
- ;;
- e*)
- eval $EDIT $TEMP
- continue 2
- ;;
- s*)
- break 2
- ;;
- esac
- done
-done
-
-#
-# Make sure the mail has got a Subject. If not, use the same as
-# in Synopsis.
-#
-
-if grep '^Subject:[ ]*$' $REF > /dev/null
-then
- SYNOPSIS=`grep '^>Synopsis:' $REF | sed -e 's/^>Synopsis:[ ]*//'`
- ed -s $REF << __EOF__
-/^Subject:/s/:.*\$/: $SYNOPSIS/
-w
-q
-__EOF__
-fi
-
-while :
-do
- if [ "x$MAILPROG" != "x" ]
- then
- # Use mail to send the PR.
- if $MAILPROG < $REF; then
- echo "$COMMAND: problem report mailed"
- echo "Thank you!"
- xs=0; exit
- else
- echo "$COMMAND: the problem report is not sent."
- fi
- else
- if pr_num=`$libexecdir/pr-edit --submit --show-prnum < $REF` ; then
- echo "$COMMAND: problem report $pr_num filed"
- xs=0; exit
- else
- echo "$COMMAND: the problem report is not sent."
- fi
- fi
- while true
- do
- if [ -z "$BATCH" ]; then
- echo -n "a)bort or s)end? "
- read input
- case "$input" in
- a*)
- break 2 ;;
- s*)
- break ;;
- esac
- else
- break 2;
- fi
- done
-done
-
-if [ -z "$BATCH" ]; then
- echo "$COMMAND: the problem report remains in $BAD and is not sent."
- mv $TEMP $BAD
-else
- echo "$COMMAND: the problem report is not sent."
-fi
-
-xs=1; exit;
diff --git a/send-pr.conf b/send-pr.conf
deleted file mode 100644
index c8dba1f..0000000
--- a/send-pr.conf
+++ /dev/null
@@ -1,5 +0,0 @@
-SUBMITTER=current-users
-TEMPLATE="/etc/gnats/send-pr.template"
-MAILPROG="/usr/lib/sendmail -oi -t"
-MAILADDR="bugs@alpinelinux.org"
-
diff --git a/send-pr.template b/send-pr.template
deleted file mode 100644
index b83a798..0000000
--- a/send-pr.template
+++ /dev/null
@@ -1,41 +0,0 @@
-SEND-PR: -*- send-pr -*-
-SEND-PR: Lines starting with `SEND-PR' will be removed automatically, as
-SEND-PR: will all comments (text enclosed in `<' and `>').
-SEND-PR:
-SEND-PR: Please consult the following URL if you are not sure how to
-SEND-PR: fill out a problem report:
-SEND-PR: http://www.alpinelinux.org/mediawiki/index.php/Problem_Report
-SEND-PR:
-SEND-PR: Note that the Synopis field is mandatory..
-SEND-PR:
-SEND-PR: Choose from the following categories:
-SEND-PR:
-SEND-PR: acf aports base doc
-SEND-PR: misc hosting
-SEND-PR:
-To: bugs@alpinelinux.org
-From: <FROM>
-Reply-To: <REPLYTO>
-X-send-pr-version: 4.1.0
-
-
->Submitter-Id: <SUBMITTER>
->Notify-List: <Addresses to notify of significant PR changes (one line)>
->Originator: <DEFAULT_ORIGINATOR>
->Organization: <Organisation if any>
->Synopsis: <One-line summary of the PR (one line)>
->Confidential: no <Alpine Linux PRs are public data>
->Severity: <[ critical | serious | non-critical ] (one line)>
->Priority: <[ high | medium | low ] (one line)>
->Category: <choose from a category listed above (one line)>
->Class: <[ sw-bug | doc-bug | change-request ] (one line)>
->Release: <ALPINE_RELEASE>
->Environment:
- System: <SYSTEM>
-
->Description:
- <Precise description of the problem (multiple lines)>
->How-To-Repeat:
- <Code/input/activities to reproduce the problem (multiple lines)>
->Fix:
- <How to correct or work around the problem, if known (multiple lines)>
diff --git a/sendbug.conf b/sendbug.conf
deleted file mode 100644
index 353a8fd..0000000
--- a/sendbug.conf
+++ /dev/null
@@ -1,2 +0,0 @@
-mailfrom=
-mailto=bugs@alpinelinux.org
diff --git a/src/Makefile b/src/Makefile
index ba4d5e1..047c474 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -2,8 +2,7 @@
CC = gcc
LD = gcc
-SBIN_TARGETS = runscript mkmntdirs
-USR_BIN_TARGETS = sendbug
+SBIN_TARGETS = mkmntdirs
TARGET = $(BIN_TARGETS) $(SBIN_TARGETS) $(USR_BIN_TARGETS)
.PHONY: all clean
@@ -12,17 +11,10 @@ all: $(TARGET)
%: %.c
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $<
-sendbug: atomicio.o sendbug.o lib.o
- $(CC) $(LDFLAGS) -o $@ $^
-
clean:
rm -f $(TARGET) *.o core *~
install: $(TARGET)
- install -m 0755 -d $(DESTDIR)/bin
install -m 0755 -d $(DESTDIR)/sbin
- install -m 0755 -d $(DESTDIR)/usr
- install -m 0755 -d $(DESTDIR)/usr/bin
- install -m 0755 $(USR_BIN_TARGETS) $(DESTDIR)/usr/bin
install -m 0755 $(SBIN_TARGETS) $(DESTDIR)/sbin
diff --git a/src/cttyhack.c b/src/cttyhack.c
deleted file mode 100644
index e54c1ec..0000000
--- a/src/cttyhack.c
+++ /dev/null
@@ -1,83 +0,0 @@
-/* This code is adapted from busybox project
- *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
- */
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <string.h>
-#include <stdio.h>
-#include <errno.h>
-
-/* From <linux/vt.h> */
-struct vt_stat {
- unsigned short v_active; /* active vt */
- unsigned short v_signal; /* signal to send */
- unsigned short v_state; /* vt bitmask */
-};
-enum { VT_GETSTATE = 0x5603 }; /* get global vt state info */
-
-/* From <linux/serial.h> */
-struct serial_struct {
- int type;
- int line;
- unsigned int port;
- int irq;
- int flags;
- int xmit_fifo_size;
- int custom_divisor;
- int baud_base;
- unsigned short close_delay;
- char io_type;
- char reserved_char[1];
- int hub6;
- unsigned short closing_wait; /* time to wait before closing */
- unsigned short closing_wait2; /* no longer used... */
- unsigned char *iomem_base;
- unsigned short iomem_reg_shift;
- unsigned int port_high;
- unsigned long iomap_base; /* cookie passed into ioremap */
- int reserved[1];
-};
-
-int main(int ergc, char **argv)
-{
- int fd;
- char console[sizeof(int)*3 + 16];
- union {
- struct vt_stat vt;
- struct serial_struct sr;
- char paranoia[sizeof(struct serial_struct) * 3];
- } u;
-
- if (!argv[1]) {
- fprintf(stderr, "Usage: cttyhack cmd [arg1] [arg2]...\n");
- return -1;
- }
-
- strcpy(console, "/dev/tty");
- if (ioctl(0, TIOCGSERIAL, &u.sr) == 0) {
- /* this is a serial console */
- sprintf(console + 8, "S%d", u.sr.line);
- } else if (ioctl(0, VT_GETSTATE, &u.vt) == 0) {
- /* this is linux virtual tty */
- sprintf(console + 8, "%d", u.vt.v_active);
- }
-
- if (console[8]) {
- fd = open(console, O_RDWR);
- if (fd >= 0) {
- //fprintf(stderr, "cttyhack: switching to '%s'\n", console);
- dup2(fd, 0);
- dup2(fd, 1);
- dup2(fd, 2);
- while (fd > 2) close(fd--);
- }
- }
-
- execvp(argv[1], argv + 1);
- fprintf(stderr, "cttyhack: failed to exec %s: %s\n",
- argv[1], strerror(errno));
- return -1;
-}
diff --git a/src/readahead.c b/src/readahead.c
deleted file mode 100644
index 9d44788..0000000
--- a/src/readahead.c
+++ /dev/null
@@ -1,56 +0,0 @@
-#include <stdlib.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sysexits.h>
-
-static const char *program = "readahead";
-
-void usage(void) {
- printf("usage: %s [-hv] FILE [...]\n", program);
- exit(EX_USAGE);
-}
-
-int main( int argc, char *argv[]) {
- int c, verbose=0;
-
- /* parse options */
- while ( (c = getopt(argc, argv, "hv")) >= 0 ) {
- switch (c) {
- case 'v': verbose++;
- break;
- case 'h':
- default: usage();
- break;
- }
- }
-
- /* check that at least one file is specified */
- if (optind == argc)
- usage();
-
- /* parse files */
- c = EX_OK;
- while (optind < argc) {
- struct stat st;
- FILE *f = fopen(argv[optind], "r");
-
-
- /* check that file exists */
- if (f == NULL) {
- perror(argv[optind]);
- c = EX_NOINPUT;
- } else {
- stat(argv[optind], &st);
- readahead( fileno(f), 0, (size_t)st.st_size );
- if (verbose)
- printf("%s\n", argv[optind]);
- fclose(f);
- }
- optind++;
- }
- return (c);
-}
-
diff --git a/src/runscript.c b/src/runscript.c
deleted file mode 100644
index 62e20c6..0000000
--- a/src/runscript.c
+++ /dev/null
@@ -1,25 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-
-#define MAXARGS 32
-
-int main(int argc, char *argv[]) {
- char *av[MAXARGS];
- int i;
- char *runscriptsh;
-
- if (!(runscriptsh = getenv("RUNSCRIPT")))
- runscriptsh = "/sbin/runscript-alpine.sh";
- for (i = 0; i < argc && i < MAXARGS ; i++) {
- av[i] = argv[i];
- }
- av[i] = NULL;
-
- if (execv(runscriptsh, av) < 0) {
- perror("execv");
- return -1;
- }
- return 0;
-}
diff --git a/src/splashbard.c b/src/splashbard.c
deleted file mode 100644
index 7fd5dce..0000000
--- a/src/splashbard.c
+++ /dev/null
@@ -1,215 +0,0 @@
-/*
-
-Splash daemon
-
-*/
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <signal.h>
-#include <string.h>
-
-char unfilled[64] = " ";
-char filled[64] = "=";
-char leftborder[64] = "[";
-char rightborder[64] = "]";
-char animation[64] = "\\|/-";
-char message[128] = "SplashD";
-
-int width = 78;
-int delay = 50000;
-int steps = 10;
-
-char sigusr1 = 0;
-char sigusr2 = 0;
-char sigterm = 0;
-
-const char options[] = "a:d:f:l:m:r:u:";
-
-void usage(int exitcode) {
- fprintf(stderr, "Usage: splashd [-adflru] [OPTION] STEPS\n");
- exit(exitcode);
-}
-
-int parse_args(int argc, char *argv[]) {
- int c;
- while ((c = getopt(argc, argv, options)) > 0) {
- switch(c) {
-
- case 'a': {
- strncpy(animation, optarg, sizeof(animation));
- break;
- }
-
- case 'd': {
- delay = atoi(optarg);
- break;
- }
-
- case 'f': {
- strncpy(filled, optarg, sizeof(filled));
- break;
- }
-
- case 'l': {
- strncpy(leftborder, optarg, sizeof(leftborder));
- break;
- }
-
- case 'm': {
- strncpy(message, optarg, sizeof(message));
- break;
- }
-
- case 'r': {
- strncpy(rightborder, optarg, sizeof(rightborder));
- break;
- }
-
- case 'u': {
- strncpy(unfilled, optarg, sizeof(unfilled));
- break;
- }
-
- case '?':
- default: {
- usage(1);
- break;
- }
-
- }
-
- }
- if (optind != argc-1) usage(1);
- return atoi(argv[optind]);
-}
-
-
-void clear_screen(void) {
- int i;
- for (i=0; i<50; i++) {
- printf("\f");
- }
- printf("\n");
-}
-
-void center(char *s) {
- int i;
- printf("\n");
- for (i=0; i < (80-strlen(s)) /2; i++) putchar(' ');
- printf("%s", s);
-}
-
-void draw_bar(int steps, char *msg) {
- int i=0;
- char bar[256];
- char *p = bar;
- int size=sizeof(bar);
-
- if (steps >= 78) steps=78;
-
- for (i=0; i < 20; i++) printf("\n");
- p += snprintf(p, (size =- strlen(leftborder)), "%s", leftborder);
-
- for (i=0; i < steps; i++) {
- p += snprintf(p, (size =-strlen(unfilled)), "%s", unfilled);
- }
- p += snprintf(p, (size =- strlen(rightborder)), "%s", rightborder);
-
- center(msg);
- printf("\n");
- center(bar);
- for (i=0; i<steps+1; i++) putchar('\b');
- fflush(stdout);
-
-}
-
-void sig_handler(int signo) {
- signal(signo, sig_handler);
- switch(signo) {
-
- case SIGUSR1: {
- sigusr1 = 1;
- break;
- }
-
- case SIGUSR2: {
- sigusr2 = 1;
- break;
- }
-
- case SIGTERM: {
- sigterm = 1;
- break;
- }
-
- default:
- exit(0);
- }
-}
-
-void fill_barstr(char *buf, size_t totsize,
- int current, int steps, char curs) {
- int i = 0;
- int lbsize = strlen(leftborder);
- int rbsize = strlen(rightborder);
- int barsize = totsize - lbsize - rbsize;
- int fillcount = current * barsize / steps;
- int fillsize = strlen(filled) * fillcount;
- char *bar = buf + lbsize;
-
- if (totsize < lbsize + rbsize + 1) return;
-
- strncpy(buf, leftborder, totsize);
- memset(bar, unfilled[0], barsize);
- memset(bar, filled[0], fillcount);
- strncpy(bar + barsize, rightborder, totsize - rbsize);
- if ( current < steps) bar[fillcount] = curs;
-}
-
-
-void run_animation(int steps) {
- int current = 0;
- int i=0;
- char buf[256];
- while (current < steps && sigterm == 0) {
- fill_barstr(buf, width, current, steps, animation[i]);
- i = (i + 1) % strlen(animation);
- printf("\r%s", buf);
- usleep(delay);
- if (sigusr1) {
- sigusr1 = 0;
- current++;
- }
-
- fflush(stdout);
- }
- fill_barstr(buf, width, steps, steps, animation[i]);
- printf("\r%s", buf);
- fflush(stdout);
-}
-
-
-int main(int argc, char *argv[]) {
- int steps;
-
- steps = parse_args(argc, argv);
-
- /* clear screen */
-// clear_screen();
-
- /* fork */
- if (fork()) {
- exit(0);
- }
-
- /* attatch to signal handler */
- signal(SIGUSR1, sig_handler);
- signal(SIGTERM, sig_handler);
-
- run_animation(steps);
- printf("\n\n");
- return 0;
-}
diff --git a/src/start-stop-daemon.c b/src/start-stop-daemon.c
deleted file mode 100644
index 315164f..0000000
--- a/src/start-stop-daemon.c
+++ /dev/null
@@ -1,1375 +0,0 @@
-/*
- * A rewrite of the original Debian's start-stop-daemon Perl script
- * in C (faster - it is executed many times during system startup).
- *
- * Written by Marek Michalkiewicz <marekm@i17linuxb.ists.pwr.wroc.pl>,
- * public domain. Based conceptually on start-stop-daemon.pl, by Ian
- * Jackson <ijackson@gnu.ai.mit.edu>. May be used and distributed
- * freely for any purpose. Changes by Christian Schwarz
- * <schwarz@monet.m.isar.de>, to make output conform to the Debian
- * Console Message Standard, also placed in public domain. Minor
- * changes by Klee Dienes <klee@debian.org>, also placed in the Public
- * Domain.
- *
- * Changes by Ben Collins <bcollins@debian.org>, added --chuid, --background
- * and --make-pidfile options, placed in public domain aswell.
- *
- * Port to OpenBSD by Sontri Tomo Huynh <huynh.29@osu.edu>
- * and Andreas Schuldei <andreas@schuldei.org>
- *
- * Changes by Ian Jackson: added --retry (and associated rearrangements).
- *
- * Modified for Gentoo rc-scripts by Donny Davies <woodchip@gentoo.org>:
- * I removed the BSD/Hurd/OtherOS stuff, added #include <stddef.h>
- * and stuck in a #define VERSION "1.9.18". Now it compiles without
- * the whole automake/config.h dance.
- *
- * Updated by Aron Griffis <agriffis@gentoo.org>:
- * Fetched updates from Debian's dpkg-1.10.20, including fix for
- * Gentoo bug 22686 (start-stop-daemon in baselayout doesn't allow
- * altered nicelevel).
- * Updated by Kito <kito@gentoo.org>:
- * Add support for Darwin, additional patches from opendarwin.org
- * fix for Gentoo bug 72145 from eldad@gentoo.org
- */
-
-#define VERSION "1.10.20"
-#include <stddef.h>
-
-#define NONRETURNPRINTFFORMAT(x, y) \
- __attribute__((noreturn, format(printf, x, y)))
-#define NONRETURNING \
- __attribute__((noreturn))
-
-#if defined(linux) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__))
-# define OSLinux
-#elif defined(__GNU__)
-# define OSHURD
-#elif defined(__sparc__)
-# define OSsunos
-#elif defined(OPENBSD) || defined(__OpenBSD__)
-# define OSOpenBSD
-#elif defined(hpux)
-# define OShpux
-#elif defined(__FreeBSD__)
-# define OSFreeBSD
-#elif defined(__NetBSD__)
-# define OSNetBSD
-#elif defined(__APPLE__)
-# define OSDarwin
-#else
-# error Unknown architecture - cannot build start-stop-daemon
-#endif
-
-#define MIN_POLL_INTERVAL 20000 /*us*/
-
-#if defined(OSHURD)
-# include <hurd.h>
-# include <ps.h>
-#endif
-
-#if defined(OSOpenBSD) || defined(OSFreeBSD) || defined(OSNetBSD) || defined(OSDarwin)
-#include <sys/param.h>
-#include <sys/user.h>
-#include <sys/proc.h>
-#include <sys/stat.h>
-#include <sys/sysctl.h>
-#include <sys/types.h>
-
-#include <err.h>
-#include <kvm.h>
-#include <limits.h>
-#endif
-
-#if defined(OShpux)
-#include <sys/param.h>
-#include <sys/pstat.h>
-#endif
-
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
-#include <signal.h>
-#include <sys/stat.h>
-#include <dirent.h>
-#include <sys/time.h>
-#include <unistd.h>
-#include <getopt.h>
-#include <pwd.h>
-#include <grp.h>
-#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <sys/termios.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <assert.h>
-#include <ctype.h>
-
-#include "headers.h"
-
-#ifdef HURD_IHASH_H
-# include <hurd/ihash.h>
-#endif
-
-static int testmode = 0;
-static int quietmode = 0;
-static int exitnodo = 1;
-static int start = 0;
-static int stop = 0;
-static int background = 0;
-static int mpidfile = 0;
-static int signal_nr = 15;
-static const char *signal_str = NULL;
-static int user_id = -1;
-static int runas_uid = -1;
-static int runas_gid = -1;
-static const char *userspec = NULL;
-static char *changeuser = NULL;
-static const char *changegroup = NULL;
-static char *changeroot = NULL;
-static const char *changedir = NULL;
-static const char *cmdname = NULL;
-static char *execname = NULL;
-static char *startas = NULL;
-static const char *pidfile = NULL;
-static char what_stop[1024];
-static const char *schedule_str = NULL;
-static const char *progname = "";
-static int nicelevel = 0;
-
-static struct stat exec_stat;
-#if defined(OSHURD)
-static struct proc_stat_list *procset;
-#endif
-
-
-struct pid_list {
- struct pid_list *next;
- pid_t pid;
-};
-
-static struct pid_list *found = NULL;
-static struct pid_list *killed = NULL;
-
-struct schedule_item {
- enum { sched_timeout, sched_signal, sched_goto, sched_forever } type;
- int value; /* seconds, signal no., or index into array */
- /* sched_forever is only seen within parse_schedule and callees */
-};
-
-static int schedule_length;
-static struct schedule_item *schedule = NULL;
-
-static void *xmalloc(int size);
-static void push(struct pid_list **list, pid_t pid);
-static void do_help(void);
-static void parse_options(int argc, char * const *argv);
-static int pid_is_user(pid_t pid, uid_t uid);
-static int pid_is_cmd(pid_t pid, const char *name);
-static void check(pid_t pid);
-static void do_pidfile(const char *name);
-static void do_stop(int signal_nr, int quietmode,
- int *n_killed, int *n_notkilled, int retry_nr);
-#if defined(OSLinux) || defined(OShpux)
-static int pid_is_exec(pid_t pid, const struct stat *esb);
-#endif
-
-#ifdef __GNUC__
-static void fatal(const char *format, ...)
- NONRETURNPRINTFFORMAT(1, 2);
-static void badusage(const char *msg)
- NONRETURNING;
-#else
-static void fatal(const char *format, ...);
-static void badusage(const char *msg);
-#endif
-
-/* This next part serves only to construct the TVCALC macro, which
- * is used for doing arithmetic on struct timeval's. It works like this:
- * TVCALC(result, expression);
- * where result is a struct timeval (and must be an lvalue) and
- * expression is the single expression for both components. In this
- * expression you can use the special values TVELEM, which when fed a
- * const struct timeval* gives you the relevant component, and
- * TVADJUST. TVADJUST is necessary when subtracting timevals, to make
- * it easier to renormalise. Whenver you subtract timeval elements,
- * you must make sure that TVADJUST is added to the result of the
- * subtraction (before any resulting multiplication or what have you).
- * TVELEM must be linear in TVADJUST.
- */
-typedef long tvselector(const struct timeval*);
-static long tvselector_sec(const struct timeval *tv) { return tv->tv_sec; }
-static long tvselector_usec(const struct timeval *tv) { return tv->tv_usec; }
-#define TVCALC_ELEM(result, expr, sec, adj) \
-{ \
- const long TVADJUST = adj; \
- long (*const TVELEM)(const struct timeval*) = tvselector_##sec; \
- (result).tv_##sec = (expr); \
-}
-#define TVCALC(result,expr) \
-do { \
- TVCALC_ELEM(result, expr, sec, (-1)); \
- TVCALC_ELEM(result, expr, usec, (+1000000)); \
- (result).tv_sec += (result).tv_usec / 1000000; \
- (result).tv_usec %= 1000000; \
-} while(0)
-
-
-static void
-fatal(const char *format, ...)
-{
- va_list arglist;
-
- fprintf(stderr, "%s: ", progname);
- va_start(arglist, format);
- vfprintf(stderr, format, arglist);
- va_end(arglist);
- putc('\n', stderr);
- exit(2);
-}
-
-
-static void *
-xmalloc(int size)
-{
- void *ptr;
-
- ptr = malloc(size);
- if (ptr)
- return ptr;
- fatal("malloc(%d) failed", size);
-}
-
-
-static void
-xgettimeofday(struct timeval *tv)
-{
- if (gettimeofday(tv,0) != 0)
- fatal("gettimeofday failed: %s", strerror(errno));
-}
-
-
-static void
-push(struct pid_list **list, pid_t pid)
-{
- struct pid_list *p;
-
- p = xmalloc(sizeof(*p));
- p->next = *list;
- p->pid = pid;
- *list = p;
-}
-
-static void
-clear(struct pid_list **list)
-{
- struct pid_list *here, *next;
-
- for (here = *list; here != NULL; here = next) {
- next = here->next;
- free(here);
- }
-
- *list = NULL;
-}
-
-static void
-do_help(void)
-{
- printf(
-"start-stop-daemon " VERSION " for Debian - small and fast C version written by\n"
-"Marek Michalkiewicz <marekm@i17linuxb.ists.pwr.wroc.pl>, public domain.\n"
-"\n"
-"Usage:\n"
-" start-stop-daemon -S|--start options ... -- arguments ...\n"
-" start-stop-daemon -K|--stop options ...\n"
-" start-stop-daemon -H|--help\n"
-" start-stop-daemon -V|--version\n"
-"\n"
-"Options (at least one of --exec|--pidfile|--user is required):\n"
-" -x|--exec <executable> program to start/check if it is running\n"
-" -p|--pidfile <pid-file> pid file to check\n"
-" -c|--chuid <name|uid[:group|gid]>\n"
-" change to this user/group before starting process\n"
-" -u|--user <username>|<uid> stop processes owned by this user\n"
-" -g|--group <group|gid> run process as this group\n"
-" -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"
-" -C|--chdir <directory> Change to <directory>(default is /)\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"
-" -R|--retry <schedule> check whether processes die, and retry\n"
-" -t|--test test mode, don't do anything\n"
-" -o|--oknodo exit status 0 (not 1) if nothing done\n"
-" -q|--quiet be more quiet\n"
-" -v|--verbose be more verbose\n"
-"Retry <schedule> is <item>|/<item>/... where <item> is one of\n"
-" -<signal-num>|[-]<signal-name> send that signal\n"
-" <timeout> wait that many seconds\n"
-" forever repeat remainder forever\n"
-"or <schedule> may be just <timeout>, meaning <signal>/<timeout>/KILL/<timeout>\n"
-"\n"
-"Exit status: 0 = done 1 = nothing done (=> 0 if --oknodo)\n"
-" 3 = trouble 2 = with --retry, processes wouldn't die\n");
-}
-
-
-static void
-badusage(const char *msg)
-{
- if (msg)
- fprintf(stderr, "%s: %s\n", progname, msg);
- fprintf(stderr, "Try `%s --help' for more information.\n", progname);
- exit(3);
-}
-
-struct sigpair {
- const char *name;
- int signal;
-};
-
-const struct sigpair siglist[] = {
- { "ABRT", SIGABRT },
- { "ALRM", SIGALRM },
- { "FPE", SIGFPE },
- { "HUP", SIGHUP },
- { "ILL", SIGILL },
- { "INT", SIGINT },
- { "KILL", SIGKILL },
- { "PIPE", SIGPIPE },
- { "QUIT", SIGQUIT },
- { "SEGV", SIGSEGV },
- { "TERM", SIGTERM },
- { "USR1", SIGUSR1 },
- { "USR2", SIGUSR2 },
- { "CHLD", SIGCHLD },
- { "CONT", SIGCONT },
- { "STOP", SIGSTOP },
- { "TSTP", SIGTSTP },
- { "TTIN", SIGTTIN },
- { "TTOU", SIGTTOU }
-};
-
-static int parse_integer(const char *string, int *value_r) {
- unsigned long ul;
- char *ep;
-
- if (!string[0])
- return -1;
-
- ul= strtoul(string,&ep,10);
- if (ul > INT_MAX || *ep != '\0')
- return -1;
-
- *value_r= ul;
- return 0;
-}
-
-static int parse_signal(const char *signal_str, int *signal_nr)
-{
- unsigned int i;
-
- if (parse_integer(signal_str, signal_nr) == 0)
- return 0;
-
- for (i = 0; i < sizeof (siglist) / sizeof (siglist[0]); i++) {
- if (strcmp (signal_str, siglist[i].name) == 0) {
- *signal_nr = siglist[i].signal;
- return 0;
- }
- }
- return -1;
-}
-
-static void
-parse_schedule_item(const char *string, struct schedule_item *item) {
- const char *after_hyph;
-
- if (!strcmp(string,"forever")) {
- item->type = sched_forever;
- } else if (isdigit(string[0])) {
- item->type = sched_timeout;
- if (parse_integer(string, &item->value) != 0)
- badusage("invalid timeout value in schedule");
- } else if ((after_hyph = string + (string[0] == '-')) &&
- parse_signal(after_hyph, &item->value) == 0) {
- item->type = sched_signal;
- } else {
- badusage("invalid schedule item (must be [-]<signal-name>, "
- "-<signal-number>, <timeout> or `forever'");
- }
-}
-
-static void
-parse_schedule(const char *schedule_str) {
- char item_buf[20];
- const char *slash;
- int count, repeatat;
- ptrdiff_t str_len;
-
- count = 0;
- for (slash = schedule_str; *slash; slash++)
- if (*slash == '/')
- count++;
-
- schedule_length = (count == 0) ? 4 : count+1;
- schedule = xmalloc(sizeof(*schedule) * schedule_length);
-
- if (count == 0) {
- schedule[0].type = sched_signal;
- schedule[0].value = signal_nr;
- parse_schedule_item(schedule_str, &schedule[1]);
- if (schedule[1].type != sched_timeout) {
- badusage ("--retry takes timeout, or schedule list"
- " of at least two items");
- }
- schedule[2].type = sched_signal;
- schedule[2].value = SIGKILL;
- schedule[3]= schedule[1];
- } else {
- count = 0;
- repeatat = -1;
- while (schedule_str != NULL) {
- slash = strchr(schedule_str,'/');
- str_len = slash ? slash - schedule_str : strlen(schedule_str);
- if (str_len >= (ptrdiff_t)sizeof(item_buf))
- badusage("invalid schedule item: far too long"
- " (you must delimit items with slashes)");
- memcpy(item_buf, schedule_str, str_len);
- item_buf[str_len] = 0;
- schedule_str = slash ? slash+1 : NULL;
-
- parse_schedule_item(item_buf, &schedule[count]);
- if (schedule[count].type == sched_forever) {
- if (repeatat >= 0)
- badusage("invalid schedule: `forever'"
- " appears more than once");
- repeatat = count;
- continue;
- }
- count++;
- }
- if (repeatat >= 0) {
- schedule[count].type = sched_goto;
- schedule[count].value = repeatat;
- count++;
- }
- assert(count == schedule_length);
- }
-}
-
-static void
-parse_options(int argc, char * const *argv)
-{
- static struct option longopts[] = {
- { "help", 0, NULL, 'H'},
- { "stop", 0, NULL, 'K'},
- { "start", 0, NULL, 'S'},
- { "version", 0, NULL, 'V'},
- { "startas", 1, NULL, 'a'},
- { "name", 1, NULL, 'n'},
- { "oknodo", 0, NULL, 'o'},
- { "pidfile", 1, NULL, 'p'},
- { "quiet", 0, NULL, 'q'},
- { "signal", 1, NULL, 's'},
- { "test", 0, NULL, 't'},
- { "user", 1, NULL, 'u'},
- { "group", 1, NULL, 'g'},
- { "chroot", 1, NULL, 'r'},
- { "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'},
- { "retry", 1, NULL, 'R'},
- { "chdir", 1, NULL, 'd'},
- { NULL, 0, NULL, 0}
- };
- int c;
-
- for (;;) {
- c = getopt_long(argc, argv, "HKSV:a:n:op:qr:s:tu:vx:c:N:bmR:g:d:",
- longopts, (int *) 0);
- if (c == -1)
- break;
- switch (c) {
- case 'H': /* --help */
- do_help();
- exit(0);
- case 'K': /* --stop */
- stop = 1;
- break;
- case 'S': /* --start */
- start = 1;
- break;
- case 'V': /* --version */
- printf("start-stop-daemon " VERSION "\n");
- exit(0);
- case 'a': /* --startas <pathname> */
- startas = optarg;
- break;
- case 'n': /* --name <process-name> */
- cmdname = optarg;
- break;
- case 'o': /* --oknodo */
- exitnodo = 0;
- break;
- case 'p': /* --pidfile <pid-file> */
- pidfile = optarg;
- break;
- case 'q': /* --quiet */
- quietmode = 1;
- break;
- case 's': /* --signal <signal> */
- signal_str = optarg;
- break;
- case 't': /* --test */
- testmode = 1;
- break;
- case 'u': /* --user <username>|<uid> */
- userspec = optarg;
- break;
- case 'v': /* --verbose */
- quietmode = -1;
- break;
- case 'x': /* --exec <executable> */
- execname = optarg;
- break;
- case 'c': /* --chuid <username>|<uid> */
- /* we copy the string just in case we need the
- * argument later. */
- changeuser = strdup(optarg);
- changeuser = strtok(changeuser, ":");
- changegroup = strtok(NULL, ":");
- break;
- case 'g': /* --group <group>|<gid> */
- changegroup = optarg;
- break;
- case 'r': /* --chroot /new/root */
- changeroot = optarg;
- break;
- case 'N': /* --nice */
- nicelevel = atoi(optarg);
- break;
- case 'b': /* --background */
- background = 1;
- break;
- case 'm': /* --make-pidfile */
- mpidfile = 1;
- break;
- case 'R': /* --retry <schedule>|<timeout> */
- schedule_str = optarg;
- break;
- case 'd': /* --chdir /new/dir */
- changedir = optarg;
- break;
- default:
- badusage(NULL); /* message printed by getopt */
- }
- }
-
- if (signal_str != NULL) {
- if (parse_signal (signal_str, &signal_nr) != 0)
- badusage("signal value must be numeric or name"
- " of signal (KILL, INT, ...)");
- }
-
- if (schedule_str != NULL) {
- parse_schedule(schedule_str);
- }
-
- if (start == stop)
- badusage("need one of --start or --stop");
-
- if (!execname && !pidfile && !userspec && !cmdname)
- badusage("need at least one of --exec, --pidfile, --user or --name");
-
- if (!startas)
- startas = execname;
-
- if (start && !startas)
- badusage("--start needs --exec or --startas");
-
- if (mpidfile && pidfile == NULL)
- badusage("--make-pidfile is only relevant with --pidfile");
-
- if (background && !start)
- badusage("--background is only relevant with --start");
-
-}
-
-#if defined(OSLinux)
-static int
-pid_is_exec(pid_t pid, const struct stat *esb)
-{
- struct stat sb;
- char buf[32];
-
- sprintf(buf, "/proc/%d/exe", pid);
- if (stat(buf, &sb) != 0)
- return 0;
- return (sb.st_dev == esb->st_dev && sb.st_ino == esb->st_ino);
-}
-
-
-static int
-pid_is_user(pid_t pid, uid_t uid)
-{
- struct stat sb;
- char buf[32];
-
- sprintf(buf, "/proc/%d", pid);
- if (stat(buf, &sb) != 0)
- return 0;
- return (sb.st_uid == uid);
-}
-
-
-static int
-pid_is_cmd(pid_t pid, const char *name)
-{
- char buf[32];
- FILE *f;
- int c;
-
- sprintf(buf, "/proc/%d/stat", pid);
- f = fopen(buf, "r");
- if (!f)
- return 0;
- while ((c = getc(f)) != EOF && c != '(')
- ;
- if (c != '(') {
- fclose(f);
- return 0;
- }
- /* this hopefully handles command names containing ')' */
- while ((c = getc(f)) != EOF && c == *name)
- name++;
- fclose(f);
- return (c == ')' && *name == '\0');
-}
-#endif /* OSLinux */
-
-
-#if defined(OSHURD)
-static int
-pid_is_user(pid_t pid, uid_t uid)
-{
- struct stat sb;
- char buf[32];
- struct proc_stat *pstat;
-
- sprintf(buf, "/proc/%d", pid);
- if (stat(buf, &sb) != 0)
- return 0;
- return (sb.st_uid == uid);
- pstat = proc_stat_list_pid_proc_stat (procset, pid);
- if (pstat == NULL)
- fatal ("Error getting process information: NULL proc_stat struct");
- proc_stat_set_flags (pstat, PSTAT_PID | PSTAT_OWNER_UID);
- return (pstat->owner_uid == uid);
-}
-
-static int
-pid_is_cmd(pid_t pid, const char *name)
-{
- struct proc_stat *pstat;
- pstat = proc_stat_list_pid_proc_stat (procset, pid);
- if (pstat == NULL)
- fatal ("Error getting process information: NULL proc_stat struct");
- proc_stat_set_flags (pstat, PSTAT_PID | PSTAT_ARGS);
- return (!strcmp (name, pstat->args));
-}
-#endif /* OSHURD */
-
-
-static int
-pid_is_running(pid_t pid)
-{
- struct stat sb;
- char buf[32];
-
- sprintf(buf, "/proc/%d", pid);
- if (stat(buf, &sb) != 0) {
- if (errno!=ENOENT)
- fatal("Error stating %s: %s", buf, strerror(errno));
- return 0;
- }
-
- return 1;
-}
-
-static void
-check(pid_t pid)
-{
-#if defined(OSLinux) || defined(OShpux)
- if (execname && !pid_is_exec(pid, &exec_stat))
- return;
-#elif defined(OSHURD) || defined(OSFreeBSD) || defined(OSNetBSD) || defined(OSDarwin)
- /* I will try this to see if it works */
- if (execname && !pid_is_cmd(pid, execname))
- return;
-#endif
- if (userspec && !pid_is_user(pid, user_id))
- return;
- if (cmdname && !pid_is_cmd(pid, cmdname))
- return;
- if (start && !pid_is_running(pid))
- return;
- push(&found, pid);
-}
-
-static void
-do_pidfile(const char *name)
-{
- FILE *f;
- pid_t pid;
-
- f = fopen(name, "r");
- if (f) {
- if (fscanf(f, "%d", &pid) == 1)
- check(pid);
- fclose(f);
- } else if (errno != ENOENT)
- fatal("open pidfile %s: %s", name, strerror(errno));
-
-}
-
-/* WTA: this needs to be an autoconf check for /proc/pid existance.
- */
-
-#if defined(OSLinux) || defined (OSsunos) || defined(OSfreebsd)
-static void
-do_procinit(void)
-{
- DIR *procdir;
- struct dirent *entry;
- int foundany;
- pid_t pid;
-
- procdir = opendir("/proc");
- if (!procdir)
- fatal("opendir /proc: %s", strerror(errno));
-
- foundany = 0;
- while ((entry = readdir(procdir)) != NULL) {
- if (sscanf(entry->d_name, "%d", &pid) != 1)
- continue;
- foundany++;
- check(pid);
- }
- closedir(procdir);
- if (!foundany)
- fatal("nothing in /proc - not mounted?");
-}
-#endif /* OSLinux */
-
-
-#if defined(OSHURD)
-error_t
-check_all(void *ptr)
-{
- struct proc_stat *pstat = ptr;
-
- check(pstat->pid);
- return 0;
-}
-
-static void
-do_procinit(void)
-{
- struct ps_context *context;
- error_t err;
-
- err = ps_context_create(getproc(), &context);
- if (err)
- error(1, err, "ps_context_create");
-
- err = proc_stat_list_create(context, &procset);
- if (err)
- error(1, err, "proc_stat_list_create");
-
- err = proc_stat_list_add_all(procset, 0, 0);
- if (err)
- error(1, err, "proc_stat_list_add_all");
-
- /* Check all pids */
- ihash_iterate(context->procs, check_all);
-}
-#endif /* OSHURD */
-
-
-#if defined(OSOpenBSD) || defined(OSFreeBSD) || defined(OSNetBSD)
-static int
-pid_is_cmd(pid_t pid, const char *name)
-{
- kvm_t *kd;
- int nentries, argv_len=0;
- struct kinfo_proc *kp;
- char errbuf[_POSIX2_LINE_MAX], buf[_POSIX2_LINE_MAX];
- char **pid_argv_p;
- char *start_argv_0_p, *end_argv_0_p;
-
-
- kd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, errbuf);
- if (kd == 0)
- errx(1, "%s", errbuf);
- if ((kp = kvm_getprocs(kd, KERN_PROC_PID, pid, &nentries)) == 0)
- errx(1, "%s", kvm_geterr(kd));
- if ((pid_argv_p = kvm_getargv(kd, kp, argv_len)) == 0)
- errx(1, "%s", kvm_geterr(kd));
-
- start_argv_0_p = *pid_argv_p;
- /* find and compare string */
-
- /* find end of argv[0] then copy and cut of str there. */
- if ((end_argv_0_p = strchr(*pid_argv_p, ' ')) == 0 )
- /* There seems to be no space, so we have the command
- * allready in its desired form. */
- start_argv_0_p = *pid_argv_p;
- else {
- /* Tests indicate that this never happens, since
- * kvm_getargv itselfe cuts of tailing stuff. This is
- * not what the manpage says, however. */
- strncpy(buf, *pid_argv_p, (end_argv_0_p - start_argv_0_p));
- buf[(end_argv_0_p - start_argv_0_p) + 1] = '\0';
- start_argv_0_p = buf;
- }
-
- if (strlen(name) != strlen(start_argv_0_p))
- return 0;
- return (strcmp(name, start_argv_0_p) == 0) ? 1 : 0;
-}
-
-static int
-pid_is_user(pid_t pid, uid_t uid)
-{
- kvm_t *kd;
- int nentries; /* Value not used */
- uid_t proc_uid;
- struct kinfo_proc *kp;
- char errbuf[_POSIX2_LINE_MAX];
-
-
- kd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, errbuf);
- if (kd == 0)
- errx(1, "%s", errbuf);
- if ((kp = kvm_getprocs(kd, KERN_PROC_PID, pid, &nentries)) == 0)
- errx(1, "%s", kvm_geterr(kd));
- if (kp->ki_ruid )
- kvm_read(kd, (u_long)&(kp->ki_ruid),
- &proc_uid, sizeof(uid_t));
- else
- return 0;
- return (proc_uid == (uid_t)uid);
-}
-
-static int
-pid_is_exec(pid_t pid, const char *name)
-{
- kvm_t *kd;
- int nentries;
- struct kinfo_proc *kp;
- char errbuf[_POSIX2_LINE_MAX], *pidexec;
-
- kd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, errbuf);
- if (kd == 0)
- errx(1, "%s", errbuf);
- if ((kp = kvm_getprocs(kd, KERN_PROC_PID, pid, &nentries)) == 0)
- errx(1, "%s", kvm_geterr(kd));
- pidexec = kp->ki_comm;
- if (strlen(name) != strlen(pidexec))
- return 0;
- return (strcmp(name, pidexec) == 0) ? 1 : 0;
-}
-
-
-static void
-do_procinit(void)
-{
- /* Nothing to do */
-}
-
-#endif /* OSOpenBSD */
-
-#if defined(OSDarwin)
-int
-pid_is_user(pid_t pid, uid_t uid)
-{
- int mib[4];
- size_t size;
- struct kinfo_proc ki;
-
- size = sizeof(ki);
- mib[0] = CTL_KERN;
- mib[1] = KERN_PROC;
- mib[2] = KERN_PROC_PID;
- mib[3] = pid;
- if (sysctl(mib, 4, &ki, &size, NULL, 0) < 0)
- errx(1, "%s", "Failure calling sysctl");
- return (uid == ki.kp_eproc.e_pcred.p_ruid);
-}
-
-static int
-pid_is_cmd(pid_t pid, const char *name)
-{
- int mib[4];
- size_t size;
- struct kinfo_proc ki;
-
- size = sizeof(ki);
- mib[0] = CTL_KERN;
- mib[1] = KERN_PROC;
- mib[2] = KERN_PROC_PID;
- mib[3] = pid;
- if (sysctl(mib, 4, &ki, &size, NULL, 0) < 0)
- errx(1, "%s", "Failure calling sysctl");
- return (!strncmp(name, ki.kp_proc.p_comm, MAXCOMLEN));
-}
-
-static void
-do_procinit(void)
-{
- int mib[3];
- size_t size;
- int nprocs, ret, i;
- struct kinfo_proc *procs = NULL, *newprocs;
-
- mib[0] = CTL_KERN;
- mib[1] = KERN_PROC;
- mib[2] = KERN_PROC_ALL;
- ret = sysctl(mib, 3, NULL, &size, NULL, 0);
- /* Allocate enough memory for entire process table */
- do {
- size += size / 10;
- newprocs = realloc(procs, size);
- if (newprocs == NULL) {
- if (procs)
- free(procs);
- errx(1, "%s", "Could not reallocate memory");
- }
- procs = newprocs;
- ret = sysctl(mib, 3, procs, &size, NULL, 0);
- } while (ret >= 0 && errno == ENOMEM);
-
- if (ret < 0)
- errx(1, "%s", "Failure calling sysctl");
-
- /* Verify size of proc structure */
- if (size % sizeof(struct kinfo_proc) != 0)
- errx(1, "%s", "proc size mismatch, userland out of sync with kernel");
- nprocs = size / sizeof(struct kinfo_proc);
- for (i = 0; i < nprocs; i++) {
- check(procs[i].kp_proc.p_pid);
- }
-}
-#endif /* OSDarwin */
-#if defined(OShpux)
-static int
-pid_is_user(pid_t pid, uid_t uid)
-{
- struct pst_status pst;
-
- if (pstat_getproc(&pst, sizeof(pst), (size_t) 0, (int) pid) < 0)
- return 0;
- return ((uid_t) pst.pst_uid == uid);
-}
-
-static int
-pid_is_cmd(pid_t pid, const char *name)
-{
- struct pst_status pst;
-
- if (pstat_getproc(&pst, sizeof(pst), (size_t) 0, (int) pid) < 0)
- return 0;
- return (strcmp(pst.pst_ucomm, name) == 0);
-}
-
-static int
-pid_is_exec(pid_t pid, const struct stat *esb)
-{
- struct pst_status pst;
-
- if (pstat_getproc(&pst, sizeof(pst), (size_t) 0, (int) pid) < 0)
- return 0;
- return ((dev_t) pst.pst_text.psf_fsid.psfs_id == esb->st_dev
- && (ino_t) pst.pst_text.psf_fileid == esb->st_ino);
-}
-
-static void
-do_procinit(void)
-{
- struct pst_status pst[10];
- int i, count;
- int idx = 0;
-
- while ((count = pstat_getproc(pst, sizeof(pst[0]), 10, idx)) > 0) {
- for (i = 0; i < count; i++)
- check(pst[i].pst_pid);
- idx = pst[count - 1].pst_idx + 1;
- }
-}
-#endif /* OShpux */
-
-
-static void
-do_findprocs(void)
-{
- clear(&found);
-
- if (pidfile)
- do_pidfile(pidfile);
- else
- do_procinit();
-}
-
-/* return 1 on failure */
-static void
-do_stop(int signal_nr, int quietmode, int *n_killed, int *n_notkilled, int retry_nr)
-{
- struct pid_list *p;
-
- do_findprocs();
-
- *n_killed = 0;
- *n_notkilled = 0;
-
- if (!found)
- return;
-
- clear(&killed);
-
- for (p = found; p; p = p->next) {
- if (testmode) {
- printf("Would send signal %d to %d.\n",
- signal_nr, p->pid);
- (*n_killed)++;
- } else if (kill(p->pid, signal_nr) == 0) {
- push(&killed, p->pid);
- (*n_killed)++;
- } else {
- printf("%s: warning: failed to kill %d: %s\n",
- progname, p->pid, strerror(errno));
- (*n_notkilled)++;
- }
- }
- if (quietmode < 0 && killed) {
- printf("Stopped %s (pid", what_stop);
- for (p = killed; p; p = p->next)
- printf(" %d", p->pid);
- putchar(')');
- if (retry_nr > 0)
- printf(", retry #%d", retry_nr);
- printf(".\n");
- }
-}
-
-
-static void
-set_what_stop(const char *str)
-{
- strncpy(what_stop, str, sizeof(what_stop));
- what_stop[sizeof(what_stop)-1] = '\0';
-}
-
-static int
-run_stop_schedule(void)
-{
- int r, position, n_killed, n_notkilled, value, ratio, anykilled, retry_nr;
- struct timeval stopat, before, after, interval, maxinterval;
-
- if (testmode) {
- if (schedule != NULL) {
- printf("Ignoring --retry in test mode\n");
- schedule = NULL;
- }
- }
-
- if (cmdname)
- set_what_stop(cmdname);
- else if (execname)
- set_what_stop(execname);
- else if (pidfile)
- sprintf(what_stop, "process in pidfile `%.200s'", pidfile);
- else if (userspec)
- sprintf(what_stop, "process(es) owned by `%.200s'", userspec);
- else
- fatal("internal error, please report");
-
- anykilled = 0;
- retry_nr = 0;
-
- if (schedule == NULL) {
- do_stop(signal_nr, quietmode, &n_killed, &n_notkilled, 0);
- if (n_notkilled > 0 && quietmode <= 0)
- printf("%d pids were not killed\n", n_notkilled);
- if (n_killed)
- anykilled = 1;
- goto x_finished;
- }
-
- for (position = 0; position < schedule_length; ) {
- value= schedule[position].value;
- n_notkilled = 0;
-
- switch (schedule[position].type) {
-
- case sched_goto:
- position = value;
- continue;
-
- case sched_signal:
- do_stop(value, quietmode, &n_killed, &n_notkilled, retry_nr++);
- if (!n_killed)
- goto x_finished;
- else
- anykilled = 1;
- goto next_item;
-
- case sched_timeout:
- /* We want to keep polling for the processes, to see if they've exited,
- * or until the timeout expires.
- *
- * This is a somewhat complicated algorithm to try to ensure that we
- * notice reasonably quickly when all the processes have exited, but
- * don't spend too much CPU time polling. In particular, on a fast
- * machine with quick-exiting daemons we don't want to delay system
- * shutdown too much, whereas on a slow one, or where processes are
- * taking some time to exit, we want to increase the polling
- * interval.
- *
- * The algorithm is as follows: we measure the elapsed time it takes
- * to do one poll(), and wait a multiple of this time for the next
- * poll. However, if that would put us past the end of the timeout
- * period we wait only as long as the timeout period, but in any case
- * we always wait at least MIN_POLL_INTERVAL (20ms). The multiple
- * (`ratio') starts out as 2, and increases by 1 for each poll to a
- * maximum of 10; so we use up to between 30% and 10% of the
- * machine's resources (assuming a few reasonable things about system
- * performance).
- */
- xgettimeofday(&stopat);
- stopat.tv_sec += value;
- ratio = 1;
- for (;;) {
- xgettimeofday(&before);
- if (timercmp(&before,&stopat,>))
- goto next_item;
-
- do_stop(0, 1, &n_killed, &n_notkilled, 0);
- if (!n_killed)
- goto x_finished;
-
- xgettimeofday(&after);
-
- if (!timercmp(&after,&stopat,<))
- goto next_item;
-
- if (ratio < 10)
- ratio++;
-
- TVCALC(interval, ratio * (TVELEM(&after) - TVELEM(&before) + TVADJUST));
- TVCALC(maxinterval, TVELEM(&stopat) - TVELEM(&after) + TVADJUST);
-
- if (timercmp(&interval,&maxinterval,>))
- interval = maxinterval;
-
- if (interval.tv_sec == 0 &&
- interval.tv_usec <= MIN_POLL_INTERVAL)
- interval.tv_usec = MIN_POLL_INTERVAL;
-
- r = select(0,0,0,0,&interval);
- if (r < 0 && errno != EINTR)
- fatal("select() failed for pause: %s",
- strerror(errno));
- }
-
- default:
- assert(!"schedule[].type value must be valid");
-
- }
-
- next_item:
- position++;
- }
-
- if (quietmode <= 0)
- printf("Program %s, %d process(es), refused to die.\n",
- what_stop, n_killed);
-
- return 2;
-
-x_finished:
- if (!anykilled) {
- if (quietmode <= 0)
- printf("No %s found running; none killed.\n", what_stop);
- return exitnodo;
- } else {
- return 0;
- }
-}
-
-
-int main(int argc, char **argv) NONRETURNING;
-int
-main(int argc, char **argv)
-{
- int devnull_fd = -1;
-#ifdef HAVE_TIOCNOTTY
- int tty_fd = -1;
-#endif
- progname = argv[0];
-
- parse_options(argc, argv);
- argc -= optind;
- argv += optind;
-
- if (execname && stat(execname, &exec_stat))
- fatal("stat %s: %s", execname, strerror(errno));
-
- if (userspec && sscanf(userspec, "%d", &user_id) != 1) {
- struct passwd *pw;
-
- pw = getpwnam(userspec);
- if (!pw)
- fatal("user `%s' not found\n", userspec);
-
- user_id = pw->pw_uid;
- }
-
- if (changegroup && sscanf(changegroup, "%d", &runas_gid) != 1) {
- struct group *gr = getgrnam(changegroup);
- if (!gr)
- fatal("group `%s' not found\n", changegroup);
- runas_gid = gr->gr_gid;
- }
- if (changeuser && sscanf(changeuser, "%d", &runas_uid) != 1) {
- struct passwd *pw = getpwnam(changeuser);
- if (!pw)
- fatal("user `%s' not found\n", changeuser);
- runas_uid = pw->pw_uid;
- if (changegroup == NULL) { /* pass the default group of this user */
- changegroup = ""; /* just empty */
- runas_gid = pw->pw_gid;
- }
- }
-
- if (stop) {
- int i = run_stop_schedule();
- exit(i);
- }
-
- do_findprocs();
-
- if (found) {
- if (quietmode <= 0)
- printf("%s already running.\n", execname ? execname : "process");
- exit(exitnodo);
- }
- if (testmode) {
- printf("Would start %s ", startas);
- while (argc-- > 0)
- printf("%s ", *argv++);
- if (changeuser != NULL) {
- printf(" (as user %s[%d]", changeuser, runas_uid);
- if (changegroup != NULL)
- printf(", and group %s[%d])", changegroup, runas_gid);
- else
- printf(")");
- }
- if (changeroot != NULL)
- printf(" in directory %s", changeroot);
- if (nicelevel)
- printf(", and add %i to the priority", nicelevel);
- printf(".\n");
- exit(0);
- }
- if (quietmode < 0)
- printf("Starting %s...\n", startas);
- *--argv = startas;
- if (background) { /* ok, we need to detach this process */
- int i;
- if (quietmode < 0)
- printf("Detatching to start %s...", startas);
- i = fork();
- if (i<0) {
- fatal("Unable to fork.\n");
- }
- if (i) { /* parent */
- if (quietmode < 0)
- printf("done.\n");
- exit(0);
- }
- /* child continues here */
-
-#ifdef HAVE_TIOCNOTTY
- tty_fd=open("/dev/tty", O_RDWR);
-#endif
- devnull_fd=open("/dev/null", O_RDWR);
- }
- if (nicelevel) {
- errno=0;
- if ((nice(nicelevel)==-1) && (errno!=0))
- 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();
- if (pidf == NULL)
- fatal("Unable to open pidfile `%s' for writing: %s", pidfile,
- strerror(errno));
- fprintf(pidf, "%d\n", pidt);
- fclose(pidf);
- }
- if (changeroot != NULL) {
- if (chdir(changeroot) < 0)
- fatal("Unable to chdir() to %s", changeroot);
- if (chroot(changeroot) < 0)
- fatal("Unable to chroot() to %s", changeroot);
- }
- if (changedir != NULL && chdir(changedir) < 0)
- fatal("Unable to chdir() to %s", changedir);
- if (changeuser != NULL) {
- if (setgid(runas_gid))
- fatal("Unable to set gid to %d", runas_gid);
- if (initgroups(changeuser, runas_gid))
- fatal("Unable to set initgroups() with gid %d", runas_gid);
- if (setuid(runas_uid))
- fatal("Unable to set uid to %s", changeuser);
- }
- if (background) { /* continue background setup */
- int i;
-#ifdef HAVE_TIOCNOTTY
- /* change tty */
- ioctl(tty_fd, TIOCNOTTY, 0);
- close(tty_fd);
-#endif
- umask(022); /* set a default for dumb programs */
- dup2(devnull_fd,0); /* stdin */
- dup2(devnull_fd,1); /* stdout */
- dup2(devnull_fd,2); /* stderr */
-#if defined(OShpux)
- /* now close all extra fds */
- for (i=sysconf(_SC_OPEN_MAX)-1; i>=3; --i) close(i);
-#else
- /* now close all extra fds */
- for (i=getdtablesize()-1; i>=3; --i) close(i);
-#endif
-
- /* create a new session */
-#ifdef HAVE_SETSID
- setsid();
-#else
- setpgid(0,0);
-#endif
- }
- execv(startas, argv);
- fatal("Unable to start %s: %s", startas, strerror(errno));
-}
-