summaryrefslogtreecommitdiffstats
path: root/mbbsd
diff options
context:
space:
mode:
authorvictor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-09-05 12:53:52 +0800
committervictor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-09-05 12:53:52 +0800
commit078b255969c6b768f2c85c35a580feadf5774f31 (patch)
tree2acd396f4b0b07e22d378c33dbd54d4d8f92f81c /mbbsd
parent24b3e689cf6429d6a09ce8910d6b1735879bfdf4 (diff)
parentdcf78b3ca3ff11ff35ec376bfc3fbff6923e154e (diff)
downloadpttbbs-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
Diffstat (limited to 'mbbsd')
-rw-r--r--mbbsd/chc.c2
-rw-r--r--mbbsd/osdep.c249
-rw-r--r--mbbsd/voteboard.c6
3 files changed, 240 insertions, 17 deletions
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;}