usr/src/cmd/init/init.c
changeset 2481 707ff18f9994
parent 1401 7127a4968f33
child 2691 85d02cc094b0
equal deleted inserted replaced
2480:6c2485164a08 2481:707ff18f9994
   223 
   223 
   224 /*
   224 /*
   225  * Flags to indicate properties of various states.
   225  * Flags to indicate properties of various states.
   226  */
   226  */
   227 #define	LSEL_RUNLEVEL	0x0001	/* runlevels you can transition to */
   227 #define	LSEL_RUNLEVEL	0x0001	/* runlevels you can transition to */
   228 #define	LSEL_NOAUDIT	0x0002	/* levels with auditing disabled */
       
   229 
   228 
   230 typedef struct lvl {
   229 typedef struct lvl {
   231 	int	lvl_state;
   230 	int	lvl_state;
   232 	int	lvl_mask;
   231 	int	lvl_mask;
   233 	char	lvl_name;
   232 	char	lvl_name;
   235 } lvl_t;
   234 } lvl_t;
   236 
   235 
   237 static lvl_t lvls[] = {
   236 static lvl_t lvls[] = {
   238 	{ LVLQ,		0,	'Q', 0					},
   237 	{ LVLQ,		0,	'Q', 0					},
   239 	{ LVLQ,		0,	'q', 0					},
   238 	{ LVLQ,		0,	'q', 0					},
   240 	{ LVL0,		MASK0,	'0', LSEL_RUNLEVEL | LSEL_NOAUDIT	},
   239 	{ LVL0,		MASK0,	'0', LSEL_RUNLEVEL			},
   241 	{ LVL1, 	MASK1,	'1', LSEL_RUNLEVEL | LSEL_NOAUDIT	},
   240 	{ LVL1, 	MASK1,	'1', LSEL_RUNLEVEL			},
   242 	{ LVL2, 	MASK2,	'2', LSEL_RUNLEVEL			},
   241 	{ LVL2, 	MASK2,	'2', LSEL_RUNLEVEL			},
   243 	{ LVL3, 	MASK3,	'3', LSEL_RUNLEVEL			},
   242 	{ LVL3, 	MASK3,	'3', LSEL_RUNLEVEL			},
   244 	{ LVL4, 	MASK4,	'4', LSEL_RUNLEVEL			},
   243 	{ LVL4, 	MASK4,	'4', LSEL_RUNLEVEL			},
   245 	{ LVL5, 	MASK5,	'5', LSEL_RUNLEVEL | LSEL_NOAUDIT	},
   244 	{ LVL5, 	MASK5,	'5', LSEL_RUNLEVEL			},
   246 	{ LVL6, 	MASK6, 	'6', LSEL_RUNLEVEL | LSEL_NOAUDIT	},
   245 	{ LVL6, 	MASK6, 	'6', LSEL_RUNLEVEL			},
   247 	{ SINGLE_USER, 	MASKSU, 'S', LSEL_RUNLEVEL | LSEL_NOAUDIT	},
   246 	{ SINGLE_USER, 	MASKSU, 'S', LSEL_RUNLEVEL			},
   248 	{ SINGLE_USER, 	MASKSU, 's', LSEL_RUNLEVEL | LSEL_NOAUDIT	},
   247 	{ SINGLE_USER, 	MASKSU, 's', LSEL_RUNLEVEL			},
   249 	{ LVLa,		MASKa,	'a', 0					},
   248 	{ LVLa,		MASKa,	'a', 0					},
   250 	{ LVLb,		MASKb,	'b', 0					},
   249 	{ LVLb,		MASKb,	'b', 0					},
   251 	{ LVLc,		MASKc,	'c', 0					}
   250 	{ LVLc,		MASKc,	'c', 0					}
   252 };
   251 };
   253 
   252 
  3477 {
  3476 {
  3478 	FILE	*fp;
  3477 	FILE	*fp;
  3479 	char	*ln;
  3478 	char	*ln;
  3480 	int	init_signal;
  3479 	int	init_signal;
  3481 	struct stat	sconbuf, conbuf;
  3480 	struct stat	sconbuf, conbuf;
  3482 	int turnoff = 0;
       
  3483 	const char *usage_msg = "Usage: init [0123456SsQqabc]\n";
  3481 	const char *usage_msg = "Usage: init [0123456SsQqabc]\n";
  3484 
  3482 
  3485 	/*
  3483 	/*
  3486 	 * We are a user invoked init.  Is there an argument and is it
  3484 	 * We are a user invoked init.  Is there an argument and is it
  3487 	 * a single character?  If not, print usage message and quit.
  3485 	 * a single character?  If not, print usage message and quit.
  3495 		(void) fprintf(stderr, usage_msg);
  3493 		(void) fprintf(stderr, usage_msg);
  3496 		(void) audit_put_record(ADT_FAILURE, ADT_FAIL_VALUE_BAD_CMD,
  3494 		(void) audit_put_record(ADT_FAILURE, ADT_FAIL_VALUE_BAD_CMD,
  3497 		    argv[1]);
  3495 		    argv[1]);
  3498 		exit(1);
  3496 		exit(1);
  3499 	}
  3497 	}
  3500 
       
  3501 	turnoff = LSEL_NOAUDIT & state_to_flags(init_signal);
       
  3502 
  3498 
  3503 	if (init_signal == SINGLE_USER) {
  3499 	if (init_signal == SINGLE_USER) {
  3504 		/*
  3500 		/*
  3505 		 * Make sure this process is talking to a legal tty line
  3501 		 * Make sure this process is talking to a legal tty line
  3506 		 * and that /dev/syscon is linked to this line.
  3502 		 * and that /dev/syscon is linked to this line.
  3553 		}
  3549 		}
  3554 	}
  3550 	}
  3555 
  3551 
  3556 	update_boot_archive(init_signal);
  3552 	update_boot_archive(init_signal);
  3557 
  3553 
  3558 	if (audit_put_record(ADT_SUCCESS, ADT_SUCCESS, argv[1]) &&
  3554 	(void) audit_put_record(ADT_SUCCESS, ADT_SUCCESS, argv[1]);
  3559 	    turnoff) {
       
  3560 		/* turn off audit daemon and try to flush audit queue */
       
  3561 
       
  3562 		if (system("/usr/sbin/audit -t")) {
       
  3563 			(void) fprintf(stderr, "%s: can't turn off auditd\n",
       
  3564 				argv[0]);
       
  3565 		} else {
       
  3566 			(void) sleep(5);
       
  3567 		}
       
  3568 	}
       
  3569 
  3555 
  3570 	/*
  3556 	/*
  3571 	 * Signal init; init will take care of telling svc.startd.
  3557 	 * Signal init; init will take care of telling svc.startd.
  3572 	 */
  3558 	 */
  3573 	if (kill(init_pid, init_signal) == FAILURE) {
  3559 	if (kill(init_pid, init_signal) == FAILURE) {