home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-06-26 | 29.8 KB | 1,247 lines |
- Newsgroups: comp.sources.unix
- From: panos@cs.colorado.edu (Panos Tsirigotis)
- Subject: v26i262: xinetd-2.1.1 - inetd replacement with access control and logging, Part18/31
- Sender: unix-sources-moderator@gw.home.vix.com
- Approved: vixie@gw.home.vix.com
-
- Submitted-By: panos@cs.colorado.edu (Panos Tsirigotis)
- Posting-Number: Volume 26, Issue 262
- Archive-Name: xinetd-2.1.1/part18
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of archive 18 (of 31)."
- # Contents: libs/src/sio/suite/print.c libs/src/timer/timer.3
- # xinetd/builtins.c
- # Wrapped by panos@mystique on Mon Jun 21 14:51:25 1993
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'libs/src/sio/suite/print.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'libs/src/sio/suite/print.c'\"
- else
- echo shar: Extracting \"'libs/src/sio/suite/print.c'\" \(8243 characters\)
- sed "s/^X//" >'libs/src/sio/suite/print.c' <<'END_OF_FILE'
- X/*
- X * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis
- X * All rights reserved. The file named COPYRIGHT specifies the terms
- X * and conditions for redistribution.
- X */
- X
- Xstatic char RCSid[] = "$Id: print.c,v 8.1 1993/03/13 01:21:48 panos Exp $" ;
- X
- X#include <stdio.h>
- X#include <math.h>
- X#include <values.h>
- X#include <string.h>
- X
- X#include "sio.h"
- X
- X#define FLUSH() fflush( stdout ) ; Sflush( 1 )
- X#define COMPARE( printf_count, sprint_count ) \
- X if ( printf_count != sprint_count ) \
- X printf( "printf_count = %d, sprint_count = %d\n", \
- X printf_count, sprint_count )
- X
- Xenum bool { NO = 0, YES = 1 } ;
- X
- Xenum test_flag
- X{
- X DECIMAL, HEX, CAP_HEX, OCTAL, UNSIGNED,
- X F_FLOAT, G_FLOAT, E_FLOAT, CAP_E_FLOAT, CAP_G_FLOAT,
- X CHAR, STRING,
- X POINTER,
- X BOUND,
- X N_FLAGS
- X} ;
- X
- Xtypedef enum test_flag FLAG ;
- X
- X#define CHECK( f ) if ( ! flags[ f ] ) return
- X
- X/*
- X * Flags
- X */
- Xenum bool flags[ N_FLAGS ] ;
- X
- Xchar *precision ;
- Xchar *width ;
- Xchar *print_flags ;
- X
- Xint i_begin = 123456 ;
- Xint i_end = 123470 ;
- Xint i_step = 1 ;
- X
- Xdouble f_begin = 1.234567654312 ;
- Xdouble f_end = 2.0 ;
- Xdouble f_step = 0.011 ;
- X
- X#define LEN( s ) ( s ? strlen( s ) : 0 )
- X
- Xchar *format( f )
- X char *f ;
- X{
- X char *malloc() ;
- X static char *newfmt ;
- X
- X if ( newfmt )
- X free( newfmt ) ;
- X
- X newfmt = malloc( strlen( f )
- X + LEN( precision ) + LEN( width ) + LEN( print_flags ) + 2 ) ;
- X (void) strcpy( newfmt, "%" ) ;
- X if ( print_flags )
- X (void) strcat( newfmt, print_flags ) ;
- X if ( width )
- X (void) strcat( newfmt, width ) ;
- X if ( precision )
- X (void) strcat( strcat( newfmt, "." ), precision ) ;
- X (void) strcat( newfmt, &f[1] ) ;
- X return( newfmt ) ;
- X}
- X
- X#define decimal_test() integer_test( "%d %d\n", DECIMAL )
- X#define hex_test() integer_test( "%x %x\n", HEX )
- X#define cap_hex_test() integer_test( "%X %X\n", CAP_HEX )
- X#define octal_test() integer_test( "%o %o\n", OCTAL )
- X#define unsigned_test() integer_test( "%u %u\n", UNSIGNED )
- X
- Xvoid integer_test( fmt, flag )
- X char *fmt ;
- X FLAG flag ;
- X{
- X int i ;
- X int ccs, ccp ;
- X
- X CHECK( flag ) ;
- X fmt = format( fmt ) ;
- X
- X for ( i = i_begin ; i < i_end ; i += i_step )
- X {
- X ccp = printf( fmt, -i, i ) ;
- X ccs = Sprint( 2, fmt, -i, i ) ;
- X FLUSH() ;
- X COMPARE( ccp, ccs ) ;
- X }
- X}
- X
- X
- X#define f_float_test() fp_test( "%f\n", F_FLOAT )
- X#define g_float_test() fp_test( "%g\n", G_FLOAT )
- X#define e_float_test() fp_test( "%e\n", E_FLOAT )
- X#define cap_e_float_test() fp_test( "%E\n", CAP_E_FLOAT )
- X#define cap_g_float_test() fp_test( "%G\n", CAP_G_FLOAT )
- X
- Xvoid fp_test( fmt, flag )
- X char *fmt ;
- X FLAG flag ;
- X{
- X double d ;
- X double step ;
- X int ccs, ccp ;
- X
- X CHECK( flag ) ;
- X fmt = format( fmt ) ;
- X
- X for ( d = f_begin, step = f_step ; d < f_end ; d += step, step += step )
- X {
- X
- X ccp = printf( fmt, d ) ;
- X ccs = Sprint( 2, fmt, d ) ;
- X FLUSH() ;
- X COMPARE( ccp, ccs ) ;
- X }
- X}
- X
- X
- Xvoid char_test()
- X{
- X char *s = "foobar" ;
- X int len = strlen( s ) ;
- X int i ;
- X char *fmt = "%c\n" ;
- X int ccs, ccp ;
- X
- X CHECK( CHAR ) ;
- X fmt = format( fmt ) ;
- X
- X for ( i = 0 ; i < len ; i++ )
- X {
- X ccp = printf( fmt, s[ i ] ) ;
- X ccs = Sprint( 2, fmt, s[ i ] ) ;
- X FLUSH() ;
- X COMPARE( ccp, ccs ) ;
- X }
- X}
- X
- X
- Xvoid string_test()
- X{
- X static char *list[] =
- X {
- X "foobar",
- X "hello",
- X "world",
- X "this is a very long string, a really long string, really, true, honest",
- X "i am getting tired of this",
- X "SO THIS IS THE END",
- X 0
- X } ;
- X char *fmt = "%s\n" ;
- X char **p ;
- X int ccp, ccs ;
- X
- X CHECK( STRING ) ;
- X fmt = format( fmt ) ;
- X
- X for ( p = &list[ 0 ] ; *p ; p++ )
- X {
- X ccp = printf( fmt, *p ) ;
- X ccs = Sprint( 2, fmt, *p ) ;
- X FLUSH() ;
- X COMPARE( ccp, ccs ) ;
- X }
- X}
- X
- X
- Xvoid pointer_test()
- X{
- X struct foo
- X {
- X char bar1 ;
- X short bar2 ;
- X int bar3 ;
- X long bar4 ;
- X char *bar5 ;
- X } foo, *end = &foo, *p ;
- X char *fmt = "%p\n" ;
- X int ccp, ccs ;
- X
- X CHECK( POINTER ) ;
- X fmt = format( fmt ) ;
- X
- X end += 10 ;
- X for ( p = &foo ; p < end ; p++ )
- X {
- X ccp = printf( fmt, p ) ;
- X ccs = Sprint( 2, fmt, p ) ;
- X FLUSH() ;
- X }
- X}
- X
- X
- X/*
- X * bound_test is only available on SunOS 4.x
- X */
- X#if defined( sun )
- X
- Xvoid bound_test()
- X{
- X char *fmt ;
- X double bound_values[ 10 ] ;
- X static char *bound_names[] =
- X {
- X "min_subnormal",
- X "max_subnormal",
- X "min_normal",
- X "max_normal",
- X "infinity",
- X "quiet_nan",
- X "signaling_nan"
- X } ;
- X int n_values ;
- X int i ;
- X int ccp, ccs ;
- X
- X bound_values[ 0 ] = min_subnormal() ;
- X bound_values[ 1 ] = max_subnormal() ;
- X bound_values[ 2 ] = min_normal() ;
- X bound_values[ 3 ] = max_normal() ;
- X bound_values[ 4 ] = infinity() ;
- X bound_values[ 5 ] = quiet_nan( 7L ) ;
- X bound_values[ 6 ] = signaling_nan( 7L ) ;
- X n_values = 7 ;
- X
- X CHECK( BOUND ) ;
- X
- X for ( i = 0 ; i < n_values ; i++ )
- X {
- X double d = bound_values[ i ] ;
- X char *name = bound_names[ i ] ;
- X
- X fmt = format( "%f (%s)\n" ) ;
- X ccp = printf( fmt, d, name ) ;
- X ccs = Sprint( 2, fmt, d, name ) ;
- X FLUSH() ;
- X COMPARE( ccp, ccs ) ;
- X
- X fmt = format( "%e (%s)\n" ) ;
- X ccp = printf( fmt, d, name ) ;
- X ccs = Sprint( 2, fmt, d, name ) ;
- X FLUSH() ;
- X COMPARE( ccp, ccs ) ;
- X
- X fmt = format( "%g (%s)\n" ) ;
- X ccp = printf( fmt, d, name ) ;
- X ccs = Sprint( 2, fmt, d, name ) ;
- X FLUSH() ;
- X COMPARE( ccp, ccs ) ;
- X }
- X
- X fmt = format( "%d (MININT)\n" ) ;
- X ccp = printf( fmt, -MAXINT-1 ) ;
- X ccs = Sprint( 2, fmt, -MAXINT-1 ) ;
- X COMPARE( ccp, ccs ) ;
- X}
- X#else
- Xvoid bound_test()
- X{
- X}
- X#endif
- X
- X
- Xint get_options( argc, argv )
- X int argc ;
- X char *argv[] ;
- X{
- X int arg_index = 1 ;
- X char *p ;
- X double atof() ;
- X
- X for ( arg_index = 1 ;
- X arg_index < argc && argv[ arg_index ][ 0 ] == '-' ; arg_index++ )
- X {
- X switch ( argv[ arg_index ][ 1 ] )
- X {
- X case 'd':
- X flags[ DECIMAL ] = YES ;
- X break ;
- X
- X case 'x':
- X flags[ HEX ] = YES ;
- X break ;
- X
- X case 'X':
- X flags[ CAP_HEX ] = YES ;
- X break ;
- X
- X case 'o':
- X flags[ OCTAL ] = YES ;
- X break ;
- X
- X case 'u':
- X flags[ UNSIGNED ] = YES ;
- X break ;
- X
- X case 'f':
- X flags[ F_FLOAT ] = YES ;
- X break ;
- X
- X case 'g':
- X flags[ G_FLOAT ] = YES ;
- X break ;
- X
- X case 'e':
- X flags[ E_FLOAT ] = YES ;
- X break ;
- X
- X case 'E':
- X flags[ CAP_E_FLOAT ] = YES ;
- X break ;
- X
- X case 'G':
- X flags[ CAP_G_FLOAT ] = YES ;
- X break ;
- X
- X case 'c':
- X flags[ CHAR ] = YES ;
- X break ;
- X
- X case 's':
- X flags[ STRING ] = YES ;
- X break ;
- X
- X case 'p':
- X flags[ POINTER ] = YES ;
- X break ;
- X
- X case 'b': /* this is for checking bounds in fp formats */
- X flags[ BOUND ] = YES ;
- X break ;
- X
- X case 'P': /* precision, must be followed by a number, e.g. -P10 */
- X precision = &argv[ arg_index ][ 2 ] ;
- X break ;
- X
- X case 'W': /* width, must be followed by a number, e.g. -w10 */
- X width = &argv[ arg_index ][ 2 ] ;
- X break ;
- X
- X case 'F': /* flags, whatever is after the F */
- X print_flags = &argv[ arg_index ][ 2 ] ;
- X break ;
- X
- X /*
- X * Options recognized in this case: -Vf, -Vi
- X * Usage: -V[if] start end step
- X */
- X case 'V':
- X /*
- X * Check if we have enough extra arguments
- X */
- X if ( argc - ( arg_index + 1 ) < 3 )
- X {
- X fprintf( stderr, "Insufficient # of args after V option\n" ) ;
- X exit( 1 ) ;
- X }
- X switch ( argv[ arg_index ][ 2 ] )
- X {
- X case 'f':
- X f_begin = atof( argv[ arg_index+1 ] ) ;
- X f_end = atof( argv[ arg_index+2 ] ) ;
- X f_step = atof( argv[ arg_index+3 ] ) ;
- X break ;
- X
- X case 'i':
- X i_begin = atoi( argv[ arg_index+1 ] ) ;
- X i_end = atoi( argv[ arg_index+2 ] ) ;
- X i_step = atoi( argv[ arg_index+3 ] ) ;
- X break ;
- X }
- X arg_index += 3 ;
- X break ;
- X
- X case 'S':
- X f_step = atof( &argv[ arg_index ][ 2 ] ) ;
- X break ;
- X }
- X }
- X return( arg_index ) ;
- X}
- X
- X
- X#define EQ( s1, s2 ) ( strcmp( s1, s2 ) == 0 )
- X
- X
- Xint main( argc, argv )
- X int argc ;
- X char *argv[] ;
- X{
- X
- X if ( Sbuftype( 2, SIO_LINEBUF ) == SIO_ERR )
- X {
- X char *msg = "Sbuftype failed\n" ;
- X
- X write( 2, msg, strlen( msg ) ) ;
- X exit( 1 ) ;
- X }
- X
- X if ( argc == 1 || argc == 2 && EQ( argv[ 1 ], "ALL" ) )
- X {
- X /* perform all tests */
- X int i ;
- X
- X for ( i = 0 ; i < N_FLAGS ; i++ )
- X flags[ i ] = YES ;
- X }
- X else
- X (void) get_options( argc, argv ) ;
- X
- X decimal_test() ;
- X hex_test() ;
- X cap_hex_test() ;
- X octal_test() ;
- X unsigned_test() ;
- X
- X f_float_test() ;
- X g_float_test() ;
- X e_float_test() ;
- X cap_g_float_test() ;
- X cap_e_float_test() ;
- X
- X string_test() ;
- X char_test() ;
- X pointer_test() ;
- X bound_test() ;
- X exit( 0 ) ;
- X}
- END_OF_FILE
- if test 8243 -ne `wc -c <'libs/src/sio/suite/print.c'`; then
- echo shar: \"'libs/src/sio/suite/print.c'\" unpacked with wrong size!
- fi
- # end of 'libs/src/sio/suite/print.c'
- fi
- if test -f 'libs/src/timer/timer.3' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'libs/src/timer/timer.3'\"
- else
- echo shar: Extracting \"'libs/src/timer/timer.3'\" \(9383 characters\)
- sed "s/^X//" >'libs/src/timer/timer.3' <<'END_OF_FILE'
- X.\"(c) Copyright 1993 by Panagiotis Tsirigotis
- X.\"All rights reserved. The file named COPYRIGHT specifies the terms
- X.\"and conditions for redistribution.
- X.\"
- X.\" $Id: timer.3,v 4.3 1993/06/01 05:54:56 panos Exp $
- X.TH TIMER 3X "20 April 1993"
- X.SH NAME
- Xtimer_create, timer_destroy, timer_start, timer_stop, timer_block, timer_unblock, timer_expirations, timer_block_type, timer_unblock_type - timer management functions
- X.SH SYNOPSIS
- X.LP
- X.nf
- X.ft B
- X#include "timer.h"
- X.LP
- X.ft B
- Xenum timer_types { TIMER_REAL, TIMER_VIRTUAL, TIMER_PROF } ;
- Xenum timer_timetypes { TIMER_ABSOLUTE, TIMER_RELATIVE } ;
- X.LP
- X.ft B
- Xextern int timer_errno ;
- X.LP
- X.ft B
- Xtimer_h timer_create( type, flags, errnop )
- Xenum timer_types type ;
- Xint flags ;
- Xint *errnop ;
- X.LP
- X.ft B
- Xvoid timer_destroy( handle )
- Xtimer_h handle ;
- X.LP
- X.ft B
- Xint timer_start( handle, itvp, time_type, action )
- Xtimer_h handle ;
- Xstruct itimerval *itvp ;
- Xenum timer_timetypes time_type ;
- Xstruct timer_action *action ;
- X.LP
- X.ft B
- Xvoid timer_stop( handle )
- Xtimer_h handle ;
- X.LP
- X.ft B
- Xvoid timer_block( handle )
- Xtimer_h handle ;
- X.LP
- X.ft B
- Xvoid timer_unblock( handle )
- Xtimer_h handle ;
- X.LP
- X.ft B
- Xunsigned timer_expirations( handle )
- Xtimer_h handle ;
- X.LP
- X.ft B
- Xvoid timer_block_type( type )
- Xenum timer_types type ;
- X.LP
- X.ft B
- Xvoid timer_unblock_type( type )
- Xenum timer_types type ;
- X.SH DESCRIPTION
- X.LP
- XThis library provides support for multiple timers of various types by
- Xmultiplexing the timers provided by the operating system.
- XAn action is associated with each timer.
- XThe action can either be a function that will be invoked when the
- Xtimer expires or
- Xit can be an integer variable that will either be set to
- X.SM TRUE
- Xwhen the timer expires or it will be increased for every expiration
- Xof the timer (it is up to the user to clear the variable after inspecting
- Xits value).
- XIf a function is used, then it is possible that while that function is running,
- Xmore timers may expire and their functions be called
- X(i.e. timer interrupts are not blocked while the function is running).
- XThe timer-action association can change through the lifetime of the timer.
- XThe timer types supported by this library depend on the operating system.
- X.\" *********************** timer_create *****************************
- X.LP
- X.B timer_create()
- Xcreates a timer and returns a handle to it. When the timer is created, it
- Xis inactive. Possible values for \fItype\fP are:
- X.TP 18
- X.SB TIMER_REAL
- Xtimers of this type are wall-clock timers
- X.TP
- X.SB TIMER_VIRTUAL
- Xtimers of this type are running only when the process is running
- X.TP
- X.SB TIMER_PROF
- Xtimers of this type are running only when the process is running
- Xor the system is doing work on behalf of the process.
- X.LP
- XPossible values for \fIflags\fP are formed by ORing any of the following
- Xconstants:
- X.TP 20
- X.SB TIMER_RETURN_ERROR
- Xif an error
- Xoccurs while handling \fIthis\fP timer an error indication will be returned
- X(the default is program termination)
- X.LP
- XYou can use the constant
- X.B TIMER_NOFLAGS
- Xto specify no flags at all.
- XThe argument
- X.I errnop
- Xis a pointer to a variable where error values will be placed
- X(the default, in case
- X.I errnop
- Xis
- X.SM NULL
- Xis \fItimer_errno\fP).
- X.\" *********************** timer_destroy *****************************
- X.LP
- X.B timer_destroy()
- Xdestroys the timer specified by \fIhandle\fP.
- XIf the timer is active, it is deactivated first.
- X.\" *********************** timer_start *****************************
- X.LP
- X.B timer_start()
- Xactivates the timer specified by
- X.I handle.
- XThe expiration time is determined by
- X.I itvp
- Xand
- X.I time_type.
- X.I time_type
- Xcan be either
- X.B TIMER_ABSOLUTE
- Xor
- X.B TIMER_RELATIVE.
- XTimers of the former
- Xtype expire at the time
- Xspecified by
- X.I "itvp->it_value"
- X(if that time is before the
- Xcurrent time then the timer expires immediately) while the expiration
- Xtime of timers of the latter type expire at
- X.I "current time + itvp->it_value."
- X.I "itvp->it_interval"
- Xis the interval between subsequent expirations of the timer after the
- Xoriginal expiration.
- XThe
- X.I action
- Xargument determines the action to be taken when the timer expires.
- X.LP
- X.I "struct timer_action"
- Xis defined as follows:
- X.sp 1
- X.PD .1v
- X.RS
- X.nf
- Xstruct timer_action
- X{
- X.RS
- X.IP "int" 15
- Xta_flags ;
- X.IP "void"
- X(*ta_func)() ;
- X.IP void
- X*ta_arg ;
- X.IP jmp_buf
- Xta_env ;
- X.RE
- X} ;
- X.RE
- X.PD
- X.fi
- X.LP
- XThe type of action taken when a timer expires depends on
- X.I ta_func
- Xand
- X.I ta_arg.
- X.RS
- X.IP "Case 1: ta_func != NULL"
- XThe function will be invoked with 2 arguments: the handle of the expired
- Xtimer and
- X.I ta_arg.
- X.I "Such functions should not use longjmp."
- X.IP "Case 2: ta_func == NULL && ta_arg != NULL"
- X.I ta_arg
- Xis assumed to be a pointer to an integer variable. This variable will
- Xeither be set to
- X.SM TRUE
- Xor its value will be increased.
- X.IP "Case 3: ta_func == NULL && ta_arg == NULL"
- Xnothing happens.
- X.RE
- X.sp 1
- X.I ta_flags
- Xis formed by ORing any of the following constants:
- X.TP 20
- X.SB TIMER_INC_VAR
- XWhen the action associated with the timer is an integer variable then
- Xthe variable will be increased by the number of timer expirations (the
- Xdefault is for the variable to be set to 1).
- X.TP
- X.SB TIMER_BLOCK_ALL
- XWhen the action associated with the timer is a function, all timer
- Xinterrupts will be blocked while the function is running.
- X.TP
- X.SB TIMER_BLOCK_SAME
- XWhen the action associated with the timer is a function, all timers
- Xof the same type will be blocked while the function is running.
- X.TP
- X.SB TIMER_LONGJMP
- XA longjmp(3) will be performed using
- X.I ta_env
- Xafter the action associated with the timer is performed.
- X.LP
- XYou can use the constant
- X.B TIMER_NOFLAGS
- Xto specify no flags at all.
- X.\" *********************** timer_stop *****************************
- X.LP
- X.B timer_stop()
- Xstops the specified timer. The timer becomes inactive and it cannot
- Xbe restarted.
- X.\" *********************** timer_block *****************************
- X.LP
- X.B timer_block()
- Xblocks the specified timer. The timer is still active and may expire
- Xbut its action will not be executed until the
- Xtimer is unblocked.
- X.\" *********************** timer_unblock *****************************
- X.LP
- X.B timer_unblock()
- Xunblocks the specified timer. If the timer is past its expiration time,
- Xthe associated action will be executed immediately.
- X.\" *********************** timer_expirations *****************************
- X.LP
- X.B timer_expirations()
- Xshould be used by the user-specified function to find out
- Xthe number of times the timer expired until the function was called.
- XMultiple expirations are possible for a timer that expires periodically.
- X.\" *********************** timer_block_type *****************************
- X.LP
- X.B timer_block_type()
- Xblocks all timers of the specified \fItype\fP.
- XThis also includes any timers started
- X.I after
- Xthis function is invoked.
- X.\" *********************** timer_unblock_type *****************************
- X.LP
- X.B timer_unblock_type()
- Xunblocks all timers of the specified \fItype\fP.
- X.\" *********************** notes *****************************
- X.SH NOTES
- X.LP
- XAny of the timer operations can be used on any timer handle at any time.
- XSpecifically, the operations can be used from within the functions
- Xinvoked when the timers expire.
- X.LP
- XThe function associated with a timer is not
- Xinvoked for each expiration of that timer.
- XIt is possible for a timer to expire
- Xmultiple times while its function is running (because timers can
- Xbe scheduled to expire periodically) or while other timer functions
- Xare running. The timer function can find out how many times its timer
- Xhas expired by using the
- X.B timer_expirations()
- Xoperation.
- X.LP
- XIt is guaranteed that the function associated with a specific timer will
- Xnot be called recursively if that timer expires multiple times.
- X.LP
- XThe order of execution of timer-associated functions for
- Xtimers that expire at the same time is undefined.
- X.LP
- XEven if a function returns a jmp_buf pointer, it is not guaranteed that
- Xthe pointer will be used. The reason is that more than one function
- Xcan expire at the same time and return a jmp_buf pointer. Since there
- Xcan be only one control flow, only one of those jmp_buf's can be used and
- Xthe choice between them is implementation-dependent.
- X.SH "RETURN VALUES"
- X.LP
- XValues for
- X.I timer_errno
- Xwill be stored in the user-specified variable if one was provided.
- X.LP
- X.B timer_create()
- Xreturns a timer handle if successful or
- X.SM NULL
- Xif it fails.
- X.LP
- X.B timer_start()
- Xreturns
- X.B TIMER_OK
- Xif successful or
- X.B TIMER_ERR
- Xif it fails.
- X.LP
- X.B timer_expirations()
- Xreturns a positive (non-zero) number when invoked from a timer-associated
- Xfunction; otherwise its return value is undefined.
- X.RE
- X.SH "ERRORS"
- XThe following is a list of error codes which will be placed in
- X.I timer_errno
- Xor the user-specified variable when a timer operation fails:
- X.RS
- X.TP 20
- X.SB TIMER_ENOMEM
- XA memory allocation request failed.
- X.TP
- X.SB TIMER_EBADTYPE
- XAn unknown timer type was specified.
- X.TP
- X.SB TIMER_ESIGPROBLEM
- XA signal handler could not be installed.
- X.TP
- X.SB TIMER_EBADSTATE
- XThe timer state does not allow this operation (for example, the timer is
- Xrunning and the operation attempted was \fBtimer_start()\fP).
- X.TP
- X.SB TIMER_EBADTIME
- XThe time value specified was negative.
- X.TP
- X.SB TIMER_ENOTAVAILABLE
- XThe requested timer type is not available.
- X.TP
- X.SB TIMER_ECANTINSERT
- XThe insertion of this timer in the queue of timers failed.
- X.TP
- X.SB TIMER_SIGPROBLEM
- XThere was an error while trying to install a signal handler.
- X.SH "SEE ALSO"
- Xsetitimer(2), setjmp(3), longjmp(3)
- END_OF_FILE
- if test 9383 -ne `wc -c <'libs/src/timer/timer.3'`; then
- echo shar: \"'libs/src/timer/timer.3'\" unpacked with wrong size!
- fi
- # end of 'libs/src/timer/timer.3'
- fi
- if test -f 'xinetd/builtins.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'xinetd/builtins.c'\"
- else
- echo shar: Extracting \"'xinetd/builtins.c'\" \(8896 characters\)
- sed "s/^X//" >'xinetd/builtins.c' <<'END_OF_FILE'
- X/*
- X * (c) Copyright 1992 by Panagiotis Tsirigotis
- X * All rights reserved. The file named COPYRIGHT specifies the terms
- X * and conditions for redistribution.
- X */
- X
- Xstatic char RCSid[] = "$Id: builtins.c,v 6.9 1993/06/15 23:25:57 panos Exp $" ;
- X
- X#include <sys/types.h>
- X#include <sys/socket.h>
- X#include <errno.h>
- X#include <time.h>
- X#include <syslog.h>
- X
- X#include "str.h"
- X
- X#include "config.h"
- X#include "state.h"
- X#include "defs.h"
- X#include "builtin.h"
- X#include "sconf.h"
- X#include "server.h"
- X
- Xextern int errno ;
- X
- Xtime_t time() ;
- X
- Xvoid msg() ;
- Xstatus_e write_buf() ;
- X
- X#define BUFFER_SIZE 1024
- X
- XPRIVATE void stream_echo() ;
- XPRIVATE void dgram_echo() ;
- XPRIVATE void stream_discard() ;
- XPRIVATE void dgram_discard() ;
- XPRIVATE void stream_time() ;
- XPRIVATE void dgram_time() ;
- XPRIVATE void stream_daytime() ;
- XPRIVATE void dgram_daytime() ;
- XPRIVATE void stream_chargen() ;
- XPRIVATE void dgram_chargen() ;
- XPRIVATE void stream_servers() ;
- XPRIVATE void stream_services() ;
- X
- X
- Xstatic struct builtin_service builtin_services[] =
- X {
- X { "echo", SOCK_STREAM, { stream_echo, FORK } },
- X { "echo", SOCK_DGRAM, { dgram_echo, NO_FORK } },
- X { "discard", SOCK_STREAM, { stream_discard, FORK } },
- X { "discard", SOCK_DGRAM, { dgram_discard, NO_FORK } },
- X { "time", SOCK_STREAM, { stream_time, NO_FORK } },
- X { "time", SOCK_DGRAM, { dgram_time, NO_FORK } },
- X { "daytime", SOCK_STREAM, { stream_daytime, NO_FORK } },
- X { "daytime", SOCK_DGRAM, { dgram_daytime, NO_FORK } },
- X { "chargen", SOCK_STREAM, { stream_chargen, FORK } },
- X { "chargen", SOCK_DGRAM, { dgram_chargen, NO_FORK } },
- X { "servers", SOCK_STREAM, { stream_servers, FORK } },
- X { "services", SOCK_STREAM, { stream_services, FORK } },
- X { NULL }
- X } ;
- X
- X
- Xbuiltin_s *builtin_find( service_name, type )
- X char *service_name ;
- X int type ;
- X{
- X register builtin_s *bsp ;
- X char *func = "builtin_find" ;
- X
- X if ( bsp = builtin_lookup( builtin_services, service_name, type ) )
- X return( bsp ) ;
- X
- X msg( LOG_ERR, func, "No such internal service: %s", service_name ) ;
- X return( NULL ) ;
- X}
- X
- X
- Xbuiltin_s *builtin_lookup( services, service_name, type )
- X struct builtin_service services[] ;
- X register char *service_name ;
- X register int type ;
- X{
- X register struct builtin_service *bsp ;
- X
- X for ( bsp = services ; bsp->bs_name != NULL ; bsp++ )
- X if ( EQ( bsp->bs_name, service_name ) && bsp->bs_socket_type == type )
- X return( &bsp->bs_handle ) ;
- X return( NULL ) ;
- X}
- X
- X
- X/*
- X * The rest of this file contains the functions that implement the
- X * builtin services
- X */
- X
- X
- XPRIVATE void stream_echo( serp )
- X struct server *serp ;
- X{
- X char buf[ BUFFER_SIZE ] ;
- X register int cc ;
- X int descriptor = SERVER_FD( serp ) ;
- X
- X for ( ;; )
- X {
- X cc = read( descriptor, buf, sizeof( buf ) ) ;
- X if ( cc == 0 )
- X break ;
- X if ( cc == -1 )
- X if ( errno == EINTR )
- X continue ;
- X else
- X break ;
- X
- X if ( write_buf( descriptor, buf, cc ) == FAILED )
- X break ;
- X }
- X}
- X
- X
- XPRIVATE void dgram_echo( serp )
- X struct server *serp ;
- X{
- X char buf[ DATAGRAM_SIZE ] ;
- X struct sockaddr_in sin ;
- X int sin_len ;
- X int cc ;
- X int descriptor = SERVER_FD( serp ) ;
- X
- X cc = recvfrom( descriptor, buf, sizeof( buf ), 0, SA( &sin ), &sin_len ) ;
- X if ( cc != -1 )
- X (void) sendto( descriptor, buf, cc, 0, SA( &sin ), sizeof( sin ) ) ;
- X}
- X
- X
- XPRIVATE void stream_discard( serp )
- X struct server *serp ;
- X{
- X char buf[ BUFFER_SIZE ] ;
- X register int cc ;
- X
- X for ( ;; )
- X {
- X cc = read( SERVER_FD( serp ), buf, sizeof( buf ) ) ;
- X if ( cc == 0 || cc == -1 && errno != EINTR )
- X break ;
- X }
- X}
- X
- X
- XPRIVATE void dgram_discard( serp )
- X struct server *serp ;
- X{
- X char buf[ 1 ] ;
- X
- X (void) recv( SERVER_FD( serp ), buf, sizeof( buf ), 0 ) ;
- X}
- X
- X
- X
- X/*
- X * Generate the current time using the SMTP format:
- X * 02 FEB 1991 12:31:42 MST
- X *
- X * The result is placed in buf.
- X * buflen is a value-result parameter. It indicates the size of
- X * buf and on exit it has the length of the string placed in buf.
- X */
- XPRIVATE void daytime_protocol( buf, buflen )
- X char *buf ;
- X int *buflen ;
- X{
- X static char *month_name[] =
- X {
- X "JAN", "FEB", "MAR", "APR", "MAY", "JUN",
- X "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"
- X } ;
- X time_t now ;
- X struct tm *tmp ;
- X int size = *buflen ;
- X
- X (void) time( &now ) ;
- X tmp = localtime( &now ) ;
- X strx_print( buflen, buf, size,
- X "%02d %s %d %02d:%02d:%02d %s\r\n",
- X tmp->tm_mday, month_name[ tmp->tm_mon ], 1900 + tmp->tm_year,
- X tmp->tm_hour, tmp->tm_min, tmp->tm_sec, tmp->tm_zone ) ;
- X}
- X
- X
- XPRIVATE void stream_daytime( serp )
- X struct server *serp ;
- X{
- X char time_buf[ BUFFER_SIZE ] ;
- X int buflen = sizeof( time_buf ) ;
- X
- X daytime_protocol( time_buf, &buflen ) ;
- X (void) write_buf( SERVER_FD( serp ), time_buf, buflen ) ;
- X}
- X
- X
- XPRIVATE void dgram_daytime( serp )
- X struct server *serp ;
- X{
- X char time_buf[ BUFFER_SIZE ] ;
- X struct sockaddr_in sin ;
- X int sin_len = sizeof( sin ) ;
- X int buflen = sizeof( time_buf ) ;
- X int descriptor = SERVER_FD( serp ) ;
- X
- X if ( recvfrom( descriptor, time_buf, sizeof( time_buf ), 0,
- X SA( &sin ), &sin_len ) == -1 )
- X return ;
- X
- X daytime_protocol( time_buf, &buflen ) ;
- X
- X (void) sendto( descriptor, time_buf, buflen, 0, SA(&sin), sizeof( sin ) ) ;
- X}
- X
- X
- X#define TIME_OFFSET 2208988800
- X
- X/*
- X * We always report the time using network-byte-order
- X */
- XPRIVATE void time_protocol( timep )
- X register unsigned long *timep ;
- X{
- X time_t now ;
- X
- X (void) time( &now ) ;
- X *timep = now + TIME_OFFSET ;
- X *timep = htonl( *timep ) ;
- X}
- X
- X
- XPRIVATE void stream_time( serp )
- X struct server *serp ;
- X{
- X unsigned long now ;
- X
- X time_protocol( &now ) ;
- X (void) write_buf( SERVER_FD( serp ), (char *) &now, sizeof( now ) ) ;
- X}
- X
- X
- XPRIVATE void dgram_time( serp )
- X struct server *serp ;
- X{
- X char buf[ 1 ] ;
- X unsigned long now ;
- X struct sockaddr_in sin ;
- X int sin_len = sizeof( sin ) ;
- X int fd = SERVER_FD( serp ) ;
- X
- X if ( recvfrom( fd, buf, sizeof( buf ), 0, SA( &sin ), &sin_len ) == -1 )
- X return ;
- X
- X time_protocol( &now ) ;
- X (void) sendto( fd, (char *) &now, sizeof( now ), 0, SA( &sin ), sin_len ) ;
- X}
- X
- X
- X#define ASCII_PRINTABLE_CHARS 94
- X#define LINE_LENGTH 72
- X
- X#define RING_BUF_SIZE ASCII_PRINTABLE_CHARS + LINE_LENGTH
- X
- Xstatic char ring_buf[ RING_BUF_SIZE ] ;
- Xstatic char *ring ;
- X
- X
- X#define ASCII_START ( ' ' + 1 )
- X#define ASCII_END 126
- X
- X#define min( a, b ) ((a)<(b) ? (a) : (b))
- X
- XPRIVATE char *generate_line( buf, len )
- X char *buf ;
- X int len ;
- X{
- X int line_len = min( LINE_LENGTH, len-2 ) ;
- X
- X if ( line_len < 0 )
- X return( NULL ) ;
- X
- X if ( ring == NULL )
- X {
- X register char ch ;
- X register char *p ;
- X
- X for ( p = ring_buf, ch = ASCII_START ;
- X p < &ring_buf[ RING_BUF_SIZE ] ; p++ )
- X {
- X *p = ch++ ;
- X if ( ch == ASCII_END )
- X ch = ASCII_START ;
- X }
- X ring = ring_buf ;
- X }
- X (void) memcpy( buf, ring, line_len ) ;
- X buf[ line_len ] = '\r' ;
- X buf[ line_len+1 ] = '\n' ;
- X
- X ring++ ;
- X if ( &ring_buf[ RING_BUF_SIZE ] - ring < LINE_LENGTH )
- X ring = ring_buf ;
- X return( buf ) ;
- X}
- X
- X
- XPRIVATE void stream_chargen( serp )
- X struct server *serp ;
- X{
- X char line_buf[ LINE_LENGTH+2 ] ;
- X int descriptor = SERVER_FD( serp ) ;
- X
- X (void) shutdown( descriptor, 0 ) ;
- X for ( ;; )
- X {
- X if ( generate_line( line_buf, sizeof( line_buf ) ) == NULL )
- X break ;
- X if ( write_buf( descriptor, line_buf, sizeof( line_buf ) ) == FAILED )
- X break ;
- X }
- X}
- X
- X
- XPRIVATE void dgram_chargen( serp )
- X struct server *serp ;
- X{
- X char buf[ BUFFER_SIZE ] ;
- X register char *p ;
- X register int len ;
- X struct sockaddr_in sin ;
- X int sin_len = sizeof( sin ) ;
- X int fd = SERVER_FD( serp ) ;
- X register int left = sizeof( buf ) ;
- X
- X if ( recvfrom( fd, buf, sizeof( buf ), 0, SA( &sin ), &sin_len ) == -1 )
- X return ;
- X
- X#if BUFFER_SIZE < LINE_LENGTH+2
- X bad_variable = 1 ; /* this will cause a compilation error */
- X#endif
- X
- X for ( p = buf ; left > 2 ; left -= len, p += len )
- X {
- X len = min( LINE_LENGTH+2, left ) ;
- X if ( generate_line( p, len ) == NULL )
- X break ;
- X }
- X (void) sendto( fd, buf, p-buf, 0, SA( &sin ), sin_len ) ;
- X}
- X
- X
- XPRIVATE void stream_servers( this_serp )
- X struct server *this_serp ;
- X{
- X register unsigned u ;
- X int descriptor = SERVER_FD( this_serp ) ;
- X
- X for ( u = 0 ; u < pset_count( SERVERS( ps ) ) ; u++ )
- X {
- X struct server *serp = SERP( pset_pointer( SERVERS( ps ), u ) ) ;
- X
- X /*
- X * We cannot report any useful information about this server because
- X * the data in the server struct are filled by the parent.
- X */
- X if ( serp == this_serp )
- X continue ;
- X
- X server_dump( serp, descriptor ) ;
- X }
- X}
- X
- X
- XPRIVATE void stream_services( serp )
- X struct server *serp ;
- X{
- X register unsigned u ;
- X int fd = SERVER_FD( serp ) ;
- X
- X for ( u = 0 ; u < pset_count( SERVICES( ps ) ) ; u++ )
- X {
- X int cc ;
- X char buf[ BUFFER_SIZE ] ;
- X struct service_config *scp ;
- X
- X scp = SVC_CONF( SP( pset_pointer( SERVICES( ps ), u ) ) ) ;
- X
- X strx_print( &cc, buf, sizeof( buf ), "%s %s %d\n",
- X SC_NAME( scp ), SC_PROTONAME( scp ), SC_PORT( scp ) ) ;
- X
- X if ( write_buf( fd, buf, cc ) == FAILED )
- X break ;
- X }
- X}
- X
- END_OF_FILE
- if test 8896 -ne `wc -c <'xinetd/builtins.c'`; then
- echo shar: \"'xinetd/builtins.c'\" unpacked with wrong size!
- fi
- # end of 'xinetd/builtins.c'
- fi
- echo shar: End of archive 18 \(of 31\).
- cp /dev/null ark18isdone
- MISSING=""
- for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked all 31 archives.
- rm -f ark[1-9]isdone ark[1-9][0-9]isdone
- else
- echo You still need to unpack the following archives:
- echo " " ${MISSING}
- fi
- ## End of shell archive.
- exit 0
-