Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Pass the value of getprogname() from the client to the serve...



details:   https://anonhg.NetBSD.org/src/rev/bdb83a642e05
branches:  trunk
changeset: 761467:bdb83a642e05
user:      pooka <pooka%NetBSD.org@localhost>
date:      Fri Jan 28 19:21:28 2011 +0000

description:
Pass the value of getprogname() from the client to the server and
record it in p_comm.  This is nice for things like sockstat, since
they now display the client command name:

pain-rustique:43:~> rump.sockstat
USER     COMMAND    PID   FD PROTO  LOCAL ADDRESS         FOREIGN ADDRESS
root     xulrunner- 16     0 tcp    192.168.2.114.65507   204.152.190.12.80
root     xulrunner- 16     1 tcp    192.168.2.114.65501   204.152.190.12.80
root     xulrunner- 16     2 tcp    192.168.2.114.65500   204.152.190.12.80
root     xulrunner- 16     3 tcp    192.168.2.114.65499   204.152.190.12.80
root     xulrunner- 16     5 tcp    192.168.2.114.65498   204.152.190.12.80
root     xulrunner- 16     6 tcp    192.168.2.114.65497   204.152.190.12.80
root     socket     62     0 tcp6   *.http                *.*
root     socket     62     1 tcp    *.http                *.*
root     socket     63     0 tcp6   *.81                  *.*
root     socket     63     1 tcp    *.81                  *.*

diffstat:

 lib/librumpclient/rumpclient.c   |  13 +++++++++++--
 lib/librumpuser/rumpuser_sp.c    |  24 ++++++++++++++++--------
 sys/rump/include/rump/rumpuser.h |   6 +++---
 sys/rump/librump/rumpkern/rump.c |  16 ++++++++++------
 4 files changed, 40 insertions(+), 19 deletions(-)

diffs (197 lines):

diff -r eaf1d1d38fd7 -r bdb83a642e05 lib/librumpclient/rumpclient.c
--- a/lib/librumpclient/rumpclient.c    Fri Jan 28 18:52:48 2011 +0000
+++ b/lib/librumpclient/rumpclient.c    Fri Jan 28 19:21:28 2011 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: rumpclient.c,v 1.20 2011/01/27 18:04:05 pooka Exp $   */
+/*      $NetBSD: rumpclient.c,v 1.21 2011/01/28 19:21:28 pooka Exp $   */
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -307,10 +307,17 @@
        struct rsp_hdr rhdr;
        struct respwait rw;
        sigset_t omask;
+       size_t bonus;
        int rv;
 
+       if (auth) {
+               bonus = sizeof(rf);
+       } else {
+               bonus = strlen(getprogname())+1;
+       }
+
        /* performs server handshake */
-       rhdr.rsp_len = sizeof(rhdr) + (auth ? sizeof(rf) : 0);
+       rhdr.rsp_len = sizeof(rhdr) + bonus;
        rhdr.rsp_class = RUMPSP_REQ;
        rhdr.rsp_type = RUMPSP_HANDSHAKE;
        if (auth)
@@ -328,6 +335,8 @@
                memcpy(rf.rf_auth, auth, AUTHLEN*sizeof(*auth));
                rf.rf_cancel = cancel;
                rv = send_with_recon(spc, &rf, sizeof(rf));
+       } else {
+               rv = dosend(spc, getprogname(), strlen(getprogname())+1);
        }
        if (rv || cancel) {
                if (haslock)
diff -r eaf1d1d38fd7 -r bdb83a642e05 lib/librumpuser/rumpuser_sp.c
--- a/lib/librumpuser/rumpuser_sp.c     Fri Jan 28 18:52:48 2011 +0000
+++ b/lib/librumpuser/rumpuser_sp.c     Fri Jan 28 19:21:28 2011 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: rumpuser_sp.c,v 1.37 2011/01/22 13:41:22 pooka Exp $  */
+/*      $NetBSD: rumpuser_sp.c,v 1.38 2011/01/28 19:21:28 pooka Exp $  */
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: rumpuser_sp.c,v 1.37 2011/01/22 13:41:22 pooka Exp $");
+__RCSID("$NetBSD: rumpuser_sp.c,v 1.38 2011/01/28 19:21:28 pooka Exp $");
 
 #include <sys/types.h>
 #include <sys/atomic.h>
@@ -85,7 +85,7 @@
 static char banner[MAXBANNER];
 
 #define PROTOMAJOR 0
-#define PROTOMINOR 1
+#define PROTOMINOR 2
 
 struct prefork {
        uint32_t pf_auth[AUTHLEN];
@@ -149,12 +149,12 @@
 }
 
 static int
-lwproc_rfork(struct spclient *spc, int flags)
+lwproc_rfork(struct spclient *spc, int flags, const char *comm)
 {
        int rv;
 
        spops.spop_schedule();
-       rv = spops.spop_lwproc_rfork(spc, flags);
+       rv = spops.spop_lwproc_rfork(spc, flags, comm);
        spops.spop_unschedule();
 
        return rv;
@@ -779,7 +779,15 @@
                }
 
                if (spc->spc_hdr.rsp_handshake == HANDSHAKE_GUEST) {
-                       if ((error = lwproc_rfork(spc, RUMP_RFCFDG)) != 0) {
+                       char *comm = (char *)spc->spc_buf;
+                       size_t commlen = spc->spc_hdr.rsp_len - HDRSZ;
+
+                       /* ensure it's 0-terminated */
+                       /* XXX make sure it contains sensible chars? */
+                       comm[commlen] = '\0';
+
+                       if ((error = lwproc_rfork(spc,
+                           RUMP_RFCFDG, comm)) != 0) {
                                shutdown(spc->spc_fd, SHUT_RDWR);
                        }
 
@@ -844,7 +852,7 @@
                         * the wrong spc pointer.  (yea, optimize
                         * interfaces some day if anyone cares)
                         */
-                       if ((error = lwproc_rfork(spc, 0)) != 0) {
+                       if ((error = lwproc_rfork(spc, 0, NULL)) != 0) {
                                send_error_resp(spc, reqno, error);
                                shutdown(spc->spc_fd, SHUT_RDWR);
                                lwproc_release();
@@ -889,7 +897,7 @@
                 * so we can safely use it here.
                 */
                lwproc_switch(spc->spc_mainlwp);
-               if ((error = lwproc_rfork(spc, RUMP_RFFDG)) != 0) {
+               if ((error = lwproc_rfork(spc, RUMP_RFFDG, NULL)) != 0) {
                        DPRINTF(("rump_sp: fork failed: %d (%p)\n",error, spc));
                        send_error_resp(spc, reqno, error);
                        lwproc_switch(NULL);
diff -r eaf1d1d38fd7 -r bdb83a642e05 sys/rump/include/rump/rumpuser.h
--- a/sys/rump/include/rump/rumpuser.h  Fri Jan 28 18:52:48 2011 +0000
+++ b/sys/rump/include/rump/rumpuser.h  Fri Jan 28 19:21:28 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rumpuser.h,v 1.64 2011/01/22 13:41:22 pooka Exp $      */
+/*     $NetBSD: rumpuser.h,v 1.65 2011/01/28 19:21:29 pooka Exp $      */
 
 /*
  * Copyright (c) 2007 Antti Kantee.  All Rights Reserved.
@@ -36,7 +36,7 @@
 #include <stdint.h>
 #endif
 
-#define RUMPUSER_VERSION 11
+#define RUMPUSER_VERSION 12
 int rumpuser_getversion(void);
 
 int rumpuser_daemonize_begin(void);
@@ -214,7 +214,7 @@
 
        void (*spop_lwproc_switch)(struct lwp *);
        void (*spop_lwproc_release)(void);
-       int (*spop_lwproc_rfork)(void *, int);
+       int (*spop_lwproc_rfork)(void *, int, const char *);
        int (*spop_lwproc_newlwp)(pid_t);
        struct lwp * (*spop_lwproc_curlwp)(void);
        int (*spop_syscall)(int, void *, register_t *);
diff -r eaf1d1d38fd7 -r bdb83a642e05 sys/rump/librump/rumpkern/rump.c
--- a/sys/rump/librump/rumpkern/rump.c  Fri Jan 28 18:52:48 2011 +0000
+++ b/sys/rump/librump/rumpkern/rump.c  Fri Jan 28 19:21:28 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rump.c,v 1.225 2011/01/28 18:48:21 pooka Exp $ */
+/*     $NetBSD: rump.c,v 1.226 2011/01/28 19:21:29 pooka Exp $ */
 
 /*
  * Copyright (c) 2007 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.225 2011/01/28 18:48:21 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.226 2011/01/28 19:21:29 pooka Exp $");
 
 #include <sys/systm.h>
 #define ELFSIZE ARCH_ELFSIZE
@@ -100,7 +100,7 @@
 #endif
 
 static int rump_proxy_syscall(int, void *, register_t *);
-static int rump_proxy_rfork(void *, int);
+static int rump_proxy_rfork(void *, int, const char *);
 static void rump_proxy_procexit(void);
 
 static char rump_msgbuf[16*1024]; /* 16k should be enough for std rump needs */
@@ -752,9 +752,10 @@
 }
 
 static int
-rump_proxy_rfork(void *priv, int flags)
+rump_proxy_rfork(void *priv, int flags, const char *comm)
 {
        struct vmspace *newspace;
+       struct proc *p;
        int error;
 
        if ((error = rump_lwproc_rfork(flags)) != 0)
@@ -764,11 +765,14 @@
         * Since it's a proxy proc, adjust the vmspace.
         * Refcount will eternally be 1.
         */
+       p = curproc;
        newspace = kmem_alloc(sizeof(*newspace), KM_SLEEP);
        newspace->vm_refcnt = 1;
        newspace->vm_map.pmap = priv;
-       KASSERT(curproc->p_vmspace == vmspace_kernel());
-       curproc->p_vmspace = newspace;
+       KASSERT(p->p_vmspace == vmspace_kernel());
+       p->p_vmspace = newspace;
+       if (comm)
+               strlcpy(p->p_comm, comm, sizeof(p->p_comm));
 
        return 0;
 }



Home | Main Index | Thread Index | Old Index