Source-Changes-HG archive

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

[src/trunk]: src/sys Replace some "panic()" calls with simple "printf() ; ret...



details:   https://anonhg.NetBSD.org/src/rev/addecdc6e48f
branches:  trunk
changeset: 998185:addecdc6e48f
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Wed Apr 10 10:03:50 2019 +0000

description:
Replace some "panic()" calls with simple "printf() ; return error"

There's no good reason for these build-time parameters to be allowed to
panic the kernel when it is easy to simply disable the module code and
fail gracefully.

While we're at it, similarly replace panic() when malloc fails to also
fail gracefully.

diffstat:

 sys/kern/sysv_ipc.c |  27 ++++++++++++++++++++++-----
 sys/kern/sysv_msg.c |  19 ++++++++++++-------
 sys/kern/sysv_sem.c |  13 ++++++++-----
 sys/kern/sysv_shm.c |  13 ++++++++-----
 sys/sys/msg.h       |   4 ++--
 sys/sys/sem.h       |   4 ++--
 sys/sys/shm.h       |   4 ++--
 7 files changed, 56 insertions(+), 28 deletions(-)

diffs (267 lines):

diff -r 7a193e4dfe45 -r addecdc6e48f sys/kern/sysv_ipc.c
--- a/sys/kern/sysv_ipc.c       Wed Apr 10 08:23:46 2019 +0000
+++ b/sys/kern/sysv_ipc.c       Wed Apr 10 10:03:50 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sysv_ipc.c,v 1.38 2019/04/09 22:05:27 pgoyette Exp $   */
+/*     $NetBSD: sysv_ipc.c,v 1.39 2019/04/10 10:03:50 pgoyette Exp $   */
 
 /*-
  * Copyright (c) 1998, 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sysv_ipc.c,v 1.38 2019/04/09 22:05:27 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysv_ipc.c,v 1.39 2019/04/10 10:03:50 pgoyette Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_sysv.h"
@@ -180,13 +180,30 @@
                 * sysctl data
                 */
 #ifdef SYSVSHM
-               shminit(&sysctl_sysvipc_clog);
+               error = shminit(&sysctl_sysvipc_clog);
+               if (error != 0)
+                       return error;
 #endif
 #ifdef SYSVSEM
-               seminit(&sysctl_sysvipc_clog);
+               error = seminit(&sysctl_sysvipc_clog);
+               if (error != 0) {
+#ifdef SYSVSHM
+                       shmfini();
+#endif
+                       return error;
+               }
 #endif
 #ifdef SYSVMSG
-               msginit(&sysctl_sysvipc_clog);
+               error = msginit(&sysctl_sysvipc_clog);
+               if (error != 0) {
+#ifdef SYSVSEM
+                       semfini();
+#endif
+#ifdef SYSVSHM
+                       shmfini();
+#endif
+                       return error;
+               }
 #endif
 
 #ifdef _MODULE
diff -r 7a193e4dfe45 -r addecdc6e48f sys/kern/sysv_msg.c
--- a/sys/kern/sysv_msg.c       Wed Apr 10 08:23:46 2019 +0000
+++ b/sys/kern/sysv_msg.c       Wed Apr 10 10:03:50 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sysv_msg.c,v 1.73 2019/02/21 03:37:19 mrg Exp $        */
+/*     $NetBSD: sysv_msg.c,v 1.74 2019/04/10 10:03:50 pgoyette Exp $   */
 
 /*-
  * Copyright (c) 1999, 2006, 2007 The NetBSD Foundation, Inc.
@@ -50,7 +50,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sysv_msg.c,v 1.73 2019/02/21 03:37:19 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysv_msg.c,v 1.74 2019/04/10 10:03:50 pgoyette Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_sysv.h"
@@ -93,7 +93,7 @@
 
 SYSCTL_SETUP_PROTO(sysctl_ipc_msg_setup);
 
-void
+int
 msginit(struct sysctllog **clog)
 {
        int i, sz;
@@ -109,12 +109,14 @@
        while (i < 1024 && i != msginfo.msgssz)
                i <<= 1;
        if (i != msginfo.msgssz) {
-               panic("msginfo.msgssz = %d, not a small power of 2",
+               printf("msginfo.msgssz = %d, not a small power of 2",
                    msginfo.msgssz);
+               return EINVAL;
        }
 
        if (msginfo.msgseg > 32767) {
-               panic("msginfo.msgseg = %d > 32767", msginfo.msgseg);
+               printf("msginfo.msgseg = %d > 32767", msginfo.msgseg);
+               return EINVAL;
        }
 
        /* Allocate the wired memory for our structures */
@@ -124,8 +126,10 @@
            ALIGN(msginfo.msgmni * sizeof(kmsq_t));
        sz = round_page(sz);
        v = uvm_km_alloc(kernel_map, sz, 0, UVM_KMF_WIRED|UVM_KMF_ZERO);
-       if (v == 0)
-               panic("sysv_msg: cannot allocate memory");
+       if (v == 0) {
+               printf("sysv_msg: cannot allocate memory");
+               return ENOMEM;
+       }
        msgpool = (void *)v;
        msgmaps = (void *)((uintptr_t)msgpool + ALIGN(msginfo.msgmax));
        msghdrs = (void *)((uintptr_t)msgmaps +
@@ -167,6 +171,7 @@
        if (clog)
                sysctl_ipc_msg_setup(clog);
 #endif
+       return 0;
 }
 
 int
diff -r 7a193e4dfe45 -r addecdc6e48f sys/kern/sysv_sem.c
--- a/sys/kern/sysv_sem.c       Wed Apr 10 08:23:46 2019 +0000
+++ b/sys/kern/sysv_sem.c       Wed Apr 10 10:03:50 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sysv_sem.c,v 1.96 2019/02/21 03:37:19 mrg Exp $        */
+/*     $NetBSD: sysv_sem.c,v 1.97 2019/04/10 10:03:50 pgoyette Exp $   */
 
 /*-
  * Copyright (c) 1999, 2007 The NetBSD Foundation, Inc.
@@ -39,7 +39,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sysv_sem.c,v 1.96 2019/02/21 03:37:19 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysv_sem.c,v 1.97 2019/04/10 10:03:50 pgoyette Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_sysv.h"
@@ -101,7 +101,7 @@
 static ONCE_DECL(exithook_control);
 static int seminit_exithook(void);
 
-void
+int
 seminit(struct sysctllog **clog)
 {
        int i, sz;
@@ -120,8 +120,10 @@
            ALIGN(seminfo.semmnu * seminfo.semusz);
        sz = round_page(sz);
        v = uvm_km_alloc(kernel_map, sz, 0, UVM_KMF_WIRED|UVM_KMF_ZERO);
-       if (v == 0)
-               panic("sysv_sem: cannot allocate memory");
+       if (v == 0) {
+               printf("sysv_sem: cannot allocate memory");
+               return ENOMEM;
+       }
        sema = (void *)v;
        sem = (void *)((uintptr_t)sema +
            ALIGN(seminfo.semmni * sizeof(struct semid_ds)));
@@ -147,6 +149,7 @@
        if (clog)
                sysctl_ipc_sem_setup(clog);
 #endif
+       return 0;
 }
 
 static int
diff -r 7a193e4dfe45 -r addecdc6e48f sys/kern/sysv_shm.c
--- a/sys/kern/sysv_shm.c       Wed Apr 10 08:23:46 2019 +0000
+++ b/sys/kern/sysv_shm.c       Wed Apr 10 10:03:50 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sysv_shm.c,v 1.133 2019/02/21 03:37:19 mrg Exp $       */
+/*     $NetBSD: sysv_shm.c,v 1.134 2019/04/10 10:03:50 pgoyette Exp $  */
 
 /*-
  * Copyright (c) 1999, 2007 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sysv_shm.c,v 1.133 2019/02/21 03:37:19 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysv_shm.c,v 1.134 2019/04/10 10:03:50 pgoyette Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_sysv.h"
@@ -962,7 +962,7 @@
        return 0;
 }
 
-void
+int
 shminit(struct sysctllog **clog)
 {
        vaddr_t v;
@@ -977,8 +977,10 @@
            ALIGN(shminfo.shmmni * sizeof(kcondvar_t));
        sz = round_page(sz);
        v = uvm_km_alloc(kernel_map, sz, 0, UVM_KMF_WIRED|UVM_KMF_ZERO);
-       if (v == 0)
-               panic("sysv_shm: cannot allocate memory");
+       if (v == 0) {
+               printf("sysv_shm: cannot allocate memory");
+               return ENOMEM;
+       }
        shmsegs = (void *)v;
        shm_cv = (void *)((uintptr_t)shmsegs +
            ALIGN(shminfo.shmmni * sizeof(struct shmid_ds)));
@@ -1010,6 +1012,7 @@
        if (clog)
                sysctl_ipc_shm_setup(clog);
 #endif
+       return 0;
 }
 
 int
diff -r 7a193e4dfe45 -r addecdc6e48f sys/sys/msg.h
--- a/sys/sys/msg.h     Wed Apr 10 08:23:46 2019 +0000
+++ b/sys/sys/msg.h     Wed Apr 10 10:03:50 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg.h,v 1.26 2015/11/06 02:26:42 pgoyette Exp $        */
+/*     $NetBSD: msg.h,v 1.27 2019/04/10 10:03:50 pgoyette Exp $        */
 
 /*-
  * Copyright (c) 1999, 2007 The NetBSD Foundation, Inc.
@@ -209,7 +209,7 @@
 
 struct proc;
 
-void   msginit(struct sysctllog **);
+int    msginit(struct sysctllog **);
 int    msgfini(void);
 int    msgctl1(struct lwp *, int, int, struct msqid_ds *);
 int    msgsnd1(struct lwp *, int, const char *, size_t, int, size_t,
diff -r 7a193e4dfe45 -r addecdc6e48f sys/sys/sem.h
--- a/sys/sys/sem.h     Wed Apr 10 08:23:46 2019 +0000
+++ b/sys/sys/sem.h     Wed Apr 10 10:03:50 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sem.h,v 1.32 2015/11/06 02:26:42 pgoyette Exp $        */
+/*     $NetBSD: sem.h,v 1.33 2019/04/10 10:03:50 pgoyette Exp $        */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -222,7 +222,7 @@
 #endif
 __END_DECLS
 #else
-void   seminit(struct sysctllog **);
+int    seminit(struct sysctllog **);
 int    semfini(void);
 void   semexit(struct proc *, void *);
 
diff -r 7a193e4dfe45 -r addecdc6e48f sys/sys/shm.h
--- a/sys/sys/shm.h     Wed Apr 10 08:23:46 2019 +0000
+++ b/sys/sys/shm.h     Wed Apr 10 10:03:50 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: shm.h,v 1.51 2015/11/06 02:26:42 pgoyette Exp $        */
+/*     $NetBSD: shm.h,v 1.52 2019/04/10 10:03:50 pgoyette Exp $        */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -172,7 +172,7 @@
 
 struct vmspace;
 
-void   shminit(struct sysctllog **);
+int    shminit(struct sysctllog **);
 int    shmfini(void);
 void   shmfork(struct vmspace *, struct vmspace *);
 void   shmexit(struct vmspace *);



Home | Main Index | Thread Index | Old Index