shrub/vere/save.c
Joe Bryan 8bf02a857a Merge branch 'master' into cc-release-rc-merge
* master: (99 commits)
  updates contact instructions
  erased some lines in raft
  updates libent submodule
  cleans up event error handling in _raft_lame
  Remove includes introduced for getentropy
  Use libent for getentropy
  Fix link in README
  remove old version of u3r_mug()
  renames test-hash
  removes temporary u3r_mug tests
  adds assertions to protect u3r_mug against stack overflow
  adds a u3_none explicit bottom stack frame to u3r_mug
  WIP simplified conditionals, still dies, appears stateful?
  WIP refactored but still dying
  WIP still dying
  WIP testing and printing
  WIP compiles but crashes
  updates CONTRIBUTING.md, removing obsolete instructions
  exit cleanly if $galaxy is already running (fake or real)
  corrects usage instructions
  ...
2019-01-17 22:05:19 -05:00

79 lines
1.3 KiB
C

/* vere/save.c
**
*/
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <termios.h>
#include <uv.h>
#include "all.h"
#include "vere/vere.h"
/* _save_time_cb(): timer callback.
*/
static void
_save_time_cb(uv_timer_t* tim_u)
{
u3_pier *pir_u = tim_u->data;
u3_save* sav_u = pir_u->sav_u;
if ( sav_u->pid_w ) {
return;
}
if ( u3A->ent_d > sav_u->ent_d ) {
// uL(fprintf(uH, "autosaving... ent_d %" PRIu64 "\n", u3A->ent_d));
// u3e_grab("save", u3_none);
u3e_save();
sav_u->ent_d = u3A->ent_d;
}
}
/* u3_save_ef_chld(): report save termination.
*/
void
u3_save_ef_chld(u3_pier *pir_u)
{
u3_save* sav_u = pir_u->sav_u;
c3_i loc_i;
c3_w pid_w;
/* modified for cases with no pid_w
*/
uL(fprintf(uH, "checkpoint: complete %d\n", sav_u->pid_w));
pid_w = wait(&loc_i);
if (0 != sav_u->pid_w) {
c3_assert(pid_w == sav_u->pid_w);
}
else {
c3_assert(pid_w > 0);
}
sav_u->pid_w = 0;
}
/* u3_save_io_init(): initialize autosave.
*/
void
u3_save_io_init(u3_pier *pir_u)
{
u3_save* sav_u = pir_u->sav_u;
sav_u->ent_d = 0;
sav_u->pid_w = 0;
sav_u->tim_u.data = pir_u;
uv_timer_init(u3L, &sav_u->tim_u);
uv_timer_start(&sav_u->tim_u, _save_time_cb, 120000, 120000);
}
/* u3_save_io_exit(): terminate save I/O.
*/
void
u3_save_io_exit(u3_pier *pir_u)
{
}