Subject: kern/7143: procfs misses #/cmdline file
To: None <gnats-bugs@gnats.netbsd.org>
From: Jaromir Dolecek <dolecek@ics.muni.cz>
List: netbsd-bugs
Date: 03/12/1999 12:41:14
>Number: 7143
>Category: kern
>Synopsis: procfs misses #/cmdline file
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: kern-bug-people (Kernel Bug People)
>State: open
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Fri Mar 12 03:50:00 1999
>Last-Modified:
>Originator: Jaromir Dolecek
>Organization:
Per4mance, Brno, Czech Republic
>Release: NetBSD-19990120 or so
>Environment:
System: NetBSD jdolecek.per4mance.cz 1.3I NetBSD 1.3I (JDOLECEK) #7: Thu Mar 11 18:33:22 MET 1999 dolecek@jdolecek.per4mance.cz:/home/dolecek/tmp/src/sys/arch/i386/compile/JDOLECEK i386
>Description:
While installing some Linux (namely Oracle) programs, I realized
they need /proc/curproc/cmdline for whatever insane reason. Oracle
installer dumped core when that file didn't exist. I got around
it by creating fake hirarchy, but it's definitely not very
comfortable. Much more convenient would be if that file would
be present in our procfs.
>How-To-Repeat:
cd /cdrom/oracle/orainst
./orainst
Segmentation violation
>Fix:
I would be very glad to see it in. It would save me lot's
of pain when I'll try to install Oracle next time (or
Oracle8i when I'll have it). Even if it would not be
considered valuable thing for NetBSD as a whole, it would
be nice if it would be present at least with COMPAT_LINUX.
The patch files are also available at
http://www.ics.muni.cz/~dolecek/NetBSD/procfs/
as procfs_cmdline_patch and procfs_cmdline_lkm_patch
Index: README
===================================================================
RCS file: /home/dolecek/cvsroot/procfs/README,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -r1.1.1.1 -r1.2
--- README 1999/03/11 16:56:05 1.1.1.1
+++ README 1999/03/12 11:03:38 1.2
@@ -47,6 +47,8 @@
will get the "right" register values.
a multi-proc kernel would need to do some
synchronisation.
+ cmdline - r/o. process command line parameters, separated
+ by NULLs
this then looks like:
@@ -76,13 +78,17 @@
3273 dr-xr-xr-x 2 jsp staff 0 Sep 21 15:06 curproc
% ls -li /proc/curproc
total 408
-3341 --w------- 1 jsp staff 0 Sep 21 15:06 ctl
-1554 -r-xr-xr-x 1 bin bin 90112 Mar 29 04:52 file
-3339 -rw------- 1 jsp staff 118784 Sep 21 15:06 mem
-3343 --w------- 1 jsp staff 0 Sep 21 15:06 note
-3344 --w------- 1 jsp staff 0 Sep 21 15:06 notepg
-3340 -rw------- 1 jsp staff 0 Sep 21 15:06 regs
-3342 -r--r--r-- 1 jsp staff 0 Sep 21 15:06 status
+total 460
+7692 -r--r--r-- 1 dolecek staff 0 Mar 12 12:02 cmdline
+7687 --w------- 1 dolecek staff 0 Mar 12 12:02 ctl
+2003 -r-xr-xr-x 1 root wheel 180224 Jan 31 23:32 file*
+7686 -rw------- 1 dolecek staff 108 Mar 12 12:02 fpregs
+7691 -r--r--r-- 1 dolecek staff 0 Mar 12 12:02 map
+7684 -rw------- 1 dolecek staff 282624 Mar 12 12:02 mem
+7689 --w------- 1 dolecek staff 0 Mar 12 12:02 note
+7690 --w------- 1 dolecek staff 0 Mar 12 12:02 notepg
+7685 -rw------- 1 dolecek staff 64 Mar 12 12:02 regs
+7688 -r--r--r-- 1 dolecek staff 0 Mar 12 12:02 status
% df /proc/curproc /proc/curproc/file
Filesystem 512-blocks Used Avail Capacity Mounted on
proc 2 2 0 100% /proc
Index: procfs.h
===================================================================
RCS file: /home/dolecek/cvsroot/procfs/procfs.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -r1.1.1.1 -r1.2
--- procfs.h 1999/03/11 16:56:05 1.1.1.1
+++ procfs.h 1999/03/11 17:01:29 1.2
@@ -54,7 +54,8 @@
Pstatus, /* process status */
Pnote, /* process notifier */
Pnotepg, /* process group notifier */
- Pmap /* memory map */
+ Pmap, /* memory map */
+ Pcmdline /* process command line args */
} pfstype;
/*
@@ -114,6 +115,7 @@
int procfs_doctl __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
int procfs_dostatus __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
int procfs_domap __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
+int procfs_docmdline __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
int procfs_checkioperm __P((struct proc *p, struct proc *t));
Index: procfs_cmdline.c
===================================================================
RCS file: procfs_cmdline.c
diff -N procfs_cmdline.c
--- /dev/null Fri Mar 12 12:24:16 1999
+++ /var/tmp/tmp.0.00691a Fri Mar 12 12:24:43 1999
@@ -0,0 +1,87 @@
+/* $NetBSD$ */
+
+/*
+ * Copyright (c) 1999 Jaromir Dolecek <dolecek@ics.muni.cz>
+ * Copyright (c) 1999 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jaromir Dolecek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/systm.h>
+#include <sys/syslimits.h>
+#include <sys/proc.h>
+#include <sys/vnode.h>
+#include <sys/exec.h>
+#include <miscfs/procfs/procfs.h>
+
+/*
+ * code for returning process's command line arguments
+ */
+int
+procfs_docmdline(curp, p, pfs, uio)
+ struct proc *curp;
+ struct proc *p;
+ struct pfsnode *pfs;
+ struct uio *uio;
+{
+ struct ps_strings pss;
+ char arg[ARG_MAX], *argv;
+ int xlen, len, count, i;
+
+ /* don't write; can't work for zombies -- they don't have any stack */
+ if (uio->uio_rw != UIO_READ || p->p_stat == SZOMB)
+ return (EOPNOTSUPP);
+
+ if (copyin(PS_STRINGS, &pss, sizeof(struct ps_strings)))
+ return EFAULT;
+ if (copyin(pss.ps_argvstr, &argv, sizeof(argv)))
+ return EFAULT;
+ len = 0;
+ count = pss.ps_nargvstr;
+ /* don't know how long the argument string is, so let's find out */
+ while(count && len < ARG_MAX && copyin(argv+len, &arg[len], 1) == 0)
+ {
+ if (len > 0 && arg[len] == '\000') count--;
+ len++;
+ }
+ if (len > 0) len--; /* exclude last NULL */
+
+ xlen = len - uio->uio_offset;
+ xlen = imin(xlen, uio->uio_resid);
+ if (xlen <= 0)
+ return 0;
+ else
+ return (uiomove(arg + uio->uio_offset, xlen, uio));
+}
Index: procfs_subr.c
===================================================================
RCS file: /home/dolecek/cvsroot/procfs/procfs_subr.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -r1.1.1.1 -r1.2
--- procfs_subr.c 1999/03/11 16:56:05 1.1.1.1
+++ procfs_subr.c 1999/03/11 17:25:00 1.2
@@ -166,6 +166,7 @@
case Pmap: /* /proc/N/map = -r--r--r-- */
case Pstatus: /* /proc/N/status = -r--r--r-- */
+ case Pcmdline: /* /proc/N/cmdline = -r--r--r-- */
pfs->pfs_mode = S_IRUSR|S_IRGRP|S_IROTH;
vp->v_type = VREG;
break;
@@ -263,6 +264,9 @@
case Pmem:
return (procfs_domem(curp, p, pfs, uio));
+
+ case Pcmdline:
+ return (procfs_docmdline(curp, p, pfs, uio));
default:
return (EOPNOTSUPP);
Index: procfs_vnops.c
===================================================================
RCS file: /home/dolecek/cvsroot/procfs/procfs_vnops.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -r1.1.1.1 -r1.2
--- procfs_vnops.c 1999/03/11 16:56:05 1.1.1.1
+++ procfs_vnops.c 1999/03/11 17:25:19 1.2
@@ -94,6 +94,7 @@
{ DT_REG, N("note"), Pnote, NULL },
{ DT_REG, N("notepg"), Pnotepg, NULL },
{ DT_REG, N("map"), Pmap, procfs_validmap },
+ { DT_REG, N("cmdline"), Pcmdline, NULL },
#undef N
};
static int nproc_targets = sizeof(proc_targets) / sizeof(proc_targets[0]);
@@ -532,6 +533,7 @@
case Pnote:
case Pnotepg:
case Pmap:
+ case Pcmdline:
vap->va_nlink = 1;
vap->va_uid = procp->p_ucred->cr_uid;
vap->va_gid = procp->p_ucred->cr_gid;
@@ -607,6 +609,7 @@
case Pnote:
case Pnotepg:
case Pmap:
+ case Pcmdline:
vap->va_bytes = vap->va_size = 0;
break;
--- sys/lkm/vfs/miscfs/procfs/Makefile.orig Fri Mar 12 12:35:31 1999
+++ sys/lkm/vfs/miscfs/procfs/Makefile Fri Mar 12 12:35:37 1999
@@ -11,6 +11,6 @@
SRCS= lkminit_vfs.c
SRCS+= procfs_ctl.c procfs_note.c procfs_status.c procfs_subr.c
-SRCS+= procfs_vfsops.c procfs_vnops.c
+SRCS+= procfs_vfsops.c procfs_vnops.c procfs_cmdline.c
.include <bsd.kmod.mk>
>Audit-Trail:
>Unformatted: