changeset 13366:c1720cb807d5

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>
author Bryan Cantrill <bryan@joyent.com>
date Fri, 28 Jan 2011 14:19:52 -0800
parents b868f9d61081
children 4844172c07f8
files usr/src/cmd/svc/svcs/svcs.c usr/src/man/man1/svcs.1
diffstat 2 files changed, 57 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/svc/svcs/svcs.c	Fri Jan 28 00:48:09 2011 -0800
+++ b/usr/src/cmd/svc/svcs/svcs.c	Fri Jan 28 14:19:52 2011 -0800
@@ -1872,7 +1872,7 @@
 	    "[-sS col] [-Z | -z zone ]\n            [<service> ...]\n"
 	    "       %1$s -d | -D [-Hpv] [-o col[,col ... ]] [-sS col] "
 	    "[-Z | -z zone ]\n            [<service> ...]\n"
-	    "       %1$s -l [-Z | -z zone] <service> ...\n"
+	    "       %1$s [-l | -L] [-Z | -z zone] <service> ...\n"
 	    "       %1$s -x [-v] [-Z | -z zone] [<service> ...]\n"
 	    "       %1$s -?\n"), progname);
 
@@ -1896,6 +1896,7 @@
 	"\t-D  list dependents of the specified service(s)\n"
 	"\t-H  omit header line from output\n"
 	"\t-l  list detailed information about the specified service(s)\n"
+	"\t-L  list the log file associated with the specified service(s)\n"
 	"\t-o  list only the specified columns in the output\n"
 	"\t-p  list process IDs and names associated with each service\n"
 	"\t-R  list only those services with the specified restarter\n"
@@ -2639,6 +2640,34 @@
 	return (0);
 }
 
+/* ARGSUSED */
+static int
+print_log(void *unused, scf_walkinfo_t *wip)
+{
+	scf_propertygroup_t *rpg;
+	char buf[MAXPATHLEN];
+
+	if ((rpg = scf_pg_create(h)) == NULL)
+		scfdie();
+
+	if (scf_instance_get_pg(wip->inst, SCF_PG_RESTARTER, rpg) != 0) {
+		if (scf_error() != SCF_ERROR_NOT_FOUND)
+			scfdie();
+
+		goto out;
+	}
+
+	if (pg_get_single_val(rpg, SCF_PROPERTY_LOGFILE,
+	    SCF_TYPE_ASTRING, buf, sizeof (buf), 0) == 0) {
+		(void) printf("%s\n", buf);
+	}
+
+out:
+	scf_pg_destroy(rpg);
+
+	return (0);
+}
+
 int
 qsort_str_compare(const void *p1, const void *p2)
 {
@@ -3426,7 +3455,7 @@
 	int show_header = 1;
 	int show_zones = 0;
 
-	const char * const options = "aHpvno:R:s:S:dDl?xZz:";
+	const char * const options = "aHpvno:R:s:S:dDlL?xZz:";
 
 	(void) setlocale(LC_ALL, "");
 
@@ -3473,6 +3502,7 @@
 		case 'd':
 		case 'D':
 		case 'l':
+		case 'L':
 			if (opt_mode != 0)
 				argserr(progname);
 
@@ -3549,6 +3579,7 @@
 		case 'd':
 		case 'D':
 		case 'l':
+		case 'L':
 		case 'n':
 		case 'x':
 			assert(opt_mode == optopt);
@@ -3721,6 +3752,17 @@
 		goto nextzone;
 	}
 
+	if (opt_mode == 'L') {
+		if ((err = scf_walk_fmri(h, argc, argv, SCF_WALK_MULTIPLE,
+		    print_log, NULL, &exit_status, uu_warn)) != 0) {
+			uu_warn(gettext("failed to iterate over "
+			    "instances: %s\n"), scf_strerror(err));
+			exit_status = UU_EXIT_FATAL;
+		}
+
+		goto nextzone;
+	}
+
 	if (opt_mode == 'n') {
 		print_notify_special();
 		if ((err = scf_walk_fmri(h, argc, argv, SCF_WALK_MULTIPLE,
--- a/usr/src/man/man1/svcs.1	Fri Jan 28 00:48:09 2011 -0800
+++ b/usr/src/man/man1/svcs.1	Fri Jan 28 14:19:52 2011 -0800
@@ -21,7 +21,7 @@
 
 .LP
 .nf
-\fBsvcs\fR \fB-l\fR [\fB-vZ\fR] [\fB-z\fR \fIzone\fR] [\fIFMRI\fR | \fIpattern\fR]...
+\fBsvcs\fR [\fB-l\fR | \fB-L\fR] [\fB-vZ\fR] [\fB-z\fR \fIzone\fR] [\fIFMRI\fR | \fIpattern\fR]...
 .fi
 
 .LP
@@ -248,6 +248,18 @@
 .ne 2
 .mk
 .na
+\fB-L\fR
+.ad
+.RS 20n
+.rt
+Display the log file of the selected services and service instances, one
+per-line.
+.RE 
+
+.sp
+.ne 2
+.mk
+.na
 \fB\fB-o\fR \fIcol\fR[,\fIcol\fR]...\fR
 .ad
 .RS 20n