From 3c0de46dc92faa131799e29a53e98fa0b0a6c415 Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Sun, 3 Aug 2003 14:42:12 +0000 Subject: [PATCH] Added more program locks --- ChangeLog | 16 +++++ lib/proglock.c | 8 +-- mbfido/mbaff.c | 165 ++++++++++++++++++++++---------------------- mbfido/mbfile.c | 8 ++- mbfido/mbfutil.c | 65 +++++++++--------- mbsebbs/mball.c | 173 ++++++++++++++++++++++++----------------------- mbsebbs/mbuser.c | 121 +++++++++++++++++---------------- mbtask/mbtask.c | 2 - 8 files changed, 296 insertions(+), 262 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9c623131..5cad5f1d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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. diff --git a/lib/proglock.c b/lib/proglock.c index 514cfd9e..62b1f7a4 100644 --- a/lib/proglock.c +++ b/lib/proglock.c @@ -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); diff --git a/mbfido/mbaff.c b/mbfido/mbaff.c index a8a5431a..1e5a6430 100644 --- a/mbfido/mbaff.c +++ b/mbfido/mbaff.c @@ -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; } diff --git a/mbfido/mbfile.c b/mbfido/mbfile.c index f7e64e5c..fc0b1fb4 100644 --- a/mbfido/mbfile.c +++ b/mbfido/mbfile.c @@ -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); diff --git a/mbfido/mbfutil.c b/mbfido/mbfutil.c index 5ea2a159..99ca6923 100644 --- a/mbfido/mbfutil.c +++ b/mbfido/mbfutil.c @@ -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); } diff --git a/mbsebbs/mball.c b/mbsebbs/mball.c index 8dbabe88..16208553 100644 --- a/mbsebbs/mball.c +++ b/mbsebbs/mball.c @@ -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; } diff --git a/mbsebbs/mbuser.c b/mbsebbs/mbuser.c index 6f1396ae..104aeff8 100644 --- a/mbsebbs/mbuser.c +++ b/mbsebbs/mbuser.c @@ -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; } diff --git a/mbtask/mbtask.c b/mbtask/mbtask.c index f6139ed9..6b175064 100644 --- a/mbtask/mbtask.c +++ b/mbtask/mbtask.c @@ -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);