WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] xenconsoled: portability fixes:

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] xenconsoled: portability fixes:
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Tue, 09 Oct 2007 14:10:09 -0700
Delivery-date: Tue, 09 Oct 2007 14:11:18 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Keir Fraser <keir@xxxxxxxxxxxxx>
# Date 1191837350 -3600
# Node ID 3d13b318349a380b885f12898e212d87f297e377
# Parent  ff99e8da117f57f6fbda7d593f1638523865df0a
xenconsoled: portability fixes:
 - Use openpty(), which does the same as the sequence
   of open(), grantpt(), unlockpt(), ptsname(), tcgetattr()
   simplifies code
 - Check return code from tcsetattr()
 - sprintf() -> snprintf()
 - OpenBSD lacks POSIX grantpt() and unlockpt()
   requires use of openpty()
 - Solaris lacks POSIX openpty() via feedback from SUN (John Levon)
   implement openpty() for Solaris, tested and ok'd by SUN (John
   Levon)

Signed-off-by: Christoph Egger <Christoph.Egger@xxxxxxx>
---
 config/StdGNU.mk             |    1 
 config/SunOS.mk              |    1 
 tools/console/Makefile       |    4 -
 tools/console/daemon/io.c    |  152 ++++++++++++++++++++++++++++---------------
 tools/console/daemon/utils.c |    2 
 5 files changed, 106 insertions(+), 54 deletions(-)

diff -r ff99e8da117f -r 3d13b318349a config/StdGNU.mk
--- a/config/StdGNU.mk  Mon Oct 08 10:47:58 2007 +0100
+++ b/config/StdGNU.mk  Mon Oct 08 10:55:50 2007 +0100
@@ -21,6 +21,7 @@ LIB64DIR = lib64
 
 SOCKET_LIBS =
 CURSES_LIBS = -lncurses
+UTIL_LIBS = -lutil
 SONAME_LDFLAG = -soname
 SHLIB_CFLAGS = -shared
 
diff -r ff99e8da117f -r 3d13b318349a config/SunOS.mk
--- a/config/SunOS.mk   Mon Oct 08 10:47:58 2007 +0100
+++ b/config/SunOS.mk   Mon Oct 08 10:55:50 2007 +0100
@@ -22,6 +22,7 @@ LIB64DIR = lib/amd64
 
 SOCKET_LIBS = -lsocket
 CURSES_LIBS = -lcurses
+UTIL_LIBS =
 SONAME_LDFLAG = -h
 SHLIB_CFLAGS = -R /usr/sfw/$(LIBDIR) -shared
 
diff -r ff99e8da117f -r 3d13b318349a tools/console/Makefile
--- a/tools/console/Makefile    Mon Oct 08 10:47:58 2007 +0100
+++ b/tools/console/Makefile    Mon Oct 08 10:55:50 2007 +0100
@@ -22,11 +22,11 @@ clean:
 
 xenconsoled: $(patsubst %.c,%.o,$(wildcard daemon/*.c))
        $(CC) $(CFLAGS) $^ -o $@ -L$(XEN_LIBXC) -L$(XEN_XENSTORE) \
-              $(SOCKET_LIBS) -lxenctrl -lxenstore
+              $(UTIL_LIBS) $(SOCKET_LIBS) -lxenctrl -lxenstore
 
 xenconsole: $(patsubst %.c,%.o,$(wildcard client/*.c))
        $(CC) $(CFLAGS) $^ -o $@ -L$(XEN_LIBXC) -L$(XEN_XENSTORE) \
-             $(SOCKET_LIBS) -lxenctrl -lxenstore
+             $(UTIL_LIBS) $(SOCKET_LIBS) -lxenctrl -lxenstore
 
 .PHONY: install
 install: $(BIN)
diff -r ff99e8da117f -r 3d13b318349a tools/console/daemon/io.c
--- a/tools/console/daemon/io.c Mon Oct 08 10:47:58 2007 +0100
+++ b/tools/console/daemon/io.c Mon Oct 08 10:55:50 2007 +0100
@@ -26,7 +26,6 @@
 #include <xen/io/console.h>
 #include <xenctrl.h>
 
-#include <malloc.h>
 #include <stdlib.h>
 #include <errno.h>
 #include <string.h>
@@ -36,6 +35,11 @@
 #include <termios.h>
 #include <stdarg.h>
 #include <sys/mman.h>
+#if defined(__NetBSD__) || defined(__OpenBSD__)
+#include <util.h>
+#elif defined(__linux__) || defined(__Linux__)
+#include <pty.h>
+#endif
 
 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
@@ -213,43 +217,81 @@ static int create_domain_log(struct doma
        return fd;
 }
 
+#ifdef __sun__
+/* Once Solaris has openpty(), this is going to be removed. */
+int openpty(int *amaster, int *aslave, char *name,
+           struct termios *termp, struct winsize *winp)
+{
+       int mfd, sfd;
+
+       *amaster = *aslave = -1;
+       mfd = sfd = -1;
+
+       mfd = open("/dev/ptmx", O_RDWR | O_NOCTTY);
+       if (mfd < 0)
+               goto err0;
+
+       if (grantpt(mfd) == -1 || unlockpt(mfd) == -1)
+               goto err1;
+
+       /* This does not match openpty specification,
+        * but as long as this does not hurt, this is acceptable.
+        */
+       mfd = sfd;
+
+       if (termp != NULL && tcgetattr(sfd, termp) < 0)
+               goto err1;      
+
+       if (amaster)
+               *amaster = mfd;
+       if (aslave)
+               *aslave = sfd;
+       if (name)
+               strlcpy(name, ptsname(mfd), sizeof(slave));
+       if (winp)
+               ioctl(sfd, TIOCSWINSZ, winp);
+
+       return 0;
+
+err1:
+       close(mfd);
+err0:
+       return -1;
+}
+#endif
+
 
 static int domain_create_tty(struct domain *dom)
 {
+       char slave[80];
+       struct termios term;
        char *path;
-       int master;
+       int master, slavefd;
+       int err;
        bool success;
-
-       if ((master = open("/dev/ptmx",O_RDWR|O_NOCTTY)) == -1 ||
-           grantpt(master) == -1 || unlockpt(master) == -1) {
-               dolog(LOG_ERR, "Failed to create tty for domain-%d",
-                     dom->domid);
+       char *data;
+       unsigned int len;
+
+       if (openpty(&master, &slavefd, slave, &term, NULL) < 0) {
                master = -1;
-       } else {
-               const char *slave = ptsname(master);
-               struct termios term;
-               char *data;
-               unsigned int len;
-
-               if (tcgetattr(master, &term) != -1) {
-                       cfmakeraw(&term);
-                       tcsetattr(master, TCSAFLUSH, &term);
-               }
-
-               if (dom->use_consolepath) {
-                       success = asprintf(&path, "%s/limit", dom->conspath) !=
-                               -1;
-                       if (!success)
-                               goto out;
-                       data = xs_read(xs, XBT_NULL, path, &len);
-                       if (data) {
-                               dom->buffer.max_capacity = strtoul(data, 0, 0);
-                               free(data);
-                       }
-                       free(path);
-               }
-
-               success = asprintf(&path, "%s/limit", dom->serialpath) != -1;
+               err = errno;
+               dolog(LOG_ERR, "Failed to create tty for domain-%d (errno = %i, 
%s)",
+                     dom->domid, err, strerror(err));
+               return master;
+       }
+
+       cfmakeraw(&term);
+       if (tcsetattr(master, TCSAFLUSH, &term) < 0) {
+               err = errno;
+               dolog(LOG_ERR, "Failed to set tty attribute  for domain-%d 
(errno = %i, %s)",
+                     dom->domid, err, strerror(err));
+               goto out;
+       }
+
+
+       if (dom->use_consolepath) {
+               success = asprintf(&path, "%s/limit", dom->conspath) !=
+                       -1;
                if (!success)
                        goto out;
                data = xs_read(xs, XBT_NULL, path, &len);
@@ -258,30 +300,38 @@ static int domain_create_tty(struct doma
                        free(data);
                }
                free(path);
-
-               success = asprintf(&path, "%s/tty", dom->serialpath) != -1;
+       }
+
+       success = asprintf(&path, "%s/limit", dom->serialpath) != -1;
+       if (!success)
+               goto out;
+       data = xs_read(xs, XBT_NULL, path, &len);
+       if (data) {
+               dom->buffer.max_capacity = strtoul(data, 0, 0);
+               free(data);
+       }
+       free(path);
+
+       success = asprintf(&path, "%s/tty", dom->serialpath) != -1;
+       if (!success)
+               goto out;
+       success = xs_write(xs, XBT_NULL, path, slave, strlen(slave));
+       free(path);
+       if (!success)
+               goto out;
+
+       if (dom->use_consolepath) {
+               success = (asprintf(&path, "%s/tty", dom->conspath) != -1);
                if (!success)
                        goto out;
                success = xs_write(xs, XBT_NULL, path, slave, strlen(slave));
                free(path);
                if (!success)
                        goto out;
-
-               if (dom->use_consolepath) {
-                       success = asprintf(&path, "%s/tty", dom->conspath) !=
-                               -1;
-                       if (!success)
-                               goto out;
-                       success = xs_write(xs, XBT_NULL, path, slave,
-                                          strlen(slave));
-                       free(path);
-                       if (!success)
-                               goto out;
-               }
-
-               if (fcntl(master, F_SETFL, O_NONBLOCK) == -1)
-                       goto out;
-       }
+       }
+
+       if (fcntl(master, F_SETFL, O_NONBLOCK) == -1)
+               goto out;
 
        return master;
  out:
@@ -410,7 +460,7 @@ static bool watch_domain(struct domain *
        char domid_str[3 + MAX_STRLEN(dom->domid)];
        bool success;
 
-       sprintf(domid_str, "dom%u", dom->domid);
+       snprintf(domid_str, sizeof(domid_str), "dom%u", dom->domid);
        if (watch) {
                success = xs_watch(xs, dom->serialpath, domid_str);
                if (success) {
diff -r ff99e8da117f -r 3d13b318349a tools/console/daemon/utils.c
--- a/tools/console/daemon/utils.c      Mon Oct 08 10:47:58 2007 +0100
+++ b/tools/console/daemon/utils.c      Mon Oct 08 10:55:50 2007 +0100
@@ -96,7 +96,7 @@ void daemonize(const char *pidfile)
                exit(1);
        }
 
-       len = sprintf(buf, "%ld\n", (long)getpid());
+       len = snprintf(buf, sizeof(buf), "%ld\n", (long)getpid());
        if (write(fd, buf, len) < 0)
                exit(1);
 

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] xenconsoled: portability fixes:, Xen patchbot-unstable <=