| 348 | |
| 349 | #ifdef INSURANCE |
| 350 | void |
| 351 | savestateinlock(void) |
| 352 | { |
| 353 | int hpid = 0; |
| 354 | char whynot[BUFSZ]; |
| 355 | NHFILE *nhfp; |
| 356 | |
| 357 | program_state.saving++; /* inhibit status and perm_invent updates */ |
| 358 | /* When checkpointing is on, the full state needs to be written |
| 359 | * on each checkpoint. When checkpointing is off, only the pid |
| 360 | * needs to be in the level.0 file, so it does not need to be |
| 361 | * constantly rewritten. When checkpointing is turned off during |
| 362 | * a game, however, the file has to be rewritten once to truncate |
| 363 | * it and avoid restoring from outdated information. |
| 364 | * |
| 365 | * Restricting gh.havestate to this routine means that an additional |
| 366 | * noop pid rewriting will take place on the first "checkpoint" after |
| 367 | * the game is started or restored, if checkpointing is off. |
| 368 | */ |
| 369 | if (flags.ins_chkpt || gh.havestate) { |
| 370 | /* save the rest of the current game state in the lock file, |
| 371 | * following the original int pid, the current level number, |
| 372 | * and the current savefile name, which should not be subject |
| 373 | * to any internal compression schemes since they must be |
| 374 | * readable by an external utility |
| 375 | */ |
| 376 | nhfp = open_levelfile(0, whynot); |
| 377 | if (tricked_fileremoved(nhfp, whynot)) { |
| 378 | program_state.saving--; |
| 379 | return; |
| 380 | } |
| 381 | |
| 382 | Sfi_int(nhfp, &hpid, "gamestate-hackpid"); |
| 383 | if (svh.hackpid != hpid) { |
| 384 | Sprintf(whynot, "Level #0 pid (%d) doesn't match ours (%d)!", |
| 385 | hpid, svh.hackpid); |
| 386 | goto giveup; |
| 387 | } |
| 388 | close_nhfile(nhfp); |
| 389 | |
| 390 | nhfp = create_levelfile(0, whynot); |
| 391 | if (!nhfp) { |
| 392 | pline1(whynot); |
| 393 | giveup: |
| 394 | Strcpy(svk.killer.name, whynot); |
| 395 | /* done(TRICKED) will return when running in wizard mode; |
| 396 | clear the display-update-suppression flag before rather |
| 397 | than after so that screen updating behaves normally; |
| 398 | game data shouldn't be inconsistent yet, unlike it would |
| 399 | become midway through saving */ |
| 400 | program_state.saving--; |
| 401 | done(TRICKED); |
| 402 | return; |
| 403 | } |
| 404 | nhfp->mode = WRITING; |
| 405 | Sfo_int(nhfp, &svh.hackpid, "gamestate-hackpid"); |
| 406 | if (flags.ins_chkpt) { |
| 407 | int currlev = ledger_no(&u.uz); |
no test coverage detected