Mailing List Archive

signal handling foo.
there's two parts.

the .h part, and a .c file. it just needs something to define either

USE_SIGACTION
USE_SIGSET

and it will use sigaction(), or sigset() [.the sysv `reliable' signal
handler installer, dating back to at least svr2], or then signal. i
have a gnu configure-style test for whether a signal handler needs
to be reinstalled or not, as well, if someone wants to add this as
well.

.mrg.

#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.1).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `!/bin/sh' line above, then type `sh FILE'.
#
# Made on 1995-09-27 11:56 EST by <mrg@dynamo.mame.mu.OZ.AU>.
# Source directory was `/guest/mrg'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 1403 -rw-rw-r-- sig.c
# 573 -rw-rw-r-- sig.h
#
touch -am 1231235999 $$.touch >/dev/null 2>&1
if test ! -f 1231235999 && test -f $$.touch; then
shar_touch=touch
else
shar_touch=:
echo
echo 'WARNING: not restoring timestamps. Consider getting and'
echo "installing GNU \`touch', distributed in GNU File Utilities..."
echo
fi
rm -f 1231235999 $$.touch
#
# ============= sig.c ==============
if test -f 'sig.c' && test X"$1" != X"-c"; then
echo 'x - skipping sig.c (file already exists)'
else
echo 'x - extracting sig.c (text)'
sed 's/^X//' << 'SHAR_EOF' > 'sig.c' &&
/*
X * ircsig.c: has a `my_signal()' that uses sigaction().
X *
X * written by matthew green, 1993.
X *
X * i stole bits of this from w. richard stevens' `advanced programming
X * in the unix environment' -mrg
X */
X
#ifndef lint
static char rcsid[] = "@(#)$Id: ircsig.c,v 1.4 1995/07/25 13:19:33 mrg Exp $";
#endif
X
#include "sig.h"
X
#ifdef USE_SIGACTION
sigfunc *
my_signal(sig_no, sig_handler, misc_flags)
X int sig_no;
X sigfunc *sig_handler;
X int misc_flags;
{
X /*
X * misc_flags is unused currently. it's planned to be used
X * to use some of the doovier bits of sigaction(), if at
X * some point we need them, -mrg
X */
X
X struct sigaction sa, osa;
X
X sa.sa_handler = sig_handler;
X
X sigemptyset(&sa.sa_mask);
X sigaddset(&sa.sa_mask, sig_no);
X
X /* this is ugly, but the `correct' way. i hate c. -mrg */
X sa.sa_flags = 0;
#if defined(SA_RESTART) || defined(SA_INTERRUPT)
X if (SIGALRM == sig_no)
X {
# if defined(SA_INTERRUPT)
X sa.sa_flags |= SA_INTERRUPT;
# endif /* SA_INTERRUPT */
X }
X else
X {
# if defined(SA_RESTART)
X sa.sa_flags |= SA_RESTART;
# endif /* SA_RESTART */
X }
#endif /* SA_RESTART || SA_INTERRUPT */
X
X if (0 > sigaction(sig_no, &sa, &osa))
X return (SIG_ERR);
X
X return (osa.sa_handler);
}
#endif /* USE_SIGACTION */
SHAR_EOF
$shar_touch -am 0927114395 'sig.c' &&
chmod 0664 'sig.c' ||
echo 'restore of sig.c failed'
shar_count="`wc -c < 'sig.c'`"
test 1403 -eq "$shar_count" ||
echo "sig.c: original size 1403, current size $shar_count"
fi
# ============= sig.h ==============
if test -f 'sig.h' && test X"$1" != X"-c"; then
echo 'x - skipping sig.h (file already exists)'
else
echo 'x - extracting sig.h (text)'
sed 's/^X//' << 'SHAR_EOF' > 'sig.h' &&
/*
X * sig.h
X *
X * from: @(#) Id: irc_std.h,v 1.20 1995/09/07 02:16:03 scottr Exp
X */
X
#ifndef __sig_h_
#define __sig_h_
X
#ifdef USE_SIGACTION
X
typedef RETSIGTYPE sigfunc _((void));
sigfunc *my_signal _((int, sigfunc *, int));
X
# define MY_SIGNAL(s_n, s_h, m_f) my_signal(s_n, s_h, m_f)
#else
# if USE_SIGSET
# define MY_SIGNAL(s_n, s_h, m_f) sigset(s_n, s_h)
# else
# define MY_SIGNAL(s_n, s_h, m_f) signal(s_n, s_h)
# endif /* USE_SIGSET */
#endif /* USE_SIGACTION */
X
#if defined(USE_SIGACTION) || defined(USE_SIGSET)
# undef SYSVSIGNALS
#endif
X
#endif /* __sig_h_ */
SHAR_EOF
$shar_touch -am 0927114495 'sig.h' &&
chmod 0664 'sig.h' ||
echo 'restore of sig.h failed'
shar_count="`wc -c < 'sig.h'`"
test 573 -eq "$shar_count" ||
echo "sig.h: original size 573, current size $shar_count"
fi
exit 0