| 1 |
/* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 |
|
| 3 |
/* |
| 4 |
* Live Update for Xen Store Daemon. |
| 5 |
* Copyright (C) 2022 Juergen Gross, SUSE LLC |
| 6 |
*/ |
| 7 |
|
| 8 |
#include <stdlib.h> |
| 9 |
#include <syslog.h> |
| 10 |
|
| 11 |
#include "talloc.h" |
| 12 |
#include "lu.h" |
| 13 |
|
| 14 |
#ifndef NO_LIVE_UPDATE |
| 15 |
char *lu_exec(const void *ctx, int argc, char **argv) |
| 16 |
{ |
| 17 |
return "NYI"; |
| 18 |
} |
| 19 |
|
| 20 |
static const char *lu_binary_alloc(const void *ctx, struct connection *conn, |
| 21 |
unsigned long size) |
| 22 |
{ |
| 23 |
const char *ret; |
| 24 |
|
| 25 |
syslog(LOG_INFO, "live-update: binary size %lu\n", size); |
| 26 |
|
| 27 |
ret = lu_begin(conn); |
| 28 |
if (ret) |
| 29 |
return ret; |
| 30 |
|
| 31 |
lu_status->kernel = talloc_size(lu_status, size); |
| 32 |
if (!lu_status->kernel) |
| 33 |
return "Allocation failure."; |
| 34 |
|
| 35 |
lu_status->kernel_size = size; |
| 36 |
lu_status->kernel_off = 0; |
| 37 |
|
| 38 |
errno = 0; |
| 39 |
return NULL; |
| 40 |
} |
| 41 |
|
| 42 |
static const char *lu_binary_save(const void *ctx, struct connection *conn, |
| 43 |
unsigned int size, const char *data) |
| 44 |
{ |
| 45 |
if (!lu_status || lu_status->conn != conn) |
| 46 |
return "Not in live-update session."; |
| 47 |
|
| 48 |
if (lu_status->kernel_off + size > lu_status->kernel_size) |
| 49 |
return "Too much kernel data."; |
| 50 |
|
| 51 |
memcpy(lu_status->kernel + lu_status->kernel_off, data, size); |
| 52 |
lu_status->kernel_off += size; |
| 53 |
|
| 54 |
errno = 0; |
| 55 |
return NULL; |
| 56 |
} |
| 57 |
|
| 58 |
const char *lu_arch(const void *ctx, struct connection *conn, const char **vec, |
| 59 |
int num) |
| 60 |
{ |
| 61 |
if (num == 2 && !strcmp(vec[0], "-b")) |
| 62 |
return lu_binary_alloc(ctx, conn, atol(vec[1])); |
| 63 |
if (num > 2 && !strcmp(vec[0], "-d")) |
| 64 |
return lu_binary_save(ctx, conn, atoi(vec[1]), vec[2]); |
| 65 |
|
| 66 |
errno = EINVAL; |
| 67 |
return NULL; |
| 68 |
} |
| 69 |
#endif |