Commit 65a1f611 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(iflag): Now static.

(rflag): Now static.
(gflag): Now static.
(sflag): Now static.
(force_output): Now static.
(unset_change_name_is_error): Now static.
(dump_text_numbers): Now static.
(main): Only lock the database when dbck might want to change it.
	Added a missing break statement.  Mark the database as modified if
	any of --pres-pres-conf, --conf-pres-conf, --motd-conf,
	--motd-of-kom or --kom-news-conf is used.
parent b0c5a05d
/*
* $Id: dbck.c,v 0.49 1999/05/21 06:52:56 ceder Exp $
* $Id: dbck.c,v 0.50 1999/05/21 12:22:43 ceder Exp $
* Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -35,7 +35,7 @@
static const char *
rcsid = "$Id: dbck.c,v 0.49 1999/05/21 06:52:56 ceder Exp $";
rcsid = "$Id: dbck.c,v 0.50 1999/05/21 12:22:43 ceder Exp $";
#include "rcs.h"
USE(rcsid);
......@@ -120,17 +120,17 @@ extern Info kom_info;
Bool truncated_texts = FALSE;
int vflag=0; /* Verbose - list statistics also. */
int iflag=0; /* Interactive - prompt user and repair. */
int rflag=0; /* Repair simple error without confirmation. */
int gflag=0; /* Garbage collect text-file. */
int sflag=0; /* Statistic flag. */
static int iflag=0; /* Interactive - prompt user and repair. */
static int rflag=0; /* Repair simple error without confirmation. */
static int gflag=0; /* Garbage collect text-file. */
static int sflag=0; /* Statistic flag. */
static Pers_no reset_pwd=0; /* Person whose password should be cleared. */
static Pers_no grant_all=0; /* Person which should receive all bits. */
/* The following variable holds the output format */
long oformat=-1; /* Output format */
long force_output=0; /* Force sync (for conversions) */
static long force_output=0; /* Force sync (for conversions) */
/* The following variables hold kom_info modifications */
......@@ -143,11 +143,11 @@ int kom_news_conf = -1;
/* The following variable corresponds to the -c flag, and is
present here due to a bug in lyskomd 1.6.1. */
int unset_change_name_is_error=0;
static int unset_change_name_is_error=0;
/* A list of all available text numbers was useful when developing
new data structures in lyskomd in 1995. Option: -t. */
int dump_text_numbers=0;
static int dump_text_numbers=0;
int modifications = 0;
......@@ -1507,6 +1507,8 @@ main (int argc,
char *default_config_file;
char *config_file;
char optc;
int need_rw = 0;
int have_lock = 0;
while ((optc = getopt_long(argc, argv, "girvstdcP:G:Fo:",
longopts, (int *) 0)) != EOF)
......@@ -1517,30 +1519,35 @@ main (int argc,
pers_pres_conf = atoi(optarg);
if (pers_pres_conf == 0)
restart_kom("%s: bad conference number %s\n", argv[0], optarg);
need_rw = 1;
break;
case OPT_CONF_PRESENTATION_CONF:
conf_pres_conf = atoi(optarg);
if (conf_pres_conf == 0)
restart_kom("%s: bad conference number %s\n", argv[0], optarg);
need_rw = 1;
break;
case OPT_MOTD_CONF:
motd_conf = atoi(optarg);
if (motd_conf == 0)
restart_kom("%s: bad conference number %s\n", argv[0], optarg);
need_rw = 1;
break;
case OPT_MOTD_OF_KOM:
motd_of_lyskom = atoi(optarg);
if (motd_of_lyskom == 0 && *optarg != '0')
restart_kom("%s: bad text number %s\n", argv[0], optarg);
need_rw = 1;
break;
case OPT_KOM_NEWS_CONF:
kom_news_conf = atoi(optarg);
if (kom_news_conf == 0)
restart_kom("%s: bad conference number %s\n", argv[0], optarg);
need_rw = 1;
break;
#ifndef NDEBUG
......@@ -1551,10 +1558,12 @@ main (int argc,
case 'i': /* Running interactively. */
iflag++; /* Will ask user and try to repair. */
need_rw = 1;
break;
case 'r': /* Repair simple errors wihtout asking. */
rflag++;
need_rw = 1;
break;
case 'v': /* Verbose: report more than errors. */
......@@ -1563,6 +1572,7 @@ main (int argc,
case 'g': /* Garbage collect: compress text-file. */
gflag++;
need_rw = 1;
break;
case 'h': /* Help: give usage message. */
......@@ -1575,6 +1585,8 @@ main (int argc,
case 'c': /* Consider an unset change_name an error. */
unset_change_name_is_error = 1;
/* No need for rw, since this only flags the condition as
an error. You still need -r or -i to fix the error. */
break;
case 't':
......@@ -1588,14 +1600,18 @@ main (int argc,
/* Seed the random number generator. */
srand(time(NULL) + getpid());
#endif
need_rw = 1;
break;
case 'G':
grant_all = atol(optarg);
kom_log("Will grant all bits to person %ld", (long)grant_all);
need_rw = 1;
break;
case 'F':
force_output = 1;
need_rw = 1;
break;
case 'o': /* Select output format */
......@@ -1636,15 +1652,30 @@ main (int argc,
*/
if (pers_pres_conf != -1)
{
kom_info.pers_pres_conf = pers_pres_conf;
modifications++;
}
if (conf_pres_conf != -1)
{
kom_info.conf_pres_conf = conf_pres_conf;
modifications++;
}
if (motd_conf != -1)
{
kom_info.motd_conf = motd_conf;
modifications++;
}
if (kom_news_conf != -1)
{
kom_info.kom_news_conf = kom_news_conf;
modifications++;
}
if (motd_of_lyskom != -1)
kom_info.motd_of_lyskom = motd_of_lyskom;
{
kom_info.motd_of_lyskom = motd_of_lyskom;
modifications++;
}
if (optind != argc)
restart_kom("%s: too many arguments. %s --help for usage.\n",
......@@ -1652,8 +1683,12 @@ main (int argc,
s_set_storage_management(smalloc, srealloc, sfree);
if (lock_db() < 0)
exit(1);
if (need_rw)
{
if (lock_db() < 0)
exit(1);
have_lock = 1;
}
init_data_base();
errors = check_data_base();
......@@ -1672,14 +1707,17 @@ main (int argc,
modifications, modifications == 1 ? "" : "s");
fflush(stdout);
fflush(stderr);
cache_sync_all();
if (have_lock)
cache_sync_all();
else
kom_log("Database not saved since the lock was not obtained.\n");
kom_log("ready.\n");
}
if ( sflag )
print_statistics();
if ( gflag )
if (gflag && have_lock)
{
if ( modifications == 0 && errors == 0 )
{
......@@ -1707,6 +1745,7 @@ main (int argc,
}
}
unlock_db();
if (have_lock)
unlock_db();
return errors != 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment