mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 02:01:24 +01:00
tools/xenstore: remove no longer needed functions from xs_lib.c
xs_daemon_tdb() in xs_lib.c is no longer used at all, so it can be removed. xs_domain_dev() and xs_write_all() are not used by xenstored, so they can be moved to tools/libs/store/xs.c. xs_daemon_rootdir() is used by xenstored only and it only calls xs_daemon_rundir(), so replace its use cases with xs_daemon_rundir() and remove it from xs_lib.c. xs_daemon_socket_ro() is needed in libxenstore only, so move it to tools/libs/store/xs.c. Move functions used by xenstore-client only to xenstore_client.c. Signed-off-by: Juergen Gross <jgross@suse.com> Acked-by: Julien Grall <jgrall@amazon.com>
This commit is contained in:
1 parent
bd1001db0a
commit
9859a80380
8 files changed
+178
-192
No files matched your search
@@ -113,6 +113,9 @@ void *xs_read(struct xs_handle *h, xs_transaction_t t,
|
|||||||
bool xs_write(struct xs_handle *h, xs_transaction_t t,
|
bool xs_write(struct xs_handle *h, xs_transaction_t t,
|
||||||
const char *path, const void *data, unsigned int len);
|
const char *path, const void *data, unsigned int len);
|
||||||
|
|
||||||
|
/* Simple write function: loops for you. */
|
||||||
|
bool xs_write_all(int fd, const void *data, unsigned int len);
|
||||||
|
|
||||||
/* Create a new directory.
|
/* Create a new directory.
|
||||||
* Returns false on failure, or success if it already exists.
|
* Returns false on failure, or success if it already exists.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -47,9 +47,6 @@ const char *xs_daemon_rundir(void);
|
|||||||
const char *xs_daemon_socket(void);
|
const char *xs_daemon_socket(void);
|
||||||
const char *xs_daemon_socket_ro(void);
|
const char *xs_daemon_socket_ro(void);
|
||||||
|
|
||||||
/* Simple write function: loops for you. */
|
|
||||||
bool xs_write_all(int fd, const void *data, unsigned int len);
|
|
||||||
|
|
||||||
/* Convert strings to permissions. False if a problem. */
|
/* Convert strings to permissions. False if a problem. */
|
||||||
bool xs_strings_to_perms(struct xs_permissions *perms, unsigned int num,
|
bool xs_strings_to_perms(struct xs_permissions *perms, unsigned int num,
|
||||||
const char *strings);
|
const char *strings);
|
||||||
|
|||||||
@@ -311,6 +311,26 @@ struct xs_handle *xs_domain_open(void)
|
|||||||
return xs_open(0);
|
return xs_open(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char *xs_domain_dev(void)
|
||||||
|
{
|
||||||
|
char *s = getenv("XENSTORED_PATH");
|
||||||
|
if (s)
|
||||||
|
return s;
|
||||||
|
#if defined(__RUMPUSER_XEN__) || defined(__RUMPRUN__)
|
||||||
|
return "/dev/xen/xenbus";
|
||||||
|
#elif defined(__linux__)
|
||||||
|
if (access("/dev/xen/xenbus", F_OK) == 0)
|
||||||
|
return "/dev/xen/xenbus";
|
||||||
|
return "/proc/xen/xenbus";
|
||||||
|
#elif defined(__NetBSD__)
|
||||||
|
return "/kern/xen/xenbus";
|
||||||
|
#elif defined(__FreeBSD__)
|
||||||
|
return "/dev/xen/xenstore";
|
||||||
|
#else
|
||||||
|
return "/dev/xen/xenbus";
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
struct xs_handle *xs_open(unsigned long flags)
|
struct xs_handle *xs_open(unsigned long flags)
|
||||||
{
|
{
|
||||||
struct xs_handle *xsh = NULL;
|
struct xs_handle *xsh = NULL;
|
||||||
@@ -431,6 +451,24 @@ out_false:
|
|||||||
#ifdef XSTEST
|
#ifdef XSTEST
|
||||||
#define read_all read_all_choice
|
#define read_all read_all_choice
|
||||||
#define xs_write_all write_all_choice
|
#define xs_write_all write_all_choice
|
||||||
|
#else
|
||||||
|
/* Simple routine for writing to sockets, etc. */
|
||||||
|
bool xs_write_all(int fd, const void *data, unsigned int len)
|
||||||
|
{
|
||||||
|
while (len) {
|
||||||
|
int done;
|
||||||
|
|
||||||
|
done = write(fd, data, len);
|
||||||
|
if (done < 0 && errno == EINTR)
|
||||||
|
continue;
|
||||||
|
if (done <= 0)
|
||||||
|
return false;
|
||||||
|
data += done;
|
||||||
|
len -= done;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int get_error(const char *errorstring)
|
static int get_error(const char *errorstring)
|
||||||
@@ -1328,6 +1366,11 @@ error:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *xs_daemon_socket_ro(void)
|
||||||
|
{
|
||||||
|
return xs_daemon_socket();
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef USE_PTHREAD
|
#ifdef USE_PTHREAD
|
||||||
static void *read_thread(void *arg)
|
static void *read_thread(void *arg)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@@ -40,12 +41,140 @@ enum mode {
|
|||||||
MODE_watch,
|
MODE_watch,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Sanitising (quoting) possibly-binary strings. */
|
||||||
|
struct expanding_buffer {
|
||||||
|
char *buf;
|
||||||
|
int avail;
|
||||||
|
};
|
||||||
|
|
||||||
static char *output_buf = NULL;
|
static char *output_buf = NULL;
|
||||||
static int output_pos = 0;
|
static int output_pos = 0;
|
||||||
static struct expanding_buffer ebuf;
|
static struct expanding_buffer ebuf;
|
||||||
|
|
||||||
static int output_size = 0;
|
static int output_size = 0;
|
||||||
|
|
||||||
|
/* Ensure that given expanding buffer has at least min_avail characters. */
|
||||||
|
static char *expanding_buffer_ensure(struct expanding_buffer *ebuf,
|
||||||
|
int min_avail)
|
||||||
|
{
|
||||||
|
int want;
|
||||||
|
char *got;
|
||||||
|
|
||||||
|
if ( ebuf->avail >= min_avail )
|
||||||
|
return ebuf->buf;
|
||||||
|
|
||||||
|
if ( min_avail >= INT_MAX/3 )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
want = ebuf->avail + min_avail + 10;
|
||||||
|
got = realloc(ebuf->buf, want);
|
||||||
|
if ( !got )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
ebuf->buf = got;
|
||||||
|
ebuf->avail = want;
|
||||||
|
return ebuf->buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* sanitise_value() may return NULL if malloc fails. */
|
||||||
|
static char *sanitise_value(struct expanding_buffer *ebuf,
|
||||||
|
const char *val, unsigned len)
|
||||||
|
{
|
||||||
|
int used, remain, c;
|
||||||
|
unsigned char *ip;
|
||||||
|
|
||||||
|
#define ADD(c) (ebuf->buf[used++] = (c))
|
||||||
|
#define ADDF(f,c) (used += sprintf(ebuf->buf+used, (f), (c)))
|
||||||
|
|
||||||
|
assert(len < INT_MAX/5);
|
||||||
|
|
||||||
|
ip = (unsigned char *)val;
|
||||||
|
used = 0;
|
||||||
|
remain = len;
|
||||||
|
|
||||||
|
if ( !expanding_buffer_ensure(ebuf, remain + 1) )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
while ( remain-- > 0 )
|
||||||
|
{
|
||||||
|
c= *ip++;
|
||||||
|
|
||||||
|
if ( c >= ' ' && c <= '~' && c != '\\' )
|
||||||
|
{
|
||||||
|
ADD(c);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !expanding_buffer_ensure(ebuf, used + remain + 5) )
|
||||||
|
/* for "<used>\\nnn<remain>\0" */
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
ADD('\\');
|
||||||
|
switch (c)
|
||||||
|
{
|
||||||
|
case '\t': ADD('t'); break;
|
||||||
|
case '\n': ADD('n'); break;
|
||||||
|
case '\r': ADD('r'); break;
|
||||||
|
case '\\': ADD('\\'); break;
|
||||||
|
default:
|
||||||
|
if ( c < 010 ) ADDF("%03o", c);
|
||||||
|
else ADDF("x%02x", c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ADD(0);
|
||||||
|
assert(used <= ebuf->avail);
|
||||||
|
return ebuf->buf;
|
||||||
|
|
||||||
|
#undef ADD
|
||||||
|
#undef ADDF
|
||||||
|
}
|
||||||
|
|
||||||
|
/* *out_len_r on entry is ignored; out must be at least strlen(in)+1 bytes. */
|
||||||
|
static void unsanitise_value(char *out, unsigned *out_len_r, const char *in)
|
||||||
|
{
|
||||||
|
const char *ip;
|
||||||
|
char *op;
|
||||||
|
unsigned c;
|
||||||
|
int n;
|
||||||
|
|
||||||
|
for ( ip = in, op = out; (c = *ip++); *op++ = c )
|
||||||
|
{
|
||||||
|
if ( c == '\\' )
|
||||||
|
{
|
||||||
|
c = *ip++;
|
||||||
|
|
||||||
|
#define GETF(f) do \
|
||||||
|
{ \
|
||||||
|
n = 0; \
|
||||||
|
sscanf(ip, f "%n", &c, &n); \
|
||||||
|
ip += n; \
|
||||||
|
} while ( 0 )
|
||||||
|
|
||||||
|
switch ( c )
|
||||||
|
{
|
||||||
|
case 't': c= '\t'; break;
|
||||||
|
case 'n': c= '\n'; break;
|
||||||
|
case 'r': c= '\r'; break;
|
||||||
|
case '\\': c= '\\'; break;
|
||||||
|
case 'x': GETF("%2x"); break;
|
||||||
|
case '0': case '4':
|
||||||
|
case '1': case '5':
|
||||||
|
case '2': case '6':
|
||||||
|
case '3': case '7': --ip; GETF("%3o"); break;
|
||||||
|
case 0: --ip; break;
|
||||||
|
default:;
|
||||||
|
}
|
||||||
|
#undef GETF
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*op = 0;
|
||||||
|
|
||||||
|
if ( out_len_r )
|
||||||
|
*out_len_r = op - out;
|
||||||
|
}
|
||||||
|
|
||||||
/* make sure there is at least 'len' more space in output_buf */
|
/* make sure there is at least 'len' more space in output_buf */
|
||||||
static void expand_buffer(size_t len)
|
static void expand_buffer(size_t len)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -560,7 +560,7 @@ static FILE *lu_dump_open(const void *ctx)
|
|||||||
char *filename;
|
char *filename;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
filename = talloc_asprintf(ctx, "%s/state_dump", xs_daemon_rootdir());
|
filename = talloc_asprintf(ctx, "%s/state_dump", xs_daemon_rundir());
|
||||||
if (!filename)
|
if (!filename)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@@ -583,7 +583,7 @@ static void lu_get_dump_state(struct lu_dump_state *state)
|
|||||||
state->size = 0;
|
state->size = 0;
|
||||||
|
|
||||||
state->filename = talloc_asprintf(NULL, "%s/state_dump",
|
state->filename = talloc_asprintf(NULL, "%s/state_dump",
|
||||||
xs_daemon_rootdir());
|
xs_daemon_rundir());
|
||||||
if (!state->filename)
|
if (!state->filename)
|
||||||
barf("Allocation failure");
|
barf("Allocation failure");
|
||||||
|
|
||||||
|
|||||||
@@ -2888,10 +2888,9 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
reopen_log();
|
reopen_log();
|
||||||
|
|
||||||
/* make sure xenstored directories exist */
|
/* Make sure xenstored directory exists. */
|
||||||
/* Errors ignored here, will be reported when we open files */
|
/* Errors ignored here, will be reported when we open files */
|
||||||
mkdir(xs_daemon_rundir(), 0755);
|
mkdir(xs_daemon_rundir(), 0755);
|
||||||
mkdir(xs_daemon_rootdir(), 0755);
|
|
||||||
|
|
||||||
if (dofork) {
|
if (dofork) {
|
||||||
openlog("xenstored", 0, LOG_DAEMON);
|
openlog("xenstored", 0, LOG_DAEMON);
|
||||||
|
|||||||
@@ -32,11 +32,6 @@ const char *xs_daemon_rundir(void)
|
|||||||
return (s ? s : XEN_RUN_STORED);
|
return (s ? s : XEN_RUN_STORED);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *xs_daemon_rootdir(void)
|
|
||||||
{
|
|
||||||
return xs_daemon_rundir();
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char *xs_daemon_path(void)
|
static const char *xs_daemon_path(void)
|
||||||
{
|
{
|
||||||
static char buf[PATH_MAX];
|
static char buf[PATH_MAX];
|
||||||
@@ -49,61 +44,11 @@ static const char *xs_daemon_path(void)
|
|||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *xs_daemon_tdb(void)
|
|
||||||
{
|
|
||||||
static char buf[PATH_MAX];
|
|
||||||
snprintf(buf, sizeof(buf), "%s/tdb", xs_daemon_rootdir());
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *xs_daemon_socket(void)
|
const char *xs_daemon_socket(void)
|
||||||
{
|
{
|
||||||
return xs_daemon_path();
|
return xs_daemon_path();
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *xs_daemon_socket_ro(void)
|
|
||||||
{
|
|
||||||
return xs_daemon_path();
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *xs_domain_dev(void)
|
|
||||||
{
|
|
||||||
char *s = getenv("XENSTORED_PATH");
|
|
||||||
if (s)
|
|
||||||
return s;
|
|
||||||
#if defined(__RUMPUSER_XEN__) || defined(__RUMPRUN__)
|
|
||||||
return "/dev/xen/xenbus";
|
|
||||||
#elif defined(__linux__)
|
|
||||||
if (access("/dev/xen/xenbus", F_OK) == 0)
|
|
||||||
return "/dev/xen/xenbus";
|
|
||||||
return "/proc/xen/xenbus";
|
|
||||||
#elif defined(__NetBSD__)
|
|
||||||
return "/kern/xen/xenbus";
|
|
||||||
#elif defined(__FreeBSD__)
|
|
||||||
return "/dev/xen/xenstore";
|
|
||||||
#else
|
|
||||||
return "/dev/xen/xenbus";
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Simple routines for writing to sockets, etc. */
|
|
||||||
bool xs_write_all(int fd, const void *data, unsigned int len)
|
|
||||||
{
|
|
||||||
while (len) {
|
|
||||||
int done;
|
|
||||||
|
|
||||||
done = write(fd, data, len);
|
|
||||||
if (done < 0 && errno == EINTR)
|
|
||||||
continue;
|
|
||||||
if (done <= 0)
|
|
||||||
return false;
|
|
||||||
data += done;
|
|
||||||
len -= done;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Convert strings to permissions. False if a problem. */
|
/* Convert strings to permissions. False if a problem. */
|
||||||
bool xs_strings_to_perms(struct xs_permissions *perms, unsigned int num,
|
bool xs_strings_to_perms(struct xs_permissions *perms, unsigned int num,
|
||||||
const char *strings)
|
const char *strings)
|
||||||
@@ -179,114 +124,3 @@ unsigned int xs_count_strings(const char *strings, unsigned int len)
|
|||||||
|
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *expanding_buffer_ensure(struct expanding_buffer *ebuf, int min_avail)
|
|
||||||
{
|
|
||||||
int want;
|
|
||||||
char *got;
|
|
||||||
|
|
||||||
if (ebuf->avail >= min_avail)
|
|
||||||
return ebuf->buf;
|
|
||||||
|
|
||||||
if (min_avail >= INT_MAX/3)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
want = ebuf->avail + min_avail + 10;
|
|
||||||
got = realloc(ebuf->buf, want);
|
|
||||||
if (!got)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
ebuf->buf = got;
|
|
||||||
ebuf->avail = want;
|
|
||||||
return ebuf->buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *sanitise_value(struct expanding_buffer *ebuf,
|
|
||||||
const char *val, unsigned len)
|
|
||||||
{
|
|
||||||
int used, remain, c;
|
|
||||||
unsigned char *ip;
|
|
||||||
|
|
||||||
#define ADD(c) (ebuf->buf[used++] = (c))
|
|
||||||
#define ADDF(f,c) (used += sprintf(ebuf->buf+used, (f), (c)))
|
|
||||||
|
|
||||||
assert(len < INT_MAX/5);
|
|
||||||
|
|
||||||
ip = (unsigned char *)val;
|
|
||||||
used = 0;
|
|
||||||
remain = len;
|
|
||||||
|
|
||||||
if (!expanding_buffer_ensure(ebuf, remain + 1))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
while (remain-- > 0) {
|
|
||||||
c= *ip++;
|
|
||||||
|
|
||||||
if (c >= ' ' && c <= '~' && c != '\\') {
|
|
||||||
ADD(c);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!expanding_buffer_ensure(ebuf, used + remain + 5))
|
|
||||||
/* for "<used>\\nnn<remain>\0" */
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
ADD('\\');
|
|
||||||
switch (c) {
|
|
||||||
case '\t': ADD('t'); break;
|
|
||||||
case '\n': ADD('n'); break;
|
|
||||||
case '\r': ADD('r'); break;
|
|
||||||
case '\\': ADD('\\'); break;
|
|
||||||
default:
|
|
||||||
if (c < 010) ADDF("%03o", c);
|
|
||||||
else ADDF("x%02x", c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ADD(0);
|
|
||||||
assert(used <= ebuf->avail);
|
|
||||||
return ebuf->buf;
|
|
||||||
|
|
||||||
#undef ADD
|
|
||||||
#undef ADDF
|
|
||||||
}
|
|
||||||
|
|
||||||
void unsanitise_value(char *out, unsigned *out_len_r, const char *in)
|
|
||||||
{
|
|
||||||
const char *ip;
|
|
||||||
char *op;
|
|
||||||
unsigned c;
|
|
||||||
int n;
|
|
||||||
|
|
||||||
for (ip = in, op = out; (c = *ip++); *op++ = c) {
|
|
||||||
if (c == '\\') {
|
|
||||||
c = *ip++;
|
|
||||||
|
|
||||||
#define GETF(f) do { \
|
|
||||||
n = 0; \
|
|
||||||
sscanf(ip, f "%n", &c, &n); \
|
|
||||||
ip += n; \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
switch (c) {
|
|
||||||
case 't': c= '\t'; break;
|
|
||||||
case 'n': c= '\n'; break;
|
|
||||||
case 'r': c= '\r'; break;
|
|
||||||
case '\\': c= '\\'; break;
|
|
||||||
case 'x': GETF("%2x"); break;
|
|
||||||
case '0': case '4':
|
|
||||||
case '1': case '5':
|
|
||||||
case '2': case '6':
|
|
||||||
case '3': case '7': --ip; GETF("%3o"); break;
|
|
||||||
case 0: --ip; break;
|
|
||||||
default:;
|
|
||||||
}
|
|
||||||
#undef GETF
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
*op = 0;
|
|
||||||
|
|
||||||
if (out_len_r)
|
|
||||||
*out_len_r = op - out;
|
|
||||||
}
|
|
||||||
@@ -21,10 +21,6 @@
|
|||||||
|
|
||||||
#include "xenstore_lib.h"
|
#include "xenstore_lib.h"
|
||||||
|
|
||||||
const char *xs_daemon_rootdir(void);
|
|
||||||
const char *xs_domain_dev(void);
|
|
||||||
const char *xs_daemon_tdb(void);
|
|
||||||
|
|
||||||
/* Convert permissions to a string (up to len MAX_STRLEN(unsigned int)+1). */
|
/* Convert permissions to a string (up to len MAX_STRLEN(unsigned int)+1). */
|
||||||
bool xs_perm_to_string(const struct xs_permissions *perm,
|
bool xs_perm_to_string(const struct xs_permissions *perm,
|
||||||
char *buffer, size_t buf_len);
|
char *buffer, size_t buf_len);
|
||||||
@@ -32,19 +28,4 @@ bool xs_perm_to_string(const struct xs_permissions *perm,
|
|||||||
/* Given a string and a length, count how many strings (nul terms). */
|
/* Given a string and a length, count how many strings (nul terms). */
|
||||||
unsigned int xs_count_strings(const char *strings, unsigned int len);
|
unsigned int xs_count_strings(const char *strings, unsigned int len);
|
||||||
|
|
||||||
/* Sanitising (quoting) possibly-binary strings. */
|
|
||||||
struct expanding_buffer {
|
|
||||||
char *buf;
|
|
||||||
int avail;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Ensure that given expanding buffer has at least min_avail characters. */
|
|
||||||
char *expanding_buffer_ensure(struct expanding_buffer *, int min_avail);
|
|
||||||
|
|
||||||
/* sanitise_value() may return NULL if malloc fails. */
|
|
||||||
char *sanitise_value(struct expanding_buffer *, const char *val, unsigned len);
|
|
||||||
|
|
||||||
/* *out_len_r on entry is ignored; out must be at least strlen(in)+1 bytes. */
|
|
||||||
void unsanitise_value(char *out, unsigned *out_len_r, const char *in);
|
|
||||||
|
|
||||||
#endif /* XS_LIB_H */
|
#endif /* XS_LIB_H */
|
||||||