diff options
author | victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2004-09-10 08:49:47 +0800 |
---|---|---|
committer | victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2004-09-10 08:49:47 +0800 |
commit | 540cfa70e8e8b4db3cc2addccfcbeeb69fffa033 (patch) | |
tree | 6a4dec7d69249e48a6f79c4436eb634cb28744b2 /util/bbsrf.c | |
parent | a8a0ef3c4d10bf576054dc26348d9b4e6efeecc2 (diff) | |
download | pttbbs-540cfa70e8e8b4db3cc2addccfcbeeb69fffa033.tar pttbbs-540cfa70e8e8b4db3cc2addccfcbeeb69fffa033.tar.gz pttbbs-540cfa70e8e8b4db3cc2addccfcbeeb69fffa033.tar.bz2 pttbbs-540cfa70e8e8b4db3cc2addccfcbeeb69fffa033.tar.lz pttbbs-540cfa70e8e8b4db3cc2addccfcbeeb69fffa033.tar.xz pttbbs-540cfa70e8e8b4db3cc2addccfcbeeb69fffa033.tar.zst pttbbs-540cfa70e8e8b4db3cc2addccfcbeeb69fffa033.zip |
merge back from branch victor.solaris
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2189 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'util/bbsrf.c')
-rw-r--r-- | util/bbsrf.c | 75 |
1 files changed, 38 insertions, 37 deletions
diff --git a/util/bbsrf.c b/util/bbsrf.c index c527d761..c3bf44a9 100644 --- a/util/bbsrf.c +++ b/util/bbsrf.c @@ -6,7 +6,6 @@ #include <stdlib.h> #include <sys/param.h> #include <sys/types.h> -#include <utmp.h> #include <pwd.h> #include <syslog.h> #include <fcntl.h> @@ -14,34 +13,56 @@ #include <sys/uio.h> #include "config.h" +#ifdef Solaris + #include <utmpx.h> + #define U_FILE UTMPX_FILE +#else + #include <utmp.h> + #define U_FILE UTMP_FILE +#endif + +#ifdef FreeBSD + #define UTMP_FILE _PATH_UTMP +#endif + +#ifndef Solaris + #if MAXHOSTNAMELEN < UT_HOSTSIZE + #define MAX_HOMENAME_LEN MAXHOSTNAMELEN + #else + #define MAX_HOMENAME_LEN UT_HOSTSIZE + #endif +#else + /* according to /usr/include/utmpx.h ... */ + #define MAX_HOMENAME_LEN 256 +#endif + /* fill the hid with from hostname */ void gethid(char *hid, char *tty) { int fd; char *tp; +#ifdef Solaris + struct utmpx data; +#else struct utmp data; +#endif - gethostname(hid, MAXHOSTNAMELEN); - hid[MAXHOSTNAMELEN] = '\0'; + gethostname(hid, MAX_HOMENAME_LEN); + hid[MAX_HOMENAME_LEN] = '\0'; tp = strrchr(tty, '/') + 1; if (tp && strlen(tp) == 5) { - fd = open(_PATH_UTMP, O_RDONLY); + fd = open(U_FILE, O_RDONLY); if (fd < 0) - syslog(LOG_ERR, "%s: %m", _PATH_UTMP); + syslog(LOG_ERR, "%s: %m", U_FILE); else { while (read(fd, &data, sizeof(data)) == sizeof(data)) if (strcmp(data.ut_line, tp) == 0) { if (data.ut_host[0]) { -#if MAXHOSTNAMELEN < UT_HOSTSIZE - strncpy(hid, data.ut_host, MAXHOSTNAMELEN); - hid[MAXHOSTNAMELEN] = '\0'; -#else - strncpy(hid, data.ut_host, UT_HOSTSIZE); - hid[UT_HOSTSIZE] = '\0'; -#endif + strncpy(hid, data.ut_host, MAX_HOMENAME_LEN); + hid[MAX_HOMENAME_LEN] = '\0'; } break; } @@ -51,30 +72,6 @@ void gethid(char *hid, char *tty) } /* - get system load averages - return 0 if success; otherwise, return -1. - */ -int getload(double load[3]) -{ - int rtv = -1; -#if defined(linux) - FILE *fp; - - fp = fopen(LOAD_FILE, "r"); - if (fp) - { - if (fscanf(fp, "%lf %lf %lf", &load[0], &load[1], &load[2]) == 3) - rtv = 0; - fclose(fp); - } -#elif defined(__FreeBSD__) - if (getloadavg(load, 3) == 3) - rtv = 0; -#endif - return rtv; -} - -/* show ban file if filename exist, print it out, sleep 1 second, and return 0; otherwise, return -1. @@ -100,9 +97,13 @@ int showbanfile(char *filename) int main(void) { int uid, rtv = 0; - char *tty, ttybuf[32], hid[MAXHOSTNAMELEN + 1]; + char *tty, ttybuf[32], hid[MAX_HOMENAME_LEN + 1]; +#ifndef Solaris openlog("bbsrf", LOG_PID | LOG_PERROR, LOG_USER); +#else + openlog("bbsrf", LOG_PID, LOG_USER); +#endif chdir(BBSHOME); uid = getuid(); |