| 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 <syslog.h> |
| 9 |
#include <sys/stat.h> |
| 10 |
|
| 11 |
#include "talloc.h" |
| 12 |
#include "core.h" |
| 13 |
#include "lu.h" |
| 14 |
|
| 15 |
#ifndef NO_LIVE_UPDATE |
| 16 |
char *lu_exec(const void *ctx, int argc, char **argv) |
| 17 |
{ |
| 18 |
argv[0] = lu_status->filename; |
| 19 |
execvp(argv[0], argv); |
| 20 |
|
| 21 |
return "Error activating new binary."; |
| 22 |
} |
| 23 |
|
| 24 |
static const char *lu_binary(const void *ctx, struct connection *conn, |
| 25 |
const char *filename) |
| 26 |
{ |
| 27 |
const char *ret; |
| 28 |
struct stat statbuf; |
| 29 |
|
| 30 |
syslog(LOG_INFO, "live-update: binary %s\n", filename); |
| 31 |
|
| 32 |
if (stat(filename, &statbuf)) |
| 33 |
return "File not accessible."; |
| 34 |
if (!(statbuf.st_mode & (S_IXOTH | S_IXGRP | S_IXUSR))) |
| 35 |
return "File not executable."; |
| 36 |
|
| 37 |
ret = lu_begin(conn); |
| 38 |
if (ret) |
| 39 |
return ret; |
| 40 |
|
| 41 |
lu_status->filename = talloc_strdup(lu_status, filename); |
| 42 |
if (!lu_status->filename) |
| 43 |
return "Allocation failure."; |
| 44 |
|
| 45 |
errno = 0; |
| 46 |
return NULL; |
| 47 |
} |
| 48 |
|
| 49 |
const char *lu_arch(const void *ctx, struct connection *conn, const char **vec, |
| 50 |
int num) |
| 51 |
{ |
| 52 |
if (num == 2 && !strcmp(vec[0], "-f")) |
| 53 |
return lu_binary(ctx, conn, vec[1]); |
| 54 |
|
| 55 |
errno = EINVAL; |
| 56 |
return NULL; |
| 57 |
} |
| 58 |
#endif |