Remove old sysv5 folders, scripts and tools following systemd 256 removal of legacy support
This commit is contained in:
parent
b95e8966ae
commit
e3ebcc3ff7
17
Makefile
17
Makefile
@ -1,5 +1,5 @@
|
||||
# Makefile for openmamba initscripts
|
||||
# Copyright (C) 2004-2021 by Silvan Calarco <silvan.calarco@mambasoft.it>
|
||||
# Copyright (C) 2004-2024 by Silvan Calarco <silvan.calarco@mambasoft.it>
|
||||
# Copyright (C) 2004-2009 by Davide Madrisan <davide.madrisan@gmail.com>
|
||||
|
||||
include VERSION
|
||||
@ -39,12 +39,6 @@ pck_catalogs := $(wildcard po/*.po)
|
||||
|
||||
all:
|
||||
|
||||
tools:
|
||||
make -C src
|
||||
|
||||
install-tools:
|
||||
make install -C src
|
||||
|
||||
install-dirs:
|
||||
$(INSTALL_DIR) $(DESTDIR)$(sbindir)
|
||||
$(INSTALL_DIR) $(DESTDIR)$(localstatedir)/run
|
||||
@ -53,13 +47,7 @@ install-dirs:
|
||||
|
||||
install-files:
|
||||
touch $(DESTDIR)$(localstatedir)/log/{btmp,lastlog,wtmp}
|
||||
cp -a etc usr $(DESTDIR)
|
||||
install -d -m0755 $(DESTDIR)$(sysconfdir)/rc.d
|
||||
for i in `seq 0 6`; do\
|
||||
install -d -m0755 $(DESTDIR)$(sysconfdir)/rc.d/rc$$i.d;\
|
||||
ln -sf rc.d/rc$$i.d/ $(DESTDIR)$(sysconfdir)/rc$$i.d;\
|
||||
done
|
||||
ln -sf rc.d/init.d/ $(DESTDIR)$(sysconfdir)/init.d
|
||||
cp -a usr $(DESTDIR)
|
||||
|
||||
install: install-dirs install-files
|
||||
|
||||
@ -81,4 +69,3 @@ clean:
|
||||
rm -f $(dist_archive)
|
||||
rm -f $(pck_catalogs:.po=.mo)
|
||||
rm -f $(PACKAGE).lang
|
||||
make clean -C src
|
||||
|
@ -1,6 +0,0 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# rc.local - This script will be executed at the end of the init process as the
|
||||
# last service and may be modified by the system administrator for its
|
||||
# own purposes. This is a startup script only.
|
||||
|
@ -1,628 +0,0 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# functions This file contains functions to be used by most or all
|
||||
# shell scripts in the /etc/init.d directory.
|
||||
#
|
||||
# Based on functions scripts from LFS-3.1 and RedHat/Fedora
|
||||
# Splash functions added by Silvan Calarco <silvan.calarco@mambasoft.it>
|
||||
# Modified for LSB and dash compliance by Davide Madrisan <davide.madrisan@gmail.com>
|
||||
|
||||
TEXTDOMAIN=initscripts
|
||||
|
||||
umask 022
|
||||
|
||||
# Set up a default search path.
|
||||
PATH="/sbin:/usr/sbin:/bin:/usr/bin"
|
||||
export PATH
|
||||
|
||||
# Get a sane screen width.
|
||||
[ -z "${COLUMNS:-}" ] && COLUMNS=80
|
||||
[ -z "${CONSOLETYPE:-}" ] && CONSOLETYPE="`/sbin/consoletype`"
|
||||
|
||||
COL=$(( $COLUMNS - 10 ))
|
||||
WCOL=$(( $COLUMNS - 30 ))
|
||||
|
||||
if [ -z "${BOOTUP:-}" ]; then
|
||||
if [ "$CONSOLETYPE" = "serial" ]; then
|
||||
BOOTUP=serial
|
||||
MOVE_TO_COL=
|
||||
MOVE_TO_WCOL=
|
||||
MOVE_TO_LCOL=
|
||||
MOVE_CURS_UP=
|
||||
SETCOLOR_NORMAL=
|
||||
SETCOLOR_SUCCESS=
|
||||
SETCOLOR_WARNING=
|
||||
SETCOLOR_FAILURE=
|
||||
else
|
||||
BOOTUP=color
|
||||
MOVE_TO_COL="/bin/echo -en \\033[${COL}G"
|
||||
MOVE_TO_WCOL="/bin/echo -en \\033[${WCOL}G"
|
||||
MOVE_TO_LCOL="/bin/echo -en \\033[0G"
|
||||
MOVE_CURS_UP="/bin/echo -en \\033[A"
|
||||
SETCOLOR_NORMAL="/bin/echo -en \\033[0;39m"
|
||||
SETCOLOR_SUCCESS="/bin/echo -en \\033[1;32m"
|
||||
SETCOLOR_WARNING="/bin/echo -en \\033[1;33m"
|
||||
SETCOLOR_FAILURE="/bin/echo -en \\033[1;31m"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "${BOOTUP:-}" != "verbose" ]; then
|
||||
INITLOG_ARGS="-q"
|
||||
else
|
||||
INITLOG_ARGS=
|
||||
fi
|
||||
|
||||
if [ -e /bin/plymouth -a -e /sbin/plymouthd ]; then
|
||||
PLYMOUTH=/bin/plymouth
|
||||
PLYMOUTHD=/sbin/plymouthd
|
||||
else
|
||||
PLYMOUTH=/bin/true
|
||||
PLYMOUTHD=/bin/true
|
||||
fi
|
||||
|
||||
# Check if $pid (could be plural) are running
|
||||
checkpid ()
|
||||
{
|
||||
local i
|
||||
|
||||
for i in $*; do
|
||||
[ -d "/proc/$i" ] && return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
#function getpids
|
||||
#{
|
||||
# # save basename
|
||||
# base=${1##*/}
|
||||
#
|
||||
# pidlist=$(pidof -o $$ -o $PPID -x $base)
|
||||
# pidlist=$(for p in $pidlist; do echo $p; done | sort)
|
||||
#}
|
||||
|
||||
|
||||
# function:
|
||||
# __pids_var_run {program} [pidfile]
|
||||
# description:
|
||||
# Set $pid to pids from /var/run* for {program}.
|
||||
# $pid should be declared local in the caller.
|
||||
# Returns LSB exit code for the 'status' action.
|
||||
__pids_var_run ()
|
||||
{
|
||||
local base=${1##*/}
|
||||
local pid_file=${2:-/var/run/$base.pid}
|
||||
|
||||
pid=
|
||||
if [ -f "$pid_file" ] ; then
|
||||
local line p
|
||||
[ -r "$pid_file" ] || return 4 # "user had insufficient privilege"
|
||||
read line < "$pid_file"
|
||||
for p in $line ; do
|
||||
case $p in *[!0-9]*) : ;;
|
||||
*) [ -d "/proc/$p" ] && pid="$pid $p" ;;
|
||||
esac
|
||||
done
|
||||
if [ -n "$pid" ]; then
|
||||
return 0
|
||||
fi
|
||||
return 1 # "Program is dead and /var/run pid file exists"
|
||||
fi
|
||||
return 3 # "Program is not running"
|
||||
}
|
||||
|
||||
# function:
|
||||
# __pids_pidof {program}
|
||||
# description:
|
||||
# Output PIDs of matching processes, found using pidof.
|
||||
__pids_pidof ()
|
||||
{
|
||||
/bin/pidof -o $$ -o $PPID -o %PPID -x "$1" || \
|
||||
/bin/pidof -o $$ -o $PPID -o %PPID -x "${1##*/}"
|
||||
}
|
||||
|
||||
# function:
|
||||
# daemon {args} [+/-nicelevel] {program}
|
||||
# description:
|
||||
# A function to start a program
|
||||
daemon ()
|
||||
{
|
||||
# test syntax
|
||||
local gotbase= force=
|
||||
local base= user= nice= bg= pid= pidfile=
|
||||
nicelevel=0
|
||||
while [ "$1" != "${1##[-+]}" ]; do
|
||||
case $1 in
|
||||
'') echo $"daemon: Usage: daemon {args} [+/-nicelevel] {program}"
|
||||
return 1
|
||||
;;
|
||||
--check)
|
||||
base=$2
|
||||
gotbase="yes"
|
||||
shift 2
|
||||
;;
|
||||
--check=?*)
|
||||
base=${1#--check=}
|
||||
gotbase="yes"
|
||||
shift
|
||||
;;
|
||||
--user)
|
||||
user=$2
|
||||
shift 2
|
||||
;;
|
||||
--user=?*)
|
||||
user=${1#--user=}
|
||||
shift
|
||||
;;
|
||||
--force)
|
||||
force="force"
|
||||
shift
|
||||
;;
|
||||
--pidfile=?*)
|
||||
pidfile=${1#--pidfile=}
|
||||
shift
|
||||
;;
|
||||
[-+][0-9]*)
|
||||
nice="nice -n $1"
|
||||
shift
|
||||
;;
|
||||
*) echo $"daemon: Usage: daemon {args} [+/-nicelevel] {program}"
|
||||
return 1 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# save basename
|
||||
[ -z "$gotbase" ] && base=${1##*/}
|
||||
|
||||
[ -z "$pidfile" ] && pidfile="/var/run/${base}.pid"
|
||||
|
||||
# see if it's already running. Look *only* at the pid file
|
||||
if [ -f $pidfile ]; then
|
||||
local line p
|
||||
read line < $pidfile
|
||||
for p in $line ; do
|
||||
[ -z "${p//[0-9]/}" -a -d "/proc/$p" ] && pid="$pid $p"
|
||||
done
|
||||
fi
|
||||
|
||||
[ -n "${pid:-}" -a -z "${force:-}" ] && return 0
|
||||
|
||||
# make sure it doesn't core dump anywhere unless requested
|
||||
ulimit -S -c ${DAEMON_COREFILE_LIMIT:-0} >/dev/null 2>&1
|
||||
|
||||
# if they set NICELEVEL in /etc/sysconfig/foo, honor it
|
||||
[ -n "$NICELEVEL" ] && nice="nice -n $NICELEVEL"
|
||||
|
||||
# echo daemon
|
||||
[ "${BOOTUP:-}" = "verbose" -a -z "$LSB" ] && echo -n " $base"
|
||||
|
||||
# and start it up
|
||||
if [ -z "$user" ]; then
|
||||
$nice initlog $INITLOG_ARGS -c "$*"
|
||||
else
|
||||
$nice initlog $INITLOG_ARGS -c "su -s /bin/bash - $user -c \"$*\""
|
||||
fi
|
||||
[ "$?" -eq 0 ] && success $"$base startup" || failure $"$base startup"
|
||||
}
|
||||
|
||||
# function:
|
||||
# killproc [-p pidfile] {program} [signal]
|
||||
# description:
|
||||
# A function to stop a program (LSB 2.x compliant).
|
||||
killproc ()
|
||||
{
|
||||
TEMP=`LANG=C POSIXLY_CORRECT=1 getopt "p:" $*`
|
||||
if [ $? -ne 0 -o $# -eq 0 ]; then
|
||||
echo $"Usage: killproc [-p <pidfile>] pathname [signal]"
|
||||
return 1
|
||||
fi
|
||||
|
||||
eval set -- "$TEMP"
|
||||
local pid_file
|
||||
while :; do
|
||||
case $1 in
|
||||
-p) pid_file=$2; shift ;;
|
||||
--) shift; break ;;
|
||||
*) echo $"Usage: killproc [-p <pidfile>] pathname [signal]"
|
||||
return 1 ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
local base=${1##*/}
|
||||
|
||||
# Check for second arg to be kill level.
|
||||
local signal=${2:-}
|
||||
|
||||
[ -z "$pid_file" ] && pid_file=/var/run/$base.pid
|
||||
|
||||
# Find pid.
|
||||
local retcode=0 pid
|
||||
__pids_var_run "$1" "$pid_file"
|
||||
|
||||
if [ ! -e "$pid_file" -a -z "$pid" ]; then
|
||||
pid="$(__pids_pidof "$1")"
|
||||
fi
|
||||
|
||||
# Kill it.
|
||||
if [ "${pid:-}" ] ; then
|
||||
# Use specified level only.
|
||||
if [ "$signal" ]; then
|
||||
if checkpid $pid 2>&1; then
|
||||
kill $signal $pid >/dev/null 2>&1
|
||||
retcode=$?
|
||||
else
|
||||
retcode=1
|
||||
fi
|
||||
else
|
||||
if checkpid $pid 2>&1; then
|
||||
# TERM first, then KILL if not dead
|
||||
kill -s TERM $pid >/dev/null 2>&1
|
||||
usleep 100000
|
||||
if checkpid $pid && sleep 1 &&
|
||||
checkpid $pid && sleep 3 &&
|
||||
checkpid $pid ; then
|
||||
kill -s KILL $pid >/dev/null 2>&1
|
||||
usleep 100000
|
||||
fi
|
||||
checkpid $pid
|
||||
retcode=$((! $? ))
|
||||
fi
|
||||
fi
|
||||
else
|
||||
[ "$signal" ] && retcode=1
|
||||
fi
|
||||
[ "$retcode" -eq 0 ] &&
|
||||
success $"$base shutdown" || failure $"$base shutdown"
|
||||
|
||||
# Remove pid file if any.
|
||||
rm -f $pidfile >/dev/null 2>&1
|
||||
return $retcode
|
||||
}
|
||||
|
||||
# function:
|
||||
# pidfileofproc {program}
|
||||
# description:
|
||||
# A function to find the pid of a program. Looks *only* at the pidfile.
|
||||
pidfileofproc ()
|
||||
{
|
||||
local base=${1##*/}
|
||||
|
||||
# Test syntax.
|
||||
if [ "$#" = 0 ] ; then
|
||||
echo $"Usage: pidfileofproc {program}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
__pids_var_run "$1"
|
||||
[ -n "$pid" ] && echo $pid
|
||||
return 0
|
||||
}
|
||||
|
||||
# function:
|
||||
# pidofproc [-p pidfile] {program}
|
||||
# description:
|
||||
# A function to find the pid of a program (LSB 2.x compliant).
|
||||
pidofproc ()
|
||||
{
|
||||
TEMP=`LANG=C POSIXLY_CORRECT=1 getopt "p:" $*`
|
||||
if [ $? -ne 0 -o $# -eq 0 ]; then
|
||||
echo $"Usage: pidofproc [-p <pidfile>] {program}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
eval set -- "$TEMP"
|
||||
local pid_file
|
||||
while :; do
|
||||
case $1 in
|
||||
-p) pid_file=$2; shift ;;
|
||||
--) shift; break ;;
|
||||
*) echo $"Usage: pidofproc [-p <pidfile>] {program}"
|
||||
return 1 ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
local base=${1##*/} rc
|
||||
|
||||
if [ -z "$pid_file" ]; then
|
||||
pid_file=/var/run/$base.pid
|
||||
else
|
||||
# Assume program is stopped
|
||||
[ -f "$pid_file" ] || return 3
|
||||
fi
|
||||
|
||||
if [ -f "$pidfile" ]; then
|
||||
__pids_var_run "$1" "$pid_file"
|
||||
rc=$?
|
||||
if [ -n "$pid" ]; then
|
||||
echo $pid
|
||||
return 0
|
||||
else
|
||||
return 1 # Dead and /var/run pid file exists
|
||||
fi
|
||||
elif [ -x /bin/pidof ]; then
|
||||
__pids_pidof "$1"
|
||||
[ "$?" = 1 ] && return 3 # Daemon stopped
|
||||
return 0
|
||||
fi
|
||||
return 4 # Service status is unknown
|
||||
}
|
||||
|
||||
# function:
|
||||
# statusproc [-p pidfile] {program}
|
||||
# description:
|
||||
# A function to check the status of a program
|
||||
statusproc ()
|
||||
{
|
||||
local base pid pid_file=
|
||||
|
||||
# Test syntax.
|
||||
if [ "$#" = 0 ] ; then
|
||||
echo $"Usage: statusproc [-p pidfile] {program}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ "$1" = "-p" ]; then
|
||||
pid_file=$2
|
||||
shift 2
|
||||
fi
|
||||
|
||||
base=${1##*/}
|
||||
|
||||
# First try "pidof"
|
||||
pid="$(__pids_pidof "$1")"
|
||||
if [ -n "$pid" ]; then
|
||||
echo $"${base} (pid $pid) is running..."
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Next try "/var/run/*.pid" files
|
||||
__pids_var_run "$1" "$pid_file"
|
||||
case "$?" in
|
||||
0) echo $"${base} (pid $pid) is running..."
|
||||
return 0
|
||||
;;
|
||||
1) echo $"${base} dead but pid file exists"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
# See if /var/lock/subsys/${base} exists.
|
||||
if [ -f /var/lock/subsys/${base} ]; then
|
||||
echo $"${base} dead but subsys locked"
|
||||
return 2
|
||||
fi
|
||||
echo $"${base} is stopped"
|
||||
return 3
|
||||
}
|
||||
|
||||
loadproc ()
|
||||
{
|
||||
if [ $# = 0 ]; then
|
||||
echo "Usage: loadproc {program}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local pid
|
||||
pid="$(__pids_pidof "$1")"
|
||||
if [ -z "$pid" ]; then
|
||||
"$@"
|
||||
[ $? -eq 0 ] && echo_success || echo_failure
|
||||
else
|
||||
$MOVE_TO_WCOL
|
||||
echo_passed
|
||||
fi
|
||||
}
|
||||
|
||||
reloadproc ()
|
||||
{
|
||||
if [ $# = 0 ]; then
|
||||
echo "Usage: reloadproc {program} [signal]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local signal
|
||||
if [ -z "$2" ]; then
|
||||
signal=HUP
|
||||
else
|
||||
signal=${2##-}
|
||||
signal=${signal##SIG}
|
||||
fi
|
||||
|
||||
local pid apid failure
|
||||
pid="$(__pids_pidof "$1")"
|
||||
if [ -n "$pid" ]; then
|
||||
failure=0
|
||||
for apid in $pid; do
|
||||
kill -s $signal $apid || failure=1
|
||||
done
|
||||
[ $failure -eq 0 ] && echo_success || echo_failure
|
||||
else
|
||||
$MOVE_TO_WCOL
|
||||
echo_warning not_running
|
||||
fi
|
||||
}
|
||||
|
||||
echo_ok ()
|
||||
{
|
||||
echo_success
|
||||
return $?
|
||||
}
|
||||
|
||||
echo_success ()
|
||||
{
|
||||
[ "$BOOTUP" = "color" ] && $MOVE_TO_COL
|
||||
echo -n "["
|
||||
[ "$BOOTUP" = "color" ] && $SETCOLOR_SUCCESS
|
||||
echo -n $" OK "
|
||||
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
|
||||
echo -n "]"
|
||||
/bin/echo -ne "\r"
|
||||
return 0
|
||||
}
|
||||
|
||||
echo_failure ()
|
||||
{
|
||||
[ "$BOOTUP" = "color" ] && $MOVE_TO_COL
|
||||
echo -n "["
|
||||
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
|
||||
echo -n $"FAILED"
|
||||
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
|
||||
echo -n "]"
|
||||
/bin/echo -ne "\r"
|
||||
return 1
|
||||
}
|
||||
|
||||
echo_warning ()
|
||||
{
|
||||
case "$1" in
|
||||
running)
|
||||
[ "$BOOTUP" = "color" ] && $MOVE_TO_WCOL
|
||||
echo $"Already running"
|
||||
[ "$BOOTUP" = "color" ] && $MOVE_CURS_UP
|
||||
;;
|
||||
not_running)
|
||||
[ "$BOOTUP" = "color" ] && $MOVE_TO_WCOL
|
||||
echo $"Stopped"
|
||||
[ "$BOOTUP" = "color" ] && $MOVE_CURS_UP
|
||||
;;
|
||||
esac
|
||||
[ "$BOOTUP" = "color" ] && $MOVE_TO_COL
|
||||
echo -n "["
|
||||
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
|
||||
echo -n $"WARNING"
|
||||
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
|
||||
echo -n "]"
|
||||
/bin/echo -ne "\r"
|
||||
return 1
|
||||
}
|
||||
|
||||
echo_passed ()
|
||||
{
|
||||
# [ "$BOOTUP" = "color" ] && $MOVE_TO_COL
|
||||
# echo -n "["
|
||||
# [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
|
||||
# echo -n $"PASSED"
|
||||
# [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
|
||||
# echo -n "]"
|
||||
# /bin/echo -ne "\r"
|
||||
echo_warning running
|
||||
return 1
|
||||
}
|
||||
|
||||
# Log that something succeeded.
|
||||
success ()
|
||||
{
|
||||
if [ -z "${IN_INITLOG:-}" ]; then
|
||||
initlog $INITLOG_ARGS -n $0 -s "$1" -e 1
|
||||
fi
|
||||
[ "$BOOTUP" != "verbose" -a -z "${LSB:-}" ] && echo_success
|
||||
return 0
|
||||
}
|
||||
|
||||
# Log that something failed.
|
||||
failure ()
|
||||
{
|
||||
local rc=$?
|
||||
if [ -z "${IN_INITLOG:-}" ]; then
|
||||
initlog $INITLOG_ARGS -n $0 -s "$1" -e 2
|
||||
fi
|
||||
[ "$BOOTUP" != "verbose" -a -z "${LSB:-}" ] && echo_failure
|
||||
return $rc
|
||||
}
|
||||
|
||||
# Log that something passed, but may have had errors. Useful for fsck
|
||||
passed ()
|
||||
{
|
||||
local rc=$?
|
||||
if [ -z "${IN_INITLOG:-}" ]; then
|
||||
initlog $INITLOG_ARGS -n $0 -s "$1" -e 1
|
||||
fi
|
||||
[ "$BOOTUP" != "verbose" -a -z "${LSB:-}" ] && echo_passed
|
||||
return $rc
|
||||
}
|
||||
|
||||
# Log a warning.
|
||||
warning ()
|
||||
{
|
||||
local rc=$?
|
||||
if [ -z "${IN_INITLOG:-}" ]; then
|
||||
initlog $INITLOG_ARGS -n $0 -s "$1" -e 1
|
||||
fi
|
||||
[ "$BOOTUP" != "verbose" -a -z "${LSB:-}" ] && echo_warning
|
||||
return $rc
|
||||
}
|
||||
|
||||
evaluate_retval ()
|
||||
{
|
||||
[ $? -eq 0 ] && echo_success || echo_failure
|
||||
}
|
||||
|
||||
# WARNING: this function is obsolete: do not use it
|
||||
print_status ()
|
||||
{
|
||||
if [ $# = 0 ]; then
|
||||
echo "Usage: $0 {success|failure|warning}"
|
||||
return 1
|
||||
fi
|
||||
case "$1" in
|
||||
success) echo_success ;;
|
||||
failure) echo_failure ;;
|
||||
warning) echo_warning $2 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Run some action. Log its output.
|
||||
action ()
|
||||
{
|
||||
local msg rc
|
||||
|
||||
msg=$1
|
||||
echo -n "$msg "
|
||||
shift
|
||||
"$@" && success $"$msg" || failure $"$msg"
|
||||
rc=$?
|
||||
echo
|
||||
return $rc
|
||||
}
|
||||
|
||||
spl_cachedir="/lib/splash/cache"
|
||||
spl_fifo="/dev/.splashfifo"
|
||||
spl_pidfile="/dev/.splashpid"
|
||||
|
||||
splash_comm_send ()
|
||||
{
|
||||
[ -w "$spl_fifo" -a -r "$spl_pidfile" ] || return 1
|
||||
[ "`pidof fbsplashd`" ] || return
|
||||
echo $* > $spl_fifo || return 1
|
||||
return 0
|
||||
}
|
||||
|
||||
splash_comm_progress ()
|
||||
{
|
||||
[ "$1" ] || return 1
|
||||
progress=`expr 65535 \* $1 / 100`
|
||||
|
||||
splash_comm_send progress ${progress}
|
||||
splash_comm_send repaint
|
||||
}
|
||||
|
||||
check_link ()
|
||||
{
|
||||
if [ $# = 0 ]; then
|
||||
echo "Usage: check_link <symlink>"
|
||||
return 1
|
||||
fi
|
||||
if [ ! -f "$1" ]; then
|
||||
echo "$1 is a broken symlink, skipping"
|
||||
return 2
|
||||
fi
|
||||
if [ ! -x "$1" ]; then
|
||||
echo "$1 is not executable, skipping"
|
||||
return 3
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
# define aliases for compatibility
|
||||
alias status=statusproc
|
||||
alias gprintf=printf
|
@ -1,5 +0,0 @@
|
||||
# DEPRECATION WARNING:
|
||||
# this file is deprecated and provided only for legacy init scripts which expect to find it or fail
|
||||
|
||||
rc_base=/etc/rc.d
|
||||
rc_functions=/etc/sysconfig/functions
|
69
src/Makefile
69
src/Makefile
@ -1,69 +0,0 @@
|
||||
# Makefile for the initscripts tools
|
||||
# Copyright (C) 2007 by Davide Madrisan <davide.madrisan@gmail.com>
|
||||
#
|
||||
# Based on the Makefile provided by Fedora in the initscripts tarball
|
||||
|
||||
PROGS = usernetctl doexec netreport usleep ipcalc minilogd initlog fstab-decode getkey consoletype genhostid
|
||||
INITLOG_OBJS = initlog.o process.o
|
||||
USLEEP_OBJS = usleep.o
|
||||
|
||||
prefix = /usr
|
||||
exec_prefix = ${prefix}
|
||||
sysconfdir = /etc
|
||||
bindir = ${exec_prefix}/bin
|
||||
sbindir = ${exec_prefix}/sbin
|
||||
mandir = ${prefix}/share/man
|
||||
localstatedir = /var
|
||||
|
||||
INSTALL = /usr/bin/install
|
||||
INSTALL_PROGRAM = ${INSTALL} -m 755
|
||||
INSTALL_DATA = ${INSTALL} -m 644
|
||||
INSTALL_DIR = ${INSTALL} -d -m 755
|
||||
INSTALL_SCRIPT = ${INSTALL_PROGRAM}
|
||||
|
||||
CFLAGS += $(RPM_OPT_FLAGS) -Wall -D_GNU_SOURCE
|
||||
|
||||
all: $(PROGS)
|
||||
|
||||
getkey: getkey.o
|
||||
$(CC) $(LDFLAGS) -o $@ $< -Wl,-Bstatic -lpopt -Wl,-Bdynamic
|
||||
|
||||
initlog: $(INITLOG_OBJS)
|
||||
$(CC) $(LDFLAGS) -o $@ $(INITLOG_OBJS) -Wl,-Bstatic -lpopt -Wl,-Bdynamic
|
||||
|
||||
ipcalc: ipcalc.o
|
||||
$(CC) $(LDFLAGS) -o $@ $< -Wl,-Bstatic -lpopt -Wl,-Bdynamic
|
||||
|
||||
usleep: $(USLEEP_OBJS)
|
||||
$(CC) $(LDFLAGS) -o $@ $(USLEEP_OBJS) -Wl,-Bstatic -lpopt -Wl,-Bdynamic
|
||||
|
||||
usernetctl.o: usernetctl.c
|
||||
$(CC) $(CFLAGS) -fPIE -c usernetctl.c -o usernetctl.o
|
||||
|
||||
usernetctl: usernetctl.c usernetctl.o
|
||||
$(CC) $(LDFLAGS) -pie -o $@ $@.o
|
||||
|
||||
install:
|
||||
$(INSTALL_DIR) $(DESTDIR)$(bindir)
|
||||
$(INSTALL_DIR) $(DESTDIR)$(sbindir)
|
||||
$(INSTALL_DIR) $(DESTDIR)$(mandir)/man{1,8}
|
||||
$(INSTALL_DIR) $(DESTDIR)$(sysconfdir)
|
||||
$(INSTALL_PROGRAM) doexec $(DESTDIR)$(bindir)/doexec
|
||||
$(INSTALL_PROGRAM) usleep $(DESTDIR)$(bindir)/usleep
|
||||
$(INSTALL_PROGRAM) ipcalc $(DESTDIR)$(bindir)/ipcalc
|
||||
$(INSTALL_PROGRAM) consoletype $(DESTDIR)$(sbindir)/consoletype
|
||||
$(INSTALL_PROGRAM) genhostid $(DESTDIR)$(sbindir)/genhostid
|
||||
$(INSTALL_PROGRAM) getkey $(DESTDIR)$(sbindir)/getkey
|
||||
$(INSTALL_PROGRAM) minilogd $(DESTDIR)$(sbindir)/minilogd
|
||||
$(INSTALL_PROGRAM) usernetctl $(DESTDIR)$(sbindir)/usernetctl
|
||||
$(INSTALL_DATA) genhostid.1 $(DESTDIR)$(mandir)/man1
|
||||
$(INSTALL_DATA) doexec.1 $(DESTDIR)$(mandir)/man1
|
||||
$(INSTALL_DATA) getkey.1 $(DESTDIR)$(mandir)/man1
|
||||
$(INSTALL_DATA) netreport.1 $(DESTDIR)$(mandir)/man1
|
||||
$(INSTALL_DATA) usleep.1 $(DESTDIR)$(mandir)/man1
|
||||
$(INSTALL_DATA) ipcalc.1 $(DESTDIR)$(mandir)/man1
|
||||
$(INSTALL_DATA) consoletype.1 $(DESTDIR)$(mandir)/man1
|
||||
$(INSTALL_DATA) usernetctl.8 $(DESTDIR)$(mandir)/man8
|
||||
|
||||
clean:
|
||||
rm -f $(PROGS) *.o
|
@ -1,77 +0,0 @@
|
||||
# Makefile for the initscripts tools
|
||||
# Copyright (C) 2007 by Davide Madrisan <davide.madrisan@gmail.com>
|
||||
# Copyright (C) 2010 by Silvan Calarco <silvan.calarco@mambasoft.it>
|
||||
#
|
||||
# Based on the Makefile provided by Fedora in the initscripts tarball
|
||||
|
||||
PROGS = usernetctl doexec netreport usleep ipcalc minilogd initlog getkey consoletype genhostid
|
||||
INITLOG_OBJS = initlog.o process.o
|
||||
USLEEP_OBJS = usleep.o
|
||||
|
||||
prefix = /usr
|
||||
exec_prefix = ${prefix}
|
||||
sysconfdir = /etc
|
||||
sbindir = ${exec_prefix}/sbin
|
||||
mandir = ${prefix}/share/man
|
||||
localstatedir = /var
|
||||
|
||||
INSTALL = /usr/bin/install
|
||||
INSTALL_PROGRAM = ${INSTALL} -m 755
|
||||
INSTALL_DATA = ${INSTALL} -m 644
|
||||
INSTALL_DIR = ${INSTALL} -d -m 755
|
||||
INSTALL_SCRIPT = ${INSTALL_PROGRAM}
|
||||
|
||||
CFLAGS += $(RPM_OPT_FLAGS) -Wall -D_GNU_SOURCE
|
||||
|
||||
all: $(PROGS)
|
||||
|
||||
getkey: getkey.o
|
||||
$(CC) $(LDFLAGS) -o $@ $< -Wl,-Bstatic -lpopt -Wl,-Bdynamic
|
||||
|
||||
initlog: $(INITLOG_OBJS)
|
||||
$(CC) $(LDFLAGS) -o $@ $(INITLOG_OBJS) -Wl,-Bstatic -lpopt -Wl,-Bdynamic
|
||||
|
||||
ipcalc: ipcalc.o
|
||||
$(CC) $(LDFLAGS) -o $@ $< -Wl,-Bstatic -lpopt -Wl,-Bdynamic
|
||||
|
||||
usleep: $(USLEEP_OBJS)
|
||||
$(CC) $(LDFLAGS) -o $@ $(USLEEP_OBJS) -Wl,-Bstatic -lpopt -Wl,-Bdynamic
|
||||
|
||||
usernetctl.o: usernetctl.c
|
||||
$(CC) $(CFLAGS) -fPIE -c usernetctl.c -o usernetctl.o
|
||||
|
||||
usernetctl: usernetctl.c usernetctl.o
|
||||
$(CC) $(LDFLAGS) -pie -o $@ $@.o
|
||||
|
||||
install:
|
||||
$(INSTALL_DIR) $(DESTDIR)/bin
|
||||
$(INSTALL_DIR) $(DESTDIR)/sbin
|
||||
$(INSTALL_DIR) $(DESTDIR)$(sbindir)
|
||||
$(INSTALL_DIR) $(DESTDIR)$(mandir)/man{1,8}
|
||||
$(INSTALL_DIR) $(DESTDIR)$(sysconfdir)
|
||||
$(INSTALL_DIR) $(DESTDIR)$(localstatedir)/run/netreport/
|
||||
$(INSTALL_PROGRAM) doexec $(DESTDIR)/bin/doexec
|
||||
$(INSTALL_PROGRAM) usleep $(DESTDIR)/bin/usleep
|
||||
$(INSTALL_PROGRAM) ipcalc $(DESTDIR)/bin/ipcalc
|
||||
$(INSTALL_PROGRAM) netreport $(DESTDIR)/sbin/netreport
|
||||
$(INSTALL_PROGRAM) consoletype $(DESTDIR)/sbin/consoletype
|
||||
$(INSTALL_PROGRAM) genhostid $(DESTDIR)/sbin/genhostid
|
||||
$(INSTALL_PROGRAM) getkey $(DESTDIR)/sbin/getkey
|
||||
$(INSTALL_PROGRAM) initlog $(DESTDIR)/sbin/initlog
|
||||
$(INSTALL_PROGRAM) minilogd $(DESTDIR)/sbin/minilogd
|
||||
$(INSTALL_PROGRAM) usernetctl $(DESTDIR)$(sbindir)/usernetctl
|
||||
$(INSTALL_DATA) initlog.1 $(DESTDIR)$(mandir)/man1
|
||||
$(INSTALL_DATA) genhostid.1 $(DESTDIR)$(mandir)/man1
|
||||
$(INSTALL_DATA) doexec.1 $(DESTDIR)$(mandir)/man1
|
||||
$(INSTALL_DATA) getkey.1 $(DESTDIR)$(mandir)/man1
|
||||
$(INSTALL_DATA) netreport.1 $(DESTDIR)$(mandir)/man1
|
||||
$(INSTALL_DATA) usleep.1 $(DESTDIR)$(mandir)/man1
|
||||
$(INSTALL_DATA) ipcalc.1 $(DESTDIR)$(mandir)/man1
|
||||
$(INSTALL_DATA) consoletype.1 $(DESTDIR)$(mandir)/man1
|
||||
$(INSTALL_DATA) usernetctl.8 $(DESTDIR)$(mandir)/man8
|
||||
$(INSTALL_DATA) initlog.conf $(DESTDIR)$(sysconfdir)
|
||||
# install -m 2755 netreport $(DESTDIR)/sbin/netreport
|
||||
# install -m 4755 usernetctl $(DESTDIR)$(sbindir)/usernetctl
|
||||
|
||||
clean:
|
||||
rm -f $(PROGS) *.o
|
@ -1,39 +0,0 @@
|
||||
.TH CONSOLETYPE 1 "Red Hat, Inc" "RH" \" -*- nroff -*-
|
||||
.SH NAME
|
||||
\fBconsoletype
|
||||
\- print type of the console connected to standard input
|
||||
.SH SYNOPSIS
|
||||
\fBconsoletype [\fIfg\fR]
|
||||
.SH DESCRIPTION
|
||||
\fBconsoletype
|
||||
prints the type of console connected to standard input, and checks
|
||||
whether the console connected to standard input is the current
|
||||
foreground virtual console. With no arguments, it prints
|
||||
\fIvt\fR
|
||||
if console is a virtual terminal (/dev/tty* or /dev/console device if not on
|
||||
a serial console),
|
||||
\fIserial\fR
|
||||
if standard input is a serial console (/dev/console or /dev/ttyS*) and
|
||||
\fIpty\fR
|
||||
if standard input is a pseudo terminal.
|
||||
.SH RETURN VALUE
|
||||
\fBconsoletype
|
||||
when passed no arguments returns
|
||||
.TP
|
||||
\fI0
|
||||
if on virtual terminal
|
||||
.TP
|
||||
\fI1
|
||||
if on serial console
|
||||
.TP
|
||||
\fI2
|
||||
if on a pseudo terminal.
|
||||
.TP
|
||||
When passed the \fIfg\fR argument, \fBconsoletype\fR returns
|
||||
.TP
|
||||
\fI0
|
||||
if the console connected to standard input is the current virtual
|
||||
terminal
|
||||
.TP
|
||||
\fI1
|
||||
otherwise.
|
@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2003 Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* This software may be freely redistributed under the terms of the GNU
|
||||
* public license.
|
||||
*
|
||||
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/sysmacros.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
unsigned char twelve = 12;
|
||||
char *type;
|
||||
int maj, min, ret = 0, fg = -1;
|
||||
struct stat sb;
|
||||
|
||||
fstat(0, &sb);
|
||||
maj = major(sb.st_rdev);
|
||||
min = minor(sb.st_rdev);
|
||||
if (maj != 3 && (maj < 136 || maj > 143)) {
|
||||
if ((fg = ioctl (0, TIOCLINUX, &twelve)) < 0) {
|
||||
type = "serial";
|
||||
ret = 1;
|
||||
} else {
|
||||
#ifdef __powerpc__
|
||||
int fd;
|
||||
char buf[65536];
|
||||
|
||||
fd = open("/proc/tty/drivers",O_RDONLY);
|
||||
read(fd, buf, 65535);
|
||||
if (strstr(buf,"vioconsole /dev/tty")) {
|
||||
type = "vio";
|
||||
ret = 3;
|
||||
} else {
|
||||
type = "vt";
|
||||
ret = 0;
|
||||
}
|
||||
#else
|
||||
type = "vt";
|
||||
ret = 0;
|
||||
#endif
|
||||
}
|
||||
} else {
|
||||
type = "pty";
|
||||
ret = 2;
|
||||
}
|
||||
if (argc > 1 && !strcmp(argv[1],"fg")) {
|
||||
if (fg < 0 || fg != (min-1))
|
||||
return 1;
|
||||
return 0;
|
||||
} else {
|
||||
printf("%s\n",type);
|
||||
return ret;
|
||||
}
|
||||
}
|
12
src/doexec.1
12
src/doexec.1
@ -1,12 +0,0 @@
|
||||
.TH DOEXEC 1 "Red Hat Software" "RHS" \" -*- nroff -*-
|
||||
.SH NAME
|
||||
doexec \- run an executable with an arbitrary argv[0]
|
||||
.SH SYNOPSIS
|
||||
.B doexec
|
||||
\fI/path/to/executable\fP \fIargv[0]\fP [\fIargv[1-n]\fP]
|
||||
.SH DESCRIPTION
|
||||
.B doexec
|
||||
simply runs the executable with the argv list provided. It allows you
|
||||
to specify an argv[0] other than the name of the executable.
|
||||
.SH OPTIONS
|
||||
All options are passed in the argv list to the executable being run.
|
19
src/doexec.c
19
src/doexec.c
@ -1,19 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1997-1999 Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* This software may be freely redistributed under the terms of the GNU
|
||||
* public license.
|
||||
*
|
||||
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char ** argv) {
|
||||
if (argc<2) return 1;
|
||||
execvp(argv[1], argv + 2);
|
||||
return 1;
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
.\" A man page for fstab-decode(8).
|
||||
.\"
|
||||
.\" Copyright (C) 2006 Red Hat, Inc. All rights reserved.
|
||||
.\"
|
||||
.\" This copyrighted material is made available to anyone wishing to use,
|
||||
.\" modify, copy, or redistribute it subject to the terms and conditions of the
|
||||
.\" GNU General Public License v.2.
|
||||
.\"
|
||||
.\" 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.,
|
||||
.\" 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
.\"
|
||||
.\" Author: Miloslav Trmac <mitr@redhat.com>
|
||||
.TH fstab-decode 8 "May 2006"
|
||||
|
||||
.SH NAME
|
||||
fstab-decode \- run a command with fstab-encoded arguments
|
||||
|
||||
.SH SYNOPSIS
|
||||
\fB fstab-decode\fR \fICOMMAND\fR [\fIARGUMENT\fR]...
|
||||
|
||||
.SH DESCRIPTION
|
||||
.B fstab-decode
|
||||
decodes escapes in the specified \FIARGUMENT\fRs
|
||||
and uses them to run \fICOMMAND\fR.
|
||||
The argument escaping uses the same rules as path escaping in
|
||||
\fB/etc/fstab\fR,
|
||||
.B /etc/mtab
|
||||
and \fB/proc/mtab\fR.
|
||||
|
||||
.SH EXIT STATUS
|
||||
.B fstab-decode
|
||||
exits with status 127 if
|
||||
.I COMMAND
|
||||
can't be run.
|
||||
Otherwise it exits with the status returned by \fICOMMAND\fR.
|
||||
|
||||
.SH EXAMPLES
|
||||
|
||||
.B fstab-decode umount $(awk '$3 == "vfat" { print $2 }' /etc/fstab)
|
@ -1,86 +0,0 @@
|
||||
/* fstab-decode(8).
|
||||
|
||||
Copyright (c) 2006 Red Hat, Inc. All rights reserved.
|
||||
|
||||
This copyrighted material is made available to anyone wishing to use, modify,
|
||||
copy, or redistribute it subject to the terms and conditions of the GNU General
|
||||
Public License v.2.
|
||||
|
||||
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., 51 Franklin
|
||||
Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
Author: Miloslav Trmac <mitr@redhat.com> */
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* Decode the fstab-encoded string in place. */
|
||||
static void
|
||||
decode(char *s)
|
||||
{
|
||||
const char *src;
|
||||
char *dest;
|
||||
|
||||
src = s;
|
||||
dest = s;
|
||||
while (*src != '\0') {
|
||||
if (*src != '\\')
|
||||
*dest = *src++;
|
||||
else {
|
||||
static const struct repl {
|
||||
char orig[4];
|
||||
size_t len;
|
||||
char new;
|
||||
} repls[] = {
|
||||
#define R(X, Y) { X, sizeof(X) - 1, Y }
|
||||
R("\\", '\\'),
|
||||
R("011", '\t'),
|
||||
R("012", '\n'),
|
||||
R("040", ' '),
|
||||
R("134", '\\')
|
||||
#undef R
|
||||
};
|
||||
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < sizeof (repls) / sizeof (repls[0]);
|
||||
i++) {
|
||||
if (memcmp(src + 1, repls[i].orig,
|
||||
repls[i].len) == 0) {
|
||||
*dest = repls[i].new;
|
||||
src += 1 + repls[i].len;
|
||||
goto found;
|
||||
}
|
||||
}
|
||||
*dest = *src++;
|
||||
found:
|
||||
;
|
||||
}
|
||||
dest++;
|
||||
}
|
||||
*dest = '\0';
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "Usage: fstab-decode command [arguments]\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
for (i = 2; i < (size_t)argc; i++)
|
||||
decode(argv[i]);
|
||||
execvp(argv[1], argv + 1);
|
||||
fprintf(stderr, "fstab-decode: %s: %s\n", argv[1], strerror(errno));
|
||||
return 127;
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
.TH GENHOSTID 1
|
||||
.SH NAME
|
||||
genhostid \- generate and set a hostid for the current host
|
||||
.SH SYNOPSIS
|
||||
.B genhostid
|
||||
|
||||
.SH DESCRIPTION
|
||||
\fBgenhostid\fR generates a random hostid and stores it in /etc/hostid,
|
||||
if /etc/hostid does not already exist.
|
||||
|
||||
.SH "SEE ALSO"
|
||||
hostid(1), gethostid(2), sethostid(2)
|
@ -1,32 +0,0 @@
|
||||
/* Copyright (C) 2003 Red Hat, Inc.
|
||||
*
|
||||
* This software may be freely redistributed under the terms of the GNU
|
||||
* public license.
|
||||
*
|
||||
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
struct stat st;
|
||||
long int n;
|
||||
if (stat ("/etc/hostid", &st) == 0 && S_ISREG (st.st_mode)
|
||||
&& st.st_size >= sizeof (n))
|
||||
return 0;
|
||||
int fd = open ("/dev/random", O_RDONLY);
|
||||
if (fd == -1 || read (fd, &n, sizeof (n)) != sizeof (n))
|
||||
{
|
||||
srand48 ((long int) time (NULL) ^ (long int) getpid ());
|
||||
n = lrand48 ();
|
||||
}
|
||||
return sethostid (n);
|
||||
}
|
80
src/getkey.1
80
src/getkey.1
@ -1,80 +0,0 @@
|
||||
.\" A man page for getkey(1). -*- nroff -*-
|
||||
.\"
|
||||
.\" Copyright (C) 2006 Red Hat, Inc. All rights reserved.
|
||||
.\"
|
||||
.\" This copyrighted material is made available to anyone wishing to use,
|
||||
.\" modify, copy, or redistribute it subject to the terms and conditions of the
|
||||
.\" GNU General Public License v.2.
|
||||
.\"
|
||||
.\" 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.,
|
||||
.\" 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
.\"
|
||||
.\" Author: Miloslav Trmac <mitr@redhat.com>
|
||||
.TH getkey 1 "Jan 2006"
|
||||
|
||||
.SH NAME
|
||||
getkey \- wait until a key is pressed
|
||||
|
||||
.SH SYNOPSIS
|
||||
\fBgetkey\fR [\fIOPTION\fR]... [\fIKEYS\fR]
|
||||
|
||||
.SH DESCRIPTION
|
||||
.B getkey
|
||||
waits until one of
|
||||
.I KEYS
|
||||
is pressed.
|
||||
If
|
||||
.I KEYS
|
||||
are not specified, any key is accepted.
|
||||
.I KEYS
|
||||
are matched case-insensitive.
|
||||
|
||||
.SH EXIT STATUS
|
||||
.B getkey
|
||||
exits with status 0 if one of the expected keys is pressed.
|
||||
If invalid arguments are specified,
|
||||
.B getkey
|
||||
exits with status 255.
|
||||
If
|
||||
.B getkey
|
||||
is interrupted or the wait times out,
|
||||
.B getkey
|
||||
exits with other non-zero status.
|
||||
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
\fB\-c\fR, \fB\-\-wait\fR \fISECONDS\fR
|
||||
Wait only for
|
||||
.I SECONDS
|
||||
seconds.
|
||||
The default is 0, which means to wait without a time limit.
|
||||
|
||||
.TP
|
||||
\fB\-i\fR, \fB\-\-ignore\-control\-chars\fR
|
||||
Don't treat Ctrl+C and Ctrl+D specially.
|
||||
When this option is not specified, these characters interrupt \fBgetkey\fR.
|
||||
|
||||
.TP
|
||||
\fB\-m\fR, \fB\-\-message\fR \fIMESSAGE\fR
|
||||
Display
|
||||
.I MESSAGE
|
||||
while waiting.
|
||||
The message is used as a format string in
|
||||
.BR sprintf (3),
|
||||
with a single argument, the number of seconds left.
|
||||
Typical usage is therefore
|
||||
\fB"Press a key within %d seconds to ..."\fR.
|
||||
If
|
||||
.I MESSAGE
|
||||
contains other format string directives, the behavior is undefined and
|
||||
.B getkey
|
||||
may crash.
|
||||
|
||||
If there is no time limit specified,
|
||||
the number of seconds left is reported as 0.
|
135
src/getkey.c
135
src/getkey.c
@ -1,135 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2003, 2006 Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* This software may be freely redistributed under the terms of the GNU
|
||||
* public license.
|
||||
*
|
||||
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
* getkey
|
||||
*
|
||||
* A very simple keygrabber.
|
||||
*
|
||||
*/
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/poll.h>
|
||||
#include "popt.h"
|
||||
|
||||
static struct termios orig_tp;
|
||||
|
||||
static void reset_term(int x) {
|
||||
tcsetattr(0,TCSANOW,&orig_tp);
|
||||
_exit(x);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
static const char default_list[] = "";
|
||||
|
||||
const char *list;
|
||||
char *waitmessage = NULL;
|
||||
char *waitprint, *waitsprint;
|
||||
int waitseconds=0;
|
||||
int alarmlen=0;
|
||||
int ignore_control=0;
|
||||
struct termios tp;
|
||||
int r;
|
||||
struct pollfd ufds; /* only one, no need for an array... */
|
||||
poptContext context;
|
||||
struct poptOption options[] = {
|
||||
{ "wait", 'c', POPT_ARG_INT, &waitseconds, 0, "Number of seconds to wait for keypress", NULL },
|
||||
{ "message", 'm', POPT_ARG_STRING, &waitmessage, 0, "Message to print out while waiting for string\nNOTE: The message may have a \"%d\" in it, to hold the number of seconds left to wait.", NULL },
|
||||
{ "ignore-control-chars", 'i', POPT_ARG_NONE, &ignore_control, 0, "Ignore Control-C and Control-D", NULL },
|
||||
POPT_AUTOHELP
|
||||
POPT_TABLEEND
|
||||
};
|
||||
|
||||
context = poptGetContext("getkey", argc, (const char **)argv, options,
|
||||
POPT_CONTEXT_POSIXMEHARDER);
|
||||
poptSetOtherOptionHelp(context, "[keys]");
|
||||
|
||||
r = poptGetNextOpt(context);
|
||||
if (r < -1) {
|
||||
fprintf(stderr, "%s: %s\n",
|
||||
poptBadOption(context, POPT_BADOPTION_NOALIAS),
|
||||
poptStrerror(r));
|
||||
|
||||
return -1;
|
||||
}
|
||||
list = poptGetArg(context);
|
||||
if (list != NULL) {
|
||||
char *p;
|
||||
|
||||
p = strdup(list);
|
||||
list = p;
|
||||
while (*p != 0) {
|
||||
*p = toupper(*p);
|
||||
p++;
|
||||
}
|
||||
} else
|
||||
list = default_list;
|
||||
if (waitseconds) {
|
||||
if (waitseconds < 0) {
|
||||
fprintf(stderr, "--wait: Invalid time %d seconds\n",
|
||||
waitseconds);
|
||||
return -1;
|
||||
}
|
||||
alarmlen = waitseconds;
|
||||
}
|
||||
|
||||
tcgetattr(0,&tp);
|
||||
orig_tp = tp;
|
||||
signal(SIGTERM,reset_term);
|
||||
if (alarmlen != 0) {
|
||||
signal(SIGALRM,reset_term);
|
||||
alarm(alarmlen);
|
||||
}
|
||||
|
||||
tp.c_iflag=0;
|
||||
tp.c_oflag &= ~OPOST;
|
||||
tp.c_lflag &= ~(ISIG | ICANON);
|
||||
tcsetattr(0,TCSANOW,&tp);
|
||||
|
||||
ufds.events = POLLIN;
|
||||
ufds.fd = 0;
|
||||
|
||||
if (waitmessage) {
|
||||
waitprint = alloca (strlen(waitmessage)+15); /* long enough */
|
||||
waitprint[0] = '\r';
|
||||
waitsprint = waitprint + 1;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
if (waitmessage) {
|
||||
sprintf (waitsprint, waitmessage, waitseconds);
|
||||
write (1, waitprint, strlen(waitprint));
|
||||
}
|
||||
r = poll(&ufds, 1, alarmlen ? 1000 : -1);
|
||||
if (r == 0) {
|
||||
/* we have waited a whole second with no keystroke... */
|
||||
waitseconds--;
|
||||
}
|
||||
if (r > 0) {
|
||||
char ch;
|
||||
|
||||
read(0, &ch, sizeof(ch));
|
||||
ch = toupper(ch);
|
||||
/* Die if we get a control-c or control-d */
|
||||
if (ignore_control == 0 && (ch == 3 || ch == 4))
|
||||
reset_term(1);
|
||||
/* Don't let a null character be interpreted as a match
|
||||
by strchr */
|
||||
if (ch != 0
|
||||
&& (strcmp(list, "") == 0 || strchr(list, ch) != NULL))
|
||||
reset_term(0);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
.TH initlog 8 "Sun Jan 24 1999"
|
||||
.SH NAME
|
||||
initlog \- log messages and events to the system logger
|
||||
.SH SYNOPSIS
|
||||
.B initlog
|
||||
[\-cefnpqrs] [\-\-cmd=ARG] [\-\-event=ARG] [\-\-facility=ARG]
|
||||
[\-\-name=ARG] [\-\-priority=ARG] [\-\-run=ARG] [\-\-string=ARG]
|
||||
.SH DESCRIPTION
|
||||
\fBinitlog\fR logs messages and events to the system logger.
|
||||
It is mainly designed for use in init scripts. initlog
|
||||
reads a configuration file
|
||||
.I /etc/initlog.conf
|
||||
by default, to determine its settings. Any line preceded with a
|
||||
.I #
|
||||
is a comment, and the following configuration directives
|
||||
are recognized:
|
||||
.TP
|
||||
.I facility <logging facility>
|
||||
Sets the default logging facility
|
||||
.TP
|
||||
.I priority <logging priority>
|
||||
Sets the default logging priority
|
||||
.TP
|
||||
.I ignore <regexp>
|
||||
Messages that match the regular expression will not be logged.
|
||||
.TP
|
||||
initlog behavior can also be configured by command-line options.
|
||||
|
||||
\fBNote that initlog is deprecated and will be removed in a future
|
||||
release.\fR
|
||||
|
||||
.SS OPTIONS
|
||||
.TP
|
||||
.I "\-c, \-\-cmd=[program]"
|
||||
Execute the specified program, logging anything output to
|
||||
stdout or stderr.
|
||||
.TP
|
||||
.I "\-e, \-\-event=[number]"
|
||||
Logs that the specified event happened. Used in conjuction
|
||||
with \fB\-\-name\fR. Currently specified events are:
|
||||
.PD 0
|
||||
.RS 8n
|
||||
.TP 3n
|
||||
.B 1
|
||||
the action completed successfully
|
||||
.TP
|
||||
.B 2
|
||||
the action failed
|
||||
.TP
|
||||
.B 3
|
||||
the action was cancelled at user request
|
||||
.TP
|
||||
.B 4
|
||||
the action failed due to the failure of a dependent action
|
||||
.RE
|
||||
.PD
|
||||
.TP
|
||||
.I "\-f, \-\-facility=[facility]"
|
||||
Log at the specified syslog facility. The default
|
||||
is \fBdaemon\fR (see syslog(3)).
|
||||
.TP
|
||||
.I "\-n, \-\-name=[string]"
|
||||
Log the event under the specified string, such as
|
||||
"inetd".
|
||||
.TP
|
||||
.I "\-p, \-\-priority=[priority]"
|
||||
Log at the specified syslog priority. The default
|
||||
is \fBnotice\fR (see syslog(3)).
|
||||
.TP
|
||||
.I "\-q"
|
||||
Do not print the program's output, unless it exits
|
||||
with a non-zero exit code.
|
||||
.TP
|
||||
.I "\-r, \-\-run=[program]"
|
||||
Execute the specified program, with an open file
|
||||
descriptor so that the program can pass back
|
||||
commands to initlog.
|
||||
.TP
|
||||
.I "\-s, \-\-string=[string]"
|
||||
Log the specified string to the logger.
|
||||
.TP
|
||||
.I "\-\-conf=[file]"
|
||||
Specifies an alternate configuration file.
|
||||
.SH FILES
|
||||
.I /etc/initlog.conf
|
||||
.SH "SEE ALSO"
|
||||
syslog(3), logger(1)
|
446
src/initlog.c
446
src/initlog.c
@ -1,446 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2003 Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* This software may be freely redistributed under the terms of the GNU
|
||||
* public license.
|
||||
*
|
||||
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <libintl.h>
|
||||
#include <locale.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define SYSLOG_NAMES
|
||||
#include <syslog.h>
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#define _(String) gettext((String))
|
||||
|
||||
#include <popt.h>
|
||||
|
||||
#include <regex.h>
|
||||
|
||||
#include "initlog.h"
|
||||
#include "process.h"
|
||||
|
||||
static int logfacility=LOG_DAEMON;
|
||||
static int logpriority=LOG_NOTICE;
|
||||
static int reexec=0;
|
||||
static int quiet=0;
|
||||
int debug=0;
|
||||
|
||||
regex_t **regList = NULL;
|
||||
|
||||
static int logEntries = 0;
|
||||
struct logInfo *logData = NULL;
|
||||
|
||||
void readConfiguration(char *fname) {
|
||||
int fd,num=0;
|
||||
struct stat sbuf;
|
||||
char *data,*line, *d;
|
||||
regex_t *regexp;
|
||||
int lfac=-1,lpri=-1;
|
||||
|
||||
if ((fd=open(fname,O_RDONLY))==-1) return;
|
||||
if (fstat(fd,&sbuf)) {
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
d = data=malloc(sbuf.st_size+1);
|
||||
if (read(fd,data,sbuf.st_size)!=sbuf.st_size) {
|
||||
close(fd);
|
||||
free(data);
|
||||
return;
|
||||
}
|
||||
close(fd);
|
||||
data[sbuf.st_size] = '\0';
|
||||
while ((line=getLine(&data))) {
|
||||
if (line[0]=='#') continue;
|
||||
if (!strncmp(line,"ignore ",7)) {
|
||||
regexp = malloc(sizeof(regex_t));
|
||||
if (!regcomp(regexp,line+7,REG_EXTENDED|REG_NOSUB|REG_NEWLINE)) {
|
||||
regList = realloc(regList,(num+2) * sizeof(regex_t *));
|
||||
regList[num] = regexp;
|
||||
regList[num+1] = NULL;
|
||||
num++;
|
||||
}
|
||||
}
|
||||
if (!strncmp(line,"facility ",9)) {
|
||||
lfac=atoi(line+9);
|
||||
if ((lfac == 0) && strcmp(line+9,"0")) {
|
||||
int x =0;
|
||||
|
||||
lfac = LOG_DAEMON;
|
||||
for (x=0;facilitynames[x].c_name;x++) {
|
||||
if (!strcmp(line+9,facilitynames[x].c_name)) {
|
||||
lfac = facilitynames[x].c_val;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!strncmp(line,"priority ",9)) {
|
||||
lpri = atoi(line+9);
|
||||
if ((lpri == 0) && strcmp(line+9,"0")) {
|
||||
int x=0;
|
||||
|
||||
lpri = LOG_NOTICE;
|
||||
for (x=0;prioritynames[x].c_name;x++) {
|
||||
if (!strcmp(line+9,prioritynames[x].c_name)) {
|
||||
lpri = prioritynames[x].c_val;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (lfac!=-1) logfacility=lfac;
|
||||
if (lpri!=-1) logpriority=lpri;
|
||||
free(d);
|
||||
}
|
||||
|
||||
char *getLine(char **data) {
|
||||
/* Get one line from data */
|
||||
/* Anything up to a carraige return (\r) or a backspace (\b) is discarded. */
|
||||
/* If this really bothers you, mail me and I might make it configurable. */
|
||||
/* It's here to avoid confilcts with fsck's progress bar. */
|
||||
char *x, *y;
|
||||
|
||||
if (!*data) return NULL;
|
||||
x=*data;
|
||||
while (*x && (*x != '\n')) {
|
||||
while (*x && (*x != '\n') && (*x != '\r') && (*x != '\b')) x++;
|
||||
if (*x && (*x=='\r' || *x =='\b')) {
|
||||
*data = x+1;
|
||||
x++;
|
||||
}
|
||||
}
|
||||
if (*x) {
|
||||
x++;
|
||||
} else {
|
||||
if (x-*data) {
|
||||
y=malloc(x-*data+1);
|
||||
y[x-*data] = 0;
|
||||
y[x-*data-1] = '\n';
|
||||
memcpy(y,*data,x-*data);
|
||||
} else {
|
||||
y=NULL;
|
||||
}
|
||||
*data = NULL;
|
||||
return y;
|
||||
}
|
||||
y = malloc(x-*data);
|
||||
y[x-*data-1] = 0;
|
||||
memcpy(y,*data,x-*data-1);
|
||||
*data = x;
|
||||
return y;
|
||||
}
|
||||
|
||||
char **toArray(char *line, int *num) {
|
||||
/* Converts a long string into an array of lines. */
|
||||
char **lines;
|
||||
char *tmpline;
|
||||
|
||||
*num = 0;
|
||||
lines = NULL;
|
||||
|
||||
while ((tmpline=getLine(&line))) {
|
||||
if (!*num)
|
||||
lines = (char **) malloc(sizeof(char *));
|
||||
else
|
||||
lines = (char **) realloc(lines, (*num+1)*sizeof(char *));
|
||||
lines[*num] = tmpline;
|
||||
(*num)++;
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
int trySocket() {
|
||||
int s;
|
||||
struct sockaddr_un addr;
|
||||
|
||||
s = socket(AF_LOCAL, SOCK_DGRAM, 0);
|
||||
if (s<0)
|
||||
return 1;
|
||||
|
||||
bzero(&addr,sizeof(addr));
|
||||
addr.sun_family = AF_LOCAL;
|
||||
strncpy(addr.sun_path,_PATH_LOG,sizeof(addr.sun_path)-1);
|
||||
|
||||
if (connect(s,(struct sockaddr *) &addr,sizeof(addr))<0) {
|
||||
if (errno == EPROTOTYPE || errno == ECONNREFUSED) {
|
||||
DDEBUG("connect failed (EPROTOTYPE), trying stream\n");
|
||||
close(s);
|
||||
s = socket(AF_LOCAL, SOCK_STREAM, 0);
|
||||
if (connect(s,(struct sockaddr *) &addr, sizeof(addr)) < 0) {
|
||||
DDEBUG("connect failed: %s\n",strerror(errno));
|
||||
close(s);
|
||||
return 1;
|
||||
}
|
||||
close(s);
|
||||
return 0;
|
||||
}
|
||||
close(s);
|
||||
DDEBUG("connect failed: %s\n",strerror(errno));
|
||||
return 1;
|
||||
} else {
|
||||
close(s);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int logLine(struct logInfo *logEnt) {
|
||||
/* Logs a line... somewhere. */
|
||||
int x;
|
||||
struct stat statbuf;
|
||||
|
||||
/* Don't log empty or null lines */
|
||||
if (!logEnt->line || !strcmp(logEnt->line,"\n")) return 0;
|
||||
|
||||
|
||||
if ((stat(_PATH_LOG,&statbuf)==-1) || trySocket()) {
|
||||
DDEBUG("starting daemon failed, pooling entry %d\n",logEntries);
|
||||
logData=realloc(logData,(logEntries+1)*sizeof(struct logInfo));
|
||||
logData[logEntries].fac = logEnt->fac;
|
||||
logData[logEntries].pri = logEnt->pri;
|
||||
logData[logEntries].cmd = strdup(logEnt->cmd);
|
||||
logData[logEntries].line = strdup(logEnt->line);
|
||||
logEntries++;
|
||||
} else {
|
||||
if (logEntries>0) {
|
||||
for (x=0;x<logEntries;x++) {
|
||||
DDEBUG("flushing log entry %d =%s=\n",x,logData[x].line);
|
||||
openlog(logData[x].cmd,0,logData[x].fac);
|
||||
syslog(logData[x].pri,"%s",logData[x].line);
|
||||
closelog();
|
||||
}
|
||||
free(logData);
|
||||
logEntries = 0;
|
||||
}
|
||||
DDEBUG("logging =%s= via syslog\n",logEnt->line);
|
||||
openlog(logEnt->cmd,0,logEnt->fac);
|
||||
syslog(logEnt->pri,"%s",logEnt->line);
|
||||
closelog();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int logEvent(char *cmd, int eventtype,char *string) {
|
||||
char *eventtable [] = {
|
||||
_("%s babbles incoherently"),
|
||||
_("%s succeeded"),
|
||||
_("%s failed"),
|
||||
_("%s cancelled at user request"),
|
||||
_("%s failed due to a failed dependency"),
|
||||
/* insert more here */
|
||||
NULL
|
||||
};
|
||||
int x=0,len, rc;
|
||||
struct logInfo logentry;
|
||||
|
||||
if (cmd) {
|
||||
logentry.cmd = basename(cmd);
|
||||
if ((logentry.cmd[0] =='K' || logentry.cmd[0] == 'S') &&
|
||||
( logentry.cmd[1] >= '0' && logentry.cmd[1] <= '9' ) &&
|
||||
( logentry.cmd[2] >= '0' && logentry.cmd[2] <= '9' ) )
|
||||
logentry.cmd+=3;
|
||||
logentry.cmd = strdup(logentry.cmd);
|
||||
} else
|
||||
logentry.cmd = strdup(_("(none)"));
|
||||
if (!string) {
|
||||
string = alloca(strlen(cmd)+1);
|
||||
strcpy(string,cmd);
|
||||
}
|
||||
|
||||
while (eventtable[x] && x<eventtype) x++;
|
||||
if (!(eventtable[x])) x=0;
|
||||
|
||||
len=strlen(eventtable[x])+strlen(string);
|
||||
logentry.line=malloc(len);
|
||||
snprintf(logentry.line,len,eventtable[x],string);
|
||||
|
||||
logentry.pri = logpriority;
|
||||
logentry.fac = logfacility;
|
||||
|
||||
rc = logLine(&logentry);
|
||||
free(logentry.line);
|
||||
free(logentry.cmd);
|
||||
return rc;
|
||||
}
|
||||
|
||||
int logString(char *cmd, char *string) {
|
||||
struct logInfo logentry;
|
||||
int rc;
|
||||
|
||||
if (cmd) {
|
||||
logentry.cmd = basename(cmd);
|
||||
if ((logentry.cmd[0] =='K' || logentry.cmd[0] == 'S') &&
|
||||
( logentry.cmd[1] >= '0' && logentry.cmd[1] <= 0x39 ) &&
|
||||
( logentry.cmd[2] >= '0' && logentry.cmd[2] <= 0x39 ) )
|
||||
logentry.cmd+=3;
|
||||
logentry.cmd = strdup(logentry.cmd);
|
||||
} else
|
||||
logentry.cmd = strdup(_(""));
|
||||
logentry.line = strdup(string);
|
||||
logentry.pri = logpriority;
|
||||
logentry.fac = logfacility;
|
||||
|
||||
rc = logLine(&logentry);
|
||||
free(logentry.line);
|
||||
free(logentry.cmd);
|
||||
return rc;
|
||||
}
|
||||
|
||||
int processArgs(int argc, char **argv, int silent) {
|
||||
char *cmdname=NULL;
|
||||
char *conffile=NULL;
|
||||
int cmdevent=0;
|
||||
char *cmd=NULL;
|
||||
char *logstring=NULL;
|
||||
char *fac=NULL,*pri=NULL;
|
||||
int lfac=-1, lpri=-1;
|
||||
poptContext context;
|
||||
int rc;
|
||||
struct poptOption optTable[] = {
|
||||
POPT_AUTOHELP
|
||||
{ "conf", 0, POPT_ARG_STRING, &conffile, 0,
|
||||
"configuration file (default: /etc/initlog.conf)", NULL
|
||||
},
|
||||
{ "name", 'n', POPT_ARG_STRING, &cmdname, 0,
|
||||
"name of service being logged", NULL
|
||||
},
|
||||
{ "event", 'e', POPT_ARG_INT, &cmdevent, 0,
|
||||
"event being logged (see man page)", NULL
|
||||
},
|
||||
{ "cmd", 'c', POPT_ARG_STRING, &cmd, 0,
|
||||
"command to run, logging output", NULL
|
||||
},
|
||||
{ "debug", 'd', POPT_ARG_NONE, &debug, 0,
|
||||
"print lots of verbose debugging info", NULL
|
||||
},
|
||||
{ "run", 'r', POPT_ARG_STRING, &cmd, 3,
|
||||
"command to run, accepting input on open fd", NULL
|
||||
},
|
||||
{ "string", 's', POPT_ARG_STRING, &logstring, 0,
|
||||
"string to log", NULL
|
||||
},
|
||||
{ "facility", 'f', POPT_ARG_STRING, &fac, 1,
|
||||
"facility to log at (default: 'local7')", NULL
|
||||
},
|
||||
{ "priority", 'p', POPT_ARG_STRING, &pri, 2,
|
||||
"priority to log at (default: 'notice')", NULL
|
||||
},
|
||||
{ "quiet", 'q', POPT_ARG_NONE, &quiet, 0,
|
||||
"suppress stdout/stderr", NULL
|
||||
},
|
||||
{ 0, 0, 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
context = poptGetContext("initlog", argc, argv, optTable, 0);
|
||||
|
||||
while ((rc = poptGetNextOpt(context)) > 0) {
|
||||
switch (rc) {
|
||||
case 1:
|
||||
lfac=atoi(fac);
|
||||
if ((lfac == 0) && strcmp(fac,"0")) {
|
||||
int x =0;
|
||||
|
||||
lfac = LOG_DAEMON;
|
||||
for (x=0;facilitynames[x].c_name;x++) {
|
||||
if (!strcmp(fac,facilitynames[x].c_name)) {
|
||||
lfac = facilitynames[x].c_val;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
lpri = atoi(pri);
|
||||
if ((lpri == 0) && strcmp(pri,"0")) {
|
||||
int x=0;
|
||||
|
||||
lpri = LOG_NOTICE;
|
||||
for (x=0;prioritynames[x].c_name;x++) {
|
||||
if (!strcmp(pri,prioritynames[x].c_name)) {
|
||||
lpri = prioritynames[x].c_val;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
reexec = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ((rc < -1)) {
|
||||
if (!silent)
|
||||
fprintf(stderr, "%s: %s\n",
|
||||
poptBadOption(context, POPT_BADOPTION_NOALIAS),
|
||||
poptStrerror(rc));
|
||||
|
||||
return -1;
|
||||
}
|
||||
if ( (cmd && logstring) || (cmd && cmdname) ) {
|
||||
if (!silent)
|
||||
fprintf(stderr, _("--cmd and --run are incompatible with --string or --name\n"));
|
||||
return -1;
|
||||
}
|
||||
if ( cmdname && (!logstring && !cmdevent)) {
|
||||
if (!silent)
|
||||
fprintf(stderr, _("--name requires one of --event or --string\n"));
|
||||
return -1;
|
||||
}
|
||||
if (cmdevent && cmd) {
|
||||
if (!silent)
|
||||
fprintf(stderr, _("--cmd and --run are incompatible with --event\n"));
|
||||
return -1;
|
||||
}
|
||||
if (conffile) {
|
||||
readConfiguration(conffile);
|
||||
} else {
|
||||
readConfiguration("/etc/initlog.conf");
|
||||
}
|
||||
if (cmd) {
|
||||
while (isspace(*cmd)) cmd++;
|
||||
}
|
||||
if (lpri!=-1) logpriority=lpri;
|
||||
if (lfac!=-1) logfacility=lfac;
|
||||
if (cmdevent) {
|
||||
logEvent(cmdname,cmdevent,logstring);
|
||||
} else if (logstring) {
|
||||
logString(cmdname,logstring);
|
||||
} else if ( cmd && *cmd) {
|
||||
return(runCommand(cmd,reexec,quiet,debug));
|
||||
} else {
|
||||
if (!silent)
|
||||
fprintf(stderr,"nothing to do!\n");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
setlocale(LC_ALL,"");
|
||||
bindtextdomain("initlog","/etc/locale");
|
||||
textdomain("initlog");
|
||||
exit(processArgs(argc,argv,0));
|
||||
}
|
@ -1,446 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2003 Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* This software may be freely redistributed under the terms of the GNU
|
||||
* public license.
|
||||
*
|
||||
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <libintl.h>
|
||||
#include <locale.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define SYSLOG_NAMES
|
||||
#include <syslog.h>
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#define _(String) gettext((String))
|
||||
|
||||
#include <popt.h>
|
||||
|
||||
#include <regex.h>
|
||||
|
||||
#include "initlog.h"
|
||||
#include "process.h"
|
||||
|
||||
static int logfacility=LOG_DAEMON;
|
||||
static int logpriority=LOG_NOTICE;
|
||||
static int reexec=0;
|
||||
static int quiet=0;
|
||||
int debug=0;
|
||||
|
||||
regex_t **regList = NULL;
|
||||
|
||||
static int logEntries = 0;
|
||||
struct logInfo *logData = NULL;
|
||||
|
||||
void readConfiguration(char *fname) {
|
||||
int fd,num=0;
|
||||
struct stat sbuf;
|
||||
char *data,*line, *d;
|
||||
regex_t *regexp;
|
||||
int lfac=-1,lpri=-1;
|
||||
|
||||
if ((fd=open(fname,O_RDONLY))==-1) return;
|
||||
if (fstat(fd,&sbuf)) {
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
d = data=malloc(sbuf.st_size+1);
|
||||
if (read(fd,data,sbuf.st_size)!=sbuf.st_size) {
|
||||
close(fd);
|
||||
free(data);
|
||||
return;
|
||||
}
|
||||
close(fd);
|
||||
data[sbuf.st_size] = '\0';
|
||||
while ((line=getLine(&data))) {
|
||||
if (line[0]=='#') continue;
|
||||
if (!strncmp(line,"ignore ",7)) {
|
||||
regexp = malloc(sizeof(regex_t));
|
||||
if (!regcomp(regexp,line+7,REG_EXTENDED|REG_NOSUB|REG_NEWLINE)) {
|
||||
regList = realloc(regList,(num+2) * sizeof(regex_t *));
|
||||
regList[num] = regexp;
|
||||
regList[num+1] = NULL;
|
||||
num++;
|
||||
}
|
||||
}
|
||||
if (!strncmp(line,"facility ",9)) {
|
||||
lfac=atoi(line+9);
|
||||
if ((lfac == 0) && strcmp(line+9,"0")) {
|
||||
int x =0;
|
||||
|
||||
lfac = LOG_DAEMON;
|
||||
for (x=0;facilitynames[x].c_name;x++) {
|
||||
if (!strcmp(line+9,facilitynames[x].c_name)) {
|
||||
lfac = facilitynames[x].c_val;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!strncmp(line,"priority ",9)) {
|
||||
lpri = atoi(line+9);
|
||||
if ((lpri == 0) && strcmp(line+9,"0")) {
|
||||
int x=0;
|
||||
|
||||
lpri = LOG_NOTICE;
|
||||
for (x=0;prioritynames[x].c_name;x++) {
|
||||
if (!strcmp(line+9,prioritynames[x].c_name)) {
|
||||
lpri = prioritynames[x].c_val;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (lfac!=-1) logfacility=lfac;
|
||||
if (lpri!=-1) logpriority=lpri;
|
||||
free(d);
|
||||
}
|
||||
|
||||
char *getLine(char **data) {
|
||||
/* Get one line from data */
|
||||
/* Anything up to a carraige return (\r) or a backspace (\b) is discarded. */
|
||||
/* If this really bothers you, mail me and I might make it configurable. */
|
||||
/* It's here to avoid confilcts with fsck's progress bar. */
|
||||
char *x, *y;
|
||||
|
||||
if (!*data) return NULL;
|
||||
x=*data;
|
||||
while (*x && (*x != '\n')) {
|
||||
while (*x && (*x != '\n') && (*x != '\r') && (*x != '\b')) x++;
|
||||
if (*x && (*x=='\r' || *x =='\b')) {
|
||||
*data = x+1;
|
||||
x++;
|
||||
}
|
||||
}
|
||||
if (*x) {
|
||||
x++;
|
||||
} else {
|
||||
if (x-*data) {
|
||||
y=malloc(x-*data+1);
|
||||
y[x-*data] = 0;
|
||||
y[x-*data-1] = '\n';
|
||||
memcpy(y,*data,x-*data);
|
||||
} else {
|
||||
y=NULL;
|
||||
}
|
||||
*data = NULL;
|
||||
return y;
|
||||
}
|
||||
y = malloc(x-*data);
|
||||
y[x-*data-1] = 0;
|
||||
memcpy(y,*data,x-*data-1);
|
||||
*data = x;
|
||||
return y;
|
||||
}
|
||||
|
||||
char **toArray(char *line, int *num) {
|
||||
/* Converts a long string into an array of lines. */
|
||||
char **lines;
|
||||
char *tmpline;
|
||||
|
||||
*num = 0;
|
||||
lines = NULL;
|
||||
|
||||
while ((tmpline=getLine(&line))) {
|
||||
if (!*num)
|
||||
lines = (char **) malloc(sizeof(char *));
|
||||
else
|
||||
lines = (char **) realloc(lines, (*num+1)*sizeof(char *));
|
||||
lines[*num] = tmpline;
|
||||
(*num)++;
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
int trySocket() {
|
||||
int s;
|
||||
struct sockaddr_un addr;
|
||||
|
||||
s = socket(AF_LOCAL, SOCK_DGRAM, 0);
|
||||
if (s<0)
|
||||
return 1;
|
||||
|
||||
bzero(&addr,sizeof(addr));
|
||||
addr.sun_family = AF_LOCAL;
|
||||
strncpy(addr.sun_path,_PATH_LOG,sizeof(addr.sun_path)-1);
|
||||
|
||||
if (connect(s,(struct sockaddr *) &addr,sizeof(addr))<0) {
|
||||
if (errno == EPROTOTYPE || errno == ECONNREFUSED) {
|
||||
DDEBUG("connect failed (EPROTOTYPE), trying stream\n");
|
||||
close(s);
|
||||
s = socket(AF_LOCAL, SOCK_STREAM, 0);
|
||||
if (connect(s,(struct sockaddr *) &addr, sizeof(addr)) < 0) {
|
||||
DDEBUG("connect failed: %s\n",strerror(errno));
|
||||
close(s);
|
||||
return 1;
|
||||
}
|
||||
close(s);
|
||||
return 0;
|
||||
}
|
||||
close(s);
|
||||
DDEBUG("connect failed: %s\n",strerror(errno));
|
||||
return 1;
|
||||
} else {
|
||||
close(s);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int logLine(struct logInfo *logEnt) {
|
||||
/* Logs a line... somewhere. */
|
||||
int x;
|
||||
struct stat statbuf;
|
||||
|
||||
/* Don't log empty or null lines */
|
||||
if (!logEnt->line || !strcmp(logEnt->line,"\n")) return 0;
|
||||
|
||||
|
||||
if ((stat(_PATH_LOG,&statbuf)==-1) || trySocket()) {
|
||||
DDEBUG("starting daemon failed, pooling entry %d\n",logEntries);
|
||||
logData=realloc(logData,(logEntries+1)*sizeof(struct logInfo));
|
||||
logData[logEntries].fac = logEnt->fac;
|
||||
logData[logEntries].pri = logEnt->pri;
|
||||
logData[logEntries].cmd = strdup(logEnt->cmd);
|
||||
logData[logEntries].line = strdup(logEnt->line);
|
||||
logEntries++;
|
||||
} else {
|
||||
if (logEntries>0) {
|
||||
for (x=0;x<logEntries;x++) {
|
||||
DDEBUG("flushing log entry %d =%s=\n",x,logData[x].line);
|
||||
openlog(logData[x].cmd,0,logData[x].fac);
|
||||
syslog(logData[x].pri,"%s",logData[x].line);
|
||||
closelog();
|
||||
}
|
||||
free(logData);
|
||||
logEntries = 0;
|
||||
}
|
||||
DDEBUG("logging =%s= via syslog\n",logEnt->line);
|
||||
openlog(logEnt->cmd,0,logEnt->fac);
|
||||
syslog(logEnt->pri,"%s",logEnt->line);
|
||||
closelog();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int logEvent(char *cmd, int eventtype,char *string) {
|
||||
char *eventtable [] = {
|
||||
_("%s babbles incoherently"),
|
||||
_("%s succeeded"),
|
||||
_("%s failed"),
|
||||
_("%s cancelled at user request"),
|
||||
_("%s failed due to a failed dependency"),
|
||||
/* insert more here */
|
||||
NULL
|
||||
};
|
||||
int x=0,len, rc;
|
||||
struct logInfo logentry;
|
||||
|
||||
if (cmd) {
|
||||
logentry.cmd = basename(cmd);
|
||||
if ((logentry.cmd[0] =='K' || logentry.cmd[0] == 'S') &&
|
||||
( logentry.cmd[1] >= '0' && logentry.cmd[1] <= '9' ) &&
|
||||
( logentry.cmd[2] >= '0' && logentry.cmd[2] <= '9' ) )
|
||||
logentry.cmd+=3;
|
||||
logentry.cmd = strdup(logentry.cmd);
|
||||
} else
|
||||
logentry.cmd = strdup(_("(none)"));
|
||||
if (!string) {
|
||||
string = alloca(strlen(cmd)+1);
|
||||
strcpy(string,cmd);
|
||||
}
|
||||
|
||||
while (eventtable[x] && x<eventtype) x++;
|
||||
if (!(eventtable[x])) x=0;
|
||||
|
||||
len=strlen(eventtable[x])+strlen(string);
|
||||
logentry.line=malloc(len);
|
||||
snprintf(logentry.line,len,eventtable[x],string);
|
||||
|
||||
logentry.pri = logpriority;
|
||||
logentry.fac = logfacility;
|
||||
|
||||
rc = logLine(&logentry);
|
||||
free(logentry.line);
|
||||
free(logentry.cmd);
|
||||
return rc;
|
||||
}
|
||||
|
||||
int logString(char *cmd, char *string) {
|
||||
struct logInfo logentry;
|
||||
int rc;
|
||||
|
||||
if (cmd) {
|
||||
logentry.cmd = basename(cmd);
|
||||
if ((logentry.cmd[0] =='K' || logentry.cmd[0] == 'S') &&
|
||||
( logentry.cmd[1] >= '0' && logentry.cmd[1] <= 0x39 ) &&
|
||||
( logentry.cmd[2] >= '0' && logentry.cmd[2] <= 0x39 ) )
|
||||
logentry.cmd+=3;
|
||||
logentry.cmd = strdup(logentry.cmd);
|
||||
} else
|
||||
logentry.cmd = strdup(_(""));
|
||||
logentry.line = strdup(string);
|
||||
logentry.pri = logpriority;
|
||||
logentry.fac = logfacility;
|
||||
|
||||
rc = logLine(&logentry);
|
||||
free(logentry.line);
|
||||
free(logentry.cmd);
|
||||
return rc;
|
||||
}
|
||||
|
||||
int processArgs(int argc, char **argv, int silent) {
|
||||
char *cmdname=NULL;
|
||||
char *conffile=NULL;
|
||||
int cmdevent=0;
|
||||
char *cmd=NULL;
|
||||
char *logstring=NULL;
|
||||
char *fac=NULL,*pri=NULL;
|
||||
int lfac=-1, lpri=-1;
|
||||
poptContext context;
|
||||
int rc;
|
||||
struct poptOption optTable[] = {
|
||||
POPT_AUTOHELP
|
||||
{ "conf", 0, POPT_ARG_STRING, &conffile, 0,
|
||||
"configuration file (default: /etc/initlog.conf)", NULL
|
||||
},
|
||||
{ "name", 'n', POPT_ARG_STRING, &cmdname, 0,
|
||||
"name of service being logged", NULL
|
||||
},
|
||||
{ "event", 'e', POPT_ARG_INT, &cmdevent, 0,
|
||||
"event being logged (see man page)", NULL
|
||||
},
|
||||
{ "cmd", 'c', POPT_ARG_STRING, &cmd, 0,
|
||||
"command to run, logging output", NULL
|
||||
},
|
||||
{ "debug", 'd', POPT_ARG_NONE, &debug, 0,
|
||||
"print lots of verbose debugging info", NULL
|
||||
},
|
||||
{ "run", 'r', POPT_ARG_STRING, &cmd, 3,
|
||||
"command to run, accepting input on open fd", NULL
|
||||
},
|
||||
{ "string", 's', POPT_ARG_STRING, &logstring, 0,
|
||||
"string to log", NULL
|
||||
},
|
||||
{ "facility", 'f', POPT_ARG_STRING, &fac, 1,
|
||||
"facility to log at (default: 'local7')", NULL
|
||||
},
|
||||
{ "priority", 'p', POPT_ARG_STRING, &pri, 2,
|
||||
"priority to log at (default: 'notice')", NULL
|
||||
},
|
||||
{ "quiet", 'q', POPT_ARG_NONE, &quiet, 0,
|
||||
"suppress stdout/stderr", NULL
|
||||
},
|
||||
{ 0, 0, 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
context = poptGetContext("initlog", argc, argv, optTable, 0);
|
||||
|
||||
while ((rc = poptGetNextOpt(context)) > 0) {
|
||||
switch (rc) {
|
||||
case 1:
|
||||
lfac=atoi(fac);
|
||||
if ((lfac == 0) && strcmp(fac,"0")) {
|
||||
int x =0;
|
||||
|
||||
lfac = LOG_DAEMON;
|
||||
for (x=0;facilitynames[x].c_name;x++) {
|
||||
if (!strcmp(fac,facilitynames[x].c_name)) {
|
||||
lfac = facilitynames[x].c_val;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
lpri = atoi(pri);
|
||||
if ((lpri == 0) && strcmp(pri,"0")) {
|
||||
int x=0;
|
||||
|
||||
lpri = LOG_NOTICE;
|
||||
for (x=0;prioritynames[x].c_name;x++) {
|
||||
if (!strcmp(pri,prioritynames[x].c_name)) {
|
||||
lpri = prioritynames[x].c_val;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
reexec = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ((rc < -1)) {
|
||||
if (!silent)
|
||||
fprintf(stderr, "%s: %s\n",
|
||||
poptBadOption(context, POPT_BADOPTION_NOALIAS),
|
||||
poptStrerror(rc));
|
||||
|
||||
return -1;
|
||||
}
|
||||
if ( (cmd && logstring) || (cmd && cmdname) ) {
|
||||
if (!silent)
|
||||
fprintf(stderr, _("--cmd and --run are incompatible with --string or --name\n"));
|
||||
return -1;
|
||||
}
|
||||
if ( cmdname && (!logstring && !cmdevent)) {
|
||||
if (!silent)
|
||||
fprintf(stderr, _("--name requires one of --event or --string\n"));
|
||||
return -1;
|
||||
}
|
||||
if (cmdevent && cmd) {
|
||||
if (!silent)
|
||||
fprintf(stderr, _("--cmd and --run are incompatible with --event\n"));
|
||||
return -1;
|
||||
}
|
||||
if (conffile) {
|
||||
readConfiguration(conffile);
|
||||
} else {
|
||||
readConfiguration("/etc/initlog.conf");
|
||||
}
|
||||
if (cmd) {
|
||||
while (isspace(*cmd)) cmd++;
|
||||
}
|
||||
if (lpri!=-1) logpriority=lpri;
|
||||
if (lfac!=-1) logfacility=lfac;
|
||||
if (cmdevent) {
|
||||
logEvent(cmdname,cmdevent,logstring);
|
||||
} else if (logstring) {
|
||||
logString(cmdname,logstring);
|
||||
} else if ( cmd && *cmd) {
|
||||
return(runCommand(cmd,reexec,quiet,debug));
|
||||
} else {
|
||||
if (!silent)
|
||||
fprintf(stderr,"nothing to do!\n");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
setlocale(LC_ALL,"");
|
||||
bindtextdomain("initlog","/etc/locale");
|
||||
textdomain("initlog");
|
||||
exit(processArgs(argc,argv,0));
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
# /etc/initlog.conf
|
||||
#
|
||||
# initlog configuration file
|
||||
#
|
||||
# lines preceded by a '#' are comments
|
||||
#
|
||||
# anything not recognized is ignored. :)
|
||||
|
||||
# This sets the default logging facility. (can override with command line arguments)
|
||||
facility local7
|
||||
|
||||
# This sets the default logging priority. (can override with command line arguments)
|
||||
priority notice
|
||||
|
||||
# ignore foo
|
||||
# means to discard any output lines that match the regular expression foo
|
||||
|
||||
# This regexp is useful if you use fsck's -C option.
|
||||
ignore [^:]+: \|[=]+
|
||||
# This regexp is useful for fsck's feature of setting file types
|
||||
ignore [^:]+: Setting filetype
|
||||
# This regexp is useful for quotacheck
|
||||
ignore ^[-\\\|\/]$
|
@ -1,20 +0,0 @@
|
||||
|
||||
#define _GNU_SOURCE 1
|
||||
|
||||
#ifndef INITLOG_H
|
||||
#define INITLOG_H
|
||||
|
||||
struct logInfo {
|
||||
char *cmd;
|
||||
char *line;
|
||||
int fac;
|
||||
int pri;
|
||||
};
|
||||
|
||||
char *getLine(char **data);
|
||||
int logString(char *cmd, char *string);
|
||||
int processArgs(int argc, char **argv, int silent);
|
||||
|
||||
#define DDEBUG if (debug) printf
|
||||
|
||||
#endif
|
58
src/ipcalc.1
58
src/ipcalc.1
@ -1,58 +0,0 @@
|
||||
.TH IPCALC 1 "April 30 2001" "Red Hat, Inc." RH \" -*- nroff -*-
|
||||
.SH NAME
|
||||
ipcalc \- perform simple manipulation of IP addresses
|
||||
.SH SYNOPSIS
|
||||
.B ipcalc
|
||||
[\fIOPTION\fR]... <\fBIP address\fR>[\fI/prefix\fR] [\fInetmask\fR]
|
||||
|
||||
.SH DESCRIPTION
|
||||
\fBipcalc\fR provides a simple way to calculate IP information for a host.
|
||||
The various options specify what information \fBipcalc\fR should display
|
||||
on standard out. Multiple options may be specified. An IP address to
|
||||
operate on must always be specified. Most operations also require a
|
||||
netmask or a CIDR prefix as well.
|
||||
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.TP
|
||||
\fB\-b\fR, \fB\-\-broadcast\fR
|
||||
Display the broadcast address for the given IP address and netmask.
|
||||
|
||||
.TP
|
||||
\fB\-h\fR, \fB\-\-hostname\fR
|
||||
Display the hostname for the given IP address.
|
||||
|
||||
.TP
|
||||
\fB\-m\fR, \fB\-\-netmask\fR
|
||||
Calculate the netmask for the given IP address. It assumes that the IP
|
||||
address is in a complete class A, B, or C network. Many networks do
|
||||
not use the default netmasks, in which case an inappropriate value will
|
||||
be returned.
|
||||
|
||||
.TP
|
||||
\fB\-p\fR, \fB\-\-prefix\fR
|
||||
Show the prefix for the given mask/IP address.
|
||||
|
||||
.TP
|
||||
\fB\-n\fR, \fB\-\-network\fR
|
||||
Display the network address for the given IP address and netmask.
|
||||
|
||||
.TP
|
||||
\fB\-s\fR, \fB\-\-silent\fR
|
||||
Don't ever display error messages.
|
||||
|
||||
.SH AUTHORS
|
||||
.nf
|
||||
Erik Troan <ewt@redhat.com>
|
||||
.nf
|
||||
Preston Brown <pbrown@redhat.com>
|
||||
.fi
|
||||
.SH "REPORTING BUGS"
|
||||
Report bugs to our bugtracking system:
|
||||
http://bugzilla.redhat.com/bugzilla.
|
||||
.SH COPYRIGHT
|
||||
Copyright \(co 1997-2001 Red Hat, Inc.
|
||||
.br
|
||||
This is free software; see the source for copying conditions. There is NO
|
||||
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
PURPOSE.
|
361
src/ipcalc.c
361
src/ipcalc.c
@ -1,361 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1997-2003 Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* This software may be freely redistributed under the terms of the GNU
|
||||
* public license.
|
||||
*
|
||||
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
* Authors:
|
||||
* Erik Troan <ewt@redhat.com>
|
||||
* Preston Brown <pbrown@redhat.com>
|
||||
*/
|
||||
|
||||
|
||||
#include <ctype.h>
|
||||
#include <popt.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
|
||||
/*!
|
||||
\def IPBITS
|
||||
\brief the number of bits in an IP address.
|
||||
*/
|
||||
#define IPBITS (sizeof(u_int32_t) * 8)
|
||||
/*!
|
||||
\def IPBYTES
|
||||
\brief the number of bytes in an IP address.
|
||||
*/
|
||||
#define IPBYTES (sizeof(u_int32_t))
|
||||
|
||||
|
||||
/*!
|
||||
\file ipcalc.c
|
||||
\brief provides utilities for manipulating IP addresses.
|
||||
|
||||
ipcalc provides utilities and a front-end command line interface for
|
||||
manipulating IP addresses, and calculating various aspects of an ip
|
||||
address/netmask/network address/prefix/etc.
|
||||
|
||||
Functionality can be accessed from other languages from the library
|
||||
interface, documented here. To use ipcalc from the shell, read the
|
||||
ipcalc(1) manual page.
|
||||
|
||||
When passing parameters to the various functions, take note of whether they
|
||||
take host byte order or network byte order. Most take host byte order, and
|
||||
return host byte order, but there are some exceptions.
|
||||
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn u_int32_t prefix2mask(int bits)
|
||||
\brief creates a netmask from a specified number of bits
|
||||
|
||||
This function converts a prefix length to a netmask. As CIDR (classless
|
||||
internet domain internet domain routing) has taken off, more an more IP
|
||||
addresses are being specified in the format address/prefix
|
||||
(i.e. 192.168.2.3/24, with a corresponding netmask 255.255.255.0). If you
|
||||
need to see what netmask corresponds to the prefix part of the address, this
|
||||
is the function. See also \ref mask2prefix.
|
||||
|
||||
\param prefix is the number of bits to create a mask for.
|
||||
\return a network mask, in network byte order.
|
||||
*/
|
||||
u_int32_t prefix2mask(int prefix) {
|
||||
return htonl(~((1 << (32 - prefix)) - 1));
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn int mask2prefix(u_int32_t mask)
|
||||
\brief calculates the number of bits masked off by a netmask.
|
||||
|
||||
This function calculates the significant bits in an IP address as specified by
|
||||
a netmask. See also \ref prefix2mask.
|
||||
|
||||
\param mask is the netmask, specified as an u_int32_teger in network byte order.
|
||||
\return the number of significant bits. */
|
||||
int mask2prefix(u_int32_t mask)
|
||||
{
|
||||
int i;
|
||||
int count = IPBITS;
|
||||
|
||||
for (i = 0; i < IPBITS; i++) {
|
||||
if (!(ntohl(mask) & ((2 << i) - 1)))
|
||||
count--;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn u_int32_t default_netmask(u_int32_t addr)
|
||||
|
||||
\brief returns the default (canonical) netmask associated with specified IP
|
||||
address.
|
||||
|
||||
When the Internet was originally set up, various ranges of IP addresses were
|
||||
segmented into three network classes: A, B, and C. This function will return
|
||||
a netmask that is associated with the IP address specified defining where it
|
||||
falls in the predefined classes.
|
||||
|
||||
\param addr an IP address in network byte order.
|
||||
\return a netmask in network byte order. */
|
||||
u_int32_t default_netmask(u_int32_t addr)
|
||||
{
|
||||
if (((ntohl(addr) & 0xFF000000) >> 24) <= 127)
|
||||
return htonl(0xFF000000);
|
||||
else if (((ntohl(addr) & 0xFF000000) >> 24) <= 191)
|
||||
return htonl(0xFFFF0000);
|
||||
else
|
||||
return htonl(0xFFFFFF00);
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn u_int32_t calc_broadcast(u_int32_t addr, int prefix)
|
||||
|
||||
\brief calculate broadcast address given an IP address and a prefix length.
|
||||
|
||||
\param addr an IP address in network byte order.
|
||||
\param prefix a prefix length.
|
||||
|
||||
\return the calculated broadcast address for the network, in network byte
|
||||
order.
|
||||
*/
|
||||
u_int32_t calc_broadcast(u_int32_t addr,
|
||||
int prefix)
|
||||
{
|
||||
return (addr & prefix2mask(prefix)) | ~prefix2mask(prefix);
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn u_int32_t calc_network(u_int32_t addr, int prefix)
|
||||
\brief calculates the network address for a specified address and prefix.
|
||||
|
||||
\param addr an IP address, in network byte order
|
||||
\param prefix the network prefix
|
||||
\return the base address of the network that addr is associated with, in
|
||||
network byte order.
|
||||
*/
|
||||
u_int32_t calc_network(u_int32_t addr, int prefix)
|
||||
{
|
||||
return (addr & prefix2mask(prefix));
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn const char *get_hostname(u_int32_t addr)
|
||||
\brief returns the hostname associated with the specified IP address
|
||||
|
||||
\param addr an IP address to find a hostname for, in network byte order
|
||||
|
||||
\return a hostname, or NULL if one cannot be determined. Hostname is stored
|
||||
in a static buffer that may disappear at any time, the caller should copy the
|
||||
data if it needs permanent storage.
|
||||
*/
|
||||
const char *get_hostname(u_int32_t addr)
|
||||
{
|
||||
struct hostent * hostinfo;
|
||||
int x;
|
||||
|
||||
hostinfo = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET);
|
||||
if (!hostinfo)
|
||||
return NULL;
|
||||
|
||||
for (x=0; hostinfo->h_name[x]; x++) {
|
||||
hostinfo->h_name[x] = tolower(hostinfo->h_name[x]);
|
||||
}
|
||||
return hostinfo->h_name;
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn main(int argc, const char **argv)
|
||||
\brief wrapper program for ipcalc functions.
|
||||
|
||||
This is a wrapper program for the functions that the ipcalc library provides.
|
||||
It can be used from shell scripts or directly from the command line.
|
||||
|
||||
For more information, please see the ipcalc(1) man page.
|
||||
*/
|
||||
int main(int argc, const char **argv) {
|
||||
int showBroadcast = 0, showPrefix = 0, showNetwork = 0;
|
||||
int showHostname = 0, showNetmask = 0;
|
||||
int beSilent = 0;
|
||||
int rc;
|
||||
poptContext optCon;
|
||||
char *ipStr, *prefixStr, *netmaskStr, *hostName, *chptr;
|
||||
struct in_addr ip, netmask, network, broadcast;
|
||||
int prefix = 0;
|
||||
char errBuf[250];
|
||||
struct poptOption optionsTable[] = {
|
||||
{ "broadcast", 'b', 0, &showBroadcast, 0,
|
||||
"Display calculated broadcast address", },
|
||||
{ "hostname", 'h', 0, &showHostname, 0,
|
||||
"Show hostname determined via DNS" },
|
||||
{ "netmask", 'm', 0, &showNetmask, 0,
|
||||
"Display default netmask for IP (class A, B, or C)" },
|
||||
{ "network", 'n', 0, &showNetwork, 0,
|
||||
"Display network address", },
|
||||
{ "prefix", 'p', 0, &showPrefix, 0,
|
||||
"Display network prefix", },
|
||||
{ "silent", 's', 0, &beSilent, 0,
|
||||
"Don't ever display error messages " },
|
||||
POPT_AUTOHELP
|
||||
{ NULL, '\0', 0, 0, 0, NULL, NULL }
|
||||
};
|
||||
|
||||
optCon = poptGetContext("ipcalc", argc, argv, optionsTable, 0);
|
||||
poptReadDefaultConfig(optCon, 1);
|
||||
|
||||
if ((rc = poptGetNextOpt(optCon)) < -1) {
|
||||
if (!beSilent) {
|
||||
fprintf(stderr, "ipcalc: bad argument %s: %s\n",
|
||||
poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
|
||||
poptStrerror(rc));
|
||||
poptPrintHelp(optCon, stderr, 0);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!(ipStr = (char *) poptGetArg(optCon))) {
|
||||
if (!beSilent) {
|
||||
fprintf(stderr, "ipcalc: ip address expected\n");
|
||||
poptPrintHelp(optCon, stderr, 0);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (strchr(ipStr,'/') != NULL) {
|
||||
prefixStr = strchr(ipStr, '/') + 1;
|
||||
prefixStr--;
|
||||
*prefixStr = '\0'; /* fix up ipStr */
|
||||
prefixStr++;
|
||||
} else
|
||||
prefixStr = NULL;
|
||||
|
||||
if (prefixStr != NULL) {
|
||||
prefix = atoi(prefixStr);
|
||||
if (prefix == 0) {
|
||||
if (!beSilent)
|
||||
fprintf(stderr, "ipcalc: bad prefix: %s\n",
|
||||
prefixStr);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (showBroadcast || showNetwork || showPrefix) {
|
||||
if (!(netmaskStr = (char *) poptGetArg(optCon)) &&
|
||||
(prefix == 0)) {
|
||||
if (!beSilent) {
|
||||
fprintf(stderr, "ipcalc: netmask or prefix expected\n");
|
||||
poptPrintHelp(optCon, stderr, 0);
|
||||
}
|
||||
return 1;
|
||||
} else if (netmaskStr && prefix != 0) {
|
||||
if (!beSilent) {
|
||||
fprintf(stderr, "ipcalc: both netmask and prefix specified\n");
|
||||
poptPrintHelp(optCon, stderr, 0);
|
||||
}
|
||||
return 1;
|
||||
} else if (netmaskStr) {
|
||||
if (!inet_aton(netmaskStr, &netmask)) {
|
||||
if (!beSilent)
|
||||
fprintf(stderr, "ipcalc: bad netmask: %s\n",
|
||||
netmaskStr);
|
||||
return 1;
|
||||
}
|
||||
prefix = mask2prefix(netmask.s_addr);
|
||||
}
|
||||
}
|
||||
|
||||
if ((chptr = (char *) poptGetArg(optCon))) {
|
||||
if (!beSilent) {
|
||||
fprintf(stderr, "ipcalc: unexpected argument: %s\n", chptr);
|
||||
poptPrintHelp(optCon, stderr, 0);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Handle CIDR entries such as 172/8 */
|
||||
if (prefix) {
|
||||
char *tmp = ipStr;
|
||||
int i;
|
||||
|
||||
for(i=3; i> 0; i--) {
|
||||
tmp = strchr(tmp,'.');
|
||||
if (!tmp)
|
||||
break;
|
||||
else
|
||||
tmp++;
|
||||
}
|
||||
tmp = NULL;
|
||||
for (; i>0; i--) {
|
||||
tmp = malloc(strlen(ipStr) + 3);
|
||||
sprintf(tmp,"%s.0",ipStr);
|
||||
ipStr = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
if (!inet_aton(ipStr, (struct in_addr *) &ip)) {
|
||||
if (!beSilent)
|
||||
fprintf(stderr, "ipcalc: bad ip address: %s\n", ipStr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
if (!(showNetmask|showPrefix|showBroadcast|showNetwork|showHostname)) {
|
||||
poptPrintHelp(optCon, stderr, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
poptFreeContext(optCon);
|
||||
|
||||
/* we know what we want to display now, so display it. */
|
||||
|
||||
if (showNetmask) {
|
||||
if (prefix) {
|
||||
netmask.s_addr = prefix2mask(prefix);
|
||||
} else {
|
||||
netmask.s_addr = default_netmask(ip.s_addr);
|
||||
prefix = mask2prefix(netmask.s_addr);
|
||||
}
|
||||
|
||||
printf("NETMASK=%s\n", inet_ntoa(netmask));
|
||||
}
|
||||
|
||||
if (showPrefix) {
|
||||
if (!prefix)
|
||||
prefix = mask2prefix(ip.s_addr);
|
||||
printf("PREFIX=%d\n", prefix);
|
||||
}
|
||||
|
||||
if (showBroadcast) {
|
||||
broadcast.s_addr = calc_broadcast(ip.s_addr, prefix);
|
||||
printf("BROADCAST=%s\n", inet_ntoa(broadcast));
|
||||
}
|
||||
|
||||
if (showNetwork) {
|
||||
network.s_addr = calc_network(ip.s_addr, prefix);
|
||||
printf("NETWORK=%s\n", inet_ntoa(network));
|
||||
}
|
||||
|
||||
if (showHostname) {
|
||||
if ((hostName = (char *) get_hostname(ip.s_addr)) == NULL) {
|
||||
if (!beSilent) {
|
||||
sprintf(errBuf, "ipcalc: cannot find hostname for %s", ipStr);
|
||||
herror(errBuf);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("HOSTNAME=%s\n", hostName);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
187
src/minilogd.c
187
src/minilogd.c
@ -1,187 +0,0 @@
|
||||
/* minilogd.c
|
||||
*
|
||||
* A pale imitation of syslogd. Most notably, doesn't write anything
|
||||
* anywhere except possibly back to syslogd.
|
||||
*
|
||||
* Copyright (c) 1999-2001 Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* This software may be freely redistributed under the terms of the GNU
|
||||
* public license.
|
||||
*
|
||||
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <syslog.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/poll.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/un.h>
|
||||
|
||||
static int we_own_log=0;
|
||||
static char **buffer=NULL;
|
||||
static int buflines=0;
|
||||
|
||||
int debug;
|
||||
|
||||
int recvsock;
|
||||
|
||||
void alarm_handler(int x) {
|
||||
alarm(0);
|
||||
close(recvsock);
|
||||
recvsock = -1;
|
||||
}
|
||||
|
||||
void freeBuffer() {
|
||||
struct sockaddr_un addr;
|
||||
int sock;
|
||||
int x=0,conn;
|
||||
|
||||
bzero(&addr,sizeof(addr));
|
||||
addr.sun_family = AF_LOCAL;
|
||||
strncpy(addr.sun_path,_PATH_LOG,sizeof(addr.sun_path)-1);
|
||||
/* wait for klogd to hit syslog */
|
||||
sleep(2);
|
||||
sock = socket(AF_LOCAL, SOCK_DGRAM,0);
|
||||
conn=connect(sock,(struct sockaddr *) &addr,sizeof(addr));
|
||||
while (x<buflines) {
|
||||
if (!conn) write(sock,buffer[x],strlen(buffer[x])+1);
|
||||
free(buffer[x]);
|
||||
x++;
|
||||
}
|
||||
}
|
||||
|
||||
void cleanup(int exitcode) {
|
||||
/* If we own the log, unlink it before trying to free our buffer.
|
||||
* Otherwise, sending the buffer to /dev/log doesn't make much sense.... */
|
||||
if (we_own_log) {
|
||||
perror("wol");
|
||||
unlink(_PATH_LOG);
|
||||
}
|
||||
/* Don't try to free buffer if we were called from a signal handler */
|
||||
if (exitcode<=0) {
|
||||
if (buffer) freeBuffer();
|
||||
exit(exitcode);
|
||||
} else
|
||||
exit(exitcode+128);
|
||||
}
|
||||
|
||||
void runDaemon(int sock) {
|
||||
struct sockaddr_un addr;
|
||||
int x,len,done=0;
|
||||
int addrlen = sizeof(struct sockaddr_un);
|
||||
char *message;
|
||||
struct stat s1,s2;
|
||||
struct pollfd pfds;
|
||||
|
||||
daemon(0,-1);
|
||||
/* try not to leave stale sockets lying around */
|
||||
/* Hopefully, we won't actually get any of these */
|
||||
signal(SIGHUP,cleanup);
|
||||
signal(SIGINT,cleanup);
|
||||
signal(SIGQUIT,cleanup);
|
||||
signal(SIGILL,cleanup);
|
||||
signal(SIGABRT,cleanup);
|
||||
signal(SIGFPE,cleanup);
|
||||
signal(SIGSEGV,cleanup);
|
||||
signal(SIGPIPE,cleanup);
|
||||
signal(SIGBUS,cleanup);
|
||||
signal(SIGTERM,cleanup);
|
||||
done = 0;
|
||||
/* Get stat info on /dev/log so we can later check to make sure we
|
||||
* still own it... */
|
||||
if (stat(_PATH_LOG,&s1) != 0)
|
||||
memset(&s1, '\0', sizeof(struct stat));
|
||||
while (!done) {
|
||||
pfds.fd = sock;
|
||||
pfds.events = POLLIN|POLLPRI;
|
||||
if ( ( (x=poll(&pfds,1,500))==-1) && errno !=EINTR) {
|
||||
perror("poll");
|
||||
cleanup(-1);
|
||||
}
|
||||
if ( (x>0) && pfds.revents & (POLLIN | POLLPRI)) {
|
||||
message = calloc(8192,sizeof(char));
|
||||
addrlen = sizeof(struct sockaddr_un);
|
||||
recvsock = accept(sock,(struct sockaddr *) &addr, &addrlen);
|
||||
if (recvsock == -1)
|
||||
continue;
|
||||
alarm(2);
|
||||
signal(SIGALRM, alarm_handler);
|
||||
len = recv(recvsock,message,8192,0);
|
||||
alarm(0);
|
||||
close(recvsock);
|
||||
if (len>0) {
|
||||
if (buflines < 200000) {
|
||||
if (buffer)
|
||||
buffer = realloc(buffer,(buflines+1)*sizeof(char *));
|
||||
else
|
||||
buffer = malloc(sizeof(char *));
|
||||
message[strlen(message)]='\n';
|
||||
buffer[buflines]=message;
|
||||
buflines++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
recvsock=-1;
|
||||
}
|
||||
}
|
||||
if ( (x>0) && ( pfds.revents & (POLLHUP | POLLNVAL)) )
|
||||
done = 1;
|
||||
/* Check to see if syslogd's yanked our socket out from under us */
|
||||
if ( (stat(_PATH_LOG,&s2)!=0) ||
|
||||
(s1.st_ino != s2.st_ino ) || (s1.st_ctime != s2.st_ctime) ||
|
||||
(s1.st_mtime != s2.st_mtime) ) {
|
||||
done = 1;
|
||||
we_own_log = 0;
|
||||
}
|
||||
}
|
||||
cleanup(0);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
struct sockaddr_un addr;
|
||||
int sock;
|
||||
int pid;
|
||||
|
||||
/* option processing made simple... */
|
||||
if (argc>1) debug=1;
|
||||
/* just in case */
|
||||
sock = open("/dev/null",O_RDWR);
|
||||
dup2(sock,0);
|
||||
dup2(sock,1);
|
||||
dup2(sock,2);
|
||||
close(sock);
|
||||
|
||||
bzero(&addr, sizeof(addr));
|
||||
addr.sun_family = AF_LOCAL;
|
||||
strncpy(addr.sun_path,_PATH_LOG,sizeof(addr.sun_path)-1);
|
||||
sock = socket(AF_LOCAL, SOCK_STREAM,0);
|
||||
unlink(_PATH_LOG);
|
||||
/* Bind socket before forking, so we know if the server started */
|
||||
if (!bind(sock,(struct sockaddr *) &addr, sizeof(addr))) {
|
||||
we_own_log = 1;
|
||||
listen(sock,5);
|
||||
if ((pid=fork())==-1) {
|
||||
perror("fork");
|
||||
exit(3);
|
||||
}
|
||||
if (pid) {
|
||||
exit(0);
|
||||
} else {
|
||||
runDaemon(sock);
|
||||
/* shouldn't get back here... */
|
||||
exit(4);
|
||||
}
|
||||
} else {
|
||||
exit(5);
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
.TH NETREPORT 1 "Red Hat, Inc." "RH" \" -*- nroff -*-
|
||||
.SH NAME
|
||||
netreport \- request notification of network interface changes
|
||||
.SH SYNOPSIS
|
||||
.B netreport
|
||||
\fI[\fP-r\fI]\fP
|
||||
.SH DESCRIPTION
|
||||
.B netreport
|
||||
tells the network management scripts to send a SIGIO signal
|
||||
to the process which called netreport when any network interface
|
||||
status changes occur.
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.B -r
|
||||
Remove the current request (if any) for the calling process.
|
||||
.PP
|
||||
.SH NOTES
|
||||
If a program does not call netreport with the
|
||||
.B -r
|
||||
option before it exits, and another process is created with the
|
||||
same PID before any changes take place in interface status, it
|
||||
is possible that the new process will receive a spurious SIGIO.
|
@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1997-2002 Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* This software may be freely redistributed under the terms of the GNU
|
||||
* public license.
|
||||
*
|
||||
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
*/
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* this will be running setgid root, so be careful! */
|
||||
|
||||
static void
|
||||
usage(void) {
|
||||
fprintf(stderr, "usage: netreport [-r]\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#define ADD 1
|
||||
#define DEL 0
|
||||
int main(int argc, char ** argv) {
|
||||
int action = ADD;
|
||||
/* more than long enough for "/var/run/netreport/<pid>\0" */
|
||||
char netreport_name[64];
|
||||
int netreport_file;
|
||||
|
||||
if (argc > 2) {
|
||||
usage();
|
||||
}
|
||||
|
||||
if (argc > 1) {
|
||||
if (argc == 2 && strcmp(argv[1], "-r") == 0) {
|
||||
action = DEL;
|
||||
} else {
|
||||
usage();
|
||||
}
|
||||
}
|
||||
|
||||
snprintf(netreport_name, sizeof(netreport_name),
|
||||
"/var/run/netreport/%d", getppid());
|
||||
if (action == ADD) {
|
||||
netreport_file = open(netreport_name,
|
||||
O_EXCL|O_CREAT|O_WRONLY|O_TRUNC|O_NOFOLLOW, 0);
|
||||
if (netreport_file == -1) {
|
||||
if (errno != EEXIST) {
|
||||
perror("Could not create netreport file");
|
||||
exit (1);
|
||||
}
|
||||
} else {
|
||||
close(netreport_file);
|
||||
}
|
||||
} else {
|
||||
/* ignore errors; not much we can do, won't hurt anything */
|
||||
unlink(netreport_name);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
324
src/process.c
324
src/process.c
@ -1,324 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2003 Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* This software may be freely redistributed under the terms of the GNU
|
||||
* public license.
|
||||
*
|
||||
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/signal.h>
|
||||
#include <sys/poll.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include <popt.h>
|
||||
|
||||
#include <regex.h>
|
||||
|
||||
#include "initlog.h"
|
||||
#include "process.h"
|
||||
|
||||
extern regex_t **regList;
|
||||
|
||||
int forkCommand(char **args, int *outfd, int *errfd, int *cmdfd, int quiet) {
|
||||
/* Fork command 'cmd', returning pid, and optionally pointer
|
||||
* to open file descriptor fd */
|
||||
int fdout=-1, fderr=-1, fdcmd=-1, pid;
|
||||
int outpipe[2], errpipe[2], fdpipe[2];
|
||||
int ourpid;
|
||||
|
||||
if ( (pipe(outpipe)==-1) || (pipe(errpipe)==-1) || (pipe(fdpipe)==-1) ) {
|
||||
perror("pipe");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (outfd) {
|
||||
fdout = outpipe[1];
|
||||
*outfd = outpipe[0];
|
||||
} else {
|
||||
if (!quiet)
|
||||
fdout=dup(1);
|
||||
}
|
||||
if (errfd) {
|
||||
fderr = errpipe[1];
|
||||
*errfd = errpipe[0];
|
||||
} else {
|
||||
if (!quiet)
|
||||
fderr=dup(2);
|
||||
}
|
||||
|
||||
if (cmdfd) {
|
||||
*cmdfd = fdpipe[0];
|
||||
fdcmd = fdpipe[1];
|
||||
} else {
|
||||
fdcmd = open("/dev/null",O_WRONLY);
|
||||
}
|
||||
if (fdout==-1 || fderr==-1 || fdcmd==-1)
|
||||
return -1;
|
||||
ourpid = getpid();
|
||||
if ((pid = fork())==-1) {
|
||||
perror("fork");
|
||||
return -1;
|
||||
}
|
||||
/* We exec the command normally as the child. However, if we're getting passed
|
||||
* back arguments via an fd, we'll exec it as the parent. Therefore, if Bill
|
||||
* fucks up and we segfault or something, we don't kill rc.sysinit. */
|
||||
if ( (cmdfd&&!pid) || (pid &&!cmdfd)) {
|
||||
/* parent */
|
||||
close(fdout);
|
||||
close(fderr);
|
||||
close(fdcmd);
|
||||
if (!pid)
|
||||
return ourpid;
|
||||
else
|
||||
return pid;
|
||||
} else {
|
||||
/* kid */
|
||||
int sc_open_max;
|
||||
|
||||
if (outfd) {
|
||||
if ( (dup2(fdout,1)==-1) ) {
|
||||
perror("dup2");
|
||||
exit(-1);
|
||||
}
|
||||
} else if (quiet)
|
||||
if ((dup2(open("/dev/null",O_WRONLY),1))==-1) {
|
||||
perror("dup2");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (errfd) {
|
||||
if ((dup2(fderr,2)==-1)) {
|
||||
perror("dup2");
|
||||
exit(-1);
|
||||
}
|
||||
} else if (quiet)
|
||||
if ((dup2(open("/dev/null",O_WRONLY),2))==-1) {
|
||||
perror("dup2");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
||||
if ((dup2(fdcmd,CMD_FD)==-1)) {
|
||||
perror("dup2");
|
||||
exit(-1);
|
||||
}
|
||||
close(fdout);
|
||||
close(fderr);
|
||||
close(fdcmd);
|
||||
if (outfd)
|
||||
close(*outfd);
|
||||
if (errfd)
|
||||
close(*errfd);
|
||||
if (cmdfd)
|
||||
close(*cmdfd);
|
||||
|
||||
/* close up extra fds, and hope this doesn't break anything */
|
||||
sc_open_max = sysconf(_SC_OPEN_MAX);
|
||||
if(sc_open_max > 1) {
|
||||
int fd;
|
||||
for(fd = 3; fd < sc_open_max; fd++) {
|
||||
if (!(cmdfd && fd == CMD_FD))
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
|
||||
execvp(args[0],args);
|
||||
perror("execvp");
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
int monitor(char *cmdname, int pid, int numfds, int *fds, int reexec, int quiet, int debug) {
|
||||
struct pollfd *pfds;
|
||||
char *outbuf=NULL;
|
||||
char *tmpstr=NULL;
|
||||
int x,y,rc=-1;
|
||||
int done=0;
|
||||
int output=0;
|
||||
char **cmdargs=NULL;
|
||||
char **tmpargs=NULL;
|
||||
int cmdargc;
|
||||
char *procpath = NULL;
|
||||
|
||||
if (reexec) {
|
||||
procpath=malloc(20*sizeof(char));
|
||||
snprintf(procpath,20,"/proc/%d",pid);
|
||||
}
|
||||
|
||||
pfds = malloc(numfds*sizeof(struct pollfd));
|
||||
for (x=0;x<numfds;x++) {
|
||||
pfds[x].fd = fds[x];
|
||||
pfds[x].events = POLLIN | POLLPRI;
|
||||
}
|
||||
|
||||
while (!done) {
|
||||
usleep(500);
|
||||
if (((x=poll(pfds,numfds,500))==-1)&&errno!=EINTR) {
|
||||
perror("poll");
|
||||
free(pfds);
|
||||
if (procpath)
|
||||
free(procpath);
|
||||
return -1;
|
||||
}
|
||||
if (!reexec) {
|
||||
if (waitpid(pid,&rc,WNOHANG))
|
||||
done=1;
|
||||
} else {
|
||||
struct stat sbuf;
|
||||
/* if /proc/pid ain't there and /proc is, it's dead... */
|
||||
if (stat(procpath,&sbuf)&&!stat("/proc/cpuinfo",&sbuf))
|
||||
done=1;
|
||||
}
|
||||
if (x<0)
|
||||
continue;
|
||||
y=0;
|
||||
while (y<numfds) {
|
||||
if ( x && ((pfds[y].revents & (POLLIN | POLLPRI)) )) {
|
||||
int bytesread = 0;
|
||||
|
||||
do {
|
||||
char *b, *buf=calloc(8193,sizeof(char));
|
||||
b = buf;
|
||||
bytesread = read(pfds[y].fd,buf,8192);
|
||||
if (bytesread==-1) {
|
||||
perror("read");
|
||||
free(pfds);
|
||||
if (procpath)
|
||||
free(procpath);
|
||||
free(buf);
|
||||
return -1;
|
||||
}
|
||||
if (bytesread) {
|
||||
if (!quiet && !reexec)
|
||||
write(1,buf,bytesread);
|
||||
if (quiet) {
|
||||
outbuf=realloc(outbuf,(outbuf ? strlen(outbuf)+bytesread+1 : bytesread+1));
|
||||
if (!output) outbuf[0]='\0';
|
||||
strcat(outbuf,buf);
|
||||
output = 1;
|
||||
}
|
||||
while ((tmpstr=getLine(&buf))) {
|
||||
int ignore=0;
|
||||
|
||||
if (regList) {
|
||||
int count=0;
|
||||
|
||||
while (regList[count]) {
|
||||
if (!regexec(regList[count],tmpstr,0,NULL,0)) {
|
||||
ignore=1;
|
||||
break;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (!ignore) {
|
||||
if (!reexec) {
|
||||
if (getenv("IN_INITLOG")) {
|
||||
char *buffer=calloc(8192,sizeof(char));
|
||||
DDEBUG("sending =%s= to initlog parent\n",tmpstr);
|
||||
snprintf(buffer,8192,"-n %s -s \"%s\"\n",
|
||||
cmdname,tmpstr);
|
||||
/* don't blow up if parent isn't there */
|
||||
signal(SIGPIPE,SIG_IGN);
|
||||
write(CMD_FD,buffer,strlen(buffer));
|
||||
signal(SIGPIPE,SIG_DFL);
|
||||
free(buffer);
|
||||
} else {
|
||||
logString(cmdname,tmpstr);
|
||||
}
|
||||
} else {
|
||||
int z;
|
||||
|
||||
cmdargs=NULL;
|
||||
tmpargs=NULL;
|
||||
cmdargc=0;
|
||||
|
||||
poptParseArgvString(tmpstr,&cmdargc,&tmpargs);
|
||||
cmdargs=malloc( (cmdargc+2) * sizeof(char *) );
|
||||
cmdargs[0]=strdup("initlog");
|
||||
for (z=0;z<(cmdargc);z++) {
|
||||
cmdargs[z+1]=tmpargs[z];
|
||||
}
|
||||
cmdargs[cmdargc+1]=NULL;
|
||||
processArgs(cmdargc+1,cmdargs,1);
|
||||
free(cmdargs[0]);
|
||||
free(tmpargs);
|
||||
free(cmdargs);
|
||||
}
|
||||
}
|
||||
if (tmpstr) free(tmpstr);
|
||||
}
|
||||
}
|
||||
free(b);
|
||||
} while ( bytesread==8192 );
|
||||
}
|
||||
y++;
|
||||
}
|
||||
}
|
||||
if ((!WIFEXITED(rc)) || (rc=WEXITSTATUS(rc))) {
|
||||
/* If there was an error and we're quiet, be loud */
|
||||
|
||||
if (quiet && output) {
|
||||
write(1,outbuf,strlen(outbuf));
|
||||
}
|
||||
free(pfds);
|
||||
if (procpath)
|
||||
free(procpath);
|
||||
if(outbuf)
|
||||
free(outbuf);
|
||||
return (rc);
|
||||
}
|
||||
free(pfds);
|
||||
if (procpath)
|
||||
free(procpath);
|
||||
if(outbuf)
|
||||
free(outbuf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int runCommand(char *cmd, int reexec, int quiet, int debug) {
|
||||
int fds[2];
|
||||
int pid,x;
|
||||
char **args, **tmpargs;
|
||||
char *cmdname;
|
||||
|
||||
poptParseArgvString(cmd,&x,&tmpargs);
|
||||
args = malloc((x+1)*sizeof(char *));
|
||||
for ( pid = 0; pid < x ; pid++) {
|
||||
args[pid] = strdup(tmpargs[pid]);
|
||||
}
|
||||
args[pid] = NULL;
|
||||
if (strcmp(args[0],"sh") && strcmp(args[0],"/bin/sh"))
|
||||
cmdname = basename(args[0]);
|
||||
else
|
||||
cmdname = basename(args[1]);
|
||||
if ((cmdname[0] =='K' || cmdname[0] == 'S') &&
|
||||
( cmdname[1] >= '0' && cmdname[1] <= '9' ) &&
|
||||
( cmdname[2] >= '0' && cmdname[2] <= '9' ) )
|
||||
cmdname+=3;
|
||||
if (!reexec) {
|
||||
pid=forkCommand(args,&fds[0],&fds[1],NULL,quiet);
|
||||
if (pid == -1)
|
||||
return -1;
|
||||
x=monitor(cmdname,pid,2,fds,reexec,quiet,debug);
|
||||
} else {
|
||||
setenv("IN_INITLOG","yes",1);
|
||||
pid=forkCommand(args,NULL,NULL,&fds[0],quiet);
|
||||
if (pid == -1)
|
||||
return -1;
|
||||
unsetenv("IN_INITLOG");
|
||||
x=monitor(cmdname,pid,1,&fds[0],reexec,quiet,debug);
|
||||
}
|
||||
return x;
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
#ifndef PROCESS_H
|
||||
#define PROCESS_H
|
||||
|
||||
|
||||
#define CMD_FD 21
|
||||
|
||||
int runCommand(char *cmd, int reexec, int quiet, int debug);
|
||||
|
||||
#endif
|
@ -1,39 +0,0 @@
|
||||
.TH USERNETCTL 8 "Red Hat, Inc." "RHS" \" -*- nroff -*-
|
||||
.SH NAME
|
||||
usernetctl \- allow a user to manipulate a network interface if permitted
|
||||
.SH SYNOPSIS
|
||||
.B usernetctl
|
||||
\fIinterface-name\fP up\fI|\fPdown\fI|\fPreport
|
||||
.SH DESCRIPTION
|
||||
.B usernetctl
|
||||
checks to see if users are allowed to manipulate the network interface
|
||||
specified by \fIinterface-name\fP, and then tries to bring the network
|
||||
interface up or down, if up or down was specified on the command line,
|
||||
or returns true or false status (respectively) if the report option was
|
||||
specified.
|
||||
|
||||
.B usernetctl
|
||||
is not really meant to be called directly by users, though it currently
|
||||
works fine that way. It is used as a wrapper by the ifup and ifdown
|
||||
scripts, so that users can do exactly the same thing as root:
|
||||
.nf
|
||||
ifup \fIinterface-name\fP
|
||||
ifdown \fIinterface-name\fP
|
||||
.fi
|
||||
and \fBifup\fP and \fBifdown\fP will call usernetctl automatically to
|
||||
allow the interface status change.
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.I "\fIinterface-name"
|
||||
The name of the network interface to check; for example, "ppp0". For
|
||||
backwards compatibility, "ifcfg-ppp0" and
|
||||
"/etc/sysconfig/network-scripts/ifcfg-ppp0" are also supported.
|
||||
.TP
|
||||
up\fI|\fPdown
|
||||
Attempt to bring the interface up or down.
|
||||
.TP
|
||||
report
|
||||
Report on whether users can bring the interface up or down.
|
||||
.SH NOTES
|
||||
Alternate device configurations may inherit the default configuration's
|
||||
permissions.
|
238
src/usernetctl.c
238
src/usernetctl.c
@ -1,238 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1997-2003 Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* This software may be freely redistributed under the terms of the GNU
|
||||
* public license.
|
||||
*
|
||||
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <alloca.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
|
||||
/* This will be running setuid root, so be careful! */
|
||||
static const char * safeEnviron[] = {
|
||||
"PATH=/bin:/sbin:/usr/bin:/usr/sbin",
|
||||
"HOME=/root",
|
||||
NULL
|
||||
};
|
||||
|
||||
#define FOUND_FALSE -1
|
||||
#define NOT_FOUND 0
|
||||
#define FOUND_TRUE 1
|
||||
|
||||
static void
|
||||
usage(void) {
|
||||
fprintf(stderr, "usage: usernetctl <interface-config> <up|down|report>\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static size_t
|
||||
testSafe(char *ifaceConfig, int fd) {
|
||||
struct stat sb;
|
||||
|
||||
/* These shouldn't be symbolic links -- anal, but that's fine w/ mkj. */
|
||||
if (fstat(fd, &sb)) {
|
||||
fprintf(stderr, "failed to stat %s: %s\n", ifaceConfig,
|
||||
strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Safety/sanity checks. */
|
||||
if (!S_ISREG(sb.st_mode)) {
|
||||
fprintf(stderr, "%s is not a normal file\n", ifaceConfig);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (sb.st_uid) {
|
||||
fprintf(stderr, "%s should be owned by root\n", ifaceConfig);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (sb.st_mode & S_IWOTH) {
|
||||
fprintf(stderr, "%s should not be world writeable\n", ifaceConfig);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return sb.st_size;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
userCtl(char *file) {
|
||||
char *buf;
|
||||
char *contents = NULL;
|
||||
char *chptr = NULL;
|
||||
char *next = NULL;
|
||||
int fd = -1, retval = NOT_FOUND;
|
||||
size_t size = 0;
|
||||
|
||||
/* Open the file and then test it to see if we like it. This way
|
||||
we avoid switcheroo attacks. */
|
||||
if ((fd = open(file, O_RDONLY)) == -1) {
|
||||
fprintf(stderr, "failed to open %s: %s\n", file, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
size = testSafe(file, fd);
|
||||
if (size > INT_MAX) {
|
||||
fprintf(stderr, "file %s is too big\n", file);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
buf = contents = malloc(size + 2);
|
||||
if (contents == NULL) {
|
||||
fprintf(stderr, "failed to allocate memory\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (read(fd, contents, size) != size) {
|
||||
perror("error reading device configuration");
|
||||
exit(1);
|
||||
}
|
||||
close(fd);
|
||||
|
||||
contents[size] = '\n';
|
||||
contents[size + 1] = '\0';
|
||||
|
||||
/* Each pass parses a single line (until an answer is found), The contents
|
||||
pointer itself points to the beginning of the current line. */
|
||||
while (*contents) {
|
||||
chptr = contents;
|
||||
while (*chptr != '\n') chptr++;
|
||||
next = chptr + 1;
|
||||
while (chptr >= contents && isspace(*chptr)) chptr--;
|
||||
*(++chptr) = '\0';
|
||||
|
||||
if (!strncasecmp(contents, "USERCTL=", 8)) {
|
||||
contents += 8;
|
||||
if ((contents[0] == '"' &&
|
||||
contents[strlen(contents) - 1] == '"') ||
|
||||
(contents[0] == '\'' &&
|
||||
contents[strlen(contents) - 1] == '\''))
|
||||
{
|
||||
contents++;
|
||||
contents[strlen(contents) - 1] = '\0';
|
||||
}
|
||||
|
||||
if (!strcasecmp(contents, "yes") || !strcasecmp(contents, "true"))
|
||||
retval = FOUND_TRUE;
|
||||
else
|
||||
retval = FOUND_FALSE;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
contents = next;
|
||||
}
|
||||
|
||||
free(buf);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char ** argv) {
|
||||
char * ifaceConfig;
|
||||
char * chptr;
|
||||
char * cmd = NULL;
|
||||
int report = 0;
|
||||
char tmp;
|
||||
|
||||
if (argc != 3) usage();
|
||||
|
||||
if (!strcmp(argv[2], "up")) {
|
||||
cmd = "./ifup";
|
||||
} else if (!strcmp(argv[2], "down")) {
|
||||
cmd = "./ifdown";
|
||||
} else if (!strcmp(argv[2], "report")) {
|
||||
report = 1;
|
||||
} else {
|
||||
usage();
|
||||
}
|
||||
|
||||
if (chdir("/etc/sysconfig/network-scripts")) {
|
||||
fprintf(stderr, "error switching to /etc/sysconfig/network-scripts: "
|
||||
"%s\n", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* force the interface configuration to be in the current directory */
|
||||
chptr = ifaceConfig = argv[1];
|
||||
while (*chptr) {
|
||||
if (*chptr == '/')
|
||||
ifaceConfig = chptr + 1;
|
||||
chptr++;
|
||||
}
|
||||
|
||||
/* automatically prepend "ifcfg-" if it is not specified */
|
||||
if (strncmp(ifaceConfig, "ifcfg-", 6)) {
|
||||
char *temp;
|
||||
size_t len = strlen(ifaceConfig);
|
||||
|
||||
/* Make sure a wise guys hasn't tried an integer wrap-around or
|
||||
stack overflow attack. There's no way it could refer to anything
|
||||
bigger than the largest filename, so cut 'em off there. */
|
||||
if (len > PATH_MAX)
|
||||
exit(1);
|
||||
|
||||
temp = (char *) alloca(len + 7);
|
||||
strcpy(temp, "ifcfg-");
|
||||
/* strcat is safe because we got the length from strlen */
|
||||
strcat(temp, ifaceConfig);
|
||||
ifaceConfig = temp;
|
||||
}
|
||||
|
||||
if(getuid() != 0)
|
||||
switch (userCtl(ifaceConfig)) {
|
||||
char *dash;
|
||||
|
||||
case NOT_FOUND:
|
||||
/* a `-' will be found at least in "ifcfg-" */
|
||||
dash = strrchr(ifaceConfig, '-');
|
||||
if (*(dash-1) != 'g') {
|
||||
/* This was a clone configuration; ask the parent config */
|
||||
tmp = *dash;
|
||||
*dash = '\0';
|
||||
if (userCtl(ifaceConfig) == FOUND_TRUE) {
|
||||
/* exit the switch; users are allowed to control */
|
||||
*dash = tmp;
|
||||
break;
|
||||
}
|
||||
*dash = tmp;
|
||||
}
|
||||
/* else fall through */
|
||||
case FOUND_FALSE:
|
||||
if (! report)
|
||||
fprintf(stderr,
|
||||
"Users are not allowed to control this interface.\n");
|
||||
exit(1);
|
||||
break;
|
||||
}
|
||||
|
||||
/* looks good to me -- let's go for it if we are changing the interface,
|
||||
* report good status to the user otherwise */
|
||||
|
||||
if (report)
|
||||
exit(0);
|
||||
|
||||
/* pppd wants the real uid to be the same as the effective (god only
|
||||
knows why when it works fine setuid out of the box) */
|
||||
setuid(geteuid());
|
||||
|
||||
execle(cmd, cmd, ifaceConfig, NULL, safeEnviron);
|
||||
fprintf(stderr, "exec of %s failed: %s\n", cmd, strerror(errno));
|
||||
|
||||
exit(1);
|
||||
}
|
25
src/usleep.1
25
src/usleep.1
@ -1,25 +0,0 @@
|
||||
.TH USLEEP 1 "Red Hat, Inc" \" -*- nroff -*-
|
||||
.SH NAME
|
||||
usleep \- sleep some number of microseconds
|
||||
.SH SYNOPSIS
|
||||
.B usleep
|
||||
[\fInumber\fP]
|
||||
.SH DESCRIPTION
|
||||
.B usleep
|
||||
sleeps some number of microseconds. The default is 1.
|
||||
.SH OPTIONS
|
||||
\fI--usage\fP
|
||||
Show short usage message.
|
||||
.TP
|
||||
\fI--help, -?\fP
|
||||
Print help information.
|
||||
.TP
|
||||
\fI-v, --version\fP
|
||||
Print version information.
|
||||
.SH BUGS
|
||||
Probably not accurate on many machines down to the microsecond. Count
|
||||
on precision only to -4 or maybe -5.
|
||||
.SH AUTHOR
|
||||
Donald Barnes <djb@redhat.com>
|
||||
.br
|
||||
Erik Troan <ewt@redhat.com>
|
76
src/usleep.c
76
src/usleep.c
@ -1,76 +0,0 @@
|
||||
/*
|
||||
* usleep
|
||||
*
|
||||
* Written by Donald Barnes <djb@redhat.com> for Red Hat, Inc.
|
||||
*
|
||||
* Copyright (c) 1997-2003 Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* This software may be freely redistributed under the terms of the GNU
|
||||
* public license.
|
||||
*
|
||||
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "popt.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
unsigned long count;
|
||||
poptContext optCon;
|
||||
int showVersion = 0;
|
||||
int showOot = 0;
|
||||
int rc;
|
||||
char * countStr = NULL;
|
||||
struct poptOption options[] = {
|
||||
{ "version", 'v', POPT_ARG_NONE, &showVersion, 0,
|
||||
"Display the version of this program, and exit" },
|
||||
{ "oot", 'o', POPT_ARG_NONE, &showOot, 0,
|
||||
"oot says hey!" },
|
||||
POPT_AUTOHELP
|
||||
{ 0, 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
optCon = poptGetContext("usleep", argc, argv, options,0);
|
||||
/*poptReadDefaultConfig(optCon, 1);*/
|
||||
poptSetOtherOptionHelp(optCon, "[microseconds]");
|
||||
|
||||
if ((rc = poptGetNextOpt(optCon)) < -1) {
|
||||
fprintf(stderr, "usleep: bad argument %s: %s\n",
|
||||
poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
|
||||
poptStrerror(rc));
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (showVersion) {
|
||||
printf("usleep version 1.2\n usleep --help for more info\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (showOot) {
|
||||
printf("oot says hey!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
countStr = poptGetArg(optCon);
|
||||
|
||||
if (countStr == NULL) count = 1;
|
||||
|
||||
else if (countStr && poptGetArg(optCon)) {
|
||||
fprintf(stderr, "%s: exactly one argument (number of microseconds) "
|
||||
"must be used\n", argv[0]);
|
||||
return 2;
|
||||
}
|
||||
|
||||
else count = strtoul(countStr, NULL, 0);
|
||||
|
||||
usleep(count);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user