diff options
author | gshapiro <gshapiro@FreeBSD.org> | 2006-03-22 16:40:03 +0000 |
---|---|---|
committer | gshapiro <gshapiro@FreeBSD.org> | 2006-03-22 16:40:03 +0000 |
commit | ef9770707c0f88e94a0c4a409f8fb74cea250716 (patch) | |
tree | f3bd1c133ce6e698fd2ff3c0280c7103bfac7af3 /contrib/sendmail/libsm | |
parent | 3f99651e549f30e601bcde5ce7907ee58c365442 (diff) | |
download | FreeBSD-src-ef9770707c0f88e94a0c4a409f8fb74cea250716.zip FreeBSD-src-ef9770707c0f88e94a0c4a409f8fb74cea250716.tar.gz |
Import sendmail 8.13.6
Security: FreeBSD-SA-06:13.sendmail
Diffstat (limited to 'contrib/sendmail/libsm')
24 files changed, 527 insertions, 97 deletions
diff --git a/contrib/sendmail/libsm/Makefile.m4 b/contrib/sendmail/libsm/Makefile.m4 index a77afea..1bd3cab 100644 --- a/contrib/sendmail/libsm/Makefile.m4 +++ b/contrib/sendmail/libsm/Makefile.m4 @@ -1,11 +1,11 @@ -dnl $Id: Makefile.m4,v 1.68 2005/02/17 23:34:25 ca Exp $ +dnl $Id: Makefile.m4,v 1.70 2005/12/22 18:31:11 ca Exp $ define(`confREQUIRE_LIBUNIX') include(confBUILDTOOLSDIR`/M4/switch.m4') define(`confREQUIRE_LIBSM', `true') PREPENDDEF(`confENVDEF', `confMAPDEF') bldPRODUCT_START(`library', `libsm') -define(`bldSOURCES', ` assert.c debug.c errstring.c exc.c heap.c match.c rpool.c strdup.c strerror.c strl.c clrerr.c fclose.c feof.c ferror.c fflush.c fget.c fpos.c findfp.c flags.c fopen.c fprintf.c fpurge.c fput.c fread.c fscanf.c fseek.c fvwrite.c fwalk.c fwrite.c get.c makebuf.c put.c refill.c rewind.c setvbuf.c smstdio.c snprintf.c sscanf.c stdio.c strio.c ungetc.c vasprintf.c vfprintf.c vfscanf.c vprintf.c vsnprintf.c wbuf.c wsetup.c string.c stringf.c xtrap.c strto.c test.c path.c strcasecmp.c strrevcmp.c signal.c clock.c config.c shm.c sem.c mbdb.c strexit.c cf.c ldap.c niprop.c mpeix.c ') +define(`bldSOURCES', ` assert.c debug.c errstring.c exc.c heap.c match.c rpool.c strdup.c strerror.c strl.c clrerr.c fclose.c feof.c ferror.c fflush.c fget.c fpos.c findfp.c flags.c fopen.c fprintf.c fpurge.c fput.c fread.c fscanf.c fseek.c fvwrite.c fwalk.c fwrite.c get.c makebuf.c put.c refill.c rewind.c setvbuf.c smstdio.c snprintf.c sscanf.c stdio.c strio.c ungetc.c vasprintf.c vfprintf.c vfscanf.c vprintf.c vsnprintf.c wbuf.c wsetup.c string.c stringf.c xtrap.c strto.c test.c path.c strcasecmp.c strrevcmp.c signal.c clock.c config.c shm.c sem.c mbdb.c strexit.c cf.c ldap.c niprop.c mpeix.c memstat.c ') bldPRODUCT_END dnl msg.c dnl syslogio.c @@ -33,5 +33,6 @@ smtest(`t-cf') smtest(`b-strcmp') dnl SM_CONF_STRL cannot be turned off dnl smtest(`b-strl') +smtest(`t-memstat') bldFINISH diff --git a/contrib/sendmail/libsm/b-strcmp.c b/contrib/sendmail/libsm/b-strcmp.c index e6d0bb0..c7dcb88 100644 --- a/contrib/sendmail/libsm/b-strcmp.c +++ b/contrib/sendmail/libsm/b-strcmp.c @@ -8,12 +8,12 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: b-strcmp.c,v 1.13 2004/08/03 20:07:59 ca Exp $") +SM_RCSID("@(#)$Id: b-strcmp.c,v 1.14 2005/06/14 23:07:20 ca Exp $") #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> -#include <sys/time.h> +#include <sm/time.h> #include <sm/string.h> #define toseconds(x, y) (x.tv_sec - y.tv_sec) diff --git a/contrib/sendmail/libsm/b-strl.c b/contrib/sendmail/libsm/b-strl.c index a696154..e0bc24e 100644 --- a/contrib/sendmail/libsm/b-strl.c +++ b/contrib/sendmail/libsm/b-strl.c @@ -19,12 +19,12 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: b-strl.c,v 1.24 2001/09/11 04:04:47 gshapiro Exp $") +SM_RCSID("@(#)$Id: b-strl.c,v 1.25 2005/06/14 23:07:20 ca Exp $") #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> -#include <sys/time.h> +#include <sm/time.h> #include <sm/string.h> #define SRC_SIZE 512 diff --git a/contrib/sendmail/libsm/clock.c b/contrib/sendmail/libsm/clock.c index c09b2d1..1bdb4fd 100644 --- a/contrib/sendmail/libsm/clock.c +++ b/contrib/sendmail/libsm/clock.c @@ -12,12 +12,12 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: clock.c,v 1.46 2004/08/03 19:57:22 ca Exp $") +SM_RCSID("@(#)$Id: clock.c,v 1.47 2005/06/14 23:07:20 ca Exp $") #include <unistd.h> #include <time.h> #include <errno.h> #if SM_CONF_SETITIMER -# include <sys/time.h> +# include <sm/time.h> #endif /* SM_CONF_SETITIMER */ #include <sm/heap.h> #include <sm/debug.h> diff --git a/contrib/sendmail/libsm/fclose.c b/contrib/sendmail/libsm/fclose.c index 1a469fb..82a7de4 100644 --- a/contrib/sendmail/libsm/fclose.c +++ b/contrib/sendmail/libsm/fclose.c @@ -13,10 +13,10 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: fclose.c,v 1.43 2004/08/03 20:17:38 ca Exp $") +SM_RCSID("@(#)$Id: fclose.c,v 1.44 2005/06/14 23:07:20 ca Exp $") #include <errno.h> #include <stdlib.h> -#include <sys/time.h> +#include <sm/time.h> #include <setjmp.h> #include <sm/io.h> #include <sm/assert.h> diff --git a/contrib/sendmail/libsm/fflush.c b/contrib/sendmail/libsm/fflush.c index 83b318e..19159e2 100644 --- a/contrib/sendmail/libsm/fflush.c +++ b/contrib/sendmail/libsm/fflush.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers. + * Copyright (c) 2000-2001, 2005, 2006 Sendmail, Inc. and its suppliers. * All rights reserved. * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -13,10 +13,10 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: fflush.c,v 1.43 2001/09/11 04:04:48 gshapiro Exp $") +SM_RCSID("@(#)$Id: fflush.c,v 1.45 2006/03/03 22:25:00 ca Exp $") #include <unistd.h> #include <errno.h> -#include <sys/time.h> +#include <sm/time.h> #include <signal.h> #include <fcntl.h> #include <string.h> @@ -145,6 +145,7 @@ sm_flush(fp, timeout) return SM_IO_EOF; } SM_IO_WR_TIMEOUT(fp, fd, *timeout); + t = 0; } } return 0; diff --git a/contrib/sendmail/libsm/fopen.c b/contrib/sendmail/libsm/fopen.c index 1737998..f15a15d 100644 --- a/contrib/sendmail/libsm/fopen.c +++ b/contrib/sendmail/libsm/fopen.c @@ -13,10 +13,10 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: fopen.c,v 1.61 2004/08/03 20:17:38 ca Exp $") +SM_RCSID("@(#)$Id: fopen.c,v 1.62 2005/06/14 23:07:20 ca Exp $") #include <errno.h> #include <setjmp.h> -#include <sys/time.h> +#include <sm/time.h> #include <sm/heap.h> #include <sm/signal.h> #include <sm/assert.h> diff --git a/contrib/sendmail/libsm/fpos.c b/contrib/sendmail/libsm/fpos.c index f75496a..4fe22bf 100644 --- a/contrib/sendmail/libsm/fpos.c +++ b/contrib/sendmail/libsm/fpos.c @@ -13,10 +13,10 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: fpos.c,v 1.38 2004/08/03 20:17:38 ca Exp $") +SM_RCSID("@(#)$Id: fpos.c,v 1.39 2005/06/14 23:07:20 ca Exp $") #include <errno.h> #include <setjmp.h> -#include <sys/time.h> +#include <sm/time.h> #include <sm/heap.h> #include <sm/signal.h> #include <sm/clock.h> diff --git a/contrib/sendmail/libsm/fseek.c b/contrib/sendmail/libsm/fseek.c index e85d41a..4b3fe10 100644 --- a/contrib/sendmail/libsm/fseek.c +++ b/contrib/sendmail/libsm/fseek.c @@ -13,14 +13,14 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: fseek.c,v 1.46 2004/08/03 20:17:38 ca Exp $") +SM_RCSID("@(#)$Id: fseek.c,v 1.47 2005/06/14 23:07:20 ca Exp $") #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdlib.h> #include <errno.h> #include <setjmp.h> -#include <sys/time.h> +#include <sm/time.h> #include <sm/signal.h> #include <sm/io.h> #include <sm/assert.h> diff --git a/contrib/sendmail/libsm/ldap.c b/contrib/sendmail/libsm/ldap.c index 3af7ffa..76e91b3 100644 --- a/contrib/sendmail/libsm/ldap.c +++ b/contrib/sendmail/libsm/ldap.c @@ -8,7 +8,7 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: ldap.c,v 1.62 2005/02/24 00:30:01 ca Exp $") +SM_RCSID("@(#)$Id: ldap.c,v 1.67 2005/12/14 00:08:03 ca Exp $") #if LDAPMAP # include <sys/types.h> @@ -47,6 +47,18 @@ static SM_LDAP_RECURSE_ENTRY *sm_ldap_add_recurse __P((SM_LDAP_RECURSE_LIST **, ** */ +#if _FFR_LDAP_VERSION +# if defined(LDAP_VERSION_MAX) && _FFR_LDAP_VERSION > LDAP_VERSION_MAX + ERROR FFR_LDAP_VERSION > _LDAP_VERSION_MAX +# endif /* defined(LDAP_VERSION_MAX) && _FFR_LDAP_VERSION > LDAP_VERSION_MAX */ +# if defined(LDAP_VERSION_MIN) && _FFR_LDAP_VERSION < LDAP_VERSION_MIN + ERROR FFR_LDAP_VERSION < _LDAP_VERSION_MIN +# endif /* defined(LDAP_VERSION_MIN) && _FFR_LDAP_VERSION < LDAP_VERSION_MIN */ +# define SM_LDAP_VERSION_DEFAULT _FFR_LDAP_VERSION +#else /* _FFR_LDAP_VERSION */ +# define SM_LDAP_VERSION_DEFAULT 0 +#endif /* _FFR_LDAP_VERSION */ + void sm_ldap_clear(lmap) SM_LDAP_STRUCT *lmap; @@ -57,7 +69,7 @@ sm_ldap_clear(lmap) lmap->ldap_host = NULL; lmap->ldap_port = LDAP_PORT; lmap->ldap_uri = NULL; - lmap->ldap_version = 0; + lmap->ldap_version = SM_LDAP_VERSION_DEFAULT; lmap->ldap_deref = LDAP_DEREF_NEVER; lmap->ldap_timelimit = LDAP_NO_LIMIT; lmap->ldap_sizelimit = LDAP_NO_LIMIT; @@ -615,6 +627,16 @@ sm_ldap_results(lmap, msgid, flags, delim, rpool, result, continue; } +#if _FFR_LDAP_SINGLEDN + if (bitset(SM_LDAP_SINGLEDN, flags) && *result != NULL) + { + /* only wanted one match */ + SM_LDAP_ERROR_CLEANUP(); + errno = ENOENT; + return EX_NOTFOUND; + } +#endif /* _FFR_LDAP_SINGLEDN */ + /* record completed DN's to prevent loops */ dn = ldap_get_dn(lmap->ldap_ld, entry); if (dn == NULL) diff --git a/contrib/sendmail/libsm/local.h b/contrib/sendmail/libsm/local.h index 6d64195..7c7798e 100644 --- a/contrib/sendmail/libsm/local.h +++ b/contrib/sendmail/libsm/local.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2002, 2004 Sendmail, Inc. and its suppliers. + * Copyright (c) 2000-2002, 2004-2006 Sendmail, Inc. and its suppliers. * All rights reserved. * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -11,7 +11,7 @@ * forth in the LICENSE file which can be found at the top level of * the sendmail distribution. * - * $Id: local.h,v 1.53 2004/01/09 18:34:22 ca Exp $ + * $Id: local.h,v 1.57 2006/02/28 18:48:25 ca Exp $ */ /* @@ -19,7 +19,7 @@ ** in particular, macros and private variables. */ -#include <sys/time.h> +#include <sm/time.h> #if !SM_CONF_MEMCHR # include <memory.h> #endif /* !SM_CONF_MEMCHR */ @@ -75,42 +75,6 @@ int sm_syslogopen __P((SM_FILE_T *, const void *, int, const void *)); int sm_syslogsetinfo __P((SM_FILE_T *, int , void *)); int sm_sysloggetinfo __P((SM_FILE_T *, int , void *)); -/* should be defined in sys/time.h */ -#ifndef timersub -# define timersub(tvp, uvp, vvp) \ - do \ - { \ - (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ - (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \ - if ((vvp)->tv_usec < 0) \ - { \ - (vvp)->tv_sec--; \ - (vvp)->tv_usec += 1000000; \ - } \ - } while (0) -#endif /* !timersub */ - -#ifndef timeradd -# define timeradd(tvp, uvp, vvp) \ - do \ - { \ - (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \ - (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \ - if ((vvp)->tv_usec >= 1000000) \ - { \ - (vvp)->tv_sec++; \ - (vvp)->tv_usec -= 1000000; \ - } \ - } while (0) -#endif /* !timeradd */ - -#ifndef timercmp -# define timercmp(tvp, uvp, cmp) \ - (((tvp)->tv_sec == (uvp)->tv_sec) ? \ - ((tvp)->tv_usec cmp (uvp)->tv_usec) : \ - ((tvp)->tv_sec cmp (uvp)->tv_sec)) -#endif /* !timercmp */ - extern bool Sm_IO_DidInit; /* Return true iff the given SM_FILE_T cannot be written now. */ @@ -192,7 +156,7 @@ extern const char SmFileMagic[]; else \ { \ (time)->tv_sec = (val) / 1000; \ - (time)->tv_usec = ((val) - ((time)->tv_sec * 1000)) * 10; \ + (time)->tv_usec = ((val) - ((time)->tv_sec * 1000)) * 1000; \ } \ if ((val) == SM_TIME_FOREVER) \ { \ @@ -276,7 +240,7 @@ extern const char SmFileMagic[]; else \ { \ sm_io_to.tv_sec = (to) / 1000; \ - sm_io_to.tv_usec = ((to) - (sm_io_to.tv_sec * 1000)) * 10; \ + sm_io_to.tv_usec = ((to) - (sm_io_to.tv_sec * 1000)) * 1000; \ } \ if (FD_SETSIZE > 0 && (fd) >= FD_SETSIZE) \ { \ @@ -289,8 +253,11 @@ extern const char SmFileMagic[]; FD_SET((fd), &sm_io_x_mask); \ if (gettimeofday(&sm_io_to_before, NULL) < 0) \ return SM_IO_EOF; \ - sm_io_to_sel = select((fd) + 1, NULL, &sm_io_to_mask, &sm_io_x_mask, \ - &sm_io_to); \ + do \ + { \ + sm_io_to_sel = select((fd) + 1, NULL, &sm_io_to_mask, \ + &sm_io_x_mask, &sm_io_to); \ + } while (sm_io_to_sel < 0 && errno == EINTR); \ if (sm_io_to_sel < 0) \ { \ /* something went wrong, errno set */ \ @@ -305,10 +272,9 @@ extern const char SmFileMagic[]; /* else loop again */ \ if (gettimeofday(&sm_io_to_after, NULL) < 0) \ return SM_IO_EOF; \ - timersub(&sm_io_to_before, &sm_io_to_after, &sm_io_to_diff); \ - timersub(&sm_io_to, &sm_io_to_diff, &sm_io_to); \ - (to) -= (sm_io_to.tv_sec * 1000); \ - (to) -= (sm_io_to.tv_usec / 10); \ + timersub(&sm_io_to_after, &sm_io_to_before, &sm_io_to_diff); \ + (to) -= (sm_io_to_diff.tv_sec * 1000); \ + (to) -= (sm_io_to_diff.tv_usec / 1000); \ if ((to) < 0) \ (to) = 0; \ } diff --git a/contrib/sendmail/libsm/memstat.c b/contrib/sendmail/libsm/memstat.c new file mode 100644 index 0000000..6c2a4d1 --- /dev/null +++ b/contrib/sendmail/libsm/memstat.c @@ -0,0 +1,333 @@ +/* + * Copyright (c) 2005 Sendmail, Inc. and its suppliers. + * All rights reserved. + * + * By using this file, you agree to the terms and conditions set + * forth in the LICENSE file which can be found at the top level of + * the sendmail distribution. + */ + +#include <sm/gen.h> +SM_RCSID("@(#)$Id: memstat.c,v 1.4 2005/12/10 00:38:48 ca Exp $") + +#include <errno.h> + +#if USESWAPCTL +#include <sys/stat.h> +#include <sys/swap.h> + +static long sc_page_size; + +/* +** SM_MEMSTAT_OPEN -- open memory statistics +** +** Parameters: +** none +** +** Results: +** errno as error code, 0: ok +*/ + +int +sm_memstat_open() +{ + sc_page_size = sysconf(_SC_PAGE_SIZE); + if (sc_page_size == -1) + return (errno != 0) ? errno : -1; + return 0; +} + +/* +** SM_MEMSTAT_CLOSE -- close memory statistics +** +** Parameters: +** none +** +** Results: +** errno as error code, 0: ok +*/ + +int +sm_memstat_close() +{ + return 0; +} + +/* +** SM_MEMSTAT_GET -- get memory statistics +** +** Parameters: +** resource -- resource to look up +** pvalue -- (pointer to) memory statistics value (output) +** +** Results: +** 0: success +** !=0: error +*/ + +int +sm_memstat_get(resource, pvalue) + char *resource; + long *pvalue; +{ + int r; + struct anoninfo ai; + + r = swapctl(SC_AINFO, &ai); + if (r == -1) + return (errno != 0) ? errno : -1; + r = ai.ani_max - ai.ani_resv; + r *= sc_page_size >> 10; + *pvalue = r; + return 0; +} + +#elif USEKSTAT + +#include <kstat.h> +#include <sys/sysinfo.h> + +static kstat_ctl_t *kc; +static kstat_t *kst; + +/* +** SM_MEMSTAT_OPEN -- open memory statistics +** +** Parameters: +** none +** +** Results: +** errno as error code, 0: ok +*/ + +int +sm_memstat_open() +{ + kstat_named_t *kn; + + kc = kstat_open(); + if (kc == NULL) + return (errno != 0) ? errno : -1; + kst = kstat_lookup(kc, "unix", 0, + (name != NULL) ? name : "system_pages"); + if (kst == 0) + return (errno != 0) ? errno : -2; + return 0; +} + +/* +** SM_MEMSTAT_CLOSE -- close memory statistics +** +** Parameters: +** none +** +** Results: +** errno as error code, 0: ok +*/ + +int +sm_memstat_close() +{ + int r; + + if (kc == NULL) + return 0; + r = kstat_close(kc); + if (r != 0) + return (errno != 0) ? errno : -1; + return 0; +} + +/* +** SM_MEMSTAT_GET -- get memory statistics +** +** Parameters: +** resource -- resource to look up +** pvalue -- (pointer to) memory statistics value (output) +** +** Results: +** 0: success +** !=0: error +*/ + +int +sm_memstat_get(resource, pvalue) + char *resource; + long *pvalue; +{ + int r; + kstat_named_t *kn; + + if (kc == NULL || kst == NULL) + return -1; + if (kstat_read(kc, kst, NULL) == -1) + return (errno != 0) ? errno : -2; + kn = kstat_data_lookup(kst, + (resource != NULL) ? resource: "freemem"); + if (kn == NULL) + return (errno != 0) ? errno : -3; + *pvalue = kn->value.ul; + return 0; +} + +#elif USEPROCMEMINFO + +/* +/proc/meminfo? + total: used: free: shared: buffers: cached: +Mem: 261468160 252149760 9318400 0 3854336 109813760 +Swap: 1052794880 62185472 990609408 +MemTotal: 255340 kB +MemFree: 9100 kB +MemShared: 0 kB +Buffers: 3764 kB +Cached: 107240 kB +Active: 104340 kB +Inact_dirty: 4220 kB +Inact_clean: 2444 kB +Inact_target: 4092 kB +HighTotal: 0 kB +HighFree: 0 kB +LowTotal: 255340 kB +LowFree: 9100 kB +SwapTotal: 1028120 kB +SwapFree: 967392 kB +*/ + +#include <stdio.h> +#include <string.h> +static FILE *fp; + +/* +** SM_MEMSTAT_OPEN -- open memory statistics +** +** Parameters: +** none +** +** Results: +** errno as error code, 0: ok +*/ + +int +sm_memstat_open() +{ + fp = fopen("/proc/meminfo", "r"); + return (fp != NULL) ? 0 : errno; +} + +/* +** SM_MEMSTAT_CLOSE -- close memory statistics +** +** Parameters: +** none +** +** Results: +** errno as error code, 0: ok +*/ + +int +sm_memstat_close() +{ + if (fp != NULL) + { + fclose(fp); + fp = NULL; + } + return 0; +} + +/* +** SM_MEMSTAT_GET -- get memory statistics +** +** Parameters: +** resource -- resource to look up +** pvalue -- (pointer to) memory statistics value (output) +** +** Results: +** 0: success +** !=0: error +*/ + +int +sm_memstat_get(resource, pvalue) + char *resource; + long *pvalue; +{ + int r; + size_t l; + char buf[80]; + + if (resource == NULL) + return EINVAL; + if (pvalue == NULL) + return EINVAL; + if (fp == NULL) + return -1; /* try to reopen? */ + rewind(fp); + l = strlen(resource); + while (fgets(buf, sizeof(buf), fp) != NULL) + { + if (strncmp(buf, resource, l) == 0 && buf[l] == ':') + { + r = sscanf(buf + l + 1, "%ld", pvalue); + return (r > 0) ? 0 : -1; + } + } + return 0; +} + +#else /* USEPROCMEMINFO */ + +/* +** SM_MEMSTAT_OPEN -- open memory statistics +** +** Parameters: +** none +** +** Results: +** errno as error code, 0: ok +*/ + +int +sm_memstat_open() +{ + return -1; +} + +/* +** SM_MEMSTAT_CLOSE -- close memory statistics +** +** Parameters: +** none +** +** Results: +** errno as error code, 0: ok +*/ + +int +sm_memstat_close() +{ + return 0; +} + +/* +** SM_MEMSTAT_GET -- get memory statistics +** +** Parameters: +** resource -- resource to look up +** pvalue -- (pointer to) memory statistics value (output) +** +** Results: +** 0: success +** !=0: error +*/ + +int +sm_memstat_get(resource, pvalue) + char *resource; + long *pvalue; +{ + return -1; +} + +#endif /* USEKSTAT */ diff --git a/contrib/sendmail/libsm/refill.c b/contrib/sendmail/libsm/refill.c index c3db172..eae6ab4 100644 --- a/contrib/sendmail/libsm/refill.c +++ b/contrib/sendmail/libsm/refill.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers. + * Copyright (c) 2000-2001, 2005-2006 Sendmail, Inc. and its suppliers. * All rights reserved. * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -13,13 +13,13 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: refill.c,v 1.50 2002/09/09 21:50:10 gshapiro Exp $") +SM_RCSID("@(#)$Id: refill.c,v 1.53 2006/02/28 18:48:25 ca Exp $") #include <stdlib.h> #include <unistd.h> #include <errno.h> #include <setjmp.h> #include <signal.h> -#include <sys/time.h> +#include <sm/time.h> #include <fcntl.h> #include <string.h> #include <sm/io.h> @@ -76,8 +76,11 @@ static int sm_lflush __P((SM_FILE_T *, int *)); FD_SET((fd), &sm_io_x_mask); \ if (gettimeofday(&sm_io_to_before, NULL) < 0) \ return SM_IO_EOF; \ - (sel_ret) = select((fd) + 1, &sm_io_to_mask, NULL, \ - &sm_io_x_mask, (to)); \ + do \ + { \ + (sel_ret) = select((fd) + 1, &sm_io_to_mask, NULL, \ + &sm_io_x_mask, (to)); \ + } while ((sel_ret) < 0 && errno == EINTR); \ if ((sel_ret) < 0) \ { \ /* something went wrong, errno set */ \ @@ -94,7 +97,7 @@ static int sm_lflush __P((SM_FILE_T *, int *)); /* calulate wall-clock time used */ \ if (gettimeofday(&sm_io_to_after, NULL) < 0) \ return SM_IO_EOF; \ - timersub(&sm_io_to_before, &sm_io_to_after, &sm_io_to_diff); \ + timersub(&sm_io_to_after, &sm_io_to_before, &sm_io_to_diff); \ timersub((to), &sm_io_to_diff, (to)); \ } diff --git a/contrib/sendmail/libsm/sem.c b/contrib/sendmail/libsm/sem.c index a429cf4..89394cb 100644 --- a/contrib/sendmail/libsm/sem.c +++ b/contrib/sendmail/libsm/sem.c @@ -8,13 +8,14 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: sem.c,v 1.12 2005/03/25 21:27:02 ca Exp $") +SM_RCSID("@(#)$Id: sem.c,v 1.13 2005/08/12 20:39:59 ca Exp $") #if SM_CONF_SEM # include <stdlib.h> # include <unistd.h> # include <sm/sem.h> # include <sm/heap.h> +# include <errno.h> /* ** SM_SEM_START -- initialize semaphores @@ -37,7 +38,7 @@ sm_sem_start(key, nsem, semflg, owner) int semflg; bool owner; { - int semid, i; + int semid, i, err; unsigned short *semvals; semvals = NULL; @@ -67,11 +68,12 @@ sm_sem_start(key, nsem, semflg, owner) return semid; error: + err = errno; if (semvals != NULL) sm_free(semvals); if (semid >= 0) sm_sem_stop(semid); - return -1; + return (err > 0) ? (0 - err) : -1; } /* diff --git a/contrib/sendmail/libsm/shm.c b/contrib/sendmail/libsm/shm.c index b68f7c6..15c1119 100644 --- a/contrib/sendmail/libsm/shm.c +++ b/contrib/sendmail/libsm/shm.c @@ -8,12 +8,13 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: shm.c,v 1.18 2005/02/09 01:54:51 ca Exp $") +SM_RCSID("@(#)$Id: shm.c,v 1.19 2005/07/14 22:34:28 ca Exp $") #if SM_CONF_SHM # include <stdlib.h> # include <unistd.h> # include <errno.h> +# include <sm/string.h> # include <sm/shm.h> diff --git a/contrib/sendmail/libsm/signal.c b/contrib/sendmail/libsm/signal.c index 9061efc..ce2e242 100644 --- a/contrib/sendmail/libsm/signal.c +++ b/contrib/sendmail/libsm/signal.c @@ -8,10 +8,10 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: signal.c,v 1.16 2001/09/11 04:04:49 gshapiro Exp $") +SM_RCSID("@(#)$Id: signal.c,v 1.17 2005/06/14 23:07:20 ca Exp $") #if SM_CONF_SETITIMER -# include <sys/time.h> +# include <sm/time.h> #endif /* SM_CONF_SETITIMER */ #include <errno.h> #include <stdlib.h> diff --git a/contrib/sendmail/libsm/stdio.c b/contrib/sendmail/libsm/stdio.c index 345a62c..5fe8f22 100644 --- a/contrib/sendmail/libsm/stdio.c +++ b/contrib/sendmail/libsm/stdio.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2004 Sendmail, Inc. and its suppliers. + * Copyright (c) 2000-2005 Sendmail, Inc. and its suppliers. * All rights reserved. * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -13,13 +13,13 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: stdio.c,v 1.69 2004/08/03 20:46:34 ca Exp $") +SM_RCSID("@(#)$Id: stdio.c,v 1.71 2005/06/14 23:07:20 ca Exp $") #include <unistd.h> #include <errno.h> #include <fcntl.h> #include <string.h> /* FreeBSD: FD_ZERO needs <string.h> */ #include <sys/stat.h> -#include <sys/time.h> +#include <sm/time.h> #include <sm/heap.h> #include <sm/assert.h> #include <sm/varargs.h> @@ -221,7 +221,7 @@ sm_stdclose(fp) ** Failure: -1 and sets errno */ -int +static int sm_stdsetmode(fp, mode) SM_FILE_T *fp; const int *mode; diff --git a/contrib/sendmail/libsm/strio.c b/contrib/sendmail/libsm/strio.c index 9f1f4af..75f3764 100644 --- a/contrib/sendmail/libsm/strio.c +++ b/contrib/sendmail/libsm/strio.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2002, 2004 Sendmail, Inc. and its suppliers. + * Copyright (c) 2000-2002, 2004, 2005 Sendmail, Inc. and its suppliers. * All rights reserved. * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -13,7 +13,7 @@ */ #include <sm/gen.h> -SM_IDSTR(id, "@(#)$Id: strio.c,v 1.43 2004/08/03 20:48:30 ca Exp $") +SM_IDSTR(id, "@(#)$Id: strio.c,v 1.44 2005/06/09 21:40:19 ca Exp $") #include <stdlib.h> #include <unistd.h> #include <fcntl.h> @@ -359,7 +359,7 @@ sm_strsetmode(fp, mode) ** Failure: -1 and sets errno */ -int +static int sm_strgetmode(fp, mode) SM_FILE_T *fp; int *mode; diff --git a/contrib/sendmail/libsm/t-event.c b/contrib/sendmail/libsm/t-event.c index c6eb82e..1096b36 100644 --- a/contrib/sendmail/libsm/t-event.c +++ b/contrib/sendmail/libsm/t-event.c @@ -8,7 +8,7 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: t-event.c,v 1.12 2004/08/03 20:50:32 ca Exp $") +SM_RCSID("@(#)$Id: t-event.c,v 1.13 2005/06/14 23:07:20 ca Exp $") #include <stdio.h> @@ -16,7 +16,7 @@ SM_RCSID("@(#)$Id: t-event.c,v 1.12 2004/08/03 20:50:32 ca Exp $") #include <unistd.h> # include <sys/wait.h> #if SM_CONF_SETITIMER -# include <sys/time.h> +# include <sm/time.h> #endif /* SM_CONF_SETITIMER */ #include <sm/clock.h> diff --git a/contrib/sendmail/libsm/t-memstat.c b/contrib/sendmail/libsm/t-memstat.c new file mode 100644 index 0000000..6ff766e --- /dev/null +++ b/contrib/sendmail/libsm/t-memstat.c @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2005 Sendmail, Inc. and its suppliers. + * All rights reserved. + * + * By using this file, you agree to the terms and conditions set + * forth in the LICENSE file which can be found at the top level of + * the sendmail distribution. + */ + +#include <sm/gen.h> +SM_IDSTR(id, "@(#)$Id: t-memstat.c,v 1.5 2005/12/22 19:05:42 ca Exp $") + +/* +** Simple test program for memstat +*/ + +#include <stdlib.h> +#include <unistd.h> +#include <stdio.h> +#include <strings.h> + +int +main(argc, argv) + int argc; + char **argv; +{ + int r, r2, i, l, slp, sz; + long v; + char *resource; + + l = 1; + sz = slp = 0; + resource = NULL; + while ((r = getopt(argc, argv, "l:m:r:s:")) != -1) + { + switch ((char) r) + { + case 'l': + l = strtol(optarg, NULL, 0); + break; + + case 'm': + sz = strtol(optarg, NULL, 0); + break; + + case 'r': + resource = strdup(optarg); + break; + + case 's': + slp = strtol(optarg, NULL, 0); + break; + + default: + break; + } + } + + r = sm_memstat_open(); + r2 = -1; + for (i = 0; i < l; i++) + { + char *mem; + + r2 = sm_memstat_get(resource, &v); + if (slp > 0 && i + 1 < l && 0 == r) + { + printf("open=%d, memstat=%d, %s=%ld\n", r, r2, + resource != NULL ? resource : "default-value", + v); + sleep(slp); + if (sz > 0) + { + /* + ** Just allocate some memory to test the + ** values that are returned. + ** Note: this is a memory leak, but that + ** doesn't matter here. + */ + + mem = malloc(sz); + if (NULL == mem) + printf("malloc(%d) failed\n", sz); + } + } + } + printf("open=%d, memstat=%d, %s=%ld\n", r, r2, + resource != NULL ? resource : "default-value", v); + r = sm_memstat_close(); + return r; +} diff --git a/contrib/sendmail/libsm/t-sem.c b/contrib/sendmail/libsm/t-sem.c index 3964327..cba784a 100644 --- a/contrib/sendmail/libsm/t-sem.c +++ b/contrib/sendmail/libsm/t-sem.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers. + * Copyright (c) 2000-2001, 2005-2006 Sendmail, Inc. and its suppliers. * All rights reserved. * * By using this file, you agree to the terms and conditions set @@ -8,7 +8,7 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: t-sem.c,v 1.14 2005/03/25 21:27:41 ca Exp $") +SM_RCSID("@(#)$Id: t-sem.c,v 1.15 2006/03/13 20:40:43 msk Exp $") #include <stdio.h> @@ -307,7 +307,7 @@ main(argc, argv) pid_t pid; printf("This test takes about 8 seconds.\n"); - printf("If it takes longer than 30 second, please interrupt it\n"); + printf("If it takes longer than 30 seconds, please interrupt it\n"); printf("and compile again without semaphore support, i.e.,"); printf("-DSM_CONF_SEM=0\n"); if ((pid = fork()) < 0) diff --git a/contrib/sendmail/libsm/ungetc.c b/contrib/sendmail/libsm/ungetc.c index 289c7be..2f90e14 100644 --- a/contrib/sendmail/libsm/ungetc.c +++ b/contrib/sendmail/libsm/ungetc.c @@ -13,12 +13,12 @@ */ #include <sm/gen.h> -SM_IDSTR(id, "@(#)$Id: ungetc.c,v 1.29 2004/08/03 20:54:49 ca Exp $") +SM_IDSTR(id, "@(#)$Id: ungetc.c,v 1.30 2005/06/14 23:07:20 ca Exp $") #include <stdlib.h> #include <string.h> #include <signal.h> -#include <sys/time.h> +#include <sm/time.h> #include <errno.h> #include <sm/io.h> #include <sm/heap.h> diff --git a/contrib/sendmail/libsm/vfprintf.c b/contrib/sendmail/libsm/vfprintf.c index e77c335..c4ca9bb 100644 --- a/contrib/sendmail/libsm/vfprintf.c +++ b/contrib/sendmail/libsm/vfprintf.c @@ -13,7 +13,7 @@ */ #include <sm/gen.h> -SM_IDSTR(id, "@(#)$Id: vfprintf.c,v 1.53 2004/08/03 20:54:49 ca Exp $") +SM_IDSTR(id, "@(#)$Id: vfprintf.c,v 1.54 2005/05/16 03:52:00 ca Exp $") /* ** Overall: @@ -535,9 +535,19 @@ reswitch: switch (ch) if (prec > 120) prec = 120; if (prec >= 0) +#if HASSNPRINTF + snprintf(out, sizeof(out), fmt, width, + prec, val); +#else /* HASSNPRINTF */ sprintf(out, fmt, width, prec, val); +#endif /* HASSNPRINTF */ else +#if HASSNPRINTF + snprintf(out, sizeof(out), fmt, width, + val); +#else /* HASSNPRINTF */ sprintf(out, fmt, width, val); +#endif /* HASSNPRINTF */ len = strlen(out); PRINT(out, len); FLUSH(); diff --git a/contrib/sendmail/libsm/vfscanf.c b/contrib/sendmail/libsm/vfscanf.c index d7f1a3d..235ee42 100644 --- a/contrib/sendmail/libsm/vfscanf.c +++ b/contrib/sendmail/libsm/vfscanf.c @@ -13,13 +13,13 @@ */ #include <sm/gen.h> -SM_IDSTR(id, "@(#)$Id: vfscanf.c,v 1.52 2004/08/03 20:56:32 ca Exp $") +SM_IDSTR(id, "@(#)$Id: vfscanf.c,v 1.53 2005/06/14 23:07:20 ca Exp $") #include <ctype.h> #include <stdlib.h> #include <errno.h> #include <setjmp.h> -#include <sys/time.h> +#include <sm/time.h> #include <sm/varargs.h> #include <sm/config.h> #include <sm/io.h> |