diff options
author | victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2004-09-05 12:53:52 +0800 |
---|---|---|
committer | victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2004-09-05 12:53:52 +0800 |
commit | 078b255969c6b768f2c85c35a580feadf5774f31 (patch) | |
tree | 2acd396f4b0b07e22d378c33dbd54d4d8f92f81c | |
parent | 24b3e689cf6429d6a09ce8910d6b1735879bfdf4 (diff) | |
parent | dcf78b3ca3ff11ff35ec376bfc3fbff6923e154e (diff) | |
download | pttbbs-078b255969c6b768f2c85c35a580feadf5774f31.tar pttbbs-078b255969c6b768f2c85c35a580feadf5774f31.tar.gz pttbbs-078b255969c6b768f2c85c35a580feadf5774f31.tar.bz2 pttbbs-078b255969c6b768f2c85c35a580feadf5774f31.tar.lz pttbbs-078b255969c6b768f2c85c35a580feadf5774f31.tar.xz pttbbs-078b255969c6b768f2c85c35a580feadf5774f31.tar.zst pttbbs-078b255969c6b768f2c85c35a580feadf5774f31.zip |
remove branch victor.screen
add branch victor.solaris with some modification
git-svn-id: http://opensvn.csie.org/pttbbs/branches/victor.solaris@2180 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | include/bbs.h | 27 | ||||
-rw-r--r-- | include/proto.h | 2 | ||||
-rw-r--r-- | innbbsd/Makefile | 5 | ||||
-rw-r--r-- | innbbsd/port.c | 2 | ||||
-rw-r--r-- | innbbsd/receive_article.c | 23 | ||||
-rw-r--r-- | mbbsd/chc.c | 2 | ||||
-rw-r--r-- | mbbsd/osdep.c | 249 | ||||
-rw-r--r-- | mbbsd/voteboard.c | 6 | ||||
-rw-r--r-- | util/tunepasswd.c | 10 |
9 files changed, 295 insertions, 31 deletions
diff --git a/include/bbs.h b/include/bbs.h index 45ca1292..81ed235e 100644 --- a/include/bbs.h +++ b/include/bbs.h @@ -42,8 +42,8 @@ #include <machine/limits.h> #endif #include <machine/param.h> -#endif -#ifdef __linux__ + +#elif defined(__linux__) #include <sys/param.h> #include <sys/ioctl.h> #include <limits.h> @@ -54,6 +54,29 @@ size_t strlcat(char *dst, const char *src, size_t size); + +#elif defined(Solaris) + +#include <alloca.h> +#include <crypt.h> +#include <sys/param.h> +#include <sys/ioctl.h> +#include <limits.h> +#include <strings.h> /* for strcasecmp() */ + +#define LOCK_EX 1 +#define LOCK_UN 2 + +int flock(int, int); + +void unsetenv(char *name); + +int scandir(const char *dirname, struct dirent ***namelist, int (*select)(struct dirent *), int (*compar)(const void *, const void *)); +int alphasort(const void *d1, const void *d2); + + +#else +#warning "Unknown OSTYPE" #endif /* our header */ diff --git a/include/proto.h b/include/proto.h index 0d66649f..ab56650a 100644 --- a/include/proto.h +++ b/include/proto.h @@ -377,7 +377,7 @@ char *completeutmp_getname(int where); /* osdep */ int cpuload(char *str); double swapused(int *total, int *used); -#ifdef __linux__ +#if defined(__linux__) || defined(Solaris) char *strcasestr(const char *big, const char *little); #endif diff --git a/innbbsd/Makefile b/innbbsd/Makefile index 9bb71f52..672ab705 100644 --- a/innbbsd/Makefile +++ b/innbbsd/Makefile @@ -7,7 +7,8 @@ # ------------------------------------------------------- # # stdarg.h patch for pttbbs by in2 03/05/05 # -OSTYPE!=uname +OS!=uname +OSTYPE?=OS #################################################### # this is a bbs <--> news gateway ##################################################### @@ -93,7 +94,7 @@ irix: @$(MAKE) EXTRAFLAGS="-DMMAP -DIRIX -DSYSV" target solaris: - @$(MAKE) EXTRAFLAGS="-DMMAP -DSOLARIS -DSYSV" LDFLAGS="-lsocket -lnsl" YACC="bison -y" target + @$(MAKE) EXTRAFLAGS="-DMMAP -DSOLARIS -DSYSV -I/usr/local/include/ -I../include/" LDFLAGS="-L/usr/local/lib -liconv -lsocket -lnsl ../mbbsd/osdep.o" YACC="bison -y" target FreeBSD: @$(MAKE) CC=cc EXTRAFLAGS="-DBSD44 -DMMAP -DGETRUSAGE" LDFLAGS="-lcrypt -liconv" target diff --git a/innbbsd/port.c b/innbbsd/port.c index 8962ea14..fab82771 100644 --- a/innbbsd/port.c +++ b/innbbsd/port.c @@ -13,6 +13,7 @@ getdtablesize() } #endif +#if 0 #if defined(SYSV) && !defined(WITH_RECORD_O) #include <fcntl.h> flock(fd, op) @@ -31,3 +32,4 @@ flock(fd, op) return lockf(fd, op, 0L); } #endif +#endif diff --git a/innbbsd/receive_article.c b/innbbsd/receive_article.c index c1d8c274..ba5a647f 100644 --- a/innbbsd/receive_article.c +++ b/innbbsd/receive_article.c @@ -31,6 +31,29 @@ #include "inntobbs.h" #include "antisplam.h" +#ifdef SOLARIS +time_t timegm (struct tm *tm) { + time_t ret; + char *tz; + char buf[256] = "TZ="; + + tz = getenv("TZ"); + putenv("TZ="); + + tzset(); + ret = mktime(tm); + if (tz){ + strcat( buf, tz); + putenv(buf); + } + else + unsetenv("TZ"); + tzset(); + return ret; +} +#endif + + extern int Junkhistory; char *post_article ARG((char *, char *, char *, int (*) (), char *, char *)); diff --git a/mbbsd/chc.c b/mbbsd/chc.c index 5ab93a00..1db17c95 100644 --- a/mbbsd/chc.c +++ b/mbbsd/chc.c @@ -306,7 +306,7 @@ chc_log_step(board_t board, rc_t *from, rc_t *to) } static int -#ifdef __linux__ +#if defined(__linux__) || defined(Solaris) chc_filter(const struct dirent *dir) #else chc_filter(struct dirent *dir) diff --git a/mbbsd/osdep.c b/mbbsd/osdep.c index 7b3fac06..8354b693 100644 --- a/mbbsd/osdep.c +++ b/mbbsd/osdep.c @@ -1,7 +1,7 @@ /* $Id$ */ #include "bbs.h" -#ifdef __linux__ +#if defined(__linux__) #include <sys/types.h> #include <string.h> @@ -139,6 +139,9 @@ size_t strlcpy(dst, src, siz) return(s - src - 1); /* count does not include NUL */ } +#endif + +#if defined(linux) || defined(Solaris) char * strcasestr(const char *big, const char *little) { @@ -156,25 +159,222 @@ strcasestr(const char *big, const char *little) #endif -#if __FreeBSD__ +#ifdef Solaris -#include <kvm.h> +/* + * Scan the directory dirname calling select to make a list of +selected + * directory entries then sort using qsort and compare routine +dcomp. + * Returns the number of entries and a pointer to a list of +pointers to + * struct dirent (through namelist). Returns -1 if there were any +errors. + */ + +#include <sys/types.h> +#include <sys/stat.h> +#include <dirent.h> +#include <stdlib.h> +#include <string.h> + +/* + * The DIRSIZ macro is the minimum record length which will hold +the directory + * entry. This requires the amount of space in struct dirent +without the + * d_name field, plus enough space for the name and a terminating +nul byte + * (dp->d_namlen + 1), rounded up to a 4 byte boundary. + */ +#undef DIRSIZ +#define DIRSIZ(dp) \ + ((sizeof(struct dirent) - sizeof(dp)->d_name) + \ + ((strlen((dp)->d_name) + 1 + 3) &~ 3)) +#if 0 + ((sizeof(struct dirent) - sizeof(dp)->d_name) + \ + (((dp)->d_namlen + 1 + 3) &~ 3)) +#endif int -cpuload(char *str) +scandir(dirname, namelist, select, dcomp) + const char *dirname; + struct dirent ***namelist; + int (*select) (struct dirent *); + int (*dcomp) (const void *, const void *); { - double l[3] = {-1, -1, -1}; - if (getloadavg(l, 3) != 3) - l[0] = -1; + register struct dirent *d, *p, **names; + register size_t nitems; + struct stat stb; + long arraysz; + DIR *dirp; - if (str) { - if (l[0] != -1) - sprintf(str, " %.2f %.2f %.2f", l[0], l[1], l[2]); - else - strcpy(str, " (unknown) "); + if ((dirp = opendir(dirname)) == NULL) + return(-1); + if (fstat(dirp->dd_fd, &stb) < 0) + return(-1); + + /* + * estimate the array size by taking the size of thedirectory file + * and dividing it by a multiple of the minimum sizeentry. + */ + arraysz = (stb.st_size / 24); + names = (struct dirent **)malloc(arraysz * sizeof(struct dirent *)); + if (names == NULL) + return(-1); + + nitems = 0; + while ((d = readdir(dirp)) != NULL) { + if (select != NULL && !(*select)(d)) + continue; /* just selected names */ + /* + * Make a minimum size copy of the data + */ + p = (struct dirent *)malloc(DIRSIZ(d)); + if (p == NULL) + return(-1); + p->d_ino = d->d_ino; + p->d_off = d->d_off; + p->d_reclen = d->d_reclen; + memcpy(p->d_name, d->d_name, strlen(d->d_name) +1); +#if 0 + p->d_fileno = d->d_fileno; + p->d_type = d->d_type; + p->d_reclen = d->d_reclen; + p->d_namlen = d->d_namlen; + bcopy(d->d_name, p->d_name, p->d_namlen + 1); +#endif + /* + * Check to make sure the array has space left and + * realloc the maximum size. + */ + if (++nitems >= arraysz) { + if (fstat(dirp->dd_fd, &stb) < 0) + return(-1); /* just might have grown */ + arraysz = stb.st_size / 12; + names = (struct dirent **)realloc((char*)names, + arraysz * sizeof(struct dirent*)); + if (names == NULL) + return(-1); + } + names[nitems-1] = p; + } + closedir(dirp); + if (nitems && dcomp != NULL) + qsort(names, nitems, sizeof(struct dirent *),dcomp); + *namelist = names; + return(nitems); +} + +/* + * Alphabetic order comparison routine for those who want it. + */ +int +alphasort(d1, d2) + const void *d1; + const void *d2; +{ + return(strcmp((*(struct dirent **)d1)->d_name, + (*(struct dirent **)d2)->d_name)); +} +int +flock (int fd, int f) +{ + if( f == LOCK_EX ) + return lockf(fd, F_LOCK, 0L); + + if( f == LOCK_UN ) + return lockf(fd, F_ULOCK, 0L); + + return -1; +} + +void +unsetenv(name) + char *name; +{ + extern char **environ; + register char **pp; + int len = strlen(name); + + for (pp = environ; *pp != NULL; pp++) + { + if (strncmp(name, *pp, len) == 0 && + ((*pp)[len] == '=' || (*pp)[len] == '\0')) + break; + } + + for (; *pp != NULL; pp++) + *pp = pp[1]; +} + + + + + +#include <sys/stat.h> +#include <sys/swap.h> +#include <sys/loadavg.h> + + +double swapused(int *total, int *used) +{ + double percent = -1; + register int cnt, i; + register int free; + struct swaptable *swt; + struct swapent *ste; + static char path[256]; + cnt = swapctl(SC_GETNSWP, 0); + swt = (struct swaptable *)malloc(sizeof(int) + + cnt * sizeof(struct swapent)); + if (swt == NULL) + { + return 0; } - return (int)l[0]; + swt->swt_n = cnt; + + /* fill in ste_path pointers: we don't care about the paths, so we point + them all to the same buffer */ + ste = &(swt->swt_ent[0]); + i = cnt; + while (--i >= 0) + { + ste++->ste_path = path; + } + /* grab all swap info */ + swapctl(SC_LIST, swt); + + /* walk thru the structs and sum up the fields */ + *total = free = 0; + ste = &(swt->swt_ent[0]); + i = cnt; + while (--i >= 0) + { + /* dont count slots being deleted */ + if (!(ste->ste_flags & ST_INDEL) && + !(ste->ste_flags & ST_DOINGDEL)) + { + *total += ste->ste_pages; + free += ste->ste_free; + } + ste++; + } + + *used = *total - free; + if( total != 0) + percent = (double)*used / (double)*total; + else + percent = 0; + + return percent; } +#endif + +#if __FreeBSD__ + +#include <kvm.h> + double swapused(int *total, int *used) @@ -198,7 +398,28 @@ swapused(int *total, int *used) return percent; } -#else +#endif + +#if _freebsd_ || defined(Solaris) + +int +cpuload(char *str) +{ + double l[3] = {-1, -1, -1}; + if (getloadavg(l, 3) != 3) + l[0] = -1; + + if (str) { + if (l[0] != -1) + sprintf(str, " %.2f %.2f %.2f", l[0], l[1], l[2]); + else + strcpy(str, " (unknown) "); + } + return (int)l[0]; +} +#endif + +#ifdef linux int cpuload(char *str) { diff --git a/mbbsd/voteboard.c b/mbbsd/voteboard.c index ccbe1ef4..b024b671 100644 --- a/mbbsd/voteboard.c +++ b/mbbsd/voteboard.c @@ -85,8 +85,10 @@ do_voteboardreply(fileheader_t * fhdr) } if ((fd = open(oldfpath, O_RDONLY)) == -1) return; - if(flock(fd, LOCK_EX)==-1 ) - {close(fd); return;} + if(flock(fd, LOCK_EX)==-1 ) { + close(fd); + return; + } if(!(fi = fopen(oldfpath, "r"))) {flock(fd, LOCK_UN); close(fd); return;} diff --git a/util/tunepasswd.c b/util/tunepasswd.c index 1d575dcc..b617fb77 100644 --- a/util/tunepasswd.c +++ b/util/tunepasswd.c @@ -1,13 +1,5 @@ /* $Id$ */ -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/file.h> -#include "config.h" -#include "pttstruct.h" -#include "common.h" +#include "bbs.h" int tune(int num) { int i, j, fin, fout; |