diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/guestfs-actions.c | 97 | ||||
-rw-r--r-- | src/guestfs-actions.h | 1 | ||||
-rw-r--r-- | src/guestfs_protocol.c | 21 | ||||
-rw-r--r-- | src/guestfs_protocol.h | 20 | ||||
-rw-r--r-- | src/guestfs_protocol.x | 9 |
5 files changed, 147 insertions, 1 deletions
diff --git a/src/guestfs-actions.c b/src/guestfs-actions.c index f36fcf06..e1ec1589 100644 --- a/src/guestfs-actions.c +++ b/src/guestfs-actions.c @@ -10263,3 +10263,100 @@ char **guestfs_sh_lines (guestfs_h *g, return ctx.ret.lines.lines_val; } +struct glob_expand_ctx { + /* This flag is set by the callbacks, so we know we've done + * the callbacks as expected, and in the right sequence. + * 0 = not called, 1 = reply_cb called. + */ + int cb_sequence; + struct guestfs_message_header hdr; + struct guestfs_message_error err; + struct guestfs_glob_expand_ret ret; +}; + +static void glob_expand_reply_cb (guestfs_h *g, void *data, XDR *xdr) +{ + guestfs_main_loop *ml = guestfs_get_main_loop (g); + struct glob_expand_ctx *ctx = (struct glob_expand_ctx *) data; + + /* This should definitely not happen. */ + if (ctx->cb_sequence != 0) { + ctx->cb_sequence = 9999; + error (g, "%s: internal error: reply callback called twice", "guestfs_glob_expand"); + return; + } + + ml->main_loop_quit (ml, g); + + if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) { + error (g, "%s: failed to parse reply header", "guestfs_glob_expand"); + return; + } + if (ctx->hdr.status == GUESTFS_STATUS_ERROR) { + if (!xdr_guestfs_message_error (xdr, &ctx->err)) { + error (g, "%s: failed to parse reply error", "guestfs_glob_expand"); + return; + } + goto done; + } + if (!xdr_guestfs_glob_expand_ret (xdr, &ctx->ret)) { + error (g, "%s: failed to parse reply", "guestfs_glob_expand"); + return; + } + done: + ctx->cb_sequence = 1; +} + +char **guestfs_glob_expand (guestfs_h *g, + const char *pattern) +{ + struct guestfs_glob_expand_args args; + struct glob_expand_ctx ctx; + guestfs_main_loop *ml = guestfs_get_main_loop (g); + int serial; + + if (check_state (g, "guestfs_glob_expand") == -1) return NULL; + guestfs_set_busy (g); + + memset (&ctx, 0, sizeof ctx); + + args.pattern = (char *) pattern; + serial = guestfs__send_sync (g, GUESTFS_PROC_GLOB_EXPAND, + (xdrproc_t) xdr_guestfs_glob_expand_args, (char *) &args); + if (serial == -1) { + guestfs_end_busy (g); + return NULL; + } + + guestfs__switch_to_receiving (g); + ctx.cb_sequence = 0; + guestfs_set_reply_callback (g, glob_expand_reply_cb, &ctx); + (void) ml->main_loop_run (ml, g); + guestfs_set_reply_callback (g, NULL, NULL); + if (ctx.cb_sequence != 1) { + error (g, "%s reply failed, see earlier error messages", "guestfs_glob_expand"); + guestfs_end_busy (g); + return NULL; + } + + if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_GLOB_EXPAND, serial) == -1) { + guestfs_end_busy (g); + return NULL; + } + + if (ctx.hdr.status == GUESTFS_STATUS_ERROR) { + error (g, "%s", ctx.err.error_message); + free (ctx.err.error_message); + guestfs_end_busy (g); + return NULL; + } + + guestfs_end_busy (g); + /* caller will free this, but we need to add a NULL entry */ + ctx.ret.paths.paths_val = + safe_realloc (g, ctx.ret.paths.paths_val, + sizeof (char *) * (ctx.ret.paths.paths_len + 1)); + ctx.ret.paths.paths_val[ctx.ret.paths.paths_len] = NULL; + return ctx.ret.paths.paths_val; +} + diff --git a/src/guestfs-actions.h b/src/guestfs-actions.h index fe9967f2..19996e8f 100644 --- a/src/guestfs-actions.h +++ b/src/guestfs-actions.h @@ -183,3 +183,4 @@ extern int guestfs_sleep (guestfs_h *handle, int secs); extern int guestfs_ntfs_3g_probe (guestfs_h *handle, int rw, const char *device); extern char *guestfs_sh (guestfs_h *handle, const char *command); extern char **guestfs_sh_lines (guestfs_h *handle, const char *command); +extern char **guestfs_glob_expand (guestfs_h *handle, const char *pattern); diff --git a/src/guestfs_protocol.c b/src/guestfs_protocol.c index 96951d9d..b2d435ee 100644 --- a/src/guestfs_protocol.c +++ b/src/guestfs_protocol.c @@ -1912,6 +1912,27 @@ xdr_guestfs_sh_lines_ret (XDR *xdrs, guestfs_sh_lines_ret *objp) } bool_t +xdr_guestfs_glob_expand_args (XDR *xdrs, guestfs_glob_expand_args *objp) +{ + register int32_t *buf; + + if (!xdr_string (xdrs, &objp->pattern, ~0)) + return FALSE; + return TRUE; +} + +bool_t +xdr_guestfs_glob_expand_ret (XDR *xdrs, guestfs_glob_expand_ret *objp) +{ + register int32_t *buf; + + if (!xdr_array (xdrs, (char **)&objp->paths.paths_val, (u_int *) &objp->paths.paths_len, ~0, + sizeof (str), (xdrproc_t) xdr_str)) + return FALSE; + return TRUE; +} + +bool_t xdr_guestfs_procedure (XDR *xdrs, guestfs_procedure *objp) { register int32_t *buf; diff --git a/src/guestfs_protocol.h b/src/guestfs_protocol.h index a9863ccf..8fdb6640 100644 --- a/src/guestfs_protocol.h +++ b/src/guestfs_protocol.h @@ -969,6 +969,19 @@ struct guestfs_sh_lines_ret { }; typedef struct guestfs_sh_lines_ret guestfs_sh_lines_ret; +struct guestfs_glob_expand_args { + char *pattern; +}; +typedef struct guestfs_glob_expand_args guestfs_glob_expand_args; + +struct guestfs_glob_expand_ret { + struct { + u_int paths_len; + str *paths_val; + } paths; +}; +typedef struct guestfs_glob_expand_ret guestfs_glob_expand_ret; + enum guestfs_procedure { GUESTFS_PROC_MOUNT = 1, GUESTFS_PROC_SYNC = 2, @@ -1082,7 +1095,8 @@ enum guestfs_procedure { GUESTFS_PROC_NTFS_3G_PROBE = 110, GUESTFS_PROC_SH = 111, GUESTFS_PROC_SH_LINES = 112, - GUESTFS_PROC_NR_PROCS = 112 + 1, + GUESTFS_PROC_GLOB_EXPAND = 113, + GUESTFS_PROC_NR_PROCS = 113 + 1, }; typedef enum guestfs_procedure guestfs_procedure; #define GUESTFS_MESSAGE_MAX 4194304 @@ -1287,6 +1301,8 @@ extern bool_t xdr_guestfs_sh_args (XDR *, guestfs_sh_args*); extern bool_t xdr_guestfs_sh_ret (XDR *, guestfs_sh_ret*); extern bool_t xdr_guestfs_sh_lines_args (XDR *, guestfs_sh_lines_args*); extern bool_t xdr_guestfs_sh_lines_ret (XDR *, guestfs_sh_lines_ret*); +extern bool_t xdr_guestfs_glob_expand_args (XDR *, guestfs_glob_expand_args*); +extern bool_t xdr_guestfs_glob_expand_ret (XDR *, guestfs_glob_expand_ret*); extern bool_t xdr_guestfs_procedure (XDR *, guestfs_procedure*); extern bool_t xdr_guestfs_message_direction (XDR *, guestfs_message_direction*); extern bool_t xdr_guestfs_message_status (XDR *, guestfs_message_status*); @@ -1450,6 +1466,8 @@ extern bool_t xdr_guestfs_sh_args (); extern bool_t xdr_guestfs_sh_ret (); extern bool_t xdr_guestfs_sh_lines_args (); extern bool_t xdr_guestfs_sh_lines_ret (); +extern bool_t xdr_guestfs_glob_expand_args (); +extern bool_t xdr_guestfs_glob_expand_ret (); extern bool_t xdr_guestfs_procedure (); extern bool_t xdr_guestfs_message_direction (); extern bool_t xdr_guestfs_message_status (); diff --git a/src/guestfs_protocol.x b/src/guestfs_protocol.x index 94d2e849..d6627267 100644 --- a/src/guestfs_protocol.x +++ b/src/guestfs_protocol.x @@ -748,6 +748,14 @@ struct guestfs_sh_lines_ret { str lines<>; }; +struct guestfs_glob_expand_args { + string pattern<>; +}; + +struct guestfs_glob_expand_ret { + str paths<>; +}; + enum guestfs_procedure { GUESTFS_PROC_MOUNT = 1, GUESTFS_PROC_SYNC = 2, @@ -861,6 +869,7 @@ enum guestfs_procedure { GUESTFS_PROC_NTFS_3G_PROBE = 110, GUESTFS_PROC_SH = 111, GUESTFS_PROC_SH_LINES = 112, + GUESTFS_PROC_GLOB_EXPAND = 113, GUESTFS_PROC_NR_PROCS }; |