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