Added locking for mbsetup

This commit is contained in:
Michiel Broek
2002-05-04 19:45:19 +00:00
parent e3961d8449
commit ff8ee89ac1
20 changed files with 148 additions and 5 deletions

View File

@@ -96,7 +96,7 @@ m_mgroup.o: ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../li
m_node.o: ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h screen.h mutil.h ledit.h grlist.h stlist.h m_global.h m_lang.h m_ticarea.h m_marea.h m_node.h
m_task.o: ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h screen.h mutil.h ledit.h m_task.h
m_users.o: ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h screen.h mutil.h ledit.h m_lang.h m_global.h m_archive.h m_protocol.h m_users.h
screen.o: ../lib/libs.h ../lib/structs.h ../lib/ansi.h ../lib/common.h screen.h
screen.o: ../lib/libs.h ../lib/structs.h ../lib/ansi.h ../lib/common.h ../lib/clcomm.h screen.h
m_bbs.o: ../lib/libs.h ../lib/structs.h ../lib/common.h screen.h mutil.h ledit.h m_lang.h m_protocol.h m_ol.h m_fgroup.h m_farea.h m_menu.h m_bbs.h m_limits.h
m_ff.o: ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/clcomm.h ../lib/common.h screen.h mutil.h ledit.h stlist.h m_global.h m_ff.h m_lang.h m_marea.h
m_hatch.o: ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h screen.h mutil.h ledit.h stlist.h m_global.h m_fgroup.h m_ticarea.h m_hatch.h

View File

@@ -42,6 +42,7 @@
int sock; /* Connected socket */
extern int bbs_free;
int yes_no(char *T_)
@@ -94,6 +95,47 @@ void errmsg(const char *format, ...)
/*
* Check if bbs is free, if so close it.
*/
int check_free(void)
{
char buf[81];
if (bbs_free) {
strcpy(buf, SockR("SCLO:0;"));
if (strncmp(buf, "100:0;", 6) == 0) {
Syslog('+', "The BBS is closed");
return TRUE;
} else {
errmsg("Cannon continue, failed to close the bbs");
return FALSE;
}
}
errmsg("You cannot edit right now, the system is busy");
return FALSE;
}
/*
* Reopen the bbs.
*/
void open_bbs(void)
{
char buf[81];
strcpy(buf, SockR("SOPE:0;"));
if (strncmp(buf, "100:0;", 6) == 0) {
Syslog('+', "The BBS is open");
} else {
errmsg("Failed to reopen the bbs");
}
}
/*
* Safe field display, does not format % characters but displays it.
*/

View File

@@ -5,6 +5,8 @@
int yes_no(char *);
void errmsg(const char *, ...);
int check_free(void);
void open_bbs(void);
void show_field(int, int, char *, int, int);
void newinsert(int, int, int);
char *edit_field(int, int, int, int, char *);

View File

@@ -309,6 +309,9 @@ void EditDomain(void)
long offset;
struct domrec tdomtrans;
if (! check_free())
return;
clr_index();
working(1, 0, 0);
IsDoing("Browsing Menu");
@@ -366,6 +369,7 @@ void EditDomain(void)
strcpy(pick, select_menurec(records));
if (strncmp(pick, "-", 1) == 0) {
open_bbs();
CloseDomain(FALSE);
return;
}

View File

@@ -487,6 +487,8 @@ void EditFilearea(void)
}
working(0, 0, 0);
o = 0;
if (! check_free())
return;
for (;;) {
clr_index();
@@ -527,6 +529,7 @@ void EditFilearea(void)
strcpy(pick, select_filearea(records, 20));
if (strncmp(pick, "-", 1) == 0) {
open_bbs();
CloseFilearea(FileForced);
return;
}

View File

@@ -136,6 +136,8 @@ void E_F(long areanr)
working(2, 0, 0);
return;
}
if (! check_free())
return;
fseek(fil, 0, SEEK_END);
records = ftell(fil) / sizeof(file);
@@ -216,6 +218,7 @@ void E_F(long areanr)
if (strncmp(menu, "-", 1) == 0) {
fclose(fil);
open_bbs();
return;
}

View File

@@ -503,6 +503,8 @@ void EditFGroup(void)
}
working(0, 0, 0);
o = 0;
if (! check_free())
return;
for (;;) {
clr_index();
@@ -544,6 +546,7 @@ void EditFGroup(void)
if (strncmp(pick, "-", 1) == 0) {
CloseFGroup(FALSE);
open_bbs();
return;
}

View File

@@ -408,6 +408,8 @@ void EditFidonet(void)
IsDoing("Browsing Menu");
working(0, 0, 0);
if (! check_free())
return;
for (;;) {
clr_index();
@@ -445,6 +447,7 @@ void EditFidonet(void)
if (strncmp(pick, "-", 1) == 0) {
CloseFidonet(FALSE);
open_bbs();
return;
}

View File

@@ -1493,6 +1493,9 @@ void global_menu(void)
{
unsigned long crc, crc1;
if (! check_free())
return;
if (cf_open() == -1)
return;
@@ -1561,6 +1564,7 @@ void global_menu(void)
Syslog('+', "Saved main config");
}
}
open_bbs();
return;
case 1:
e_fidoakas();

View File

@@ -433,8 +433,6 @@ int EditConnections(FILE *fil)
if (System.aka.zone) {
set_color(CYAN,BLACK);
sprintf(temp, "%3d. %s %s", o+i, status, aka2str(System.aka));
// System.aka.zone, System.aka.net, System.aka.node,
// System.aka.point, System.aka.domain);
} else {
set_color(LIGHTBLUE, BLACK);
sprintf(temp, "%3d.", o+i);
@@ -1251,6 +1249,8 @@ void EditMsgarea(void)
}
working(0, 0, 0);
o = 0;
if (! check_free())
return;
for (;;) {
clr_index();
@@ -1288,6 +1288,7 @@ void EditMsgarea(void)
if (strncmp(pick, "-", 1) == 0) {
CloseMsgarea(MailForced);
open_bbs();
return;
}

View File

@@ -440,6 +440,8 @@ void EditMGroup(void)
}
working(0, 0, 0);
o = 0;
if (! check_free())
return;
for (;;) {
clr_index();
@@ -481,6 +483,7 @@ void EditMGroup(void)
if (strncmp(pick, "-", 1) == 0) {
CloseMGroup(FALSE);
open_bbs();
return;
}

View File

@@ -921,6 +921,8 @@ void EditNodes(void)
}
working(0, 0, 0);
o = 0;
if (! check_free())
return;
for (;;) {
clr_index();
@@ -962,6 +964,7 @@ void EditNodes(void)
if (strncmp(pick, "-", 1) == 0) {
CloseNoderec(FALSE);
open_bbs();
return;
}

View File

@@ -977,6 +977,8 @@ void EditTicarea(void)
}
working(0, 0, 0);
o = 0;
if (! check_free())
return;
for (;;) {
clr_index();
@@ -1015,6 +1017,7 @@ Comment);
if (strncmp(pick, "-", 1) == 0) {
CloseTicarea(FALSE);
open_bbs();
return;
}

View File

@@ -566,6 +566,8 @@ void EditUsers(void)
}
working(0, 0, 0);
o = 0;
if (! check_free())
return;
for (;;) {
clr_index();
@@ -607,6 +609,7 @@ void EditUsers(void)
if (strncmp(pick, "-", 1) == 0) {
CloseUsers(FALSE);
open_bbs();
return;
}

View File

@@ -70,10 +70,12 @@
mode_t oldmask; /* Old umask value */
extern int do_quiet; /* Suppress log to screen */
extern int bbs_free; /* Free/Busy status */
int exp_golded = FALSE; /* Export GoldED config */
int init = FALSE; /* Run init only */
static void die(int onsig)
{
FILE *fp;
@@ -423,6 +425,7 @@ int main(int argc, char *argv[])
Syslog(' ', "MBSETUP v%s started by %s", VERSION, pw->pw_name);
if (init)
Syslog('+', "Cmd: mbsetup init");
bbs_free = FALSE;
initdatabases();
if (!init) {

View File

@@ -32,10 +32,13 @@
#include "../lib/structs.h"
#include "../lib/ansi.h"
#include "../lib/common.h"
#include "../lib/clcomm.h"
#include "screen.h"
extern int init;
int bbs_free;
/*************************************************************************
@@ -95,7 +98,7 @@ static time_t lasttime;
void show_date(int fg, int bg, int y, int x)
{
time_t now;
char *p;
char *p, buf[128];
now = time(NULL);
if (now != lasttime) {
@@ -107,6 +110,27 @@ void show_date(int fg, int bg, int y, int x)
p = asctime(gmtime(&now));
Striplf(p);
mvprintw(2, 44, (char *)"%s UTC", p);
/*
* Indicator if bbs is free
*/
strcpy(buf, SockR("SFRE:0;"));
if (strncmp(buf, "100:0;", 6) == 0) {
strcpy(buf, SockR("SBBS:0;"));
if (strncmp(buf, "100:2,1", 7) == 0) {
set_color(WHITE, RED);
mvprintw(2,74, (char *)" Down ");
} else {
set_color(WHITE, BLUE);
mvprintw(2,74, (char *)" Free ");
}
bbs_free = TRUE;
} else {
set_color(WHITE, RED);
mvprintw(2,74, (char *)" Busy ");
bbs_free = FALSE;
}
if (y && x)
locate(y, x);
set_color(fg, bg);