1 0 stevel /* 2 0 stevel * CDDL HEADER START 3 0 stevel * 4 0 stevel * The contents of this file are subject to the terms of the 5 3125 jacobs * Common Development and Distribution License (the "License"). 6 3125 jacobs * You may not use this file except in compliance with the License. 7 0 stevel * 8 0 stevel * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 0 stevel * or http://www.opensolaris.org/os/licensing. 10 0 stevel * See the License for the specific language governing permissions 11 0 stevel * and limitations under the License. 12 0 stevel * 13 0 stevel * When distributing Covered Code, include this CDDL HEADER in each 14 0 stevel * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 0 stevel * If applicable, add the following below this CDDL HEADER, with the 16 0 stevel * fields enclosed by brackets "[]" replaced with your own identifying 17 0 stevel * information: Portions Copyright [yyyy] [name of copyright owner] 18 0 stevel * 19 0 stevel * CDDL HEADER END 20 0 stevel */ 21 3125 jacobs 22 3125 jacobs /* 23 3125 jacobs * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 24 3125 jacobs * Use is subject to license terms. 25 3125 jacobs */ 26 3125 jacobs 27 0 stevel /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 28 0 stevel /* All Rights Reserved */ 29 0 stevel 30 0 stevel 31 0 stevel #pragma ident "%Z%%M% %I% %E% SMI" 32 0 stevel 33 0 stevel #include "lpsched.h" 34 0 stevel 35 0 stevel /* 36 0 stevel * terminate() - STOP A CHILD PROCESS 37 0 stevel * 38 0 stevel * Note: If you're trying to debug lpsched, and worried about 39 0 stevel * seeing lots of calls to terminate() in the debug output, 40 0 stevel * don't be; it gets called once for each entry in the child 41 0 stevel * process table, whether or not there's such a child. 42 0 stevel */ 43 0 stevel 44 0 stevel void 45 0 stevel terminate(register EXEC *ep) 46 0 stevel { 47 0 stevel int retries; /* fix for sunsoft bugid 1108465 */ 48 0 stevel 49 0 stevel if (ep->pid <= 0) 50 0 stevel return; 51 0 stevel 52 0 stevel if (ep->flags & EXF_KILLED) 53 0 stevel return; 54 0 stevel ep->flags |= EXF_KILLED; 55 0 stevel 56 0 stevel /* 57 0 stevel * Theoretically, the following "if-then" is not needed, 58 0 stevel * but there's some bug in the code that occasionally 59 0 stevel * prevents us from hearing from a finished child. 60 0 stevel * (Kill -9 on the child would do that, of course, but 61 0 stevel * the problem has occurred in other cases.) 62 0 stevel */ 63 0 stevel if (kill(-ep->pid, SIGTERM) == -1 && errno == ESRCH) { 64 0 stevel ep->pid = -99; 65 0 stevel ep->status = SIGTERM; 66 0 stevel ep->Errno = 0; 67 0 stevel DoneChildren++; 68 0 stevel return; 69 0 stevel } 70 0 stevel 71 0 stevel /* 72 0 stevel * Start fix for sunsoft bugid 1108465 73 0 stevel * the original code here was extremely optimistic, and 74 0 stevel * under certain circumstances, the pid's would still be 75 0 stevel * left around. here we get really serious about killing 76 0 stevel * the sucker. 77 0 stevel * we patiently wait for the pid to die. if it doesn't 78 0 stevel * do so in a reasonable amount of time, we get more forceful. 79 0 stevel * note that the original "ep->pid == -99" is a crude hack; 80 0 stevel * but that the convention is being followed. sigh. 81 0 stevel */ 82 0 stevel for (retries = 5; retries > 0; retries--) { 83 0 stevel /* see if the process is still there */ 84 0 stevel if ((kill(-ep->pid, 0) == -1) && (errno == ESRCH)) { 85 0 stevel ep->pid = -99; 86 0 stevel ep->status = SIGTERM; 87 0 stevel ep->Errno = 0; 88 0 stevel DoneChildren++; 89 0 stevel return; 90 0 stevel } else if (errno == EINTR) 91 0 stevel break; 92 0 stevel 93 0 stevel sleep(2); 94 0 stevel } 95 0 stevel 96 0 stevel /* if it's still not dead, then get more forceful */ 97 0 stevel for (retries = 5; retries > 0; retries--) { 98 0 stevel if ((kill(-ep->pid, SIGKILL) == -1) && (errno == ESRCH)) { 99 0 stevel ep->pid = -99; 100 0 stevel ep->status = SIGTERM; 101 0 stevel ep->Errno = 0; 102 0 stevel DoneChildren++; 103 0 stevel return; 104 0 stevel } 105 0 stevel sleep(3); 106 0 stevel } 107 0 stevel /* end of sunsoft bugfix 1108465 */ 108 0 stevel /* 109 0 stevel * well hardkill didn't work so just flag this request as done 110 0 stevel */ 111 0 stevel ep->pid = -99; 112 0 stevel ep->status = SIGTERM; 113 0 stevel ep->Errno = 0; 114 0 stevel DoneChildren++; 115 0 stevel } 116