Date: Fri, 6 Feb 1998 13:57:40 -0500 (EST) From: "Bruce M. Walter" <walter@fortean.com> To: John Fieber <jfieber@indiana.edu>, Mike Smith <mike@smith.net.au>, Calin Andrian <calin@ibd.dbio.ro> Cc: hackers@FreeBSD.ORG Subject: Re: Powering off the system/UPS Message-ID: <Pine.BSF.3.95q.980206134838.25495A-100000@callisto.fortean.com> In-Reply-To: <Pine.BSF.3.95q.980206113512.22744A-100000@callisto.fortean.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Alright, here's my first cut at patches to add a third at_shutdown queue and for adding ordered queues to the at_shutdown interface. They are against 2.2-STABLE (sorry) but should apply with very little modification to 3.0-CURRENT. I'd appreciate anyone with an inclination to look these over and let me know what you think. - Bruce *** sys/systm.h.orig Sun Aug 10 22:04:12 1997 --- sys/systm.h Fri Feb 6 13:24:15 1998 *************** *** 168,176 **** --- 168,181 ---- /* shutdown callout list definitions */ typedef void (*bootlist_fn)(int,void *); int at_shutdown(bootlist_fn function, void *arg, int); + int pri_at_shutdown(bootlist_fn function, void *arg, int, int); int rm_at_shutdown(bootlist_fn function, void *arg); #define SHUTDOWN_PRE_SYNC 0 #define SHUTDOWN_POST_SYNC 1 + #define SHUTDOWN_PRE_HALT 2 + #define SHUTDOWN_PRI_MAX 1 + #define SHUTDOWN_PRI_MIN 20 + #define SHUTDOWN_PRI_DEFAULT 10 /* forking */ /* XXX not yet */ typedef void (*forklist_fn)(struct proc *parent,struct proc *child,int flags); *** kern/kern_shutdown.c.orig Sun Aug 10 22:04:14 1997 --- kern/kern_shutdown.c Fri Feb 6 13:34:10 1998 *************** *** 110,115 **** --- 110,116 ---- struct shutdown_list_element *next; bootlist_fn function; void *arg; + int priority; } *sle_p; /* *************** *** 118,123 **** --- 119,125 ---- */ static sle_p shutdown_list1; static sle_p shutdown_list2; + static sle_p shutdown_list3; static void dumpsys(void); *************** *** 248,253 **** --- 250,266 ---- ep = ep->next; } splhigh(); + + /* + * Ok, now do any last things we need to before cpu death + */ + ep = shutdown_list3; + while (ep) { + shutdown_list3 = ep->next; + (*ep->function)(howto, ep->arg); + ep = ep->next; + } + if (howto & RB_HALT) { printf("\n"); printf("The operating system has halted.\n"); *************** *** 391,397 **** } /* ! * Two routines to handle adding/deleting items on the * shutdown callout lists * * at_shutdown(): --- 404,410 ---- } /* ! * Three routines to handle adding/deleting items on the * shutdown callout lists * * at_shutdown(): *************** *** 402,408 **** int at_shutdown(bootlist_fn function, void *arg, int position) { ! sle_p ep, *epp; switch(position) { case SHUTDOWN_PRE_SYNC: --- 415,436 ---- int at_shutdown(bootlist_fn function, void *arg, int position) { ! return (pri_at_shutdown(function,arg,position,SHUTDOWN_PRI_DEFAULT)); ! } ! ! /* ! * Three routines to handle adding/deleting items on the ! * shutdown callout lists ! * ! * pri_at_shutdown(): ! * Take the arguments given and put them onto the shutdown callout list with ! * the given execution priority. ! * returns 0 on success. ! */ ! int ! pri_at_shutdown(bootlist_fn function, void *arg, int position, int priority) ! { ! sle_p ep, ip, lp, *epp; switch(position) { case SHUTDOWN_PRE_SYNC: *************** *** 411,429 **** case SHUTDOWN_POST_SYNC: epp = &shutdown_list2; break; default: printf("bad exit callout list specified\n"); return (EINVAL); } if (rm_at_shutdown(function, arg)) printf("exit callout entry already present\n"); ep = malloc(sizeof(*ep), M_TEMP, M_NOWAIT); if (ep == NULL) return (ENOMEM); - ep->next = *epp; ep->function = function; ep->arg = arg; ! *epp = ep; return (0); } --- 439,482 ---- case SHUTDOWN_POST_SYNC: epp = &shutdown_list2; break; + case SHUTDOWN_PRE_HALT: + epp = &shutdown_list3; + break; default: printf("bad exit callout list specified\n"); return (EINVAL); } + if ((priority < SHUTDOWN_PRI_MAX) || (priority > SHUTDOWN_PRI_MIN)) { + printf("bad callout priority specified\n"); + return (EINVAL); + } if (rm_at_shutdown(function, arg)) printf("exit callout entry already present\n"); ep = malloc(sizeof(*ep), M_TEMP, M_NOWAIT); if (ep == NULL) return (ENOMEM); ep->function = function; ep->arg = arg; ! ep->priority = priority; ! ! lp = NULL; ! ip = *epp; ! if (*epp) { ! while (ip) { ! if (ip->priority >= priority) ! break; ! lp = ip; ! ip = ip->next; ! } ! } ! if (lp) { ! ep->next = lp->next; ! lp->next = ep; ! } else { ! ep->next = ip; ! *epp = ep; ! } ! return (0); } *************** *** 451,456 **** --- 504,521 ---- ep = *epp; } epp = &shutdown_list2; + ep = *epp; + while (ep) { + if ((ep->function == function) && (ep->arg == arg)) { + *epp = ep->next; + free(ep, M_TEMP); + count++; + } else { + epp = &ep->next; + } + ep = *epp; + } + epp = &shutdown_list3; ep = *epp; while (ep) { if ((ep->function == function) && (ep->arg == arg)) { ======================================================================== || Bruce M. Walter || 107 Timber Hollow Court #335 || || Senior Network Consultant || Chapel Hill, NC 27514 || || Fortean Technologies, Inc. || Tel: 919-967-4766 || || Information Technology Consultants || Fax: 919-967-4395 || ======================================================================== || BSD Unix -- It's not just a job, it's a way of life! || ========================================================================
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.3.95q.980206134838.25495A-100000>