From 60979251d628adf1820c6fa15a9b4cf7c735aa89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Grubbstr=C3=B6m=20=28Grubba=29?= <grubba@grubba.org> Date: Tue, 28 Jan 1997 19:34:54 +0100 Subject: [PATCH] Moved syslog to system-module Rev: src/modules/spider/configure.in:1.13 Rev: src/modules/spider/spider.c:1.21 Rev: src/modules/system/Makefile.in:1.2 Rev: src/modules/system/configure.in:1.4 Rev: src/modules/system/syslog.c:1.1 Rev: src/modules/system/system.c:1.8 --- .gitattributes | 1 + src/modules/spider/configure.in | 4 +- src/modules/spider/spider.c | 168 ----------------------------- src/modules/system/Makefile.in | 2 +- src/modules/system/configure.in | 8 +- src/modules/system/syslog.c | 184 ++++++++++++++++++++++++++++++++ src/modules/system/system.c | 16 ++- 7 files changed, 208 insertions(+), 175 deletions(-) create mode 100644 src/modules/system/syslog.c diff --git a/.gitattributes b/.gitattributes index 41ace0daac..2e3cb1f184 100644 --- a/.gitattributes +++ b/.gitattributes @@ -68,6 +68,7 @@ testfont binary /src/modules/spider/dumudp.c foreign_ident /src/modules/sprintf/sprintf.c foreign_ident /src/modules/ssleay/ssleay.c foreign_ident +/src/modules/system/syslog.c foreign_ident /src/modules/system/system.c foreign_ident /src/modules/system/system_machine.h.in foreign_ident /src/modules/zlibmod/zlibmod.c foreign_ident diff --git a/src/modules/spider/configure.in b/src/modules/spider/configure.in index e5e73cc2c1..393d16a17f 100644 --- a/src/modules/spider/configure.in +++ b/src/modules/spider/configure.in @@ -7,14 +7,14 @@ AC_PROG_RANLIB AC_CHECK_LIB(socket, socket) AC_CHECK_LIB(nsl, gethostbyname) -AC_HAVE_HEADERS(syslog.h sys/syslog.h arpa/inet.h sys/socketvar.h \ +AC_HAVE_HEADERS(arpa/inet.h sys/socketvar.h \ netinet/in.h sys/mman.h sys/utsname.h netdb.h sys/socket.h pwd.h\ shadow.h sync.h sys/sockio.h sys/conf.h stropts.h\ sys/uio.h linux/mman.h) AC_FUNC_MMAP -AC_HAVE_FUNCS(syslog perror strdup getpwnam getspnam sendmsg getpwent setpwent endpwent) +AC_HAVE_FUNCS(perror strdup getpwnam getspnam sendmsg getpwent setpwent endpwent) AC_CHECK_TYPE(time_t, long) diff --git a/src/modules/spider/spider.c b/src/modules/spider/spider.c index 294487af7e..8f1fbde6b5 100644 --- a/src/modules/spider/spider.c +++ b/src/modules/spider/spider.c @@ -1017,168 +1017,6 @@ void f_timezone(INT32 args) #endif } -#ifdef HAVE_SYSLOG - -#ifdef HAVE_SYSLOG_H -#include <syslog.h> -#endif - -#ifdef HAVE_SYS_SYSLOG_H -#ifndef HAVE_SYSLOG_H -#include <sys/syslog.h> -#endif -#endif - - -#ifndef LOG_PID -#define LOG_PID 0 -#endif -#ifndef LOG_AUTH -#define LOG_AUTH 0 -#endif -#ifndef LOG_AUTHPRIV -#define LOG_AUTHPRIV 0 -#endif -#ifndef LOG_CRON -#define LOG_CRON 0 -#endif -#ifndef LOG_DAEMON -#define LOG_DAEMON 0 -#endif -#ifndef LOG_KERN -#define LOG_KERN 0 -#endif -#ifndef LOG_LOCAL0 -#define LOG_LOCAL0 0 -#endif -#ifndef LOG_LOCAL1 -#define LOG_LOCAL1 0 -#endif -#ifndef LOG_LOCAL2 -#define LOG_LOCAL2 0 -#endif -#ifndef LOG_LOCAL3 -#define LOG_LOCAL3 0 -#endif -#ifndef LOG_LOCAL4 -#define LOG_LOCAL4 0 -#endif -#ifndef LOG_LOCAL5 -#define LOG_LOCAL5 0 -#endif -#ifndef LOG_LOCAL6 -#define LOG_LOCAL6 0 -#endif -#ifndef LOG_LOCAL7 -#define LOG_LOCAL7 0 -#endif -#ifndef LOG_LPR -#define LOG_LPR 0 -#endif -#ifndef LOG_MAIL -#define LOG_MAIL 0 -#endif -#ifndef LOG_NEWS -#define LOG_NEWS 0 -#endif -#ifndef LOG_SYSLOG -#define LOG_SYSLOG 0 -#endif -#ifndef LOG_USER -#define LOG_USER 0 -#endif -#ifndef LOG_UUCP -#define LOG_UUCP 0 -#endif -#ifndef LOG_CONS -#define LOG_CONS 0 -#endif -#ifndef LOG_NDELAY -#define LOG_NDELAY 0 -#endif -#ifndef LOG_PERROR -#define LOG_PERROR 0 -#endif -void f_openlog(INT32 args) -{ - int option=0, facility=0, i; - if(args < 3) - error("Wrong number of arguments to openlog(string,int,int)\n"); - if(sp[-args].type != T_STRING - &&sp[-args+1].type != T_INT - &&sp[-args+2].type != T_INT) - error("Wrong type of arguments to openlog(string,int,int)\n"); - - i=sp[-args+1].u.integer; - - if(i & (1<<0)) option |= LOG_CONS; - if(i & (1<<1)) option |= LOG_NDELAY; - if(i & (1<<2)) option |= LOG_PERROR; - if(i & (1<<3)) option |= LOG_PID; - - i=sp[-args+2].u.integer; - - if(i & (1<<0)) facility |= LOG_AUTH; /* Don't use */ - if(i & (1<<1)) facility |= LOG_AUTHPRIV; - if(i & (1<<2)) facility |= LOG_CRON; - if(i & (1<<3)) facility |= LOG_DAEMON; - if(i & (1<<4)) facility |= LOG_KERN; - if(i & (1<<5)) facility |= LOG_LOCAL0; - if(i & (1<<6)) facility |= LOG_LOCAL1; - if(i & (1<<7)) facility |= LOG_LOCAL2; - if(i & (1<<8)) facility |= LOG_LOCAL3; - if(i & (1<<9)) facility |= LOG_LOCAL4; - if(i & (1<<10)) facility |= LOG_LOCAL5; - if(i & (1<<11)) facility |= LOG_LOCAL6; - if(i & (1<<12)) facility |= LOG_LOCAL7; - if(i & (1<<13)) facility |= LOG_LPR; - if(i & (1<<14)) facility |= LOG_MAIL; - if(i & (1<<15)) facility |= LOG_NEWS; - if(i & (1<<16)) facility |= LOG_SYSLOG; - if(i & (1<<17)) facility |= LOG_USER; - if(i & (1<<18)) facility |= LOG_UUCP; - - openlog((char *)sp[-args].u.string->str, option, facility); -} - -void f_syslog(INT32 args) -{ - int pri=0, i; - - if(args < 2) - error("Wrong number of arguments to syslog(int, string)\n"); - if(sp[-args].type != T_INT || - sp[-args+1].type != T_STRING) - error("Wrong type of arguments to syslog(int, string)\n"); - - reference_shared_string(sp[-args+1].u.string); - push_string(sp[-args+1].u.string); - push_string(make_shared_string("%")); - push_string(make_shared_string("%%")); - f_replace(3); - - i=sp[-args].u.integer; - if(i & (1<<0)) pri |= LOG_EMERG; - if(i & (1<<1)) pri |= LOG_ALERT; - if(i & (1<<2)) pri |= LOG_CRIT; - if(i & (1<<3)) pri |= LOG_ERR; - if(i & (1<<4)) pri |= LOG_WARNING; - if(i & (1<<5)) pri |= LOG_NOTICE; - if(i & (1<<6)) pri |= LOG_INFO; - if(i & (1<<6)) pri |= LOG_DEBUG; - - syslog(pri, (char *)sp[-1].u.string->str,"%s","%s","%s","%s","%s","%s", - "%s","%s","%s","%s"); - pop_n_elems(args); -} - -void f_closelog(INT32 args) -{ - closelog(); - pop_n_elems(args); -} -#endif - #ifdef HAVE_PERROR void f_real_perror(INT32 args) { @@ -1475,12 +1313,6 @@ void init_spider_efuns(void) add_efun("real_perror",f_real_perror, "function(:void)",OPT_EXTERNAL_DEPEND); #endif -#ifdef HAVE_SYSLOG - add_efun("openlog", f_openlog, "function(string,int,int:void)", 0); - add_efun("syslog", f_syslog, "function(int,string:void)", 0); - add_efun("closelog", f_closelog, "function(:void)", 0); -#endif - add_efun("discdate", f_discdate, "function(int:array)", 0); add_efun("stardate", f_stardate, "function(int,void|int:int)", 0); diff --git a/src/modules/system/Makefile.in b/src/modules/system/Makefile.in index ceffddaeff..59be7cbe04 100644 --- a/src/modules/system/Makefile.in +++ b/src/modules/system/Makefile.in @@ -1,6 +1,6 @@ SRCDIR=@srcdir@ VPATH=@srcdir@:@srcdir@/../..:../.. -FILES=system.o +FILES=system.o syslog.o all: system.a diff --git a/src/modules/system/configure.in b/src/modules/system/configure.in index 1abb41da7d..ef35ec2dc1 100644 --- a/src/modules/system/configure.in +++ b/src/modules/system/configure.in @@ -13,9 +13,13 @@ module_makefile=$srcdir/../module_makefile AC_CHECK_LIB(socket, socket) AC_CHECK_LIB(nsl, gethostbyname) -AC_HAVE_HEADERS(sys/types.h errno.h unistd.h pwd.h sys/conf.h sys/socket.h netinet/in.h arpa/inet.h netdb.h stdarg.h varargs.h sys/utsname.h) +AC_HAVE_HEADERS(syslog.h sys/syslog.h sys/types.h errno.h unistd.h pwd.h \ + sys/conf.h sys/socket.h netinet/in.h arpa/inet.h netdb.h stdarg.h \ + sys/utsname.h) -AC_HAVE_FUNCS(link symlink readlink initgroups seteuid setresuid geteuid getpgrp getpgid getppid fchroot uname gethostname gethostbyname) +AC_HAVE_FUNCS(syslog link symlink readlink \ + initgroups seteuid setresuid geteuid getpgrp getpgid getppid \ + fchroot uname gethostname gethostbyname) AC_CHECK_LIB(nsl, gethostbyname) diff --git a/src/modules/system/syslog.c b/src/modules/system/syslog.c new file mode 100644 index 0000000000..5e6f41545a --- /dev/null +++ b/src/modules/system/syslog.c @@ -0,0 +1,184 @@ +/* + * $Id: syslog.c,v 1.1 1997/01/28 18:34:52 grubba Exp $ + * + * Access to syslog from Pike. + * + * Henrik Grubbström 1997-01-28 + */ + +/* + * Includes + */ + +#include "system_machine.h" + +#include <global.h> + +#ifdef HAVE_SYSLOG + +RCSID("$Id: syslog.c,v 1.1 1997/01/28 18:34:52 grubba Exp $"); + +#ifdef HAVE_SYSLOG_H +#include <syslog.h> +#elif defined(HAVE_SYS_SYSLOG_H) +#include <sys/syslog.h> +#endif + +#ifndef LOG_PID +#define LOG_PID 0 +#endif +#ifndef LOG_AUTH +#define LOG_AUTH 0 +#endif +#ifndef LOG_AUTHPRIV +#define LOG_AUTHPRIV 0 +#endif +#ifndef LOG_CRON +#define LOG_CRON 0 +#endif +#ifndef LOG_DAEMON +#define LOG_DAEMON 0 +#endif +#ifndef LOG_KERN +#define LOG_KERN 0 +#endif +#ifndef LOG_LOCAL0 +#define LOG_LOCAL0 0 +#endif +#ifndef LOG_LOCAL1 +#define LOG_LOCAL1 0 +#endif +#ifndef LOG_LOCAL2 +#define LOG_LOCAL2 0 +#endif +#ifndef LOG_LOCAL3 +#define LOG_LOCAL3 0 +#endif +#ifndef LOG_LOCAL4 +#define LOG_LOCAL4 0 +#endif +#ifndef LOG_LOCAL5 +#define LOG_LOCAL5 0 +#endif +#ifndef LOG_LOCAL6 +#define LOG_LOCAL6 0 +#endif +#ifndef LOG_LOCAL7 +#define LOG_LOCAL7 0 +#endif +#ifndef LOG_LPR +#define LOG_LPR 0 +#endif +#ifndef LOG_MAIL +#define LOG_MAIL 0 +#endif +#ifndef LOG_NEWS +#define LOG_NEWS 0 +#endif +#ifndef LOG_SYSLOG +#define LOG_SYSLOG 0 +#endif +#ifndef LOG_USER +#define LOG_USER 0 +#endif +#ifndef LOG_UUCP +#define LOG_UUCP 0 +#endif +#ifndef LOG_CONS +#define LOG_CONS 0 +#endif +#ifndef LOG_NDELAY +#define LOG_NDELAY 0 +#endif +#ifndef LOG_PERROR +#define LOG_PERROR 0 +#endif + +/* openlog(string ident, int option, int facility) */ +void f_openlog(INT32 args) +{ + char *ident; + int p_option, p_facility; + int option=0, facility=0; + + get_all_args("openlog", args, "%s%i%i", &ident, &p_option, &p_facility); + + if(p_option & (1<<0)) option |= LOG_CONS; + if(p_option & (1<<1)) option |= LOG_NDELAY; + if(p_option & (1<<2)) option |= LOG_PERROR; + if(p_option & (1<<3)) option |= LOG_PID; + + if(p_facility & (1<<0)) facility |= LOG_AUTH; /* Don't use */ + if(p_facility & (1<<1)) facility |= LOG_AUTHPRIV; + if(p_facility & (1<<2)) facility |= LOG_CRON; + if(p_facility & (1<<3)) facility |= LOG_DAEMON; + if(p_facility & (1<<4)) facility |= LOG_KERN; + if(p_facility & (1<<5)) facility |= LOG_LOCAL0; + if(p_facility & (1<<6)) facility |= LOG_LOCAL1; + if(p_facility & (1<<7)) facility |= LOG_LOCAL2; + if(p_facility & (1<<8)) facility |= LOG_LOCAL3; + if(p_facility & (1<<9)) facility |= LOG_LOCAL4; + if(p_facility & (1<<10)) facility |= LOG_LOCAL5; + if(p_facility & (1<<11)) facility |= LOG_LOCAL6; + if(p_facility & (1<<12)) facility |= LOG_LOCAL7; + if(p_facility & (1<<13)) facility |= LOG_LPR; + if(p_facility & (1<<14)) facility |= LOG_MAIL; + if(p_facility & (1<<15)) facility |= LOG_NEWS; + if(p_facility & (1<<16)) facility |= LOG_SYSLOG; + if(p_facility & (1<<17)) facility |= LOG_USER; + if(p_facility & (1<<18)) facility |= LOG_UUCP; + + openlog(ident, option, facility); + + pop_n_elems(args); +} + +void f_syslog(INT32 args) +{ + struct pike_string *s; + int pri=0, i; + char *message; + + get_all_args("syslog", args, "%i%S", &i, &s); + + if(args < 2) + error("Wrong number of arguments to syslog(int, string)\n"); + if(sp[-args].type != T_INT || + sp[-args+1].type != T_STRING) + error("Wrong type of arguments to syslog(int, string)\n"); + + if(i & (1<<0)) pri |= LOG_EMERG; + if(i & (1<<1)) pri |= LOG_ALERT; + if(i & (1<<2)) pri |= LOG_CRIT; + if(i & (1<<3)) pri |= LOG_ERR; + if(i & (1<<4)) pri |= LOG_WARNING; + if(i & (1<<5)) pri |= LOG_NOTICE; + if(i & (1<<6)) pri |= LOG_INFO; + if(i & (1<<6)) pri |= LOG_DEBUG; + + reference_shared_string(s); + push_string(s); + push_string(make_shared_string("%")); + push_string(make_shared_string("%%")); + f_replace(3); + + message = sp[-1].u.string->str; + + THREADS_ALLOW(); + + syslog(pri, message, + "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s"); + + THREADS_DISALLOW(); + + pop_n_elems(args + 1); +} + +void f_closelog(INT32 args) +{ + closelog(); + pop_n_elems(args); +} + + +#endif /* HAVE_SYSLOG */ diff --git a/src/modules/system/system.c b/src/modules/system/system.c index 417f5e955e..f6d9cbf435 100644 --- a/src/modules/system/system.c +++ b/src/modules/system/system.c @@ -1,5 +1,5 @@ /* - * $Id: system.c,v 1.7 1997/01/27 22:48:00 grubba Exp $ + * $Id: system.c,v 1.8 1997/01/28 18:34:54 grubba Exp $ * * System-call module for Pike * @@ -13,7 +13,7 @@ #include "system_machine.h" #include <global.h> -RCSID("$Id: system.c,v 1.7 1997/01/27 22:48:00 grubba Exp $"); +RCSID("$Id: system.c,v 1.8 1997/01/28 18:34:54 grubba Exp $"); #include <module_support.h> #include <las.h> #include <interpret.h> @@ -692,6 +692,9 @@ void f_gethostbyname(INT32 args) void init_system_efuns(void) { + /* + * From this file: + */ #ifdef HAVE_LINK add_efun("hardlink", f_hardlink, "function(string, string:void)", OPT_SIDE_EFFECT); #endif /* HAVE_LINK */ @@ -745,6 +748,15 @@ void init_system_efuns(void) add_efun("gethostbyaddr", f_gethostbyaddr, "function(string:array)", OPT_TRY_OPTIMIZE); #endif /* HAVE_GETHOSTBYNAME */ + + /* + * From syslog.c: + */ +#ifdef HAVE_SYSLOG + add_efun("openlog", f_openlog, "function(string,int,int:void)", 0); + add_efun("syslog", f_syslog, "function(int,string:void)", 0); + add_efun("closelog", f_closelog, "function(:void)", 0); +#endif /* HAVE_SYSLOG */ } void init_system_programs(void) -- GitLab