Part of OpenBSD porting

This commit is contained in:
Michiel Broek 2004-12-29 12:39:47 +00:00
parent 139ec0d628
commit 7265273d1a
10 changed files with 126 additions and 71 deletions

View File

@ -203,9 +203,9 @@ fi
dnl
dnl For FreeBSD we need -pthread for gcc and don't need libpthread
dnl For FreeBSD and OpenBSD we need -pthread for gcc and don't need libpthread
dnl
if test "$SYSTEM" = "FreeBSD"; then
if test "$SYSTEM" = "FreeBSD" || test "$SYSTEM" = "OpenBSD"; then
CFLAGS="-pthread $CFLAGS"
else
AC_CHECK_LIB(pthread,pthread_create,result=yes,result=no)

View File

@ -2018,7 +2018,6 @@ struct _route {
};
extern char SigName[32][16];

View File

@ -122,7 +122,11 @@ extern int disk_run; /* Disk watch running */
/*
* Global thread vaiables
*/
pthread_t p_thread[NUM_THREADS]; /* thread's structure */
pthread_t pt_ping;
pthread_t pt_command;
pthread_t pt_disk;
pthread_t pt_scheduler;
// pthread_t p_thread[NUM_THREADS]; /* thread's structure */
@ -946,7 +950,11 @@ void start_scheduler(void)
char *cmd = NULL;
int rc;
if (nodaemon)
printf("init fidonet\n");
InitFidonet();
if (nodaemon)
printf("done\n");
/*
* Registrate this server for mbmon in slot 0.
@ -958,6 +966,8 @@ void start_scheduler(void)
strcpy(reginfo[0].city, "localhost");
strcpy(reginfo[0].doing, "Start");
reginfo[0].started = time(NULL);
if (nodaemon)
printf("reginfo filled\n");
Processing = TRUE;
TouchSema((char *)"mbtask.last");
@ -980,6 +990,8 @@ void start_scheduler(void)
WriteError("$Can't bind socket %s", spath);
die(MBERR_INIT_ERROR);
}
if (nodaemon)
printf("sockets created\n");
/*
* The flag masterinit is set if a new config.data is created, this
@ -996,30 +1008,37 @@ void start_scheduler(void)
masterinit = FALSE;
}
if (nodaemon)
printf("init nodelists\n");
initnl();
sem_set((char *)"scanout", TRUE);
if (!TCFG.max_tcp && !pots_lines && !isdn_lines) {
Syslog('?', "WARNING: this system cannot connect to other systems, check setup");
}
if (nodaemon)
printf("creating threads\n");
/*
* Install the threads that do the real work.
*/
if ((rc = pthread_create(&p_thread[0], NULL, (void (*))ping_thread, NULL))) {
if ((rc = pthread_create(&pt_ping, NULL, /* (void (*)) */ ping_thread, NULL))) {
WriteError("$pthread_create ping_thread rc=%d", rc);
die(SIGTERM);
} else if ((rc = pthread_create(&p_thread[1], NULL, (void (*))cmd_thread, NULL))) {
} else if ((rc = pthread_create(&pt_command, NULL, (void (*))cmd_thread, NULL))) {
WriteError("$pthread_create cmd_thread rc=%d", rc);
die(SIGTERM);
} else if ((rc = pthread_create(&p_thread[2], NULL, (void (*))disk_thread, NULL))) {
} else if ((rc = pthread_create(&pt_disk, NULL, (void (*))disk_thread, NULL))) {
WriteError("$pthread_create disk_thread rc=%d", rc);
die(SIGTERM);
} else if ((rc = pthread_create(&p_thread[3], NULL, (void (*))scheduler, NULL))) {
} else if ((rc = pthread_create(&pt_scheduler, NULL, (void (*))scheduler, NULL))) {
WriteError("$pthread_create scheduler rc=%d", rc);
die(SIGTERM);
} else {
Syslog('+', "All threads installed");
}
if (nodaemon)
printf("threads installed\n");
/*
* Sleep until we die
@ -1043,7 +1062,7 @@ void *scheduler(void)
char *cmd = NULL, opts[41], port[21];
static char doing[32];
time_t now;
struct tm *tm, *utm;
struct tm tm, utm;
#if defined(__linux__)
FILE *fp;
#endif
@ -1127,15 +1146,20 @@ void *scheduler(void)
* Reload configuration data if some file is changed.
*/
now = time(NULL);
tm = localtime(&now);
utm = gmtime(&now);
if (tm->tm_min != olddo) {
#if defined(__OpenBSD__)
localtime_r(&now, &tm);
gmtime_r(&now, &utm);
#else
tm = *localtime(&now);
utm = *gmtime(&now);
#endif
if (tm.tm_min != olddo) {
/*
* Each minute we execute this part
*/
if (tosswait)
tosswait--;
olddo = tm->tm_min;
olddo = tm.tm_min;
TouchSema((char *)"mbtask.last");
if (file_time(tcfgfn) != tcfg_time) {
Syslog('+', "Task configuration changed, reloading");
@ -1163,8 +1187,8 @@ void *scheduler(void)
/*
* If the next event time is reached, rescan the outbound
*/
if ((utm->tm_hour == nxt_hour) && (utm->tm_min == nxt_min)) {
Syslog('+', "It is now %02d:%02d UTC, starting new event", utm->tm_hour, utm->tm_min);
if ((utm.tm_hour == nxt_hour) && (utm.tm_min == nxt_min)) {
Syslog('+', "It is now %02d:%02d UTC, starting new event", utm.tm_hour, utm.tm_min);
sem_set((char *)"scanout", TRUE);
}
}
@ -1188,8 +1212,8 @@ void *scheduler(void)
* Check Pause Timer, make sure it's only checked
* once each second. Also do pingcheck.
*/
if (tm->tm_sec != oldsec) {
oldsec = tm->tm_sec;
if (tm.tm_sec != oldsec) {
oldsec = tm.tm_sec;
if (ptimer)
ptimer--;
}
@ -1274,12 +1298,12 @@ void *scheduler(void)
} /* if (Processing) */
if ((tm->tm_sec / SLOWRUN) != oldmin) {
if ((tm.tm_sec / SLOWRUN) != oldmin) {
/*
* These tasks run once per 20 seconds.
*/
oldmin = tm->tm_sec / SLOWRUN;
oldmin = tm.tm_sec / SLOWRUN;
if (Processing) {
@ -1410,18 +1434,16 @@ int main(int argc, char **argv)
* but that's live. This daemon should only be stopped by SIGTERM.
*/
for (i = 0; i < NSIG; i++) {
if ((i == SIGHUP) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV))
if ((i == SIGHUP) || (i == SIGPIPE) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV))
signal(i, (void (*))die);
else if ((i == SIGINT) || (i == SIGTERM))
signal(i, (void (*))start_shutdown);
else if (i == SIGCHLD)
signal(i, SIG_DFL);
else if ((i != SIGKILL) && (i != SIGSTOP))
signal(i, SIG_IGN);
// else if ((i != SIGKILL) && (i != SIGSTOP))
// signal(i, SIG_IGN);
}
init_pingsocket();
/*
* Secret undocumented startup switch, ie: no help available.
*/
@ -1429,6 +1451,8 @@ int main(int argc, char **argv)
nodaemon = TRUE;
}
init_pingsocket();
/*
* mbtask is setuid root, drop privileges to user mbse.
* This will stay forever like this, no need to become
@ -1463,10 +1487,16 @@ int main(int argc, char **argv)
sprintf(cfgfn, "%s/etc/config.data", getenv("MBSE_ROOT"));
load_maincfg();
if (nodaemon)
printf("main config loaded\n");
mypid = getpid();
if (nodaemon)
printf("my pid is %d\n", mypid);
Syslog(' ', " ");
Syslog(' ', "MBTASK v%s", VERSION);
if (nodaemon)
Syslog('+', "Starting in no-daemon mode");
@ -1496,6 +1526,7 @@ int main(int argc, char **argv)
* For debugging, run in foreground mode
*/
mypid = getpid();
printf("init complete, starting scheduler ...\n");
start_scheduler();
} else {
/*

View File

@ -116,13 +116,17 @@ void set_next(int, int);
void set_next(int hour, int min)
{
time_t now;
struct tm *etm;
struct tm etm;
int uhour, umin;
now = time(NULL);
#if defined(__OpenBSD__)
gmtime_r(&now, &etm);
#else
etm = gmtime(&now);
uhour = etm->tm_hour; /* For some reason, these intermediate integers are needed */
umin = etm->tm_min;
#endif
uhour = etm.tm_hour; /* For some reason, these intermediate integers are needed */
umin = etm.tm_min;
if ((hour > uhour) || ((hour == uhour) && (min > umin))) {
if (hour < nxt_hour) {
@ -257,7 +261,7 @@ int outstat()
struct _alist *tmp, *old;
char digit[6], flstr[13], *temp, as[6], be[6], utc[6], flavor, *temp2;
time_t now;
struct tm *tm;
struct tm tm;
int uhour, umin, thour, tmin;
pp_list *tpl;
faddr *fa;
@ -277,9 +281,13 @@ int outstat()
itnmask = (*tmpm)->mask;
}
now = time(NULL);
tm = gmtime(&now); /* UTC time */
uhour = tm->tm_hour;
umin = tm->tm_min;
#if defined(__OpenBSD__)
gmtime_r(&now, &tm);
#else
tm = *gmtime(&now); /* UTC time */
#endif
uhour = tm.tm_hour;
umin = tm.tm_min;
sprintf(utc, "%02d:%02d", uhour, umin);
Syslog('+', "Scanning outbound at %s UTC.", utc);
nxt_hour = 24;

View File

@ -329,7 +329,7 @@ void init_pingsocket(void)
/*
* Ping thread
*/
void *ping_thread(void)
void *ping_thread(void *dummy)
{
int rc = 0;
static int pingnr, pingresult[2];
@ -337,6 +337,8 @@ void *ping_thread(void)
static time_t pingsend;
time_t now;
printf("Start ping thread\n");
Syslog('+', "Starting ping thread");
pingresult[1] = pingresult[2] = FALSE;
pingnr = 2;

View File

@ -11,6 +11,6 @@
#define SET_SOCKA_LEN4(socka)
void init_pingsocket(void);
void *ping_thread(void);
void *ping_thread(void*);
#endif

View File

@ -36,7 +36,7 @@
* Signal handler signal names.
*/
#ifdef __i386__
#if defined(__i386__)
char SigName[32][16] = { "NOSIGNAL",
"SIGHUP", "SIGINT", "SIGQUIT", "SIGILL",
@ -48,11 +48,10 @@ char SigName[32][16] = { "NOSIGNAL",
"SIGXFSZ", "SIGVTALRM", "SIGPROF", "SIGWINCH",
"SIGIO", "SIGPWR", "SIGUNUSED"};
#endif
#ifdef __PPC__
#elif defined(__PPC__)
char SigName[32][16] = { "NOSIGNAL",
char SgName[32][16] = { "NOSIGNAL",
"SIGHUP", "SIGINT", "SIGQUIT", "SIGILL",
"SIGTRAP", "SIGIOT", "SIGBUS", "SIGFPE",
"SIGKILL", "SIGUSR1", "SIGSEGV", "SIGUSR2",
@ -62,11 +61,10 @@ char SigName[32][16] = { "NOSIGNAL",
"SIGXFSZ", "SIGVTALRM", "SIGPROF", "SIGWINCH",
"SIGIO", "SIGPWR", "SIGUNUSED"};
#endif
#ifdef __sparc__
#elif defined(__sparc__)
char SigName[32][16] = { "NOSIGNAL",
char SgName[32][16] = { "NOSIGNAL",
"SIGHUP", "SIGINT", "SIGQUIT", "SIGILL",
"SIGTRAP", "SIGIOT", "SIGEMT", "SIGFPE",
"SIGKILL", "SIGBUS", "SIGSEGV", "SIGSYS",
@ -75,11 +73,10 @@ char SigName[32][16] = { "NOSIGNAL",
"SIGTTIN", "SIGTTOU", "SIGIO", "SIGXCPU",
"SIGXFSZ", "SIGVTALRM", "SIGPROF", "SIGWINCH",
"SIGLOST", "SIGUSR1", "SIGUSR2"};
#endif
#ifdef __alpha__
#elif defined(__alpha__)
char SigName[32][16] = { "NOSIGNAL",
char SgName[32][16] = { "NOSIGNAL",
"SIGHUP", "SIGINT", "SIGQUIT", "SIGILL",
"SIGTRAP", "SIGABRT", "SIGEMT", "SIGFPE",
"SIGKILL", "SIGBUS", "SIGSEGV", "SIGSYS",
@ -89,20 +86,18 @@ char SigName[32][16] = { "NOSIGNAL",
"SIGXFSZ", "SIGVTALRM", "SIGPROF", "SIGWINCH",
"SIGINFO", "SIGUSR1", "SIGUSR2"};
#elif defined(__hppa__)
#endif
#ifdef __hppa__
char SigName[32][16] = { "NOSIGNAL",
char SigName[32][16] = { "NOSIGNAL",
"SIGHUP", "SIGINT", "SIGQUIT", "SIGILL",
"SIGTRAP", "SIGABRT", "SIGEMT", "SIGFPE",
"SIGKILL", "SIGBUS", "SIGSEGV", "SIGSYS",
"SIGPIPE", "SIGALRM", "SIGTERM", "SIGUSR1",
"SIGUSR2", "SIGCHLD", "SIGPWR", "SIGVTALRM",
"SIGPROF", "SIGIO", "SIGWINCH", "SIGSTOP",
"SIGTSTP", "SIGCONT", "SIGTTIN", "SIGTTOU",
"SIGURG", "SIGLOST", "SIGUNUSED"};
"SIGPIPE", "SIGALRM", "SIGTERM", "SIGURG",
"SIGSTOP", "SIGTSTP", "SIGCONT", "SIGCHLD",
"SIGTTIN", "SIGTTOU", "SIGWIO", "SIGXCPU",
"SIGXFSZ", "SIGVTALRM", "SIGPROF", "SIGWINCH",
"SIGINFO", "SIGUSR1", "SIGUSR2"};
#else
#error "Cannot make SigName array on this platform"
#endif

View File

@ -4,7 +4,7 @@
/* $Id$ */
char SigName[32][16];
// char SigName[32][16];
#endif

View File

@ -143,19 +143,27 @@ void status_write(void);
void status_write(void)
{
int d, stat_fd, yday;
struct tm *ttm;
struct tm ttm;
time_t temp;
#if defined(__OpenBSD)
temp = time(NULL);
ttm = localtime(&temp);
yday = ttm->tm_yday;
localtime_r(&temp, &ttm);
yday = ttm.tm_yday;
temp = status.daily;
localtime_r(&temp, &ttm);
#else
temp = time(NULL);
ttm = *localtime(&temp);
yday = ttm.tm_yday;
temp = status.daily; // On a Sparc, first put the time in temp, then pass it to locattime.
ttm = localtime(&temp);
ttm = *localtime(&temp);
#endif
/*
* If we passed to the next day, zero the today counters
*/
if (yday != ttm->tm_yday) {
if (yday != ttm.tm_yday) {
Syslog('+', "Last days statistics:");
Syslog('+', "Total clients : %lu", status.today.tot_clt);
Syslog('+', "Peak clients : %lu", status.today.peak_clt);
@ -201,13 +209,17 @@ void status_write(void)
*/
int get_zmh()
{
struct tm *l_date;
struct tm l_date;
char sstime[6];
time_t Now;
Now = time(NULL);
l_date = gmtime(&Now);
sprintf(sstime, "%02d:%02d", l_date->tm_hour, l_date->tm_min);
#if defined(__OpenBSD__)
gmtime_r(&Now, &l_date);
#else
l_date = *gmtime(&Now);
#endif
sprintf(sstime, "%02d:%02d", l_date.tm_hour, l_date.tm_min);
if ((strncmp(sstime, TCFG.zmh_start, 5) >= 0) && (strncmp(sstime, TCFG.zmh_end, 5) < 0)) {
if (!ZMH) {
@ -292,7 +304,7 @@ char *stat_status()
buf[0] = '\0';
sprintf(buf, "100:20,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%d,%d,%d,%d,%d,%2.2f,%lu;",
status.start, status.laststart, status.daily,
(long)status.start, (long)status.laststart, (long)status.daily,
status.startups, status.clients,
status.total.tot_clt, status.total.peak_clt,
status.total.s_error, status.total.c_error,

View File

@ -70,7 +70,11 @@ char *date(void)
static char buf[20];
now = time(NULL);
#if defined(__OpenBSD__)
localtime_r(&now, &ptm);
#else
ptm = *localtime(&now);
#endif
sprintf(buf,"%02d-%s-%04d %02d:%02d:%02d", ptm.tm_mday, mon[ptm.tm_mon], ptm.tm_year+1900,
ptm.tm_hour, ptm.tm_min, ptm.tm_sec);
return(buf);
@ -476,15 +480,19 @@ static char *dow[] = {(char *)"su", (char *)"mo", (char *)"tu", (char *)"we",
char *dayname(void)
{
time_t tt;
struct tm *ptm;
static char buf[3];
time_t tt;
struct tm ptm;
static char buf[3];
tt = time(NULL);
ptm = localtime(&tt);
sprintf(buf, "%s", dow[ptm->tm_wday]);
tt = time(NULL);
#if defined(__OpenBSD__)
localtime_r(&tt, &ptm);
#else
ptm = *localtime(&tt);
#endif
sprintf(buf, "%s", dow[ptm.tm_wday]);
return buf;
return buf;
}