Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add memcr version info #91

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ endif

PCFLAGS += -Wstrict-prototypes -fno-stack-protector -fpie -nostdlib -ffreestanding -fomit-frame-pointer -Wa,--noexecstack

GIT_VERSION = $(shell git describe --dirty 2>/dev/null | sed 's/^v//' || echo "unknown")

GOFF = ./gen-offsets.sh

B ?= .
Expand Down Expand Up @@ -141,7 +143,7 @@ $(B)/cpu.o: arch/$(ARCH)/cpu.c
$(CC) $(MCFLAGS) -c $^ -o $@

$(B)/memcr.o: memcr.c $(B)/parasite-blob.h
$(CC) $(MCFLAGS) -I$(B) -c $< -o $@
$(CC) $(MCFLAGS) -DGIT_VERSION='"$(GIT_VERSION)"' -I$(B) -c $< -o $@

$(B)/memcr: $(B)/memcr.o $(B)/cpu.o $(B)/enter.o
$(CC) $(MCFLAGS) $^ $(LDFLAGS) -o $@
Expand All @@ -150,7 +152,7 @@ $(B)/memcr: $(B)/memcr.o $(B)/cpu.o $(B)/enter.o


$(B)/memcr-client.o: memcr-client.c
$(CC) $(CFLAGS) -I$(B) -c $< -o $@
$(CC) $(CFLAGS) -DGIT_VERSION='"$(GIT_VERSION)"' -I$(B) -c $< -o $@

$(B)/memcr-client: $(B)/memcr-client.o
$(CC) $(CFLAGS) $^ -o $@
Expand Down
16 changes: 13 additions & 3 deletions memcr-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,23 @@ static int send_cmd(int cd, struct service_command cmd)
return resp.resp_code;
}

static void print_version(void)
{
fprintf(stdout, "[i] memcr-client version %s\n", GIT_VERSION);
}

static void usage(const char *name, int status)
{
fprintf(status ? stderr : stdout,
"%s -l PORT|PATH -p PID [-c -r]\n" \
"%s -l PORT|PATH -p PID [-c -r] [-V]\n" \
"options: \n" \
" -h --help\t\thelp\n" \
" -l --location\t\tTCP port number of localhost memcr service\n" \
"\t\t\t or filesystem path to memcr service UNIX socket\n" \
" -p --pid\t\tprocess ID to be checkpointed / restored\n" \
" -c --checkpoint\tsend checkpoint command to memcr service\n" \
" -r --restore\t\tsend restore command to memcr service\n",
" -r --restore\t\tsend restore command to memcr service\n" \
" -V --version\t\tprint version and exit\n",
name);
exit(status);
}
Expand All @@ -123,10 +129,11 @@ int main(int argc, char *argv[])
{ "pid", 1, 0, 'p'},
{ "checkpoint", 0, 0, 'c'},
{ "restore", 0, 0, 'r'},
{ "version", 0, 0, 'V'},
{ NULL, 0, 0, 0 }
};

while ((opt = getopt_long(argc, argv, "hl:p:cr", long_options, &option_index)) != -1) {
while ((opt = getopt_long(argc, argv, "hl:p:crV", long_options, &option_index)) != -1) {
switch (opt) {
case 'h':
usage(argv[0], 0);
Expand All @@ -143,6 +150,9 @@ int main(int argc, char *argv[])
case 'r':
restore = 1;
break;
case 'V':
print_version();
exit(0);
default: /* '?' */
usage(argv[0], 1);
break;
Expand Down
18 changes: 15 additions & 3 deletions memcr.c
Original file line number Diff line number Diff line change
Expand Up @@ -2833,10 +2833,15 @@ static int user_interactive_mode(pid_t pid)
return ret;
}

static void print_version(void)
{
fprintf(stdout, "[i] memcr version %s\n", GIT_VERSION);
}

static void usage(const char *name, int status)
{
fprintf(status ? stderr : stdout,
"%s [-h] [-p PID] [-d DIR] [-S DIR] [-l PORT|PATH] [-n] [-m] [-f] [-z] [-c] [-e]\n" \
"%s [-h] [-p PID] [-d DIR] [-S DIR] [-l PORT|PATH] [-n] [-m] [-f] [-z] [-c] [-e] [-V]\n" \
"options:\n" \
" -h --help help\n" \
" -p --pid target processs pid\n" \
Expand All @@ -2854,7 +2859,8 @@ static void usage(const char *name, int status)
" -z --compress compress memory dump\n" \
" -c --checksum enable md5 checksum for memory dump\n" \
" -e --encrypt enable encryption of memory dump\n" \
" -t --timeout timeout in seconds for checkpoint/restore execution in service mode\n",
" -t --timeout timeout in seconds for checkpoint/restore execution in service mode\n" \
" -v --version print version and exit\n",
name);

exit(status);
Expand Down Expand Up @@ -2895,14 +2901,15 @@ int main(int argc, char *argv[])
{ "checksum", 0, NULL, 'c'},
{ "encrypt", 2, 0, 'e'},
{ "timeout", 1, 0, 't'},
{ "version", 0, 0, 'V'},
{ NULL, 0, NULL, 0 }
};

dump_dir = "/tmp";
parasite_socket_dir = NULL;
parasite_socket_use_netns = 0;

while ((opt = getopt_long(argc, argv, "hp:d:S:Nl:nmfzce::t:", long_options, &option_index)) != -1) {
while ((opt = getopt_long(argc, argv, "hp:d:S:Nl:nmfzce::t:V", long_options, &option_index)) != -1) {
switch (opt) {
case 'h':
usage(argv[0], 0);
Expand Down Expand Up @@ -2954,6 +2961,9 @@ int main(int argc, char *argv[])
case 't':
timeout = atoi(optarg);
break;
case 'V':
print_version();
exit(0);
default: /* '?' */
usage(argv[0], 1);
}
Expand All @@ -2965,6 +2975,8 @@ int main(int argc, char *argv[])
if (pid <= 0 && !listen_location)
die("pid must be > 0\n");

print_version();

ret = access("/proc/self/pagemap", F_OK);
if (ret)
die("/proc/self/pagemap not present (depends on CONFIG_PROC_PAGE_MONITOR)\n");
Expand Down
4 changes: 4 additions & 0 deletions memcr.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
#include <stdint.h>
#include <assert.h>

#ifndef GIT_VERSION
#define GIT_VERSION "unknown"
#endif

#ifndef PAGE_SIZE
#define PAGE_SIZE 4096
#endif
Expand Down