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
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:
Added language prompts 18 and 19.

View File

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

View File

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

View File

@ -4,7 +4,7 @@
* Purpose: File Database Maintenance
*
*****************************************************************************
* Copyright (C) 1997-2002
* Copyright (C) 1997-2003
*
* Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10
@ -218,6 +218,12 @@ int main(int argc, char **argv)
if (!diskfree(CFG.freespace))
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) {
AdoptFile(Area, FileName, Description);
die(MBERR_OK);

View File

@ -4,7 +4,7 @@
* Purpose: File Database Maintenance - utilities
*
*****************************************************************************
* Copyright (C) 1997-2002
* Copyright (C) 1997-2003
*
* Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10
@ -66,43 +66,44 @@ void ProgName(void)
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 ((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);
}
if (!do_quiet)
system("stty sane");
}
/*
* In case the child had the tty in raw mode...
*/
if (!do_quiet)
system("stty sane");
}
signal(onsig, SIG_IGN);
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) {
if (onsig <= NSIG)
WriteError("Terminated on signal %d (%s)", onsig, SigName[onsig]);
else
WriteError("Terminated with error %d", onsig);
}
ulockprogram((char *)"mbfile");
t_end = time(NULL);
Syslog(' ', "MBFILE finished in %s", t_elapsed(t_start, t_end));
t_end = time(NULL);
Syslog(' ', "MBFILE finished in %s", t_elapsed(t_start, t_end));
if (!do_quiet) {
colour(LIGHTGRAY, BLACK);
fflush(stdout);
}
ExitClient(onsig);
if (!do_quiet) {
colour(LIGHTGRAY, BLACK);
fflush(stdout);
}
ExitClient(onsig);
}

View File

@ -67,42 +67,43 @@ void ProgName()
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 ((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);
}
system("stty sane");
}
/*
* In case the child had the tty in raw mode...
*/
system("stty sane");
}
signal(onsig, SIG_IGN);
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) {
if (onsig <= NSIG)
WriteError("Terminated on signal %d (%s)", onsig, SigName[onsig]);
else
WriteError("Terminated with error %d", onsig);
}
ulockprogram((char *)"mball");
t_end = time(NULL);
Syslog(' ', "MBALL finished in %s", t_elapsed(t_start, t_end));
t_end = time(NULL);
Syslog(' ', "MBALL finished in %s", t_elapsed(t_start, t_end));
if (!do_quiet) {
colour(7, 0);
printf("\n");
}
ExitClient(onsig);
if (!do_quiet) {
colour(7, 0);
printf("\n");
}
ExitClient(onsig);
}
@ -132,76 +133,82 @@ void Help()
int main(int argc, char **argv)
{
int i;
char *cmd;
struct passwd *pw;
int i;
char *cmd;
struct passwd *pw;
#ifdef MEMWATCH
mwInit();
mwInit();
#endif
InitConfig();
TermInit(1);
t_start = time(NULL);
umask(000);
InitConfig();
TermInit(1);
t_start = time(NULL);
umask(000);
/*
* Catch all signals we can, and ignore the rest.
*/
for (i = 0; i < NSIG; i++) {
if ((i == SIGHUP) || (i == SIGKILL) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM))
signal(i, (void (*))die);
else
signal(i, SIG_IGN);
}
/*
* Catch all signals we can, and ignore the rest.
*/
for (i = 0; i < NSIG; i++) {
if ((i == SIGHUP) || (i == SIGKILL) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM))
signal(i, (void (*))die);
else
signal(i, SIG_IGN);
}
if(argc < 2)
Help();
if(argc < 2)
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, argv[i]);
cmd = xstrcat(cmd, (char *)" ");
cmd = xstrcat(cmd, argv[i]);
if (!strncasecmp(argv[i], "l", 1))
do_list = TRUE;
if (!strncasecmp(argv[i], "-q", 2))
do_quiet = TRUE;
if (!strncasecmp(argv[i], "-z", 2))
do_zip = TRUE;
}
if (!strncasecmp(argv[i], "l", 1))
do_list = TRUE;
if (!strncasecmp(argv[i], "-q", 2))
do_quiet = TRUE;
if (!strncasecmp(argv[i], "-z", 2))
do_zip = TRUE;
}
if (!do_list)
Help();
if (!do_list)
Help();
ProgName();
pw = getpwuid(getuid());
InitClient(pw->pw_name, (char *)"mball", CFG.location, CFG.logfile, CFG.util_loglevel, CFG.error_log, CFG.mgrlog);
ProgName();
pw = getpwuid(getuid());
InitClient(pw->pw_name, (char *)"mball", CFG.location, CFG.logfile, CFG.util_loglevel, CFG.error_log, CFG.mgrlog);
Syslog(' ', " ");
Syslog(' ', "MBALL v%s", VERSION);
Syslog(' ', cmd);
free(cmd);
Syslog(' ', " ");
Syslog(' ', "MBALL v%s", VERSION);
Syslog(' ', cmd);
free(cmd);
if (!do_quiet) {
colour(3, 0);
printf("\n");
}
if (do_list) {
Masterlist();
if (do_zip)
MakeArc();
CreateSema((char *)"mailin");
}
if (!do_quiet) {
colour(3, 0);
printf("\n");
}
if (lockprogram((char *)"mball")) {
if (!do_quiet)
printf("Done!\n");
printf("Can't lock mball, abort.\n");
die(MBERR_NO_PROGLOCK);
}
die(MBERR_OK);
return 0;
if (do_list) {
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
*
*****************************************************************************
* Copyright (C) 1997-2002
* Copyright (C) 1997-2003
*
* Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10
@ -53,77 +53,84 @@ mode_t oldmask; /* Old umask value */
int main(int argc, char **argv)
{
int i, pack = FALSE;
char *cmd;
struct passwd *pw;
int i, pack = FALSE;
char *cmd;
struct passwd *pw;
#ifdef MEMWATCH
mwInit();
mwInit();
#endif
InitConfig();
TermInit(1);
Days = 0;
Level = 0;
InitConfig();
TermInit(1);
Days = 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();
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:");
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 == 0) || (Level == 0))
Help();
}
}
if ((Days + Level + pack) == 0)
Help();
if ((Days + Level + pack) == 0)
Help();
ProgName();
pw = getpwuid(getuid());
InitClient(pw->pw_name, (char *)"mbuser", CFG.location, CFG.logfile, CFG.util_loglevel, CFG.error_log, CFG.mgrlog);
Syslog(' ', " ");
Syslog(' ', "MBUSER v%s", VERSION);
Syslog(' ', cmd);
free(cmd);
ProgName();
pw = getpwuid(getuid());
InitClient(pw->pw_name, (char *)"mbuser", CFG.location, CFG.logfile, CFG.util_loglevel, CFG.error_log, CFG.mgrlog);
Syslog(' ', " ");
Syslog(' ', "MBUSER v%s", VERSION);
Syslog(' ', cmd);
free(cmd);
if (!diskfree(CFG.freespace))
ExitClient(MBERR_DISK_FULL);
if (!diskfree(CFG.freespace))
ExitClient(MBERR_DISK_FULL);
oldmask = umask(027);
if (lockprogram((char *)"mbuser")) {
if (!do_quiet)
colour(3, 0);
UserPack(Days, Level, pack);
umask(oldmask);
printf("Can't lock mbuser, abort.\n");
ExitClient(MBERR_NO_PROGLOCK);
}
t_end = time(NULL);
Syslog(' ', "MBUSER finished in %s", t_elapsed(t_start, t_end));
oldmask = umask(027);
if (!do_quiet)
colour(3, 0);
UserPack(Days, Level, pack);
umask(oldmask);
if (!do_quiet)
colour(7, 0);
ExitClient(MBERR_OK);
return 0;
ulockprogram((char *)"mbuser");
t_end = time(NULL);
Syslog(' ', "MBUSER finished in %s", t_elapsed(t_start, t_end));
if (!do_quiet)
colour(7, 0);
ExitClient(MBERR_OK);
return 0;
}

View File

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