Home | History | Annotate | Line # | Download | only in procfs
procfs_cmdline.c revision 1.1
      1  1.1  christos /*	$NetBSD: procfs_cmdline.c,v 1.1 1999/03/12 18:45:40 christos Exp $	*/
      2  1.1  christos 
      3  1.1  christos /*
      4  1.1  christos  * Copyright (c) 1999 Jaromir Dolecek <dolecek (at) ics.muni.cz>
      5  1.1  christos  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      6  1.1  christos  * All rights reserved.
      7  1.1  christos  *
      8  1.1  christos  * This code is derived from software contributed to The NetBSD Foundation
      9  1.1  christos  * by Jaromir Dolecek.
     10  1.1  christos  *
     11  1.1  christos  * Redistribution and use in source and binary forms, with or without
     12  1.1  christos  * modification, are permitted provided that the following conditions
     13  1.1  christos  * are met:
     14  1.1  christos  * 1. Redistributions of source code must retain the above copyright
     15  1.1  christos  *    notice, this list of conditions and the following disclaimer.
     16  1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     18  1.1  christos  *    documentation and/or other materials provided with the distribution.
     19  1.1  christos  * 3. All advertising materials mentioning features or use of this software
     20  1.1  christos  *    must display the following acknowledgement:
     21  1.1  christos  *	This product includes software developed by the NetBSD
     22  1.1  christos  *	Foundation, Inc. and its contributors.
     23  1.1  christos  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  1.1  christos  *    contributors may be used to endorse or promote products derived
     25  1.1  christos  *    from this software without specific prior written permission.
     26  1.1  christos  *
     27  1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  1.1  christos  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  1.1  christos  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  1.1  christos  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  1.1  christos  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  1.1  christos  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  1.1  christos  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  1.1  christos  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  1.1  christos  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  1.1  christos  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  1.1  christos  * POSSIBILITY OF SUCH DAMAGE.
     38  1.1  christos  */
     39  1.1  christos 
     40  1.1  christos #include <sys/param.h>
     41  1.1  christos #include <sys/types.h>
     42  1.1  christos #include <sys/systm.h>
     43  1.1  christos #include <sys/syslimits.h>
     44  1.1  christos #include <sys/proc.h>
     45  1.1  christos #include <sys/vnode.h>
     46  1.1  christos #include <sys/exec.h>
     47  1.1  christos #include <miscfs/procfs/procfs.h>
     48  1.1  christos 
     49  1.1  christos /*
     50  1.1  christos  * code for returning process's command line arguments
     51  1.1  christos  */
     52  1.1  christos int
     53  1.1  christos procfs_docmdline(curp, p, pfs, uio)
     54  1.1  christos 	struct proc *curp;
     55  1.1  christos 	struct proc *p;
     56  1.1  christos 	struct pfsnode *pfs;
     57  1.1  christos 	struct uio *uio;
     58  1.1  christos {
     59  1.1  christos 	struct ps_strings pss;
     60  1.1  christos 	char arg[ARG_MAX], *argv;
     61  1.1  christos 	int xlen, len, count, i;
     62  1.1  christos 
     63  1.1  christos 	/* don't write; can't work for zombies -- they don't have any stack */
     64  1.1  christos 	if (uio->uio_rw != UIO_READ || p->p_stat == SZOMB)
     65  1.1  christos 		return EOPNOTSUPP;
     66  1.1  christos 
     67  1.1  christos 	if (copyin(PS_STRINGS, &pss, sizeof(struct ps_strings)))
     68  1.1  christos 		return EFAULT;
     69  1.1  christos 	if (copyin(pss.ps_argvstr, &argv, sizeof(argv)))
     70  1.1  christos 		return EFAULT;
     71  1.1  christos 	len = 0;
     72  1.1  christos 	count = pss.ps_nargvstr;
     73  1.1  christos 	/* don't know how long the argument string is, so let's find out */
     74  1.1  christos 	while(count && len < ARG_MAX && copyin(argv+len, &arg[len], 1) == 0) {
     75  1.1  christos 		if (len > 0 && arg[len] == '\0') count--;
     76  1.1  christos 		len++;
     77  1.1  christos 	}
     78  1.1  christos 	if (len > 0) len--; /* exclude last NULL */
     79  1.1  christos 
     80  1.1  christos 	xlen = len - uio->uio_offset;
     81  1.1  christos 	xlen = imin(xlen, uio->uio_resid);
     82  1.1  christos 	if (xlen <= 0)
     83  1.1  christos 		return 0;
     84  1.1  christos 	else
     85  1.1  christos 		return (uiomove(arg + uio->uio_offset, xlen, uio));
     86  1.1  christos }
     87