|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T c
Length: 6255 (0x186f)
Types: TextFile
Names: »ckp.c«
└─⟦a0efdde77⟧ Bits:30001252 EUUGD11 Tape, 1987 Spring Conference Helsinki
└─⟦this⟧ »EUUGD11/euug-87hel/sec8/mcp/src/ckp.c«
/****************************************************************************\
* *
* ckp.c *
* *
* These are the routines that put changes that have not been saved, into *
* the .mcp checkpoint files. An important thing to remember here is that *
* checkpointing should not be interupted by anything, particularly not by *
* another checkpoint, or chaos will ensue. There are only one set ot temp *
* files shared by save and the checkpoint routines. This was done for the *
* sake of simplicity and also since the tempfiles are in the same *
* filesystem as their accounting counterparts, these can be rename()'d into *
* place without the possibility of being caught by a system crash with a *
* file copy partially completed. *
* *
\****************************************************************************/
#include <stdio.h>
#include <sys/types.h>
#include <signal.h>
#include <lastlog.h>
#include "sysdep.h"
#include "macros.h"
#include "mem.h"
#include "lists.h"
#ifdef SENDMAIL
#include "alias.h"
#endif
#include "account.h"
#include "class.h"
#include "sig.h"
#include "range.h"
#include "groupmap.h"
#include "save.h"
extern int ModBits;
#ifdef SENDMAIL
extern struct list AliasList;
#endif
extern struct list AccountList, GroupMapList, SigList, ClassList, RangeList;
extern struct list Vigs, Jobs;
ckp_pw()
{
FILE *pwf;
register int i;
struct account *ac;
pwf = fopen(PWDTMP, "w");
if (pwf == NULL) {
perr(PWDTMP);
return;
}
for (i=0; i < AccountList.l_count; i++) {
ac = (struct account *) AccountList.l_list[i];
(void) fprintf(pwf, "%s:%s:%d:%d:%s:%s:%s\n",
ac->ac_name,
ac->ac_passwd,
ac->ac_uid,
ac->ac_gid,
ac->ac_gecos,
ac->ac_dir,
ac->ac_shell);
}
(void) fclose(pwf);
if (rename(PWDTMP, PWDCKP) == -1) {
perr(PWDTMP);
return;
}
return;
}
#ifdef SENDMAIL
ckp_al()
{
FILE *alf, *bindf;
struct alias *al;
register int i;
alf = fopen(ALIASTMP, "w");
if (alf == NULL) {
perr(ALIASTMP);
return;
}
bindf = fopen(ALBINDTMP, "w");
if (bindf == NULL) {
perr(ALBINDTMP);
(void) fclose(alf);
return;
}
for (i=0; i < AliasList.l_count; i++) {
al = (struct alias *) AliasList.l_list[i];
(void) fprintf(alf, "%s:", al->al_name);
listout(&al->al_addresses, alf);
fputs("\n", alf);
(void) fprintf(bindf, "%s:", al->al_name);
listout(&al->al_groups, bindf);
fputs(":", bindf);
listout(&al->al_classes, bindf);
fputs(":", bindf);
listout(&al->al_sigs, bindf);
fputs("\n", bindf);
}
(void) fclose(alf);
(void) fclose(bindf);
if (rename(ALIASTMP, ALIASCKP) == -1) {
perr(ALIASTMP);
return;
}
if (rename(ALBINDTMP, ALBINDCKP) == -1) {
perr(ALBINDTMP);
return;
}
return;
}
#endif
ckp_ac()
{
FILE *acf;
register int i;
struct account *ac;
acf = fopen(ACTMP, "w");
if (acf == NULL) {
perr(ACTMP);
return;
}
for (i=0; i < AccountList.l_count; i++) {
ac = (struct account *) AccountList.l_list[i];
(void) fprintf(acf, "%s:%s:%s:%d:%d:",
ac->ac_name,
ac->ac_realname,
ac->ac_id,
ac->ac_uid,
ac->ac_gid);
listout(&ac->ac_groups, acf);
fputs(":", acf);
listout(&ac->ac_classes, acf);
fputs(":", acf);
listout(&ac->ac_sigs, acf);
fputs(":", acf);
#ifdef SENDMAIL
listout(&ac->ac_aliases, acf);
#endif
fputs("\n", acf);
}
(void) fclose(acf);
if (rename(ACTMP, ACCKP) == -1) {
perr(ACTMP);
return;
}
return;
}
ckp_gr()
{
FILE *grf;
register int i;
struct groupmap *gm;
grf = fopen(GRPTMP, "w");
if (grf == NULL) {
perr(GRPTMP);
return;
}
for (i=0; i < GroupMapList.l_count; i++) {
gm = (struct groupmap *) GroupMapList.l_list[i];
(void) fprintf(grf, "%s:%s:%d:",
gm->gm_name,
gm->gm_passwd,
gm->gm_gid);
listout(&gm->gm_mem, grf);
fputs("\n", grf);
}
(void) fclose(grf);
if (rename(GRPTMP, GRPCKP) == -1) {
perr(GRPTMP);
return;
}
return;
}
ckp_cs()
{
struct class *cs;
register int i;
FILE *csf;
csf = fopen(CSTMP, "w");
if (csf == NULL) {
perr(CSTMP);
return;
}
for (i=0; i < ClassList.l_count; i++) {
cs = (struct class *) ClassList.l_list[i];
(void) fprintf(csf, "%s %d %d\n", cs->cs_name, cs->cs_dsize,
cs->cs_exptime);
(void) fprintf(csf, "%s", cs->cs_desc);
}
(void) fclose(csf);
if (rename(CSTMP, CSCKP) == -1) {
perr(CSTMP);
return;
}
return;
}
ckp_sg()
{
struct sig *sg;
register int i;
FILE *sgf;
sgf = fopen(SIGTMP, "w");
if (sgf == NULL) {
perr(SIGTMP);
return;
}
for (i=0; i < SigList.l_count; i++) {
sg = (struct sig *) SigList.l_list[i];
(void) fprintf(sgf, "%s %d %d\n", sg->sg_name, sg->sg_dsize,
sg->sg_exptime);
(void) fprintf(sgf, "%s", sg->sg_desc);
}
(void) fclose(sgf);
if (rename(SIGTMP, SIGCKP) == -1) {
perr(SIGTMP);
return;
}
return;
}
ckp_rg()
{
struct range *rg;
register int i;
FILE *rgf;
rgf = fopen(RANGETMP, "w");
if (rgf == NULL) {
perr(RANGETMP);
return;
}
for (i=0; i < RangeList.l_count; i++) {
rg = (struct range *) RangeList.l_list[i];
(void) fprintf(rgf, "%s\t%d\t%d\t%s\n",
rg->rg_name,
rg->rg_from,
rg->rg_to,
(rg->rg_mode == RG_SHARED ? "shared" : "exclusive"));
}
(void) fclose(rgf);
if (rename(RANGETMP, RANGECKP) == -1) {
perr(RANGETMP);
return;
}
return;
}
ckp_vg()
{
register int i;
FILE *vgf;
vgf = fopen(VIGTMP, "w");
if (vgf == NULL) {
perr(VIGTMP);
return;
}
for (i=0; i < Vigs.l_count; i++)
(void) fprintf(vgf, "%s\n", Vigs.l_list[i]);
(void) fclose(vgf);
if (rename(VIGTMP, VIGCKP) == -1) {
perr(VIGTMP);
return;
}
return;
}
panic(reason)
char *reason;
{
err("");
err(reason);
if (ModBits) {
msg("Checkpointing...");
ckpchanges();
err("All changes made to the accounting files");
err("have been checkpointed.");
}
goodbye(1);
}
ckpchanges()
{
/*
* All signals that could cause an unwanted checkpoint are blocked
* here lest file collisions and choas ensue.
*/
critical();
(ModBits&PW) && ckp_pw();
(ModBits&AC) && ckp_ac();
#ifdef SENDMAIL
(ModBits&AL) && ckp_al();
#endif
(ModBits&CS) && ckp_cs();
(ModBits&GR) && ckp_gr();
(ModBits&RG) && ckp_rg();
(ModBits&SG) && ckp_sg();
(ModBits&VG) && ckp_vg();
sync();
non_critical();
return;
}