kern_exit.c (17702) | kern_exit.c (17768) |
---|---|
1/*- 2 * Copyright (c) 1982, 1986, 1989, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. --- 22 unchanged lines hidden (view full) --- 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * @(#)kern_exit.c 8.7 (Berkeley) 2/12/94 | 1/*- 2 * Copyright (c) 1982, 1986, 1989, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. --- 22 unchanged lines hidden (view full) --- 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * @(#)kern_exit.c 8.7 (Berkeley) 2/12/94 |
39 * $Id: kern_exit.c,v 1.36 1996/08/19 02:28:23 julian Exp $ | 39 * $Id: kern_exit.c,v 1.37 1996/08/20 07:17:47 smpatel Exp $ |
40 */ 41 42#include "opt_ktrace.h" 43 44#include <sys/param.h> 45#include <sys/systm.h> 46#include <sys/sysproto.h> 47#include <sys/sysent.h> --- 77 unchanged lines hidden (view full) --- 125 printf("init died (signal %d, exit %d)\n", 126 WTERMSIG(rv), WEXITSTATUS(rv)); 127 panic("Going nowhere without my init!"); 128 } 129#ifdef PGINPROF 130 vmsizmon(); 131#endif 132 /* | 40 */ 41 42#include "opt_ktrace.h" 43 44#include <sys/param.h> 45#include <sys/systm.h> 46#include <sys/sysproto.h> 47#include <sys/sysent.h> --- 77 unchanged lines hidden (view full) --- 125 printf("init died (signal %d, exit %d)\n", 126 WTERMSIG(rv), WEXITSTATUS(rv)); 127 panic("Going nowhere without my init!"); 128 } 129#ifdef PGINPROF 130 vmsizmon(); 131#endif 132 /* |
133 * Check if any LKMs need anything done at process exit | 133 * Check if any LKMs need anything done at process exit. |
134 * e.g. SYSV IPC stuff 135 * XXX what if one of these generates an error? 136 */ | 134 * e.g. SYSV IPC stuff 135 * XXX what if one of these generates an error? 136 */ |
137 while(ep) { | 137 while (ep) { |
138 (*ep->function)(p); 139 ep = ep->next; 140 } 141 142 if (p->p_flag & P_PROFIL) 143 stopprofclock(p); 144 MALLOC(p->p_ru, struct rusage *, sizeof(struct rusage), 145 M_ZOMBIE, M_WAITOK); --- 350 unchanged lines hidden (view full) --- 496 if (child->p_pptr == parent) 497 return; 498 499 LIST_REMOVE(child, p_sibling); 500 LIST_INSERT_HEAD(&parent->p_children, child, p_sibling); 501 child->p_pptr = parent; 502} 503 | 138 (*ep->function)(p); 139 ep = ep->next; 140 } 141 142 if (p->p_flag & P_PROFIL) 143 stopprofclock(p); 144 MALLOC(p->p_ru, struct rusage *, sizeof(struct rusage), 145 M_ZOMBIE, M_WAITOK); --- 350 unchanged lines hidden (view full) --- 496 if (child->p_pptr == parent) 497 return; 498 499 LIST_REMOVE(child, p_sibling); 500 LIST_INSERT_HEAD(&parent->p_children, child, p_sibling); 501 child->p_pptr = parent; 502} 503 |
504/********************************************************* 505 * general routines to handle adding/deleting items on the | 504/* 505 * The next two functions are to handle adding/deleting items on the |
506 * exit callout list | 506 * exit callout list |
507 ***** 508 * Take the arguments given and put them onto the exit callout list. | 507 * 508 * at_exit(): 509 * Take the arguments given and put them onto the exit callout list, |
509 * However first make sure that it's not already there. 510 * returns 0 on success. 511 */ 512int 513at_exit(exitlist_fn function) 514{ 515 ele_p ep; | 510 * However first make sure that it's not already there. 511 * returns 0 on success. 512 */ 513int 514at_exit(exitlist_fn function) 515{ 516 ele_p ep; |
516 if(rm_at_exit(function)) { | 517 518 /* Be noisy if the programmer has lost track of things */ 519 if (rm_at_exit(function)) |
517 printf("exit callout entry already present\n"); | 520 printf("exit callout entry already present\n"); |
518 } 519 ep = malloc(sizeof(*ep),M_TEMP,M_NOWAIT); 520 if(!ep) return ENOMEM; | 521 ep = malloc(sizeof(*ep), M_TEMP, M_NOWAIT); 522 if (ep == NULL) 523 return (ENOMEM); |
521 ep->next = exit_list; 522 ep->function = function; 523 exit_list = ep; | 524 ep->next = exit_list; 525 ep->function = function; 526 exit_list = ep; |
524 return 0; | 527 return (0); |
525} 526/* 527 * Scan the exit callout list for the given items and remove them. 528 * Returns the number of items removed. | 528} 529/* 530 * Scan the exit callout list for the given items and remove them. 531 * Returns the number of items removed. |
532 * Logically this can only be 0 or 1. |
|
529 */ 530int 531rm_at_exit(exitlist_fn function) 532{ | 533 */ 534int 535rm_at_exit(exitlist_fn function) 536{ |
533 ele_p *epp,ep; 534 int count = 0; | 537 ele_p *epp, ep; 538 int count; |
535 | 539 |
540 count = 0; |
|
536 epp = &exit_list; 537 ep = *epp; | 541 epp = &exit_list; 542 ep = *epp; |
538 while(ep) { 539 if(ep->function == function) { | 543 while (ep) { 544 if (ep->function == function) { |
540 *epp = ep->next; | 545 *epp = ep->next; |
541 free(ep,M_TEMP); | 546 free(ep, M_TEMP); |
542 count++; 543 } else { 544 epp = &ep->next; 545 } 546 ep = *epp; 547 } | 547 count++; 548 } else { 549 epp = &ep->next; 550 } 551 ep = *epp; 552 } |
548 return count; | 553 return (count); |
549} 550 551 | 554} 555 556 |