From: Anthony Liguori <aliguori@us.ibm.com>
To: xen-devel <xen-devel@lists.xensource.com>
Subject: [PATCH] consoled updates
Date: Tue, 02 Aug 2005 11:51:59 -0500 [thread overview]
Message-ID: <42EFA4AF.1040901@us.ibm.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 427 bytes --]
The following patch brings xen-unstable up-to-date with the changes I
had for consoled in my local repository.
That includes:
1) Make more functions in io.c static
2) Fix memory leak in domain free
3) Fix error path in read (reported by aq)
4) Move reading of buffer limit to tty reconnect so that changes in
limit take affect more quickly.
Regards,
Anthony Liguori
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
[-- Attachment #2: consoled_update.diff --]
[-- Type: text/x-patch, Size: 4411 bytes --]
diff -r dcdcec634c2d tools/consoled/io.c
--- a/tools/consoled/io.c Tue Aug 2 16:11:31 2005
+++ b/tools/consoled/io.c Tue Aug 2 11:48:05 2005
@@ -48,7 +48,7 @@
size_t max_capacity;
};
-void buffer_append(struct buffer *buffer, const void *data, size_t size)
+static void buffer_append(struct buffer *buffer, const void *data, size_t size)
{
if ((buffer->capacity - buffer->size) < size) {
buffer->capacity += (size + 1024);
@@ -71,12 +71,12 @@
}
}
-bool buffer_empty(struct buffer *buffer)
+static bool buffer_empty(struct buffer *buffer)
{
return buffer->size == 0;
}
-void buffer_advance(struct buffer *buffer, size_t size)
+static void buffer_advance(struct buffer *buffer, size_t size)
{
size = MIN(size, buffer->size);
memmove(buffer->data, buffer + size, buffer->size - size);
@@ -93,7 +93,7 @@
static struct domain *dom_head;
-bool domain_is_valid(int domid)
+static bool domain_is_valid(int domid)
{
bool ret;
xc_dominfo_t info;
@@ -104,18 +104,21 @@
return ret;
}
-int domain_create_tty(int domid)
+static int domain_create_tty(struct domain *dom)
{
char path[1024];
int master;
if ((master = getpt()) == -1 ||
grantpt(master) == -1 || unlockpt(master) == -1) {
- dolog(LOG_ERR, "Failed to create tty for domain-%d", domid);
+ dolog(LOG_ERR, "Failed to create tty for domain-%d",
+ dom->domid);
master = -1;
} else {
const char *slave = ptsname(master);
struct termios term;
+ char *data;
+ unsigned int len;
if (tcgetattr(master, &term) != -1) {
cfmakeraw(&term);
@@ -123,22 +126,26 @@
}
xs_mkdir(xs, "/console");
- snprintf(path, sizeof(path), "/console/%d", domid);
+ snprintf(path, sizeof(path), "/console/%d", dom->domid);
xs_mkdir(xs, path);
strcat(path, "/tty");
xs_write(xs, path, slave, strlen(slave), O_CREAT);
+
+ snprintf(path, sizeof(path), "/console/%d/limit", dom->domid);
+ data = xs_read(xs, path, &len);
+ if (data) {
+ dom->buffer.max_capacity = strtoul(data, 0, 0);
+ free(data);
+ }
}
return master;
}
-struct domain *create_domain(int domid)
+static struct domain *create_domain(int domid)
{
struct domain *dom;
- char *data;
- unsigned int len;
- char path[1024];
dom = (struct domain *)malloc(sizeof(struct domain));
if (dom == NULL) {
@@ -148,25 +155,18 @@
}
dom->domid = domid;
- dom->tty_fd = domain_create_tty(domid);
+ dom->tty_fd = domain_create_tty(dom);
dom->buffer.data = 0;
dom->buffer.size = 0;
dom->buffer.capacity = 0;
dom->buffer.max_capacity = 0;
- snprintf(path, sizeof(path), "/console/%d/limit", domid);
- data = xs_read(xs, path, &len);
- if (data) {
- dom->buffer.max_capacity = strtoul(data, 0, 0);
- free(data);
- }
-
dolog(LOG_DEBUG, "New domain %d", domid);
return dom;
}
-struct domain *lookup_domain(int domid)
+static struct domain *lookup_domain(int domid)
{
struct domain **pp;
@@ -186,7 +186,7 @@
return *pp;
}
-void remove_domain(struct domain *dom)
+static void remove_domain(struct domain *dom)
{
struct domain **pp;
@@ -197,13 +197,16 @@
if (dom->domid == d->domid) {
*pp = d->next;
+ if (d->buffer.data) {
+ free(d->buffer.data);
+ }
free(d);
break;
}
}
}
-void handle_tty_read(struct domain *dom)
+static void handle_tty_read(struct domain *dom)
{
ssize_t len;
xcs_msg_t msg;
@@ -219,7 +222,7 @@
close(dom->tty_fd);
if (domain_is_valid(dom->domid)) {
- dom->tty_fd = domain_create_tty(dom->domid);
+ dom->tty_fd = domain_create_tty(dom);
} else {
remove_domain(dom);
}
@@ -235,7 +238,7 @@
}
}
-void handle_tty_write(struct domain *dom)
+static void handle_tty_write(struct domain *dom)
{
ssize_t len;
@@ -244,7 +247,7 @@
close(dom->tty_fd);
if (domain_is_valid(dom->domid)) {
- dom->tty_fd = domain_create_tty(dom->domid);
+ dom->tty_fd = domain_create_tty(dom);
} else {
remove_domain(dom);
}
@@ -253,7 +256,7 @@
}
}
-void handle_xcs_msg(int fd)
+static void handle_xcs_msg(int fd)
{
xcs_msg_t msg;
diff -r dcdcec634c2d tools/consoled/xc_console.c
--- a/tools/consoled/xc_console.c Tue Aug 2 16:11:31 2005
+++ b/tools/consoled/xc_console.c Tue Aug 2 11:48:05 2005
@@ -126,7 +126,7 @@
return 0;
}
- if (len == 0 && len == -1) {
+ if (len == 0 || len == -1) {
if (len == -1 &&
(errno == EINTR || errno == EAGAIN)) {
continue;
[-- Attachment #3: Type: text/plain, Size: 138 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
reply other threads:[~2005-08-02 16:51 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=42EFA4AF.1040901@us.ibm.com \
--to=aliguori@us.ibm.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.