forked from Lainports/opnsense-ports
opnsense/clog: no longer needed
This commit is contained in:
parent
6bcbdffe9f
commit
5e6cc7d160
7 changed files with 0 additions and 418 deletions
|
|
@ -1,28 +0,0 @@
|
||||||
PORTNAME= clog
|
|
||||||
PORTVERSION= 1.0.2
|
|
||||||
CATEGORIES= sysutils
|
|
||||||
MASTER_SITES= # empty
|
|
||||||
DISTFILES= # none
|
|
||||||
EXTRACT_ONLY= # empty
|
|
||||||
|
|
||||||
MAINTAINER= franco@opnsense.org
|
|
||||||
COMMENT= Circular log support for FreeBSD syslogd
|
|
||||||
|
|
||||||
LICENSE= BSD2CLAUSE
|
|
||||||
|
|
||||||
.include <bsd.port.pre.mk>
|
|
||||||
|
|
||||||
do-extract:
|
|
||||||
mkdir -p ${WRKSRC}
|
|
||||||
|
|
||||||
do-build:
|
|
||||||
${CC} ${LDFLAGS} ${CFLAGS} -o ${WRKSRC}/clog ${FILESDIR}/clog.c
|
|
||||||
cp ${FILESDIR}/clog.8 ${WRKSRC}/clog.8
|
|
||||||
gzip ${WRKSRC}/clog.8
|
|
||||||
|
|
||||||
do-install:
|
|
||||||
${INSTALL_MAN} ${WRKSRC}/clog.8.gz ${STAGEDIR}${PREFIX}/man/man8
|
|
||||||
${INSTALL_DATA} ${FILESDIR}/clog.h ${STAGEDIR}${PREFIX}/include
|
|
||||||
${INSTALL_PROGRAM} ${WRKSRC}/clog ${STAGEDIR}${PREFIX}/sbin
|
|
||||||
|
|
||||||
.include <bsd.port.post.mk>
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
# @(#)Makefile 8.1 (Berkeley) 6/6/93
|
|
||||||
# $Id$
|
|
||||||
|
|
||||||
PROG= clog
|
|
||||||
SRCS= clog.c
|
|
||||||
MAN8= clog.8
|
|
||||||
COPTS+= -Wall -pedantic
|
|
||||||
|
|
||||||
.include <bsd.prog.mk>
|
|
||||||
|
|
@ -1,98 +0,0 @@
|
||||||
.\" Copyright (c) 2001
|
|
||||||
.\" Jeffrey D. Wheelhouse. All rights reserved.
|
|
||||||
.\"
|
|
||||||
.\" This code was originally developed by Jeff Wheelhouse (jdw@wwwi.com).
|
|
||||||
.\"
|
|
||||||
.\" Redistribution and use in source and binary forms, with or without
|
|
||||||
.\" modification, are permitted provided that the following conditions
|
|
||||||
.\" are met:
|
|
||||||
.\" 1. Redistributions of source code must retain the above copyright
|
|
||||||
.\" notice, this list of conditions and the following disclaimer.
|
|
||||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
.\" notice, this list of conditions and the following disclaimer in the
|
|
||||||
.\" documentation and/or other materials provided with the distribution.
|
|
||||||
.\"
|
|
||||||
.\" THIS SOFTWARE IS PROVIDED BY JEFF WHEELHOUSE ``AS IS'' AND ANY EXPRESS OR
|
|
||||||
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
||||||
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
|
||||||
.\" NO EVENT SHALL JEFF WHEELHOUSE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
||||||
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING BUT NOT
|
|
||||||
.\" LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
||||||
.\" OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
||||||
.\" LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
||||||
.\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
||||||
.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
.\"
|
|
||||||
.\" $Id$
|
|
||||||
.\"
|
|
||||||
.Dd October 1, 2001
|
|
||||||
.Dt CLOG 8
|
|
||||||
.Os BSD 4
|
|
||||||
.Sh NAME
|
|
||||||
.Nm clog
|
|
||||||
.Nd "display or initialize a circular system log"
|
|
||||||
.Sh SYNOPSIS
|
|
||||||
.Nm
|
|
||||||
.Op Fl f
|
|
||||||
.Op Fl i Fl s Ar size
|
|
||||||
.Ar logfile
|
|
||||||
.Sh DESCRIPTION
|
|
||||||
.Nm Clog
|
|
||||||
displays or initializes a circular log file.
|
|
||||||
.Pp
|
|
||||||
The options are as follows:
|
|
||||||
.Bl -tag -width indent
|
|
||||||
.It Fl f
|
|
||||||
Display the contents of the circular logfile
|
|
||||||
.Ar logfile ,
|
|
||||||
then go into a loop waiting for
|
|
||||||
new material to arrive. This is essentially the same as using the
|
|
||||||
.Fl f
|
|
||||||
option of the
|
|
||||||
.Xr tail 1
|
|
||||||
command on a standard syslog file.
|
|
||||||
.It Fl i
|
|
||||||
Initialize
|
|
||||||
.Ar logfile
|
|
||||||
rather than reading it. This option requires the
|
|
||||||
.Fl s
|
|
||||||
option. If
|
|
||||||
.Ar logfile
|
|
||||||
already exists, it will be truncated and recreated by this command.
|
|
||||||
.It Fl s
|
|
||||||
This option specifies the size in bytes of the circular logfile that should
|
|
||||||
be created. This option requires the
|
|
||||||
.Fl i
|
|
||||||
option.
|
|
||||||
.El
|
|
||||||
.Sh ABOUT CIRCULAR LOGFILES
|
|
||||||
The
|
|
||||||
.Nm
|
|
||||||
command supports circular logfiles for
|
|
||||||
.Xr syslogd 8 .
|
|
||||||
A circular logfile differs from a standard syslog file in that is has a fixed
|
|
||||||
size. It does not grow, and does not need to be rotated. When
|
|
||||||
.Xr syslogd 8
|
|
||||||
reaches the end of a circular logfile, it simply begins again at the beginning,
|
|
||||||
overwriting the oldest data. The circular logfile also contains information
|
|
||||||
allowing
|
|
||||||
.Nm
|
|
||||||
to establish what parts of the file are valid, and in what order they should
|
|
||||||
be displayed.
|
|
||||||
.Pp
|
|
||||||
Circular logfiles are primarily useful for their ability to control the amount
|
|
||||||
of storage devoted to logfiles. This may be valuable when storage space is
|
|
||||||
at a premium or when the consequences of running out of storage space are
|
|
||||||
unacceptable. Circular logfiles can safely be used on a memory disk (see
|
|
||||||
.Xr md 4 ).
|
|
||||||
.Pp
|
|
||||||
Circular logfiles are also useful to catch messages that are generated rapidly
|
|
||||||
but soon lose relevance, such as messages logged at debug priority.
|
|
||||||
|
|
||||||
.Sh SEE ALSO
|
|
||||||
.Xr syslogd 8 ,
|
|
||||||
.Xr syslog.conf 5
|
|
||||||
.Sh HISTORY
|
|
||||||
The
|
|
||||||
.Nm
|
|
||||||
command was written for FreeBSD 4.3 but is not yet part of a BSD distribution.
|
|
||||||
|
|
@ -1,226 +0,0 @@
|
||||||
/*-
|
|
||||||
* Copyright (c) 2001
|
|
||||||
* Jeff Wheelhouse (jdw@wwwi.com)
|
|
||||||
*
|
|
||||||
* This code was originally developed by Jeff Wheelhouse (jdw@wwwi.com).
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions
|
|
||||||
* are met:
|
|
||||||
* 1. Redistribution of source code must retail the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY JEFF WHEELHOUSE ``AS IS'' AND ANY EXPRESS OR
|
|
||||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
||||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
|
||||||
* NO EVENT SHALL JEFF WHEELHOUSE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
||||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
||||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
||||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
||||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* $Id$
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <poll.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include <sys/mman.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/sched.h>
|
|
||||||
#include <sys/uio.h>
|
|
||||||
|
|
||||||
|
|
||||||
#include "clog.h"
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* The BUFFER_SIZE value is just used to allocate a buffer full of NULLs
|
|
||||||
* so that a new logfile can be extended to its full size.
|
|
||||||
*
|
|
||||||
* Compiling with -pedantic complains when the buffer array is declared
|
|
||||||
* if I declare this as a const instead of a #define.
|
|
||||||
*/
|
|
||||||
#define BUFFER_SIZE 16384
|
|
||||||
|
|
||||||
void init_log __P((const char *lname, size_t size));
|
|
||||||
void read_log __P((const char *lname, int optf));
|
|
||||||
void usage __P((void));
|
|
||||||
|
|
||||||
const char *pname;
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
|
||||||
int ch;
|
|
||||||
int init = 0;
|
|
||||||
int size = 0;
|
|
||||||
int optf = 0;
|
|
||||||
|
|
||||||
pname = argv[0];
|
|
||||||
|
|
||||||
while ((ch = getopt(argc, argv, "fis:")) != -1)
|
|
||||||
switch(ch) {
|
|
||||||
case 'i':
|
|
||||||
init = 1;
|
|
||||||
break;
|
|
||||||
case 's':
|
|
||||||
size = atol(optarg);
|
|
||||||
if (size==0) usage();
|
|
||||||
break;
|
|
||||||
case 'f':
|
|
||||||
optf = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((size>0)&&(init==0)) {
|
|
||||||
fprintf(stderr,"%s: WARNING: -s argument ignored without -i.\n",pname);
|
|
||||||
size = 0;
|
|
||||||
}
|
|
||||||
if (argv[optind]==NULL) {
|
|
||||||
fprintf(stderr,"%s: ERROR: log_file argument must be specified.\n",pname);
|
|
||||||
usage();
|
|
||||||
}
|
|
||||||
if ((init==1)&&(size==0)) {
|
|
||||||
fprintf(stderr,"%s: ERROR: -i argument requires -s.\n",pname);
|
|
||||||
usage();
|
|
||||||
}
|
|
||||||
if ((init==1)&&(optf==1)) {
|
|
||||||
fprintf(stderr,"%s: ERROR: flags -f and -i are incompatible.\n",pname);
|
|
||||||
usage();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (init==1) init_log(argv[optind],size);
|
|
||||||
/* if (optf==1) follow_log(artv[optind]); */
|
|
||||||
read_log(argv[optind],optf);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void usage() {
|
|
||||||
fprintf(stderr,"usage: %s [-i -s log_size] [ -f ] log_file\n",pname);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void read_log(const char *lname, int optf) {
|
|
||||||
int fd;
|
|
||||||
struct stat sb;
|
|
||||||
struct clog_footer *pcf;
|
|
||||||
char *pbuffer;
|
|
||||||
struct iovec iov[2];
|
|
||||||
int iovcnt = 0;
|
|
||||||
uint32_t start = 0;
|
|
||||||
uint32_t next;
|
|
||||||
struct pollfd pfd;
|
|
||||||
|
|
||||||
pfd.fd = -1;
|
|
||||||
|
|
||||||
fd = open(lname,O_RDONLY);
|
|
||||||
if (fd==-1) {
|
|
||||||
fprintf(stderr,"%s: ERROR: could not open %s (%s)\n",pname,lname,strerror(errno));
|
|
||||||
exit(11);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fstat(fd,&sb)==-1) {
|
|
||||||
fprintf(stderr,"%s: ERROR: could not stat %s (%s)\n",pname,lname,strerror(errno));
|
|
||||||
exit(13);
|
|
||||||
}
|
|
||||||
pbuffer = mmap(NULL,sb.st_size,PROT_READ,MAP_SHARED,fd,0);
|
|
||||||
if (pbuffer==NULL) {
|
|
||||||
fprintf(stderr,"%s: ERROR: could not mmap %s body (%s)\n",pname,lname,strerror(errno));
|
|
||||||
exit(14);
|
|
||||||
}
|
|
||||||
pcf = (struct clog_footer*)(pbuffer + sb.st_size - sizeof(struct clog_footer));
|
|
||||||
|
|
||||||
if (pcf->cf_wrap==1) start = pcf->cf_next + 1;
|
|
||||||
while(1) {
|
|
||||||
while(pcf->cf_lock==1) sched_yield();
|
|
||||||
next = pcf->cf_next;
|
|
||||||
iovcnt = 0;
|
|
||||||
if (start>next) {
|
|
||||||
iov[iovcnt].iov_base = pbuffer + start;
|
|
||||||
iov[iovcnt++].iov_len = pcf->cf_max - start;
|
|
||||||
start = 0;
|
|
||||||
}
|
|
||||||
iov[iovcnt].iov_base = pbuffer + start;
|
|
||||||
iov[iovcnt++].iov_len = next - start;
|
|
||||||
if (writev(1,iov,iovcnt)==-1) {
|
|
||||||
fprintf(stderr,"%s: ERROR: could not write output (%s)\n",pname,strerror(errno));
|
|
||||||
exit(15);
|
|
||||||
}
|
|
||||||
start = next;
|
|
||||||
if (optf==0) break;
|
|
||||||
if (poll(&pfd,1,50)==-1) {
|
|
||||||
fprintf(stderr,"%s: ERROR: could not poll (%s)\n",pname,strerror(errno));
|
|
||||||
exit(16);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
(void)munmap(pbuffer,sb.st_size);
|
|
||||||
(void)close(fd);
|
|
||||||
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void init_log(const char *lname, size_t size) {
|
|
||||||
int fd;
|
|
||||||
size_t fill = size;
|
|
||||||
char buffer[BUFFER_SIZE];
|
|
||||||
struct clog_footer cf;
|
|
||||||
|
|
||||||
memset(&cf, 0, sizeof(cf));
|
|
||||||
memcpy(&cf.cf_magic,MAGIC_CONST,4);
|
|
||||||
cf.cf_max = size - sizeof(struct clog_footer);
|
|
||||||
|
|
||||||
(void)memset(buffer,0,BUFFER_SIZE);
|
|
||||||
|
|
||||||
fd = open(lname,O_RDWR|O_CREAT,0666);
|
|
||||||
if (fd==-1) {
|
|
||||||
fprintf(stderr,"%s: ERROR: could not open %s (%s)\n",pname,lname,strerror(errno));
|
|
||||||
exit(2);
|
|
||||||
}
|
|
||||||
if (ftruncate(fd,(off_t)0)==-1) {
|
|
||||||
fprintf(stderr,"%s: ERROR: could not truncate %s (%s)\n",pname,lname,strerror(errno));
|
|
||||||
exit(3);
|
|
||||||
}
|
|
||||||
|
|
||||||
while(fill>BUFFER_SIZE) {
|
|
||||||
if (write(fd,buffer,BUFFER_SIZE)==-1){
|
|
||||||
fprintf(stderr,"%s: ERROR: could not write %s (%s)\n",pname,lname,strerror(errno));
|
|
||||||
exit(4);
|
|
||||||
}
|
|
||||||
fill -= BUFFER_SIZE;
|
|
||||||
}
|
|
||||||
assert(fill<=BUFFER_SIZE);
|
|
||||||
if (fill>0) {
|
|
||||||
if (write(fd,buffer,fill)==-1) {
|
|
||||||
fprintf(stderr,"%s: ERROR: could not write %s (%s)\n",pname,lname,strerror(errno));
|
|
||||||
exit(5);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (lseek(fd,-(off_t)(sizeof(struct clog_footer)),SEEK_END)==-1) {
|
|
||||||
fprintf(stderr,"%s: ERROR: could not seek in %s (%s)\n",pname,lname,strerror(errno));
|
|
||||||
exit(6);
|
|
||||||
}
|
|
||||||
if (write(fd,&cf,sizeof(cf))==-1) {
|
|
||||||
fprintf(stderr,"%s: ERROR: could not write magic in %s (%s)\n",pname,lname,strerror(errno));
|
|
||||||
exit(7);
|
|
||||||
}
|
|
||||||
(void)close(fd);
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,53 +0,0 @@
|
||||||
/*-
|
|
||||||
* Copyright (c) 2001
|
|
||||||
* Jeff Wheelhouse (jdw@wwwi.com)
|
|
||||||
*
|
|
||||||
* This code was originally developed by Jeff Wheelhouse (jdw@wwwi.com).
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions
|
|
||||||
* are met:
|
|
||||||
* 1. Redistribution of source code must retail the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY JEFF WHEELHOUSE ``AS IS'' AND ANY EXPRESS OR
|
|
||||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
||||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
|
||||||
* NO EVENT SHALL JEFF WHEELHOUSE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
||||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
||||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
||||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
||||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* $Id$
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef _CLOG_H_
|
|
||||||
#define _CLOG_H_
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This magic constant is used to identify a valid circular log file.
|
|
||||||
* syslogd will ignore any circular log file that doesn't have this constant.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const char MAGIC_CONST[4] = "CLOG";
|
|
||||||
|
|
||||||
|
|
||||||
struct clog_footer {
|
|
||||||
uint32_t cf_magic;
|
|
||||||
uint32_t cf_wrap;
|
|
||||||
uint32_t cf_next;
|
|
||||||
uint32_t cf_max;
|
|
||||||
uint32_t cf_lock;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* _CLOG_H_ */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
Circular log support for FreeBSD syslogd
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
include/clog.h
|
|
||||||
man/man8/clog.8.gz
|
|
||||||
sbin/clog
|
|
||||||
Loading…
Add table
Reference in a new issue