Source-Changes-HG archive

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

[src/trunk]: src/sys/miscfs/procfs add a node for the process resource limits.



details:   https://anonhg.NetBSD.org/src/rev/aaf13486e13d
branches:  trunk
changeset: 449971:aaf13486e13d
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Mar 30 23:28:30 2019 +0000

description:
add a node for the process resource limits.

diffstat:

 sys/miscfs/procfs/files.procfs    |   3 +-
 sys/miscfs/procfs/procfs.h        |  55 ++++++++++++----------
 sys/miscfs/procfs/procfs_limit.c  |  94 +++++++++++++++++++++++++++++++++++++++
 sys/miscfs/procfs/procfs_subr.c   |   8 ++-
 sys/miscfs/procfs/procfs_vfsops.c |   5 +-
 sys/miscfs/procfs/procfs_vnops.c  |  35 +++++++------
 6 files changed, 153 insertions(+), 47 deletions(-)

diffs (truncated from 328 to 300 lines):

diff -r 0a6cc6b2d444 -r aaf13486e13d sys/miscfs/procfs/files.procfs
--- a/sys/miscfs/procfs/files.procfs    Sat Mar 30 21:06:42 2019 +0000
+++ b/sys/miscfs/procfs/files.procfs    Sat Mar 30 23:28:30 2019 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.procfs,v 1.12 2017/08/28 00:46:07 kamil Exp $
+#      $NetBSD: files.procfs,v 1.13 2019/03/30 23:28:30 christos Exp $
 
 deffs  PROCFS: PTRACE_HOOKS
 
@@ -7,6 +7,7 @@
 file   miscfs/procfs/procfs_cmdline.c  procfs
 file   miscfs/procfs/procfs_fd.c       procfs
 file   miscfs/procfs/procfs_fpregs.c   procfs
+file   miscfs/procfs/procfs_limit.c    procfs
 file   miscfs/procfs/procfs_linux.c    procfs
 file   miscfs/procfs/procfs_map.c      procfs
 file   miscfs/procfs/procfs_mem.c      procfs
diff -r 0a6cc6b2d444 -r aaf13486e13d sys/miscfs/procfs/procfs.h
--- a/sys/miscfs/procfs/procfs.h        Sat Mar 30 21:06:42 2019 +0000
+++ b/sys/miscfs/procfs/procfs.h        Sat Mar 30 23:28:30 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: procfs.h,v 1.74 2017/12/31 03:29:18 christos Exp $     */
+/*     $NetBSD: procfs.h,v 1.75 2019/03/30 23:28:30 christos Exp $     */
 
 /*
  * Copyright (c) 1993
@@ -79,38 +79,39 @@
  * The different types of node in a procfs filesystem
  */
 typedef enum {
-       PFSroot,        /* the filesystem root */
+       PFSauxv,        /* ELF Auxiliary Vector */
+       PFSchroot,      /* the process's current root directory */
+       PFScmdline,     /* process command line args */
+       PFScpuinfo,     /* CPU info (if -o linux) */
+       PFScpustat,     /* status info (if -o linux) */
        PFScurproc,     /* symbolic link for curproc */
-       PFSself,        /* like curproc, but this is the Linux name */
-       PFSproc,        /* a process-specific sub-directory */
-       PFSfile,        /* the executable file */
+       PFScwd,         /* the process's current working directory */
+       PFSdevices,     /* major/device name mappings (if -o linux) */
+       PFSemul,        /* the process's emulation */
+       PFSenviron,     /* process environment */
        PFSexe,         /* symlink to the executable file */
-       PFSmem,         /* the process's memory image */
-       PFSregs,        /* the process's register set */
+       PFSfd,          /* a directory containing the processes open fd's */
+       PFSfile,        /* the executable file */
        PFSfpregs,      /* the process's FP register set */
-       PFSstat,        /* process status (if -o linux) */
-       PFSstatus,      /* process status */
+       PFSloadavg,     /* load average (if -o linux) */
+       PFSlimit,       /* resource limits */
+       PFSmap,         /* memory map */
+       PFSmaps,        /* memory map, Linux style (if -o linux) */
+       PFSmem,         /* the process's memory image */
+       PFSmeminfo,     /* system memory info (if -o linux) */
+       PFSmounts,      /* mounted filesystems (if -o linux) */
        PFSnote,        /* process notifier */
        PFSnotepg,      /* process group notifier */
-       PFSmap,         /* memory map */
-       PFScmdline,     /* process command line args */
-       PFSenviron,     /* process environment */
-       PFSmeminfo,     /* system memory info (if -o linux) */
-       PFScpuinfo,     /* CPU info (if -o linux) */
-       PFSmaps,        /* memory map, Linux style (if -o linux) */
-       PFSfd,          /* a directory containing the processes open fd's */
+       PFSproc,        /* a process-specific sub-directory */
+       PFSregs,        /* the process's register set */
+       PFSroot,        /* the filesystem root */
+       PFSself,        /* like curproc, but this is the Linux name */
+       PFSstat,        /* process status (if -o linux) */
+       PFSstatm,       /* process memory info (if -o linux) */
+       PFSstatus,      /* process status */
+       PFStask,        /* task subdirector (if -o linux) */
        PFSuptime,      /* elapsed time since (if -o linux) */
-       PFSmounts,      /* mounted filesystems (if -o linux) */
-       PFScwd,         /* the process's current working directory */
-       PFSchroot,      /* the process's current root directory */
-       PFSemul,        /* the process's emulation */
-       PFSdevices,     /* major/device name mappings (if -o linux) */
-       PFScpustat,     /* status info (if -o linux) */
-       PFSloadavg,     /* load average (if -o linux) */
-       PFSstatm,       /* process memory info (if -o linux) */
        PFSversion,     /* kernel version (if -o linux) */
-       PFStask,        /* task subdirector (if -o linux) */
-       PFSauxv,        /* ELF Auxiliary Vector */
 #ifdef __HAVE_PROCFS_MACHDEP
        PROCFS_MACHDEP_NODE_TYPES
 #endif
@@ -234,6 +235,8 @@
     struct uio *);
 int procfs_doauxv(struct lwp *, struct proc *, struct pfsnode *,
     struct uio *);
+int procfs_dolimit(struct lwp *, struct proc *, struct pfsnode *,
+    struct uio *);
 
 void procfs_revoke_vnodes(struct proc *, void *);
 int procfs_getfp(struct pfsnode *, struct proc *, struct file **);
diff -r 0a6cc6b2d444 -r aaf13486e13d sys/miscfs/procfs/procfs_limit.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/miscfs/procfs/procfs_limit.c  Sat Mar 30 23:28:30 2019 +0000
@@ -0,0 +1,94 @@
+/*     $NetBSD: procfs_limit.c,v 1.1 2019/03/30 23:28:30 christos Exp $        */
+
+/*-
+ * Copyright (c) 2019 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * 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.
+ *
+ * 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/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: procfs_limit.c,v 1.1 2019/03/30 23:28:30 christos Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/proc.h>
+#include <sys/malloc.h>
+#include <sys/resource.h>
+#include <miscfs/procfs/procfs.h>
+
+#define MAXBUFFERSIZE (256 * 1024)
+
+static size_t
+prl(char *buf, size_t len, intmax_t lim, char sep)
+{
+       if (lim == RLIM_INFINITY)
+               return snprintf(buf, len, "%#20jx%c", lim, sep);
+       else
+               return snprintf(buf, len, "%20jd%c", lim, sep);
+}
+
+int
+procfs_dolimit(struct lwp *curl, struct proc *p, struct pfsnode *pfs,
+     struct uio *uio)
+{
+       static const char *label[] = RLIM_STRINGS;
+       int error;
+       char *buffer;
+       size_t bufsize, pos, i;
+       struct rlimit rl[RLIM_NLIMITS];
+
+       if (uio->uio_rw != UIO_READ)
+               return EOPNOTSUPP;
+
+       mutex_enter(proc_lock);
+       mutex_enter(p->p_lock);
+       memcpy(rl, p->p_rlimit, sizeof(rl));
+       mutex_exit(p->p_lock);
+       mutex_exit(proc_lock);
+
+       error = 0;
+
+       bufsize = (64 * 3) * __arraycount(rl);
+       buffer = malloc(bufsize, M_TEMP, M_WAITOK);
+       pos = 0;
+       for (i = 0; i < __arraycount(rl); i++) {
+               pos += snprintf(buffer + pos, bufsize - pos, "%20.20s ",
+                   label[i]);
+               pos += prl(buffer + pos, bufsize - pos, rl[i].rlim_cur, ' ');
+               pos += prl(buffer + pos, bufsize - pos, rl[i].rlim_max, '\n');
+       }
+
+       if (uio->uio_offset < pos)
+               error = uiomove(buffer + uio->uio_offset,
+                   pos - uio->uio_offset, uio);
+       else
+               error = 0;
+
+       if (buffer != NULL)
+               free(buffer, M_TEMP);
+
+       return error;
+}
diff -r 0a6cc6b2d444 -r aaf13486e13d sys/miscfs/procfs/procfs_subr.c
--- a/sys/miscfs/procfs/procfs_subr.c   Sat Mar 30 21:06:42 2019 +0000
+++ b/sys/miscfs/procfs/procfs_subr.c   Sat Mar 30 23:28:30 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: procfs_subr.c,v 1.112 2018/04/16 20:27:38 hannken Exp $        */
+/*     $NetBSD: procfs_subr.c,v 1.113 2019/03/30 23:28:30 christos Exp $       */
 
 /*-
  * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -102,7 +102,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: procfs_subr.c,v 1.112 2018/04/16 20:27:38 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_subr.c,v 1.113 2019/03/30 23:28:30 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -210,6 +210,10 @@
                error = procfs_do_pid_stat(curl, l, pfs, uio);
                break;
 
+       case PFSlimit:
+               error = procfs_dolimit(curl, p, pfs, uio);
+               break;
+
        case PFSmap:
                error = procfs_domap(curl, p, pfs, uio, 0);
                break;
diff -r 0a6cc6b2d444 -r aaf13486e13d sys/miscfs/procfs/procfs_vfsops.c
--- a/sys/miscfs/procfs/procfs_vfsops.c Sat Mar 30 21:06:42 2019 +0000
+++ b/sys/miscfs/procfs/procfs_vfsops.c Sat Mar 30 23:28:30 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: procfs_vfsops.c,v 1.100 2017/12/31 03:29:18 christos Exp $     */
+/*     $NetBSD: procfs_vfsops.c,v 1.101 2019/03/30 23:28:30 christos Exp $     */
 
 /*
  * Copyright (c) 1993
@@ -76,7 +76,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: procfs_vfsops.c,v 1.100 2017/12/31 03:29:18 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_vfsops.c,v 1.101 2019/03/30 23:28:30 christos Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -406,6 +406,7 @@
        case PFSloadavg:        /* /proc/loadavg = -r--r--r-- */
        case PFSstatm:          /* /proc/N/statm = -r--r--r-- */
        case PFSversion:        /* /proc/version = -r--r--r-- */
+       case PFSlimit:          /* /proc/limit = -r--r--r-- */
                pfs->pfs_mode = S_IRUSR|S_IRGRP|S_IROTH;
                vp->v_type = VREG;
                break;
diff -r 0a6cc6b2d444 -r aaf13486e13d sys/miscfs/procfs/procfs_vnops.c
--- a/sys/miscfs/procfs/procfs_vnops.c  Sat Mar 30 21:06:42 2019 +0000
+++ b/sys/miscfs/procfs/procfs_vnops.c  Sat Mar 30 23:28:30 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: procfs_vnops.c,v 1.205 2018/10/14 17:37:40 jdolecek Exp $      */
+/*     $NetBSD: procfs_vnops.c,v 1.206 2019/03/30 23:28:30 christos Exp $      */
 
 /*-
  * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -105,7 +105,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: procfs_vnops.c,v 1.205 2018/10/14 17:37:40 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_vnops.c,v 1.206 2019/03/30 23:28:30 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -159,25 +159,26 @@
        { DT_DIR, N("."),       PFSproc,        NULL },
        { DT_DIR, N(".."),      PFSroot,        NULL },
        { DT_DIR, N("fd"),      PFSfd,          NULL },
-       { DT_REG, N("file"),    PFSfile,        procfs_validfile },
+       { DT_DIR, N("task"),    PFStask,        procfs_validfile_linux },
+       { DT_LNK, N("cwd"),     PFScwd,         NULL },
+       { DT_LNK, N("emul"),    PFSemul,        NULL },
+       { DT_LNK, N("root"),    PFSchroot,      NULL },
        { DT_REG, N("auxv"),    PFSauxv,        procfs_validauxv },
-       { DT_REG, N("mem"),     PFSmem,         NULL },
-       { DT_REG, N("regs"),    PFSregs,        procfs_validregs },
-       { DT_REG, N("fpregs"),  PFSfpregs,      procfs_validfpregs },
-       { DT_REG, N("stat"),    PFSstat,        procfs_validfile_linux },
-       { DT_REG, N("status"),  PFSstatus,      NULL },
-       { DT_REG, N("note"),    PFSnote,        NULL },
-       { DT_REG, N("notepg"),  PFSnotepg,      NULL },
-       { DT_REG, N("map"),     PFSmap,         procfs_validmap },
-       { DT_REG, N("maps"),    PFSmaps,        procfs_validmap },
        { DT_REG, N("cmdline"), PFScmdline,     NULL },
        { DT_REG, N("environ"), PFSenviron,     NULL },
        { DT_REG, N("exe"),     PFSexe,         procfs_validfile },
-       { DT_LNK, N("cwd"),     PFScwd,         NULL },
-       { DT_LNK, N("root"),    PFSchroot,      NULL },
-       { DT_LNK, N("emul"),    PFSemul,        NULL },
+       { DT_REG, N("file"),    PFSfile,        procfs_validfile },
+       { DT_REG, N("fpregs"),  PFSfpregs,      procfs_validfpregs },
+       { DT_REG, N("limit"),   PFSlimit,       NULL },
+       { DT_REG, N("map"),     PFSmap,         procfs_validmap },



Home | Main Index | Thread Index | Old Index