Subject: Re: matlab core dump
To: Lasse Kliemann <lasse-private-2005@plastictree.net>
From: Christos Zoulas <christos@zoulas.com>
List: netbsd-help
Date: 04/11/2006 18:42:11
On Apr 11, 11:06pm, lasse-private-2005@plastictree.net ("Lasse Kliemann") wrote:
-- Subject: Re: matlab core dump
| lki is the name of the account under which I tried to run=20
| matlab.
I see what's going on. struct ptmget only allows for 16 chars in the
pty name. Your mount path [the chroot mount] causes it to exceed this.
I've adjusted it to remove the chrooted portion which is the right
behavior. This patch is untested and from current...
christos
Index: fs/ptyfs/ptyfs_subr.c
===================================================================
RCS file: /cvsroot/src/sys/fs/ptyfs/ptyfs_subr.c,v
retrieving revision 1.5
diff -u -u -r1.5 ptyfs_subr.c
--- fs/ptyfs/ptyfs_subr.c 11 Dec 2005 12:24:29 -0000 1.5
+++ fs/ptyfs/ptyfs_subr.c 11 Apr 2006 22:40:22 -0000
@@ -136,7 +136,7 @@
* from the inode
*/
if ((error = (*ptyfs_save_ptm->makename)(
- ptyfs_save_ptm, ttyname, sizeof(ttyname),
+ ptyfs_save_ptm, l, ttyname, sizeof(ttyname),
ptyfs->ptyfs_pty, ptyfs->ptyfs_type == PTYFSpts ? 't'
: 'p')) != 0)
goto out;
Index: fs/ptyfs/ptyfs_vfsops.c
===================================================================
RCS file: /cvsroot/src/sys/fs/ptyfs/ptyfs_vfsops.c,v
retrieving revision 1.12
diff -u -u -r1.12 ptyfs_vfsops.c
--- fs/ptyfs/ptyfs_vfsops.c 11 Dec 2005 12:24:29 -0000 1.12
+++ fs/ptyfs/ptyfs_vfsops.c 11 Apr 2006 22:40:22 -0000
@@ -53,6 +53,7 @@
#include <sys/malloc.h>
#include <sys/syslog.h>
#include <sys/select.h>
+#include <sys/filedesc.h>
#include <sys/tty.h>
#include <sys/pty.h>
@@ -75,7 +76,8 @@
static int ptyfs__allocvp(struct ptm_pty *, struct lwp *, struct vnode **,
dev_t, char);
-static int ptyfs__makename(struct ptm_pty *, char *, size_t, dev_t, char);
+static int ptyfs__makename(struct ptm_pty *, struct lwp *, char *, size_t,
+ dev_t, char);
static void ptyfs__getvattr(struct ptm_pty *, struct proc *, struct vattr *);
/*
@@ -91,9 +93,35 @@
NULL
};
+static const char *
+ptyfs__getpath(struct lwp *l, const struct mount *mp)
+{
+ struct cwdinfo *cwdi = l->l_proc->p_cwdi;
+ char buf[sizeof(mp->mnt_stat.f_mntonname) + 32];
+ size_t len;
+ char *bp;
+ int error;
+
+ if (cwdi->cwdi_rdir == NULL)
+ return mp->mnt_stat.f_mntonname;
+
+ bp = buf + sizeof(buf);
+ *--bp = '\0';
+ error = getcwd_common(cwdi->cwdi_rdir, rootvnode, &bp,
+ buf, sizeof(buf) / 2, 0, l);
+ if (error) /* XXX */
+ return mp->mnt_stat.f_mntonname;
+
+ len = strlen(bp);
+ if (len >= sizeof(mp->mnt_stat.f_mntonname)) /* XXX */
+ return mp->mnt_stat.f_mntonname;
+ else
+ return &mp->mnt_stat.f_mntonname[len];
+}
+
static int
-ptyfs__makename(struct ptm_pty *pt, char *tbuf, size_t bufsiz, dev_t dev,
- char ms)
+ptyfs__makename(struct ptm_pty *pt, struct lwp *l, char *tbuf, size_t bufsiz,
+ dev_t dev, char ms)
{
struct mount *mp = pt->arg;
size_t len;
@@ -104,7 +132,7 @@
len = snprintf(tbuf, bufsiz, "/dev/null");
break;
case 't':
- len = snprintf(tbuf, bufsiz, "%s/%d", mp->mnt_stat.f_mntonname,
+ len = snprintf(tbuf, bufsiz, "%s/%d", ptyfs__getpath(l, mp),
minor(dev));
break;
default:
Index: kern/tty_bsdpty.c
===================================================================
RCS file: /cvsroot/src/sys/kern/tty_bsdpty.c,v
retrieving revision 1.6
diff -u -u -r1.6 tty_bsdpty.c
--- kern/tty_bsdpty.c 23 Mar 2006 23:53:54 -0000 1.6
+++ kern/tty_bsdpty.c 11 Apr 2006 22:40:22 -0000
@@ -76,7 +76,8 @@
#define TTY_OLD_SUFFIX "0123456789abcdef"
#define TTY_NEW_SUFFIX "ghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
-static int pty_makename(struct ptm_pty *, char *, size_t, dev_t, char);
+static int pty_makename(struct ptm_pty *, struct lwp *, char *, size_t, dev_t,
+ char);
static int pty_allocvp(struct ptm_pty *, struct lwp *, struct vnode **,
dev_t, char);
static void pty_getvattr(struct ptm_pty *, struct proc *, struct vattr *);
@@ -90,7 +91,8 @@
static int
/*ARGSUSED*/
-pty_makename(struct ptm_pty *ptm, char *bf, size_t bufsiz, dev_t dev, char c)
+pty_makename(struct ptm_pty *ptm, struct lwp *l, char *bf, size_t bufsiz,
+ dev_t dev, char c)
{
size_t nt;
dev_t minor = minor(dev);
@@ -126,7 +128,7 @@
struct nameidata nd;
char name[TTY_NAMESIZE];
- error = (*ptm->makename)(ptm, name, sizeof(name), dev, ms);
+ error = (*ptm->makename)(ptm, l, name, sizeof(name), dev, ms);
if (error)
return error;
Index: kern/tty_ptm.c
===================================================================
RCS file: /cvsroot/src/sys/kern/tty_ptm.c,v
retrieving revision 1.7
diff -u -u -r1.7 tty_ptm.c
--- kern/tty_ptm.c 11 Dec 2005 12:24:30 -0000 1.7
+++ kern/tty_ptm.c 11 Apr 2006 22:40:23 -0000
@@ -289,7 +289,7 @@
}
int
-pty_fill_ptmget(dev_t dev, int cfd, int sfd, void *data)
+pty_fill_ptmget(struct lwp *l, dev_t dev, int cfd, int sfd, void *data)
{
struct ptmget *ptmg = data;
int error;
@@ -300,11 +300,11 @@
ptmg->cfd = cfd == -1 ? minor(dev) : cfd;
ptmg->sfd = sfd == -1 ? minor(dev) : sfd;
- error = (*ptm->makename)(ptm, ptmg->cn, sizeof(ptmg->cn), dev, 'p');
+ error = (*ptm->makename)(ptm, l, ptmg->cn, sizeof(ptmg->cn), dev, 'p');
if (error)
return error;
- return (*ptm->makename)(ptm, ptmg->sn, sizeof(ptmg->sn), dev, 't');
+ return (*ptm->makename)(ptm, l, ptmg->sn, sizeof(ptmg->sn), dev, 't');
}
void
@@ -372,7 +372,7 @@
goto bad;
/* now, put the indices and names into struct ptmget */
- return pty_fill_ptmget(newdev, cfd, sfd, data);
+ return pty_fill_ptmget(l, newdev, cfd, sfd, data);
default:
DPRINTF(("ptmioctl EINVAL\n"));
return EINVAL;
Index: kern/tty_pty.c
===================================================================
RCS file: /cvsroot/src/sys/kern/tty_pty.c,v
retrieving revision 1.87
diff -u -u -r1.87 tty_pty.c
--- kern/tty_pty.c 5 Mar 2006 16:57:16 -0000 1.87
+++ kern/tty_pty.c 11 Apr 2006 22:40:23 -0000
@@ -1053,7 +1053,7 @@
#ifndef NO_DEV_PTM
/* Allow getting the name from either the master or the slave */
if (cmd == TIOCPTSNAME)
- return pty_fill_ptmget(dev, -1, -1, data);
+ return pty_fill_ptmget(l, dev, -1, -1, data);
#endif
cdev = cdevsw_lookup(dev);
Index: sys/pty.h
===================================================================
RCS file: /cvsroot/src/sys/sys/pty.h,v
retrieving revision 1.5
diff -u -u -r1.5 pty.h
--- sys/pty.h 11 Dec 2005 12:25:21 -0000 1.5
+++ sys/pty.h 11 Apr 2006 22:40:23 -0000
@@ -43,7 +43,7 @@
#ifndef NO_DEV_PTM
void ptmattach(int);
-int pty_fill_ptmget(dev_t, int, int, void *);
+int pty_fill_ptmget(struct lwp *, dev_t, int, int, void *);
int pty_grant_slave(struct lwp *, dev_t);
dev_t pty_makedev(char, int);
int pty_vn_open(struct vnode *, struct lwp *);
@@ -53,7 +53,7 @@
struct ptm_pty {
int (*allocvp)(struct ptm_pty *, struct lwp *, struct vnode **, dev_t,
char);
- int (*makename)(struct ptm_pty *, char *, size_t, dev_t, char);
+ int (*makename)(struct ptm_pty *, struct lwp *, char *, size_t, dev_t, char);
void (*getvattr)(struct ptm_pty *, struct proc *, struct vattr *);
void *arg;
};