945 want easy script access to service log files
authorBryan Cantrill <bryan@joyent.com>
Fri Jan 28 14:19:52 2011 -0800 (11 months ago)
changeset 13366c1720cb807d5
parent 13365 b868f9d61081
child 13367 4844172c07f8
945 want easy script access to service log files
Reviewed by: Eric Schrock <eric.schrock@delphix.com>
Reviewed by: Albert Lee <trisk@opensolaris.org>
Reviewed by: Garrett D'Amore <garrett@nexenta.com>
Approved by: Garrett D'Amore <garrett@nexenta.com>
usr/src/cmd/svc/svcs/svcs.c
usr/src/man/man1/svcs.1
     1.1 --- a/usr/src/cmd/svc/svcs/svcs.c	Fri Jan 28 00:48:09 2011 -0800
     1.2 +++ b/usr/src/cmd/svc/svcs/svcs.c	Fri Jan 28 14:19:52 2011 -0800
     1.3 @@ -1872,7 +1872,7 @@
     1.4  	    "[-sS col] [-Z | -z zone ]\n            [<service> ...]\n"
     1.5  	    "       %1$s -d | -D [-Hpv] [-o col[,col ... ]] [-sS col] "
     1.6  	    "[-Z | -z zone ]\n            [<service> ...]\n"
     1.7 -	    "       %1$s -l [-Z | -z zone] <service> ...\n"
     1.8 +	    "       %1$s [-l | -L] [-Z | -z zone] <service> ...\n"
     1.9  	    "       %1$s -x [-v] [-Z | -z zone] [<service> ...]\n"
    1.10  	    "       %1$s -?\n"), progname);
    1.11  
    1.12 @@ -1896,6 +1896,7 @@
    1.13  	"\t-D  list dependents of the specified service(s)\n"
    1.14  	"\t-H  omit header line from output\n"
    1.15  	"\t-l  list detailed information about the specified service(s)\n"
    1.16 +	"\t-L  list the log file associated with the specified service(s)\n"
    1.17  	"\t-o  list only the specified columns in the output\n"
    1.18  	"\t-p  list process IDs and names associated with each service\n"
    1.19  	"\t-R  list only those services with the specified restarter\n"
    1.20 @@ -2639,6 +2640,34 @@
    1.21  	return (0);
    1.22  }
    1.23  
    1.24 +/* ARGSUSED */
    1.25 +static int
    1.26 +print_log(void *unused, scf_walkinfo_t *wip)
    1.27 +{
    1.28 +	scf_propertygroup_t *rpg;
    1.29 +	char buf[MAXPATHLEN];
    1.30 +
    1.31 +	if ((rpg = scf_pg_create(h)) == NULL)
    1.32 +		scfdie();
    1.33 +
    1.34 +	if (scf_instance_get_pg(wip->inst, SCF_PG_RESTARTER, rpg) != 0) {
    1.35 +		if (scf_error() != SCF_ERROR_NOT_FOUND)
    1.36 +			scfdie();
    1.37 +
    1.38 +		goto out;
    1.39 +	}
    1.40 +
    1.41 +	if (pg_get_single_val(rpg, SCF_PROPERTY_LOGFILE,
    1.42 +	    SCF_TYPE_ASTRING, buf, sizeof (buf), 0) == 0) {
    1.43 +		(void) printf("%s\n", buf);
    1.44 +	}
    1.45 +
    1.46 +out:
    1.47 +	scf_pg_destroy(rpg);
    1.48 +
    1.49 +	return (0);
    1.50 +}
    1.51 +
    1.52  int
    1.53  qsort_str_compare(const void *p1, const void *p2)
    1.54  {
    1.55 @@ -3426,7 +3455,7 @@
    1.56  	int show_header = 1;
    1.57  	int show_zones = 0;
    1.58  
    1.59 -	const char * const options = "aHpvno:R:s:S:dDl?xZz:";
    1.60 +	const char * const options = "aHpvno:R:s:S:dDlL?xZz:";
    1.61  
    1.62  	(void) setlocale(LC_ALL, "");
    1.63  
    1.64 @@ -3473,6 +3502,7 @@
    1.65  		case 'd':
    1.66  		case 'D':
    1.67  		case 'l':
    1.68 +		case 'L':
    1.69  			if (opt_mode != 0)
    1.70  				argserr(progname);
    1.71  
    1.72 @@ -3549,6 +3579,7 @@
    1.73  		case 'd':
    1.74  		case 'D':
    1.75  		case 'l':
    1.76 +		case 'L':
    1.77  		case 'n':
    1.78  		case 'x':
    1.79  			assert(opt_mode == optopt);
    1.80 @@ -3721,6 +3752,17 @@
    1.81  		goto nextzone;
    1.82  	}
    1.83  
    1.84 +	if (opt_mode == 'L') {
    1.85 +		if ((err = scf_walk_fmri(h, argc, argv, SCF_WALK_MULTIPLE,
    1.86 +		    print_log, NULL, &exit_status, uu_warn)) != 0) {
    1.87 +			uu_warn(gettext("failed to iterate over "
    1.88 +			    "instances: %s\n"), scf_strerror(err));
    1.89 +			exit_status = UU_EXIT_FATAL;
    1.90 +		}
    1.91 +
    1.92 +		goto nextzone;
    1.93 +	}
    1.94 +
    1.95  	if (opt_mode == 'n') {
    1.96  		print_notify_special();
    1.97  		if ((err = scf_walk_fmri(h, argc, argv, SCF_WALK_MULTIPLE,
     2.1 --- a/usr/src/man/man1/svcs.1	Fri Jan 28 00:48:09 2011 -0800
     2.2 +++ b/usr/src/man/man1/svcs.1	Fri Jan 28 14:19:52 2011 -0800
     2.3 @@ -21,7 +21,7 @@
     2.4  
     2.5  .LP
     2.6  .nf
     2.7 -\fBsvcs\fR \fB-l\fR [\fB-vZ\fR] [\fB-z\fR \fIzone\fR] [\fIFMRI\fR | \fIpattern\fR]...
     2.8 +\fBsvcs\fR [\fB-l\fR | \fB-L\fR] [\fB-vZ\fR] [\fB-z\fR \fIzone\fR] [\fIFMRI\fR | \fIpattern\fR]...
     2.9  .fi
    2.10  
    2.11  .LP
    2.12 @@ -248,6 +248,18 @@
    2.13  .ne 2
    2.14  .mk
    2.15  .na
    2.16 +\fB-L\fR
    2.17 +.ad
    2.18 +.RS 20n
    2.19 +.rt
    2.20 +Display the log file of the selected services and service instances, one
    2.21 +per-line.
    2.22 +.RE 
    2.23 +
    2.24 +.sp
    2.25 +.ne 2
    2.26 +.mk
    2.27 +.na
    2.28  \fB\fB-o\fR \fIcol\fR[,\fIcol\fR]...\fR
    2.29  .ad
    2.30  .RS 20n