From d5426651e8c731c0c985ebdb74ac77f5cf5fe541 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Fri, 6 Mar 2009 05:16:36 +0100 Subject: [PATCH] Added minilogd-2009.01 template, from Arch Linux. --HG-- extra : convert_revision : d4949b0d88c7cc0a1bd82d7d89660e0684dbaf62 --- templates/minilogd/files/minilogd.c | 188 ++++++++++++++++++++++++++++ templates/minilogd/template | 26 ++++ 2 files changed, 214 insertions(+) create mode 100755 templates/minilogd/files/minilogd.c create mode 100644 templates/minilogd/template diff --git a/templates/minilogd/files/minilogd.c b/templates/minilogd/files/minilogd.c new file mode 100755 index 00000000000..b48f0b16734 --- /dev/null +++ b/templates/minilogd/files/minilogd.c @@ -0,0 +1,188 @@ +/* minilogd.c + * + * A pale imitation of syslogd. Most notably, doesn't write anything + * anywhere except possibly back to syslogd. + * + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#define MAX_BUF_LINES 10000 +#define BUF_LINE_SIZE 8192 + +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_STREAM,0); + conn=connect(sock,(struct sockaddr *) &addr,sizeof(addr)); + while (x0) && pfds.revents & (POLLIN | POLLPRI)) { + message = calloc(BUF_LINE_SIZE,sizeof(char)); + recvsock = accept(sock,(struct sockaddr *) &addr, &addrlen); + alarm(2); + signal(SIGALRM, alarm_handler); + len = read(recvsock,message,BUF_LINE_SIZE); + alarm(0); + close(recvsock); + if (len>0) { + /*printf("line recv'd: %s\n", message);*/ + if (buflines < MAX_BUF_LINES) { + 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) ) { /*|| (s1.st_atime != s2.st_atime) ) {*/ + done = 1; + we_own_log = 0; + /*printf("someone stole our %s\n", _PATH_LOG); + printf("st_ino: %d %d\n", s1.st_ino, s2.st_ino); + printf("st_ctime: %d %d\n", s1.st_ctime, s2.st_ctime); + printf("st_atime: %d %d\n", s1.st_atime, s2.st_atime); + printf("st_mtime: %d %d\n", s1.st_mtime, s2.st_mtime);*/ + } + } + 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); + + 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 { + /*printf("starting daemon...\n");*/ + runDaemon(sock); + /* shouldn't get back here... */ + exit(4); + } + } else { + exit(5); + } +} +/* vim: set ts=2 noet: */ diff --git a/templates/minilogd/template b/templates/minilogd/template new file mode 100644 index 00000000000..cc4f61cdf02 --- /dev/null +++ b/templates/minilogd/template @@ -0,0 +1,26 @@ +# Template file for 'minilogd' +pkgname=minilogd +version=2009.01 +build_style=custom-install +short_desc="The Arch linux mini log daemon" +maintainer="Juan RP " +long_desc=" + minlogd is a small log daemon, designed to handle some early + messages sent by consumers until a real syslog is run. + + minilogd comes from the Arch linux distribution." + +Add_dependency run glibc + +do_install() +{ + local destdir=$XBPS_DESTDIR/$pkgname-$version + local filesdir=$XBPS_TEMPLATESDIR/$pkgname/files + + install -d ${destdir}/sbin + + cd ${filesdir} + gcc ${CFLAGS} minilogd.c -o minilogd + chmod 755 minilogd + mv minilogd ${destdir}/sbin +}