Added more program locks

This commit is contained in:
Michiel Broek 2003-08-03 14:42:12 +00:00
parent 709a2ad3af
commit 3c0de46dc9
8 changed files with 296 additions and 262 deletions

View File

@ -36,6 +36,22 @@ v0.37.5 12-Jul-2003
Added program locking, only one mbmon can run at the same time Added program locking, only one mbmon can run at the same time
to prevent troubles with chat and sysop available. to prevent troubles with chat and sysop available.
mbaff:
Added program locking to prevent that more than one mbaff can
run at the same time.
mball:
Added program locking to prevent that more than one mball can
run at the same time.
mbfile:
Added program locking to prevent that more than one mbfile can
run at the same time.
mbuser:
Added program locking to prevent that more than one mbuser can
run at the same time.
lang: lang:
Added language prompts 18 and 19. Added language prompts 18 and 19.

View File

@ -30,15 +30,11 @@
#include "../config.h" #include "../config.h"
#include "../lib/libs.h" #include "../lib/libs.h"
//#include "../lib/memwatch.h"
#include "../lib/structs.h" #include "../lib/structs.h"
#include "../lib/users.h" #include "../lib/users.h"
#include "../lib/records.h" #include "../lib/records.h"
#include "../lib/common.h" #include "../lib/common.h"
#include "../lib/clcomm.h" #include "../lib/clcomm.h"
//#include "../lib/dbcfg.h"
//#include "../lib/dbftn.h"
//#include "../lib/mberrors.h"
extern int do_quiet; /* Quiet flag */ extern int do_quiet; /* Quiet flag */
@ -53,7 +49,7 @@ int lockprogram(char *progname)
FILE *fp; FILE *fp;
pid_t oldpid; pid_t oldpid;
tempfile = calloc(PATH_MAX, sizeof(char)); tempfile = calloc(PATH_MAX, sizeof(char));
lockfile = calloc(PATH_MAX, sizeof(char)); lockfile = calloc(PATH_MAX, sizeof(char));
sprintf(tempfile, "%s/var/run/%s.tmp", getenv("MBSE_ROOT"), progname); sprintf(tempfile, "%s/var/run/%s.tmp", getenv("MBSE_ROOT"), progname);
@ -141,8 +137,6 @@ void ulockprogram(char *progname)
if (oldpid == getpid()) { if (oldpid == getpid()) {
(void)unlink(lockfile); (void)unlink(lockfile);
} else {
WriteError("Lockfile owned by pid %d, not removed", oldpid);
} }
free(lockfile); free(lockfile);

View File

@ -56,122 +56,127 @@ time_t t_end; /* End time */
void ProgName(void) void ProgName(void)
{ {
if (do_quiet) if (do_quiet)
return; return;
colour(15, 0); colour(15, 0);
printf("\nMBAFF: MBSE BBS %s Announce new files and FileFind\n", VERSION); printf("\nMBAFF: MBSE BBS %s Announce new files and FileFind\n", VERSION);
colour(14, 0); colour(14, 0);
printf(" %s\n", COPYRIGHT); printf(" %s\n", COPYRIGHT);
} }
void die(int onsig) void die(int onsig)
{ {
signal(onsig, SIG_IGN); signal(onsig, SIG_IGN);
if (onsig) { if (onsig) {
if (onsig <= NSIG) if (onsig <= NSIG)
WriteError("Terminated on signal %d (%s)", onsig, SigName[onsig]); WriteError("Terminated on signal %d (%s)", onsig, SigName[onsig]);
else else
WriteError("Terminated with error %d", onsig); WriteError("Terminated with error %d", onsig);
} }
t_end = time(NULL); ulockprogram((char *)"mbaff");
Syslog(' ', "MBAFF finished in %s", t_elapsed(t_start, t_end)); t_end = time(NULL);
Syslog(' ', "MBAFF finished in %s", t_elapsed(t_start, t_end));
if (!do_quiet) { if (!do_quiet) {
colour(7, 0); colour(7, 0);
printf("\n"); printf("\n");
} }
ExitClient(onsig); ExitClient(onsig);
} }
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int i, Mail = FALSE; int i, Mail = FALSE;
char *cmd; char *cmd;
struct passwd *pw; struct passwd *pw;
struct tm *t; struct tm *t;
#ifdef MEMWATCH #ifdef MEMWATCH
mwInit(); mwInit();
#endif #endif
InitConfig(); InitConfig();
TermInit(1); TermInit(1);
t_start = time(NULL); t_start = time(NULL);
t = localtime(&t_start); t = localtime(&t_start);
Diw = t->tm_wday; Diw = t->tm_wday;
Miy = t->tm_mon; Miy = t->tm_mon;
umask(002); umask(002);
/* /*
* Catch all signals we can, and ignore the rest. * Catch all signals we can, and ignore the rest.
*/ */
for (i = 0; i < NSIG; i++) { for (i = 0; i < NSIG; i++) {
if ((i == SIGHUP) || (i == SIGINT) || (i == SIGBUS) || if ((i == SIGHUP) || (i == SIGINT) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM))
(i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM) || signal(i, (void (*))die);
(i == SIGKILL)) else
signal(i, (void (*))die); signal(i, SIG_IGN);
else }
signal(i, SIG_IGN);
}
if(argc < 2) if (argc < 2)
Help(); Help();
cmd = xstrcpy((char *)"Command line: mbaff"); cmd = xstrcpy((char *)"Command line: mbaff");
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
cmd = xstrcat(cmd, (char *)" "); cmd = xstrcat(cmd, (char *)" ");
cmd = xstrcat(cmd, tl(argv[i])); cmd = xstrcat(cmd, tl(argv[i]));
if (!strncmp(argv[i], "a", 1)) if (!strncmp(argv[i], "a", 1))
do_announce = TRUE; do_announce = TRUE;
if (!strncmp(argv[i], "f", 1)) if (!strncmp(argv[i], "f", 1))
do_filefind = TRUE; do_filefind = TRUE;
if (!strncmp(argv[i], "-q", 2)) if (!strncmp(argv[i], "-q", 2))
do_quiet = TRUE; do_quiet = TRUE;
} }
ProgName(); ProgName();
pw = getpwuid(getuid()); pw = getpwuid(getuid());
InitClient(pw->pw_name, (char *)"mbaff", CFG.location, CFG.logfile, CFG.util_loglevel, CFG.error_log, CFG.mgrlog); InitClient(pw->pw_name, (char *)"mbaff", CFG.location, CFG.logfile, CFG.util_loglevel, CFG.error_log, CFG.mgrlog);
Syslog(' ', " "); Syslog(' ', " ");
Syslog(' ', "MBAFF v%s", VERSION); Syslog(' ', "MBAFF v%s", VERSION);
Syslog(' ', cmd); Syslog(' ', cmd);
free(cmd); free(cmd);
if (!do_quiet)
printf("\n");
if (!diskfree(CFG.freespace))
die(MBERR_DISK_FULL);
if (lockprogram((char *)"mbaff")) {
if (!do_quiet) if (!do_quiet)
printf("\n"); printf("Can't lock mbaff, abort.\n");
die(MBERR_NO_PROGLOCK);
}
if (!diskfree(CFG.freespace)) memset(&MsgBase, 0, sizeof(MsgBase));
die(MBERR_DISK_FULL);
memset(&MsgBase, 0, sizeof(MsgBase)); if (do_announce)
if (Announce())
Mail = TRUE;
if (do_announce) if (do_filefind)
if (Announce()) if (Filefind())
Mail = TRUE; Mail = TRUE;
if (do_filefind) if (Mail) {
if (Filefind()) CreateSema((char *)"mailout");
Mail = TRUE; CreateSema((char *)"msglink");
}
if (Mail) { die(MBERR_OK);
CreateSema((char *)"mailout"); return 0;
CreateSema((char *)"msglink");
}
die(MBERR_OK);
return 0;
} }

View File

@ -4,7 +4,7 @@
* Purpose: File Database Maintenance * Purpose: File Database Maintenance
* *
***************************************************************************** *****************************************************************************
* Copyright (C) 1997-2002 * Copyright (C) 1997-2003
* *
* Michiel Broek FIDO: 2:280/2802 * Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10 * Beekmansbos 10
@ -218,6 +218,12 @@ int main(int argc, char **argv)
if (!diskfree(CFG.freespace)) if (!diskfree(CFG.freespace))
die(MBERR_DISK_FULL); die(MBERR_DISK_FULL);
if (lockprogram((char *)"mbfile")) {
if (!do_quiet)
printf("Can't lock mbfile, abort.\n");
die(MBERR_NO_PROGLOCK);
}
if (do_adopt) { if (do_adopt) {
AdoptFile(Area, FileName, Description); AdoptFile(Area, FileName, Description);
die(MBERR_OK); die(MBERR_OK);

View File

@ -4,7 +4,7 @@
* Purpose: File Database Maintenance - utilities * Purpose: File Database Maintenance - utilities
* *
***************************************************************************** *****************************************************************************
* Copyright (C) 1997-2002 * Copyright (C) 1997-2003
* *
* Michiel Broek FIDO: 2:280/2802 * Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10 * Beekmansbos 10
@ -66,43 +66,44 @@ void ProgName(void)
void die(int onsig) void die(int onsig)
{ {
/*
* First check if a child is running, if so, kill it.
*/
if (e_pid) {
if ((kill(e_pid, SIGTERM)) == 0)
Syslog('+', "SIGTERM to pid %d succeeded", e_pid);
else {
if ((kill(e_pid, SIGKILL)) == 0)
Syslog('+', "SIGKILL to pid %d succeded", e_pid);
else
WriteError("$Failed to kill pid %d", e_pid);
}
/* /*
* First check if a child is running, if so, kill it. * In case the child had the tty in raw mode...
*/ */
if (e_pid) { if (!do_quiet)
if ((kill(e_pid, SIGTERM)) == 0) system("stty sane");
Syslog('+', "SIGTERM to pid %d succeeded", e_pid); }
else {
if ((kill(e_pid, SIGKILL)) == 0)
Syslog('+', "SIGKILL to pid %d succeded", e_pid);
else
WriteError("$Failed to kill pid %d", e_pid);
}
/* signal(onsig, SIG_IGN);
* In case the child had the tty in raw mode...
*/
if (!do_quiet)
system("stty sane");
}
signal(onsig, SIG_IGN); if (onsig) {
if (onsig <= NSIG)
WriteError("Terminated on signal %d (%s)", onsig, SigName[onsig]);
else
WriteError("Terminated with error %d", onsig);
}
if (onsig) { ulockprogram((char *)"mbfile");
if (onsig <= NSIG) t_end = time(NULL);
WriteError("Terminated on signal %d (%s)", onsig, SigName[onsig]); Syslog(' ', "MBFILE finished in %s", t_elapsed(t_start, t_end));
else
WriteError("Terminated with error %d", onsig);
}
t_end = time(NULL); if (!do_quiet) {
Syslog(' ', "MBFILE finished in %s", t_elapsed(t_start, t_end)); colour(LIGHTGRAY, BLACK);
fflush(stdout);
if (!do_quiet) { }
colour(LIGHTGRAY, BLACK); ExitClient(onsig);
fflush(stdout);
}
ExitClient(onsig);
} }

View File

@ -67,42 +67,43 @@ void ProgName()
void die(int onsig) void die(int onsig)
{ {
/*
* First check if a child is running, if so, kill it.
*/
if (e_pid) {
if ((kill(e_pid, SIGTERM)) == 0)
Syslog('+', "SIGTERM to pid %d succeeded", e_pid);
else {
if ((kill(e_pid, SIGKILL)) == 0)
Syslog('+', "SIGKILL to pid %d succeded", e_pid);
else
WriteError("$Failed to kill pid %d", e_pid);
}
/* /*
* First check if a child is running, if so, kill it. * In case the child had the tty in raw mode...
*/ */
if (e_pid) { system("stty sane");
if ((kill(e_pid, SIGTERM)) == 0) }
Syslog('+', "SIGTERM to pid %d succeeded", e_pid);
else {
if ((kill(e_pid, SIGKILL)) == 0)
Syslog('+', "SIGKILL to pid %d succeded", e_pid);
else
WriteError("$Failed to kill pid %d", e_pid);
}
/* signal(onsig, SIG_IGN);
* In case the child had the tty in raw mode...
*/
system("stty sane");
}
signal(onsig, SIG_IGN); if (onsig) {
if (onsig <= NSIG)
WriteError("Terminated on signal %d (%s)", onsig, SigName[onsig]);
else
WriteError("Terminated with error %d", onsig);
}
if (onsig) { ulockprogram((char *)"mball");
if (onsig <= NSIG) t_end = time(NULL);
WriteError("Terminated on signal %d (%s)", onsig, SigName[onsig]); Syslog(' ', "MBALL finished in %s", t_elapsed(t_start, t_end));
else
WriteError("Terminated with error %d", onsig);
}
t_end = time(NULL); if (!do_quiet) {
Syslog(' ', "MBALL finished in %s", t_elapsed(t_start, t_end)); colour(7, 0);
printf("\n");
if (!do_quiet) { }
colour(7, 0); ExitClient(onsig);
printf("\n");
}
ExitClient(onsig);
} }
@ -132,76 +133,82 @@ void Help()
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int i; int i;
char *cmd; char *cmd;
struct passwd *pw; struct passwd *pw;
#ifdef MEMWATCH #ifdef MEMWATCH
mwInit(); mwInit();
#endif #endif
InitConfig(); InitConfig();
TermInit(1); TermInit(1);
t_start = time(NULL); t_start = time(NULL);
umask(000); umask(000);
/* /*
* Catch all signals we can, and ignore the rest. * Catch all signals we can, and ignore the rest.
*/ */
for (i = 0; i < NSIG; i++) { for (i = 0; i < NSIG; i++) {
if ((i == SIGHUP) || (i == SIGKILL) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM)) if ((i == SIGHUP) || (i == SIGKILL) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM))
signal(i, (void (*))die); signal(i, (void (*))die);
else else
signal(i, SIG_IGN); signal(i, SIG_IGN);
} }
if(argc < 2) if(argc < 2)
Help(); Help();
cmd = xstrcpy((char *)"Command line: mball"); cmd = xstrcpy((char *)"Command line: mball");
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
cmd = xstrcat(cmd, (char *)" "); cmd = xstrcat(cmd, (char *)" ");
cmd = xstrcat(cmd, argv[i]); cmd = xstrcat(cmd, argv[i]);
if (!strncasecmp(argv[i], "l", 1)) if (!strncasecmp(argv[i], "l", 1))
do_list = TRUE; do_list = TRUE;
if (!strncasecmp(argv[i], "-q", 2)) if (!strncasecmp(argv[i], "-q", 2))
do_quiet = TRUE; do_quiet = TRUE;
if (!strncasecmp(argv[i], "-z", 2)) if (!strncasecmp(argv[i], "-z", 2))
do_zip = TRUE; do_zip = TRUE;
} }
if (!do_list) if (!do_list)
Help(); Help();
ProgName(); ProgName();
pw = getpwuid(getuid()); pw = getpwuid(getuid());
InitClient(pw->pw_name, (char *)"mball", CFG.location, CFG.logfile, CFG.util_loglevel, CFG.error_log, CFG.mgrlog); InitClient(pw->pw_name, (char *)"mball", CFG.location, CFG.logfile, CFG.util_loglevel, CFG.error_log, CFG.mgrlog);
Syslog(' ', " "); Syslog(' ', " ");
Syslog(' ', "MBALL v%s", VERSION); Syslog(' ', "MBALL v%s", VERSION);
Syslog(' ', cmd); Syslog(' ', cmd);
free(cmd); free(cmd);
if (!do_quiet) { if (!do_quiet) {
colour(3, 0); colour(3, 0);
printf("\n"); printf("\n");
} }
if (do_list) {
Masterlist();
if (do_zip)
MakeArc();
CreateSema((char *)"mailin");
}
if (lockprogram((char *)"mball")) {
if (!do_quiet) if (!do_quiet)
printf("Done!\n"); printf("Can't lock mball, abort.\n");
die(MBERR_NO_PROGLOCK);
}
die(MBERR_OK); if (do_list) {
return 0; Masterlist();
if (do_zip)
MakeArc();
CreateSema((char *)"mailin");
}
if (!do_quiet)
printf("Done!\n");
die(MBERR_OK);
return 0;
} }

View File

@ -4,7 +4,7 @@
* Purpose ...............: User Pack Util * Purpose ...............: User Pack Util
* *
***************************************************************************** *****************************************************************************
* Copyright (C) 1997-2002 * Copyright (C) 1997-2003
* *
* Michiel Broek FIDO: 2:280/2802 * Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10 * Beekmansbos 10
@ -53,77 +53,84 @@ mode_t oldmask; /* Old umask value */
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int i, pack = FALSE; int i, pack = FALSE;
char *cmd; char *cmd;
struct passwd *pw; struct passwd *pw;
#ifdef MEMWATCH #ifdef MEMWATCH
mwInit(); mwInit();
#endif #endif
InitConfig(); InitConfig();
TermInit(1); TermInit(1);
Days = 0; Days = 0;
Level = 0; Level = 0;
t_start = time(NULL); t_start = time(NULL);
if (argc < 2) if (argc < 2)
Help();
cmd = xstrcpy((char *)"Command line:");
for (i = 1; i < argc; i++) {
cmd = xstrcat(cmd, (char *)" ");
cmd = xstrcat(cmd, tl(argv[i]));
if (strncasecmp(tl(argv[i]), "-q", 2) == 0)
do_quiet = TRUE;
if (strncasecmp(tl(argv[i]), "p", 1) == 0)
pack = TRUE;
if (strncasecmp(tl(argv[i]), "k", 1) == 0) {
if (argc <= (i + 2))
Help(); Help();
i++;
cmd = xstrcat(cmd, (char *)" ");
cmd = xstrcat(cmd, argv[i]);
Days = atoi(argv[i]);
i++;
cmd = xstrcat(cmd, (char *)" ");
cmd = xstrcat(cmd, argv[i]);
Level = atoi(argv[i]);
cmd = xstrcpy((char *)"Command line:"); if ((Days == 0) || (Level == 0))
Help();
for (i = 1; i < argc; i++) {
cmd = xstrcat(cmd, (char *)" ");
cmd = xstrcat(cmd, tl(argv[i]));
if (strncasecmp(tl(argv[i]), "-q", 2) == 0)
do_quiet = TRUE;
if (strncasecmp(tl(argv[i]), "p", 1) == 0)
pack = TRUE;
if (strncasecmp(tl(argv[i]), "k", 1) == 0) {
if (argc <= (i + 2))
Help();
i++;
cmd = xstrcat(cmd, (char *)" ");
cmd = xstrcat(cmd, argv[i]);
Days = atoi(argv[i]);
i++;
cmd = xstrcat(cmd, (char *)" ");
cmd = xstrcat(cmd, argv[i]);
Level = atoi(argv[i]);
if ((Days == 0) || (Level == 0))
Help();
}
} }
}
if ((Days + Level + pack) == 0) if ((Days + Level + pack) == 0)
Help(); Help();
ProgName(); ProgName();
pw = getpwuid(getuid()); pw = getpwuid(getuid());
InitClient(pw->pw_name, (char *)"mbuser", CFG.location, CFG.logfile, CFG.util_loglevel, CFG.error_log, CFG.mgrlog); InitClient(pw->pw_name, (char *)"mbuser", CFG.location, CFG.logfile, CFG.util_loglevel, CFG.error_log, CFG.mgrlog);
Syslog(' ', " "); Syslog(' ', " ");
Syslog(' ', "MBUSER v%s", VERSION); Syslog(' ', "MBUSER v%s", VERSION);
Syslog(' ', cmd); Syslog(' ', cmd);
free(cmd); free(cmd);
if (!diskfree(CFG.freespace)) if (!diskfree(CFG.freespace))
ExitClient(MBERR_DISK_FULL); ExitClient(MBERR_DISK_FULL);
oldmask = umask(027); if (lockprogram((char *)"mbuser")) {
if (!do_quiet) if (!do_quiet)
colour(3, 0); printf("Can't lock mbuser, abort.\n");
UserPack(Days, Level, pack); ExitClient(MBERR_NO_PROGLOCK);
umask(oldmask); }
t_end = time(NULL); oldmask = umask(027);
Syslog(' ', "MBUSER finished in %s", t_elapsed(t_start, t_end)); if (!do_quiet)
colour(3, 0);
UserPack(Days, Level, pack);
umask(oldmask);
if (!do_quiet) ulockprogram((char *)"mbuser");
colour(7, 0); t_end = time(NULL);
ExitClient(MBERR_OK); Syslog(' ', "MBUSER finished in %s", t_elapsed(t_start, t_end));
return 0;
if (!do_quiet)
colour(7, 0);
ExitClient(MBERR_OK);
return 0;
} }

View File

@ -788,8 +788,6 @@ void ulocktask(void)
if (oldpid == getpid()) { if (oldpid == getpid()) {
(void)unlink(lockfile); (void)unlink(lockfile);
} else {
WriteError("Lockfile owned by pid %d, not removed", oldpid);
} }
free(lockfile); free(lockfile);