Updated mbtask and main Makefile
This commit is contained in:
parent
8453035be1
commit
79a4875bee
@ -29,6 +29,9 @@ v0.39.4 08-Dec-2003
|
|||||||
mbsetup:
|
mbsetup:
|
||||||
Added default record for french language.
|
Added default record for french language.
|
||||||
|
|
||||||
|
mbtask:
|
||||||
|
Moved the scheduler in a thread.
|
||||||
|
|
||||||
script:
|
script:
|
||||||
Dropped support for Slackware pre 7.0.
|
Dropped support for Slackware pre 7.0.
|
||||||
Changed startup scripts for NetBSD.
|
Changed startup scripts for NetBSD.
|
||||||
|
8
Makefile
8
Makefile
@ -49,8 +49,12 @@ install:
|
|||||||
${CHOWN} ${OWNER}:${GROUP} ${PREFIX}/etc ; \
|
${CHOWN} ${OWNER}:${GROUP} ${PREFIX}/etc ; \
|
||||||
fi
|
fi
|
||||||
@chmod 0775 ${PREFIX}/etc
|
@chmod 0775 ${PREFIX}/etc
|
||||||
@chmod -f 0660 ${PREFIX}/etc/lastcall.data
|
@if [ -f ${PREFIX}/etc/lastcall.data ] ; then \
|
||||||
@chmod -f 0660 ${PREFIX}/etc/sysinfo.data
|
chmod 0660 ${PREFIX}/etc/lastcall.data ; \
|
||||||
|
fi
|
||||||
|
@if [ -f ${PREFIX}/etc/sysinfo.data ] ; then \
|
||||||
|
chmod 0660 ${PREFIX}/etc/sysinfo.data ; \
|
||||||
|
fi
|
||||||
@if [ ! -d ${PREFIX}/doc ] ; then \
|
@if [ ! -d ${PREFIX}/doc ] ; then \
|
||||||
mkdir ${PREFIX}/doc ; \
|
mkdir ${PREFIX}/doc ; \
|
||||||
${CHOWN} ${OWNER}:${GROUP} ${PREFIX}/doc ; \
|
${CHOWN} ${OWNER}:${GROUP} ${PREFIX}/doc ; \
|
||||||
|
101
mbtask/mbtask.c
101
mbtask/mbtask.c
@ -48,7 +48,7 @@
|
|||||||
#include "mbtask.h"
|
#include "mbtask.h"
|
||||||
|
|
||||||
|
|
||||||
#define NUM_THREADS 2 /* Max. nr of threads */
|
#define NUM_THREADS 3 /* Max. nr of threads */
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -113,6 +113,8 @@ int T_Shutdown = FALSE; /* Shutdown threads */
|
|||||||
int nodaemon = FALSE; /* Run in foreground */
|
int nodaemon = FALSE; /* Run in foreground */
|
||||||
extern int cmd_run; /* Cmd running */
|
extern int cmd_run; /* Cmd running */
|
||||||
extern int ping_run; /* Ping running */
|
extern int ping_run; /* Ping running */
|
||||||
|
int sched_run = FALSE; /* Scheduler running */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -654,7 +656,6 @@ void die(int onsig)
|
|||||||
int i, count;
|
int i, count;
|
||||||
time_t now;
|
time_t now;
|
||||||
|
|
||||||
T_Shutdown = TRUE;
|
|
||||||
signal(onsig, SIG_IGN);
|
signal(onsig, SIG_IGN);
|
||||||
|
|
||||||
if ((onsig == SIGTERM) || (nodaemon && (onsig == SIGINT))) {
|
if ((onsig == SIGTERM) || (nodaemon && (onsig == SIGINT))) {
|
||||||
@ -690,7 +691,16 @@ void die(int onsig)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd_run || ping_run)
|
if ((count = checktasks(0)))
|
||||||
|
Syslog('?', "Shutdown with %d tasks still running", count);
|
||||||
|
else
|
||||||
|
Syslog('+', "Good, no more tasks running");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Now stop the threads
|
||||||
|
*/
|
||||||
|
T_Shutdown = TRUE;
|
||||||
|
if (cmd_run || ping_run || sched_run)
|
||||||
Syslog('+', "Waiting for threads to stop");
|
Syslog('+', "Waiting for threads to stop");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -698,15 +708,10 @@ void die(int onsig)
|
|||||||
* build to stop within a second.
|
* build to stop within a second.
|
||||||
*/
|
*/
|
||||||
now = time(NULL) + 2;
|
now = time(NULL) + 2;
|
||||||
while ((cmd_run || ping_run) && (time(NULL) < now)) {
|
while ((cmd_run || ping_run || sched_run) && (time(NULL) < now)) {
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((count = checktasks(0)))
|
|
||||||
Syslog('?', "Shutdown with %d tasks still running", count);
|
|
||||||
else
|
|
||||||
Syslog('+', "Good, no more tasks running");
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Free memory
|
* Free memory
|
||||||
*/
|
*/
|
||||||
@ -902,22 +907,12 @@ void check_sema(void)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void scheduler(void)
|
void start_scheduler(void)
|
||||||
{
|
{
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
int running = 0, i, found;
|
char *cmd = NULL;
|
||||||
static int LOADhi = FALSE, oldmin = 70, olddo = 70, oldsec = 70;
|
int rc;
|
||||||
char *cmd = NULL, opts[41], port[21];
|
pthread_attr_t attr;
|
||||||
static char doing[32];
|
|
||||||
time_t now;
|
|
||||||
struct tm *tm, *utm;
|
|
||||||
#if defined(__linux__)
|
|
||||||
FILE *fp;
|
|
||||||
#endif
|
|
||||||
int call_work = 0;
|
|
||||||
static int call_entry = MAXTASKS;
|
|
||||||
double loadavg[3];
|
|
||||||
pp_list *tpl;
|
|
||||||
|
|
||||||
InitFidonet();
|
InitFidonet();
|
||||||
|
|
||||||
@ -934,7 +929,6 @@ void scheduler(void)
|
|||||||
|
|
||||||
Processing = TRUE;
|
Processing = TRUE;
|
||||||
TouchSema((char *)"mbtask.last");
|
TouchSema((char *)"mbtask.last");
|
||||||
pw = getpwuid(getuid());
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Setup UNIX Datagram socket
|
* Setup UNIX Datagram socket
|
||||||
@ -961,6 +955,7 @@ void scheduler(void)
|
|||||||
* mbsetup init to create the default databases.
|
* mbsetup init to create the default databases.
|
||||||
*/
|
*/
|
||||||
if (masterinit) {
|
if (masterinit) {
|
||||||
|
pw = getpwuid(getuid());
|
||||||
cmd = xstrcpy(pw->pw_dir);
|
cmd = xstrcpy(pw->pw_dir);
|
||||||
cmd = xstrcat(cmd, (char *)"/bin/mbsetup");
|
cmd = xstrcat(cmd, (char *)"/bin/mbsetup");
|
||||||
launch(cmd, (char *)"init", (char *)"mbsetup", MBINIT);
|
launch(cmd, (char *)"init", (char *)"mbsetup", MBINIT);
|
||||||
@ -978,12 +973,50 @@ void scheduler(void)
|
|||||||
/*
|
/*
|
||||||
* Install threads
|
* Install threads
|
||||||
*/
|
*/
|
||||||
thr_id[0] = pthread_create(&p_thread[0], NULL, (void (*))ping_thread, NULL);
|
pthread_attr_init(&attr);
|
||||||
Syslog('l', "pthread_create ping_thread rc=%d", thr_id[0]);
|
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
|
||||||
thr_id[1] = pthread_create(&p_thread[1], NULL, (void (*))cmd_thread, NULL);
|
rc = pthread_create(&p_thread[0], NULL, (void (*))ping_thread, NULL);
|
||||||
Syslog('l', "pthread_create cmd_thread rc=%d", thr_id[1]);
|
Syslog('l', "pthread_create ping_thread rc=%d", rc);
|
||||||
|
rc = pthread_create(&p_thread[1], NULL, (void (*))cmd_thread, NULL);
|
||||||
|
Syslog('l', "pthread_create cmd_thread rc=%d", rc);
|
||||||
|
rc = pthread_create(&p_thread[2], NULL, (void (*))scheduler, NULL);
|
||||||
|
Syslog('l', "pthread_create scheduler rc=%d", rc);
|
||||||
|
pthread_attr_destroy(&attr);
|
||||||
|
Syslog('+', "All threads installed");
|
||||||
|
|
||||||
Syslog('l', "Entering scheduler loop");
|
/*
|
||||||
|
* Sleep until we die
|
||||||
|
*/
|
||||||
|
while (TRUE) {
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Scheduler thread
|
||||||
|
*/
|
||||||
|
void *scheduler(void)
|
||||||
|
{
|
||||||
|
struct passwd *pw;
|
||||||
|
int running = 0, i, found;
|
||||||
|
static int LOADhi = FALSE, oldmin = 70, olddo = 70, oldsec = 70;
|
||||||
|
char *cmd = NULL, opts[41], port[21];
|
||||||
|
static char doing[32];
|
||||||
|
time_t now;
|
||||||
|
struct tm *tm, *utm;
|
||||||
|
#if defined(__linux__)
|
||||||
|
FILE *fp;
|
||||||
|
#endif
|
||||||
|
int call_work = 0;
|
||||||
|
static int call_entry = MAXTASKS;
|
||||||
|
double loadavg[3];
|
||||||
|
pp_list *tpl;
|
||||||
|
|
||||||
|
Syslog('+', "Starting scheduler thread with pid %d", (int)getpid());
|
||||||
|
sched_run = TRUE;
|
||||||
|
pw = getpwuid(getuid());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Enter the mainloop (forever)
|
* Enter the mainloop (forever)
|
||||||
@ -993,6 +1026,8 @@ void scheduler(void)
|
|||||||
Syslog('l', "Starting scheduler loop");
|
Syslog('l', "Starting scheduler loop");
|
||||||
#endif
|
#endif
|
||||||
sleep(1);
|
sleep(1);
|
||||||
|
if (T_Shutdown)
|
||||||
|
break;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check all registered connections and semafore's
|
* Check all registered connections and semafore's
|
||||||
@ -1304,7 +1339,11 @@ void scheduler(void)
|
|||||||
} /* if (Processing) */
|
} /* if (Processing) */
|
||||||
} /* if ((tm->tm_sec / SLOWRUN) != oldmin) */
|
} /* if ((tm->tm_sec / SLOWRUN) != oldmin) */
|
||||||
|
|
||||||
} while (TRUE);
|
} while (! T_Shutdown);
|
||||||
|
|
||||||
|
sched_run = FALSE;
|
||||||
|
Syslog('+', "Scheduler thread stopped");
|
||||||
|
pthread_exit(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1451,7 +1490,7 @@ int main(int argc, char **argv)
|
|||||||
_exit(MBERR_EXEC_FAILED);
|
_exit(MBERR_EXEC_FAILED);
|
||||||
}
|
}
|
||||||
mypid = getpid();
|
mypid = getpid();
|
||||||
scheduler();
|
start_scheduler();
|
||||||
/* Not reached */
|
/* Not reached */
|
||||||
default:
|
default:
|
||||||
/*
|
/*
|
||||||
|
@ -47,7 +47,8 @@ pid_t launch(char *, char *, char *, int);
|
|||||||
int runtasktype(int);
|
int runtasktype(int);
|
||||||
int checktasks(int);
|
int checktasks(int);
|
||||||
void die(int);
|
void die(int);
|
||||||
void scheduler(void);
|
void start_scheduler(void);
|
||||||
|
void *scheduler(void);
|
||||||
int locktask(char *);
|
int locktask(char *);
|
||||||
void ulocktask(void);
|
void ulocktask(void);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user