Merge remote-tracking branch 'stefanha/trivial-patches' into staging
This commit is contained in:
commit
ca062aaed0
164
cmd.c
164
cmd.c
@ -45,13 +45,11 @@ compare(const void *a, const void *b)
|
|||||||
((const cmdinfo_t *)b)->name);
|
((const cmdinfo_t *)b)->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void add_command(const cmdinfo_t *ci)
|
||||||
add_command(
|
|
||||||
const cmdinfo_t *ci)
|
|
||||||
{
|
{
|
||||||
cmdtab = realloc((void *)cmdtab, ++ncmds * sizeof(*cmdtab));
|
cmdtab = g_realloc((void *)cmdtab, ++ncmds * sizeof(*cmdtab));
|
||||||
cmdtab[ncmds - 1] = *ci;
|
cmdtab[ncmds - 1] = *ci;
|
||||||
qsort(cmdtab, ncmds, sizeof(*cmdtab), compare);
|
qsort(cmdtab, ncmds, sizeof(*cmdtab), compare);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -122,16 +120,10 @@ find_command(
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void add_user_command(char *optarg)
|
||||||
add_user_command(char *optarg)
|
|
||||||
{
|
{
|
||||||
ncmdline++;
|
cmdline = g_realloc(cmdline, ++ncmdline * sizeof(char *));
|
||||||
cmdline = realloc(cmdline, sizeof(char*) * (ncmdline));
|
cmdline[ncmdline-1] = optarg;
|
||||||
if (!cmdline) {
|
|
||||||
perror("realloc");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
cmdline[ncmdline-1] = optarg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -160,45 +152,44 @@ static void prep_fetchline(void *opaque)
|
|||||||
|
|
||||||
static char *get_prompt(void);
|
static char *get_prompt(void);
|
||||||
|
|
||||||
void
|
void command_loop(void)
|
||||||
command_loop(void)
|
|
||||||
{
|
{
|
||||||
int c, i, j = 0, done = 0, fetchable = 0, prompted = 0;
|
int c, i, j = 0, done = 0, fetchable = 0, prompted = 0;
|
||||||
char *input;
|
char *input;
|
||||||
char **v;
|
char **v;
|
||||||
const cmdinfo_t *ct;
|
const cmdinfo_t *ct;
|
||||||
|
|
||||||
for (i = 0; !done && i < ncmdline; i++) {
|
for (i = 0; !done && i < ncmdline; i++) {
|
||||||
input = strdup(cmdline[i]);
|
input = strdup(cmdline[i]);
|
||||||
if (!input) {
|
if (!input) {
|
||||||
fprintf(stderr,
|
fprintf(stderr, _("cannot strdup command '%s': %s\n"),
|
||||||
_("cannot strdup command '%s': %s\n"),
|
cmdline[i], strerror(errno));
|
||||||
cmdline[i], strerror(errno));
|
exit(1);
|
||||||
exit(1);
|
}
|
||||||
}
|
v = breakline(input, &c);
|
||||||
v = breakline(input, &c);
|
if (c) {
|
||||||
if (c) {
|
ct = find_command(v[0]);
|
||||||
ct = find_command(v[0]);
|
if (ct) {
|
||||||
if (ct) {
|
if (ct->flags & CMD_FLAG_GLOBAL) {
|
||||||
if (ct->flags & CMD_FLAG_GLOBAL)
|
done = command(ct, c, v);
|
||||||
done = command(ct, c, v);
|
} else {
|
||||||
else {
|
j = 0;
|
||||||
j = 0;
|
while (!done && (j = args_command(j))) {
|
||||||
while (!done && (j = args_command(j)))
|
done = command(ct, c, v);
|
||||||
done = command(ct, c, v);
|
}
|
||||||
}
|
}
|
||||||
} else
|
} else {
|
||||||
fprintf(stderr, _("command \"%s\" not found\n"),
|
fprintf(stderr, _("command \"%s\" not found\n"), v[0]);
|
||||||
v[0]);
|
}
|
||||||
}
|
|
||||||
doneline(input, v);
|
|
||||||
}
|
|
||||||
if (cmdline) {
|
|
||||||
free(cmdline);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
doneline(input, v);
|
||||||
|
}
|
||||||
|
if (cmdline) {
|
||||||
|
g_free(cmdline);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
while (!done) {
|
while (!done) {
|
||||||
if (!prompted) {
|
if (!prompted) {
|
||||||
printf("%s", get_prompt());
|
printf("%s", get_prompt());
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
@ -212,22 +203,24 @@ command_loop(void)
|
|||||||
if (!fetchable) {
|
if (!fetchable) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ((input = fetchline()) == NULL)
|
input = fetchline();
|
||||||
break;
|
if (input == NULL) {
|
||||||
v = breakline(input, &c);
|
break;
|
||||||
if (c) {
|
}
|
||||||
ct = find_command(v[0]);
|
v = breakline(input, &c);
|
||||||
if (ct)
|
if (c) {
|
||||||
done = command(ct, c, v);
|
ct = find_command(v[0]);
|
||||||
else
|
if (ct) {
|
||||||
fprintf(stderr, _("command \"%s\" not found\n"),
|
done = command(ct, c, v);
|
||||||
v[0]);
|
} else {
|
||||||
}
|
fprintf(stderr, _("command \"%s\" not found\n"), v[0]);
|
||||||
doneline(input, v);
|
}
|
||||||
|
}
|
||||||
|
doneline(input, v);
|
||||||
|
|
||||||
prompted = 0;
|
prompted = 0;
|
||||||
fetchable = 0;
|
fetchable = 0;
|
||||||
}
|
}
|
||||||
qemu_aio_set_fd_handler(STDIN_FILENO, NULL, NULL, NULL, NULL, NULL);
|
qemu_aio_set_fd_handler(STDIN_FILENO, NULL, NULL, NULL, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -331,29 +324,32 @@ static char *qemu_strsep(char **input, const char *delim)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
char **
|
char **breakline(char *input, int *count)
|
||||||
breakline(
|
|
||||||
char *input,
|
|
||||||
int *count)
|
|
||||||
{
|
{
|
||||||
int c = 0;
|
int c = 0;
|
||||||
char *p;
|
char *p;
|
||||||
char **rval = calloc(sizeof(char *), 1);
|
char **rval = calloc(sizeof(char *), 1);
|
||||||
|
char **tmp;
|
||||||
|
|
||||||
while (rval && (p = qemu_strsep(&input, " ")) != NULL) {
|
while (rval && (p = qemu_strsep(&input, " ")) != NULL) {
|
||||||
if (!*p)
|
if (!*p) {
|
||||||
continue;
|
continue;
|
||||||
c++;
|
}
|
||||||
rval = realloc(rval, sizeof(*rval) * (c + 1));
|
c++;
|
||||||
if (!rval) {
|
tmp = realloc(rval, sizeof(*rval) * (c + 1));
|
||||||
c = 0;
|
if (!tmp) {
|
||||||
break;
|
free(rval);
|
||||||
}
|
rval = NULL;
|
||||||
rval[c - 1] = p;
|
c = 0;
|
||||||
rval[c] = NULL;
|
break;
|
||||||
}
|
} else {
|
||||||
*count = c;
|
rval = tmp;
|
||||||
return rval;
|
}
|
||||||
|
rval[c - 1] = p;
|
||||||
|
rval[c] = NULL;
|
||||||
|
}
|
||||||
|
*count = c;
|
||||||
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -113,7 +113,7 @@ static void platform_fixed_ioport_writew(void *opaque, uint32_t addr, uint32_t v
|
|||||||
{
|
{
|
||||||
PCIXenPlatformState *s = opaque;
|
PCIXenPlatformState *s = opaque;
|
||||||
|
|
||||||
switch (addr - XEN_PLATFORM_IOPORT) {
|
switch (addr) {
|
||||||
case 0:
|
case 0:
|
||||||
/* Unplug devices. Value is a bitmask of which devices to
|
/* Unplug devices. Value is a bitmask of which devices to
|
||||||
unplug, with bit 0 the IDE devices, bit 1 the network
|
unplug, with bit 0 the IDE devices, bit 1 the network
|
||||||
@ -152,7 +152,7 @@ static void platform_fixed_ioport_writew(void *opaque, uint32_t addr, uint32_t v
|
|||||||
static void platform_fixed_ioport_writel(void *opaque, uint32_t addr,
|
static void platform_fixed_ioport_writel(void *opaque, uint32_t addr,
|
||||||
uint32_t val)
|
uint32_t val)
|
||||||
{
|
{
|
||||||
switch (addr - XEN_PLATFORM_IOPORT) {
|
switch (addr) {
|
||||||
case 0:
|
case 0:
|
||||||
/* PV driver version */
|
/* PV driver version */
|
||||||
break;
|
break;
|
||||||
@ -163,7 +163,7 @@ static void platform_fixed_ioport_writeb(void *opaque, uint32_t addr, uint32_t v
|
|||||||
{
|
{
|
||||||
PCIXenPlatformState *s = opaque;
|
PCIXenPlatformState *s = opaque;
|
||||||
|
|
||||||
switch (addr - XEN_PLATFORM_IOPORT) {
|
switch (addr) {
|
||||||
case 0: /* Platform flags */ {
|
case 0: /* Platform flags */ {
|
||||||
hvmmem_type_t mem_type = (val & PFFLAG_ROM_LOCK) ?
|
hvmmem_type_t mem_type = (val & PFFLAG_ROM_LOCK) ?
|
||||||
HVMMEM_ram_ro : HVMMEM_ram_rw;
|
HVMMEM_ram_ro : HVMMEM_ram_rw;
|
||||||
@ -186,7 +186,7 @@ static uint32_t platform_fixed_ioport_readw(void *opaque, uint32_t addr)
|
|||||||
{
|
{
|
||||||
PCIXenPlatformState *s = opaque;
|
PCIXenPlatformState *s = opaque;
|
||||||
|
|
||||||
switch (addr - XEN_PLATFORM_IOPORT) {
|
switch (addr) {
|
||||||
case 0:
|
case 0:
|
||||||
if (s->drivers_blacklisted) {
|
if (s->drivers_blacklisted) {
|
||||||
/* The drivers will recognise this magic number and refuse
|
/* The drivers will recognise this magic number and refuse
|
||||||
@ -205,7 +205,7 @@ static uint32_t platform_fixed_ioport_readb(void *opaque, uint32_t addr)
|
|||||||
{
|
{
|
||||||
PCIXenPlatformState *s = opaque;
|
PCIXenPlatformState *s = opaque;
|
||||||
|
|
||||||
switch (addr - XEN_PLATFORM_IOPORT) {
|
switch (addr) {
|
||||||
case 0:
|
case 0:
|
||||||
/* Platform flags */
|
/* Platform flags */
|
||||||
return s->flags;
|
return s->flags;
|
||||||
@ -221,7 +221,7 @@ static void platform_fixed_ioport_reset(void *opaque)
|
|||||||
{
|
{
|
||||||
PCIXenPlatformState *s = opaque;
|
PCIXenPlatformState *s = opaque;
|
||||||
|
|
||||||
platform_fixed_ioport_writeb(s, XEN_PLATFORM_IOPORT, 0);
|
platform_fixed_ioport_writeb(s, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
const MemoryRegionPortio xen_platform_ioport[] = {
|
const MemoryRegionPortio xen_platform_ioport[] = {
|
||||||
@ -251,7 +251,7 @@ static void platform_fixed_ioport_init(PCIXenPlatformState* s)
|
|||||||
static uint32_t xen_platform_ioport_readb(void *opaque, uint32_t addr)
|
static uint32_t xen_platform_ioport_readb(void *opaque, uint32_t addr)
|
||||||
{
|
{
|
||||||
if (addr == 0) {
|
if (addr == 0) {
|
||||||
return platform_fixed_ioport_readb(opaque, XEN_PLATFORM_IOPORT);
|
return platform_fixed_ioport_readb(opaque, 0);
|
||||||
} else {
|
} else {
|
||||||
return ~0u;
|
return ~0u;
|
||||||
}
|
}
|
||||||
@ -263,7 +263,7 @@ static void xen_platform_ioport_writeb(void *opaque, uint32_t addr, uint32_t val
|
|||||||
|
|
||||||
switch (addr) {
|
switch (addr) {
|
||||||
case 0: /* Platform flags */
|
case 0: /* Platform flags */
|
||||||
platform_fixed_ioport_writeb(opaque, XEN_PLATFORM_IOPORT, val);
|
platform_fixed_ioport_writeb(opaque, 0, val);
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
log_writeb(s, val);
|
log_writeb(s, val);
|
||||||
@ -321,7 +321,7 @@ static int xen_platform_post_load(void *opaque, int version_id)
|
|||||||
{
|
{
|
||||||
PCIXenPlatformState *s = opaque;
|
PCIXenPlatformState *s = opaque;
|
||||||
|
|
||||||
platform_fixed_ioport_writeb(s, XEN_PLATFORM_IOPORT, s->flags);
|
platform_fixed_ioport_writeb(s, 0, s->flags);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -236,7 +236,7 @@ static void readline_hist_add(ReadLineState *rs, const char *cmdline)
|
|||||||
new_entry = hist_entry;
|
new_entry = hist_entry;
|
||||||
/* Put this entry at the end of history */
|
/* Put this entry at the end of history */
|
||||||
memmove(&rs->history[idx], &rs->history[idx + 1],
|
memmove(&rs->history[idx], &rs->history[idx + 1],
|
||||||
(READLINE_MAX_CMDS - idx + 1) * sizeof(char *));
|
(READLINE_MAX_CMDS - (idx + 1)) * sizeof(char *));
|
||||||
rs->history[READLINE_MAX_CMDS - 1] = NULL;
|
rs->history[READLINE_MAX_CMDS - 1] = NULL;
|
||||||
for (; idx < READLINE_MAX_CMDS; idx++) {
|
for (; idx < READLINE_MAX_CMDS; idx++) {
|
||||||
if (rs->history[idx] == NULL)
|
if (rs->history[idx] == NULL)
|
||||||
|
Loading…
Reference in New Issue
Block a user