From d5c6878f09d369f50900b01afe3c7a03d2398679 Mon Sep 17 00:00:00 2001 From: Bryan Cantrill Date: Fri, 28 Jan 2011 14:19:52 -0800 Subject: 945 want easy script access to service log files Reviewed by: Eric Schrock Reviewed by: Albert Lee Reviewed by: Garrett D'Amore Approved by: Garrett D'Amore --- usr/src/cmd/svc/svcs/svcs.c | 46 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) (limited to 'usr/src/cmd/svc') diff --git a/usr/src/cmd/svc/svcs/svcs.c b/usr/src/cmd/svc/svcs/svcs.c index 44ebfd4e85..049dec9d30 100644 --- a/usr/src/cmd/svc/svcs/svcs.c +++ b/usr/src/cmd/svc/svcs/svcs.c @@ -1872,7 +1872,7 @@ print_usage(const char *progname, FILE *f, boolean_t do_exit) "[-sS col] [-Z | -z zone ]\n [ ...]\n" " %1$s -d | -D [-Hpv] [-o col[,col ... ]] [-sS col] " "[-Z | -z zone ]\n [ ...]\n" - " %1$s -l [-Z | -z zone] ...\n" + " %1$s [-l | -L] [-Z | -z zone] ...\n" " %1$s -x [-v] [-Z | -z zone] [ ...]\n" " %1$s -?\n"), progname); @@ -1896,6 +1896,7 @@ print_help(const char *progname) "\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 @@ restarter_common: 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 @@ main(int argc, char **argv) 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 @@ main(int argc, char **argv) case 'd': case 'D': case 'l': + case 'L': if (opt_mode != 0) argserr(progname); @@ -3549,6 +3579,7 @@ main(int argc, char **argv) case 'd': case 'D': case 'l': + case 'L': case 'n': case 'x': assert(opt_mode == optopt); @@ -3721,6 +3752,17 @@ again: 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, -- cgit v1.2.3