Skip to content

Commit

Permalink
extend pause example with configurable sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
Dorian Eikenberg committed Jan 21, 2020
1 parent 44fc705 commit 7aa51cb
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions c_examples/pause.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#include <stdio.h>
#include <stdlib.h>
#include "libmicrovmi.h"
#include <unistd.h>

void pause(MicrovmiContext* driver) {
void pause_vm(MicrovmiContext* driver, unsigned long sleep_duration) {
if (microvmi_pause(driver) == MicrovmiSuccess) {
printf("Paused.\n");
} else {
printf("Unable to pause VM.\n");
return;
}
usleep(sleep_duration);
if (microvmi_resume(driver) == MicrovmiSuccess) {
printf("Resumed.\n");
} else {
Expand All @@ -16,12 +19,17 @@ void pause(MicrovmiContext* driver) {
}

int main(int argc, char* argv[]) {
if (argc < 2) {
printf("No domain name given.\n");
if (argc < 3) {
printf("Usage: regs-dump <vm_name> <sleep_seconds>.\n");
return 1;
}
unsigned long sleep_duration_sec = strtoul(argv[2], NULL, 0);
if (sleep_duration_sec == 0) {
printf("Unable to parse sleep duration or zero provided.\n");
return 1;
}
MicrovmiContext* driver = microvmi_init(argv[1], NULL);
pause(driver);
pause_vm(driver, sleep_duration_sec * 1000000);
microvmi_destroy(driver);
return 0;
}

0 comments on commit 7aa51cb

Please sign in to comment.