… | |
… | |
367 | |
367 | |
368 | $coro |
368 | $coro |
369 | } |
369 | } |
370 | |
370 | |
371 | sub write_runtime { |
371 | sub write_runtime { |
|
|
372 | my $runtime = "$LOCALDIR/runtime"; |
|
|
373 | |
|
|
374 | # first touch the runtime file to show we are still running: |
|
|
375 | # the fsync below can take a very very long time. |
|
|
376 | |
|
|
377 | warn "touching runtime...\n";#d# |
|
|
378 | if (my $fh = aio_open $runtime, O_WRONLY, 0) { |
|
|
379 | utime undef, undef, $fh; |
|
|
380 | } |
|
|
381 | |
372 | my $guard = cf::lock_acquire "write_runtime"; |
382 | my $guard = cf::lock_acquire "write_runtime"; |
373 | |
383 | |
374 | my $runtime = "$LOCALDIR/runtime"; |
384 | warn "starting to write runtime...\n";#d# |
375 | |
|
|
376 | my $fh = aio_open "$runtime~", O_WRONLY | O_CREAT, 0644 |
385 | my $fh = aio_open "$runtime~", O_WRONLY | O_CREAT, 0644 |
377 | or return; |
386 | or return; |
378 | |
387 | |
379 | my $value = $cf::RUNTIME + 90 + 10; |
388 | my $value = $cf::RUNTIME + 90 + 10; |
380 | # 10 is the runtime save interval, for a monotonic clock |
389 | # 10 is the runtime save interval, for a monotonic clock |
… | |
… | |
385 | |
394 | |
386 | # always fsync - this file is important |
395 | # always fsync - this file is important |
387 | aio_fsync $fh |
396 | aio_fsync $fh |
388 | and return; |
397 | and return; |
389 | |
398 | |
|
|
399 | # touch it again to show we are up-to-date |
|
|
400 | utime undef, undef, $fh; |
|
|
401 | |
390 | close $fh |
402 | close $fh |
391 | or return; |
403 | or return; |
392 | |
404 | |
393 | aio_rename "$runtime~", $runtime |
405 | aio_rename "$runtime~", $runtime |
394 | and return; |
406 | and return; |
|
|
407 | |
|
|
408 | warn "... done writing runtime.\n";#d# |
395 | |
409 | |
396 | 1 |
410 | 1 |
397 | } |
411 | } |
398 | |
412 | |
399 | =item cf::datalog type => key => value, ... |
413 | =item cf::datalog type => key => value, ... |