[syslog-ng]BSDi strptime function ?

jon@dumbo.pobox.com jon@dumbo.pobox.com
Wed, 6 Dec 2000 13:11:27 -0500


it doesn't want to compile on my box.  i did the following.
(already did a make && make install of libol)
su-2.02# tar xvf tars/syslog-ng-1.5.0.tar
su-2.02# cd syslog-ng-1.5.0/
su-2.02# ./configure
su-2.02# gmake -- this uses gnu make

i get a lot of stuff..then this:
gcc  -O2 -Wall -I/usr/local/include/libol -D_GNU_SOURCE  -o syslog-ng  main.o sources.o center.o filters.o destinations.o log.o cfgfile.o cfg-grammar.o cfg-lex.o affile.o afsocket.o afunix.o afinet.o afinter.o afuser.o afstreams.o afprogram.o utils.o sysl
log.o: In function `parse_log_msg':
log.o(.text+0x130): undefined reference to `strptime'
gmake[3]: *** [syslog-ng] Error 1
gmake[3]: Leaving directory `/usr/src/syslog-ng-1.5.0/src'
gmake[2]: *** [all-recursive] Error 1
gmake[2]: Leaving directory `/usr

syslog_ng_OBJECTS =  main.o sources.o center.o filters.o destinations.o \
log.o cfgfile.o cfg-grammar.o cfg-lex.o affile.o afsocket.o afunix.o \
afinet.o afinter.o afuser.o afstreams.o afprogram.o utils.o \
syslog-names.o strptime.o

even then, it complains about not having config.h and strptime.h
gcc -DHAVE_CONFIG_H -I. -I/usr/src/syslog-ng-1.5.0/src -I.     -O2 -Wall -I/usr/local/include/libol -D_GNU_SOURCE -c strptime.c
strptime.c:32: strptime.h: No such file or directory
*** Error code 1


On Wed, Dec 06, 2000 at 12:46:45PM +0100, Balazs Scheidler wrote:
| > Wanted to know if anyone on this list had any success with a function to
| > replace strptime() function for BSDi ? Any inputs (pros and cons) regarding
| > working with syslog-ng on BSDi systems are most welcome.
| 
| attached you'll find a patch against syslog-ng 1.5.0 with a replacement
| strptime function added. Please check out if it works. (you'll need autoconf
| & automake to regenerate the makefiles, if you don't have them I may send
| you a full tarball in private) 
| 
| It's not tested at all, but it does compile.
| 
| diff -urN syslog-ng-1.5.0/ChangeLog syslog-ng-1.5.1/ChangeLog
| --- syslog-ng-1.5.0/ChangeLog	Wed Nov 29 12:54:33 2000
| +++ syslog-ng-1.5.1/ChangeLog	Wed Dec  6 12:42:17 2000
| @@ -1,3 +1,8 @@
| +2000-12-06  Balazs Scheidler  <bazsi@balabit.hu>
| +
| +	* src/strptime.c: new file for systems lacking an strptime()
| +	function
| +
|  2000-11-29  Balazs Scheidler  <bazsi@balabit.hu>
|  
|  	* src/center.c (do_distribute_log): evaluate DEFAULT filters in
| diff -urN syslog-ng-1.5.0/configure.in syslog-ng-1.5.1/configure.in
| --- syslog-ng-1.5.0/configure.in	Wed Nov 29 12:38:13 2000
| +++ syslog-ng-1.5.1/configure.in	Wed Dec  6 12:42:24 2000
| @@ -2,7 +2,7 @@
|  dnl Process this file with autoconf to produce a configure script.
|  AC_INIT(src/affile.c)
|  
| -AM_INIT_AUTOMAKE(syslog-ng, "1.5.0")
| +AM_INIT_AUTOMAKE(syslog-ng, "1.5.1")
|  LIBOL_REQ_MAJOR=0
|  LIBOL_REQ_MINOR=2
|  LIBOL_REQ_PATCH=20
| @@ -99,6 +99,7 @@
|  AC_CHECK_FUNCS(select snprintf vsnprintf strerror inet_aton strncpy getutent)
|  AC_CHECK_FUNC(getopt_long,,[LIBOBJS="getopt.o getopt1.o $LIBOBJS"])
|  AC_CHECK_FUNC(strcasecmp,,[LIBOBJS="strcasecmp.o $LIBOBJS"])
| +AC_CHECK_FUNC(strptime,,[LIBOBJS="strptime.o $LIBOBJS"])
|  
|  if test "x$ac_cv_func_snprintf" = "xno" -o \
|  	"x$ac_cv_func_vsnprintf" = "xno"; then
| diff -urN syslog-ng-1.5.0/src/strptime.c syslog-ng-1.5.1/src/strptime.c
| --- syslog-ng-1.5.0/src/strptime.c	Thu Jan  1 01:00:00 1970
| +++ syslog-ng-1.5.1/src/strptime.c	Wed Dec  6 12:41:28 2000
| @@ -0,0 +1,304 @@
| +
| +/***************************************************************
| + * STRPTIME.C -- strptime() for IRIX                           *
| + *            -- Michael Jennings                              *
| + *            -- 2 April 1997                                  *
| + ***************************************************************/
| +/*
| + * This file is original work by Michael Jennings <mej@eterm.org>.
| + *
| + * Copyright (C) 1997, Michael Jennings
| + *
| + * This program is free software; you can redistribute it and/or modify
| + * it under the terms of the GNU General Public License as published by
| + * the Free Software Foundation; either version 2 of the License, or
| + * (at your option) any later version.
| + * 
| + * This program is distributed in the hope that it will be useful,
| + * but WITHOUT ANY WARRANTY; without even the implied warranty of
| + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
| + * GNU General Public License for more details.
| + * 
| + * You should have received a copy of the GNU General Public License
| + * along with this program; if not, write to the Free Software
| + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
| + * 
| + */
| +
| +static const char cvs_ident[] = "$Id: strptime.c,v 1.1.1.1.2.1 1999/08/18 23:54:23 mej Exp $";
| +
| +#include <config.h>
| +
| +#include "strptime.h"
| +
| +#include <stdio.h>
| +#include <string.h>
| +#include <ctype.h>
| +
| +#define sizeofone(s)      (sizeof(s) / sizeof((s)[0]))
| +
| +#define NUM_MONTHS     12
| +#define NUM_DAYS        7
| +
| +typedef struct dtmap_struct {
| +  char *Months[NUM_MONTHS];
| +  char *MonthsAbbrev[NUM_MONTHS];
| +  char *Days[NUM_DAYS];
| +  char *DaysAbbrev[NUM_DAYS];
| +  char *DateFormat;
| +  char *TimeFormat;
| +  char *DateTimeFormat;
| +  char *LocaleDateFormat;
| +  char *AM;
| +  char *PM;
| +} DTMap;
| +
| +static DTMap USMap = {
| +  { "January", "February", "March", "April",
| +    "May", "June", "July", "August",
| +    "September", "October", "November", "December" },
| +  { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
| +    "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" },
| +  { "Sunday", "Monday", "Tuesday", "Wednesday",
| +    "Thursday", "Friday", "Saturday" },
| +  { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" },
| +  "%m/%d/%y",
| +  "%H:%M:%S",
| +  "%a %b %e %T %Z %Y",
| +  "%A, %B, %e, %Y",
| +  "AM",
| +  "PM"
| +};
| +
| +char *
| +strptime(const char *buf, const char *format, struct tm *tm)
| +{
| +
| +  register char c;
| +  register const char *tmp;
| +  register int i, len;
| +
| +  for (tmp = format; *tmp;) {
| +    if (!(*buf))
| +      break;
| +
| +    if ((c = *tmp++) != '%') {
| +      if (!isspace(*buf) && c != *buf++)
| +	return ((char *) NULL);
| +      for (; *buf != 0 && isspace(*buf); buf++);
| +      continue;
| +    }
| +    switch ((c = *tmp++)) {
| +      case 0:
| +      case '%':
| +	if (*buf++ != '%')
| +	  return ((char *) NULL);
| +	break;
| +
| +      case 'C':
| +	buf = strptime(buf, USMap.LocaleDateFormat, tm);
| +	if (!buf)
| +	  return ((char *) NULL);
| +	break;
| +
| +      case 'c':
| +	buf = strptime(buf, "%x %X", tm);
| +	if (!buf)
| +	  return ((char *) NULL);
| +	break;
| +
| +      case 'D':
| +	buf = strptime(buf, "%m/%d/%y", tm);
| +	if (!buf)
| +	  return ((char *) NULL);
| +	break;
| +
| +      case 'R':
| +	buf = strptime(buf, "%H:%M", tm);
| +	if (!buf)
| +	  return ((char *) NULL);
| +	break;
| +
| +      case 'r':
| +	buf = strptime(buf, "%I:%M:%S %p", tm);
| +	if (!buf)
| +	  return ((char *) NULL);
| +	break;
| +
| +      case 'T':
| +	buf = strptime(buf, "%H:%M:%S", tm);
| +	if (!buf)
| +	  return ((char *) NULL);
| +	break;
| +
| +      case 'X':
| +	buf = strptime(buf, USMap.TimeFormat, tm);
| +	if (!buf)
| +	  return ((char *) NULL);
| +	break;
| +
| +      case 'x':
| +	buf = strptime(buf, USMap.DateFormat, tm);
| +	if (!buf)
| +	  return ((char *) NULL);
| +	break;
| +
| +      case 'j':
| +	if (!isdigit(*buf))
| +	  return ((char *) NULL);
| +	for (i = 0; *buf != 0 && isdigit(*buf); buf++) {
| +	  i *= 10;
| +	  i += *buf - '0';
| +	}
| +	if (i > 365)
| +	  return ((char *) NULL);
| +	tm->tm_yday = i;
| +	break;
| +
| +      case 'M':
| +      case 'S':
| +	if (!(*buf) || isspace(*buf))
| +	  break;
| +	if (!isdigit(*buf))
| +	  return ((char *) NULL);
| +	for (i = 0; *buf != 0 && isdigit(*buf); buf++) {
| +	  i *= 10;
| +	  i += *buf - '0';
| +	}
| +	if (i > 59)
| +	  return ((char *) NULL);
| +	if (c == 'M')
| +	  tm->tm_min = i;
| +	else
| +	  tm->tm_sec = i;
| +
| +	if (*buf && isspace(*buf))
| +	  for (; *tmp && !isspace(*tmp); tmp++);
| +	break;
| +
| +      case 'H':
| +      case 'I':
| +      case 'k':
| +      case 'l':
| +	if (!isdigit(*buf))
| +	  return ((char *) NULL);
| +	for (i = 0; *buf && isdigit(*buf); buf++) {
| +	  i *= 10;
| +	  i += *buf - '0';
| +	}
| +	if (c == 'H' || c == 'k') {
| +	  if (i > 23)
| +	    return ((char *) NULL);
| +	} else if (i > 11)
| +	  return ((char *) NULL);
| +	tm->tm_hour = i;
| +	if (*buf && isspace(*buf))
| +	  for (; *tmp && !isspace(*tmp); tmp++);
| +	break;
| +
| +      case 'p':
| +	len = strlen(USMap.AM);
| +	if (!strncasecmp(buf, USMap.AM, len)) {
| +	  if (tm->tm_hour > 12)
| +	    return ((char *) NULL);
| +	  if (tm->tm_hour == 12)
| +	    tm->tm_hour = 0;
| +	  buf += len;
| +	  break;
| +	}
| +	len = strlen(USMap.PM);
| +	if (!strncasecmp(buf, USMap.PM, len)) {
| +	  if (tm->tm_hour > 12)
| +	    return ((char *) NULL);
| +	  if (tm->tm_hour != 12)
| +	    tm->tm_hour += 12;
| +	  buf += len;
| +	  break;
| +	}
| +	return ((char *) NULL);
| +
| +      case 'A':
| +      case 'a':
| +	for (i = 0; i < NUM_DAYS; i++) {
| +	  len = strlen(USMap.Days[i]);
| +	  if (!strncasecmp(buf, USMap.Days[i], len))
| +	    break;
| +	  len = strlen(USMap.DaysAbbrev[i]);
| +	  if (!strncasecmp(buf, USMap.DaysAbbrev[i], len))
| +	    break;
| +	}
| +	if (i == NUM_DAYS)
| +	  return ((char *) NULL);
| +	tm->tm_wday = i;
| +	buf += len;
| +	break;
| +
| +      case 'd':
| +      case 'e':
| +	if (!isdigit(*buf))
| +	  return ((char *) NULL);
| +	for (i = 0; *buf && isdigit(*buf); buf++) {
| +	  i *= 10;
| +	  i += *buf - '0';
| +	}
| +	if (i > 31)
| +	  return ((char *) NULL);
| +	tm->tm_mday = i;
| +	if (*buf && isspace(*buf))
| +	  for (; *tmp && !isspace(*tmp); tmp++);
| +	break;
| +
| +      case 'B':
| +      case 'b':
| +      case 'h':
| +	for (i = 0; i < NUM_MONTHS; i++) {
| +	  len = strlen(USMap.Months[i]);
| +	  if (!strncasecmp(buf, USMap.Months[i], len))
| +	    break;
| +	  len = strlen(USMap.MonthsAbbrev[i]);
| +	  if (!strncasecmp(buf, USMap.MonthsAbbrev[i], len))
| +	    break;
| +	}
| +	if (i == NUM_MONTHS)
| +	  return ((char *) NULL);
| +	tm->tm_mon = i;
| +	buf += len;
| +	break;
| +
| +      case 'm':
| +	if (!isdigit(*buf))
| +	  return ((char *) NULL);
| +	for (i = 0; *buf && isdigit(*buf); buf++) {
| +	  i *= 10;
| +	  i += *buf - '0';
| +	}
| +	if (i < 1 || i > 12)
| +	  return ((char *) NULL);
| +	tm->tm_mon = i - 1;
| +	if (*buf && isspace(*buf))
| +	  for (; *tmp && !isspace(*tmp); tmp++);
| +	break;
| +
| +      case 'Y':
| +      case 'y':
| +	if (!(*buf) || isspace(*buf))
| +	  break;
| +	if (!isdigit(*buf))
| +	  return ((char *) NULL);
| +	for (i = 0; *buf && isdigit(*buf); buf++) {
| +	  i *= 10;
| +	  i += *buf - '0';
| +	}
| +	if (c == 'Y')
| +	  i -= 1900;
| +	if (i < 0)
| +	  return ((char *) NULL);
| +	tm->tm_year = i;
| +	if (*buf && isspace(*buf))
| +	  for (; *tmp && !isspace(*tmp); tmp++);
| +	break;
| +    }
| +  }
| +  return (char *) (buf);
| +}
| +
| diff -urN syslog-ng-1.5.0/syslog-ng.spec syslog-ng-1.5.1/syslog-ng.spec
| --- syslog-ng-1.5.0/syslog-ng.spec	Wed Nov 29 12:49:40 2000
| +++ syslog-ng-1.5.1/syslog-ng.spec	Wed Dec  6 12:42:30 2000
| @@ -1,5 +1,5 @@
|  %define name syslog-ng
| -%define version 1.5.0
| +%define version 1.5.1
|  %define release 0
|  %define prefix /usr
|  
| 
| 
| -- 
| Bazsi
| PGP info: KeyID 9AF8D0A9 Fingerprint CD27 CFB0 802C 0944 9CFD 804E C82C 8EB1
|      url: http://www.balabit.hu/pgpkey.txt
| 
| _______________________________________________
| syslog-ng maillist  -  syslog-ng@lists.balabit.hu
| https://lists.balabit.hu/mailman/listinfo/syslog-ng