Print this page
14019 Allow more control over zone init exit actions (fix mismerge)
14019 Allow more control over zone init exit actions
Portions contributed by: Joshua M. Clulow <jmc@joyent.com>
Portions contributed by: Andy Fiddaman <andy@omnios.org>
Reviewed by: C Fraire <cfraire@me.com>
Reviewed by: Gordon Ross <Gordon.W.Ross@gmail.com>
Approved by: Robert Mustacchi <rm@fingolfin.org>


 454                 /*
 455                  * Some init programs in branded zones only want to restart if
 456                  * they exit 0, otherwise the zone should shutdown. Setting the
 457                  * "zone_restart_init_0" member controls this behavior.
 458                  *
 459                  * In this case we only restart init if it exited successfully.
 460                  */
 461                 if (why == CLD_EXITED && what == 0 &&
 462                     restart_init(what, why) == 0) {
 463                         return (B_TRUE);
 464                 }
 465         } else {
 466                 /*
 467                  * No restart modifiers on the zone, attempt to restart init.
 468                  */
 469                 if (restart_init(what, why) == 0) {
 470                         return (B_TRUE);
 471                 }
 472         }
 473 
 474 
 475         /*
 476          * The restart failed, the zone will shut down.

 477          */
 478         z->zone_init_status = wstat(why, what);
 479         (void) zone_kadmin(A_SHUTDOWN, AD_HALT, NULL, zone_kcred());
 480         z->zone_proc_initpid = -1;
 481         return (B_FALSE);
 482 }
 483 
 484 /*
 485  * Return value:
 486  *   1 - exitlwps() failed, call (or continue) lwp_exit()
 487  *   0 - restarting init.  Return through system call path
 488  */
 489 int
 490 proc_exit(int why, int what)
 491 {
 492         kthread_t *t = curthread;
 493         klwp_t *lwp = ttolwp(t);
 494         proc_t *p = ttoproc(t);
 495         zone_t *z = p->p_zone;
 496         timeout_id_t tmp_id;


 511         /*
 512          * Stop and discard the process's lwps except for the current one,
 513          * unless some other lwp beat us to it.  If exitlwps() fails then
 514          * return and the calling lwp will call (or continue in) lwp_exit().
 515          */
 516         proc_is_exiting(p);
 517         if (exitlwps(0) != 0)
 518                 return (1);
 519 
 520         mutex_enter(&p->p_lock);
 521         if (p->p_ttime > 0) {
 522                 /*
 523                  * Account any remaining ticks charged to this process
 524                  * on its way out.
 525                  */
 526                 (void) task_cpu_time_incr(p->p_task, p->p_ttime);
 527                 p->p_ttime = 0;
 528         }
 529         mutex_exit(&p->p_lock);
 530 







 531         if (p->p_pid == z->zone_proc_initpid) {
 532                 /* If zone's init restarts, we're done here. */
 533                 if (zone_init_exit(z, why, what))
 534                         return (0);
 535         }
 536 
 537         /*
 538          * Delay firing probes (and performing brand cleanup) until after the
 539          * zone_proc_initpid check. Cases which result in zone shutdown or
 540          * restart via zone_kadmin eventually result in a call back to
 541          * proc_exit.
 542          */
 543         DTRACE_PROC(lwp__exit);
 544         DTRACE_PROC1(exit, int, why);
 545 
 546         /*
 547          * Will perform any brand specific proc exit processing. Since this
 548          * is always the last lwp, will also perform lwp exit/free and proc
 549          * exit. Brand data will be freed when the process is reaped.
 550          */




 454                 /*
 455                  * Some init programs in branded zones only want to restart if
 456                  * they exit 0, otherwise the zone should shutdown. Setting the
 457                  * "zone_restart_init_0" member controls this behavior.
 458                  *
 459                  * In this case we only restart init if it exited successfully.
 460                  */
 461                 if (why == CLD_EXITED && what == 0 &&
 462                     restart_init(what, why) == 0) {
 463                         return (B_TRUE);
 464                 }
 465         } else {
 466                 /*
 467                  * No restart modifiers on the zone, attempt to restart init.
 468                  */
 469                 if (restart_init(what, why) == 0) {
 470                         return (B_TRUE);
 471                 }
 472         }
 473 

 474         /*
 475          * The restart failed, or the criteria for a restart are not met;
 476          * the zone will shut down.
 477          */
 478         z->zone_init_status = wstat(why, what);
 479         (void) zone_kadmin(A_SHUTDOWN, AD_HALT, NULL, zone_kcred());
 480         z->zone_proc_initpid = -1;
 481         return (B_FALSE);
 482 }
 483 
 484 /*
 485  * Return value:
 486  *   1 - exitlwps() failed, call (or continue) lwp_exit()
 487  *   0 - restarting init.  Return through system call path
 488  */
 489 int
 490 proc_exit(int why, int what)
 491 {
 492         kthread_t *t = curthread;
 493         klwp_t *lwp = ttolwp(t);
 494         proc_t *p = ttoproc(t);
 495         zone_t *z = p->p_zone;
 496         timeout_id_t tmp_id;


 511         /*
 512          * Stop and discard the process's lwps except for the current one,
 513          * unless some other lwp beat us to it.  If exitlwps() fails then
 514          * return and the calling lwp will call (or continue in) lwp_exit().
 515          */
 516         proc_is_exiting(p);
 517         if (exitlwps(0) != 0)
 518                 return (1);
 519 
 520         mutex_enter(&p->p_lock);
 521         if (p->p_ttime > 0) {
 522                 /*
 523                  * Account any remaining ticks charged to this process
 524                  * on its way out.
 525                  */
 526                 (void) task_cpu_time_incr(p->p_task, p->p_ttime);
 527                 p->p_ttime = 0;
 528         }
 529         mutex_exit(&p->p_lock);
 530 
 531         /*
 532          * Don't let init exit unless zone_start_init() failed its exec, or
 533          * we are shutting down the zone or the machine.
 534          *
 535          * Since we are single threaded, we don't need to lock the
 536          * following accesses to zone_proc_initpid.
 537          */
 538         if (p->p_pid == z->zone_proc_initpid) {
 539                 /* If zone's init restarts, we're done here. */
 540                 if (zone_init_exit(z, why, what))
 541                         return (0);
 542         }
 543 
 544         /*
 545          * Delay firing probes (and performing brand cleanup) until after the
 546          * zone_proc_initpid check. Cases which result in zone shutdown or
 547          * restart via zone_kadmin eventually result in a call back to
 548          * proc_exit.
 549          */
 550         DTRACE_PROC(lwp__exit);
 551         DTRACE_PROC1(exit, int, why);
 552 
 553         /*
 554          * Will perform any brand specific proc exit processing. Since this
 555          * is always the last lwp, will also perform lwp exit/free and proc
 556          * exit. Brand data will be freed when the process is reaped.
 557          */