diff options
author | Andy Fiddaman <omnios@citrus-it.net> | 2017-10-05 17:56:56 +0000 |
---|---|---|
committer | Robert Mustacchi <rm@joyent.com> | 2017-10-18 20:16:11 +0000 |
commit | ad3ad82ad2fb99c424a8482bd1908d08b990ccea (patch) | |
tree | 3b053807745d39aed3cb8ce52e90ca753c8abdcd | |
parent | 4dfc19d7036761a315a6ece34c6cf9cb4268518f (diff) | |
download | illumos-joyent-ad3ad82ad2fb99c424a8482bd1908d08b990ccea.tar.gz |
5112 svcadm manpage needs more 5021-related updates
5593 Recent versions of svcadm invoked for multiple FMRIs say "Partial FMRI matches multiple instances"
8688 svcadm does not handle multiple partial FMRI arguments
Reviewed by: Dominik Hassler <hadfl@omniosce.org>
Reviewed by: Chris Fraire <cfraire@me.com>
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Approved by: Robert Mustacchi <rm@joyent.com>
-rw-r--r-- | usr/src/lib/libscf/common/error.c | 3 | ||||
-rw-r--r-- | usr/src/lib/libscf/common/lowlevel.c | 132 | ||||
-rw-r--r-- | usr/src/man/man1m/svcadm.1m | 19 |
3 files changed, 85 insertions, 69 deletions
diff --git a/usr/src/lib/libscf/common/error.c b/usr/src/lib/libscf/common/error.c index 43aff95a3b..d3fb4d8327 100644 --- a/usr/src/lib/libscf/common/error.c +++ b/usr/src/lib/libscf/common/error.c @@ -23,6 +23,7 @@ * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * Copyright 2013 Joyent, Inc. All rights reserved. + * Copyright 2017 OmniOS Community Edition (OmniOSce) Association. */ #include "libscf_impl.h" @@ -199,7 +200,7 @@ scf_get_msg(scf_msg_t msg) case SCF_MSG_PATTERN_MULTIPARTIAL: return (dgettext(TEXT_DOMAIN, - "Partial FMRI matches multiple instances\n")); + "Partial FMRI '%s' matches multiple instances:\n")); default: abort(); diff --git a/usr/src/lib/libscf/common/lowlevel.c b/usr/src/lib/libscf/common/lowlevel.c index eb0d29b236..536fab236e 100644 --- a/usr/src/lib/libscf/common/lowlevel.c +++ b/usr/src/lib/libscf/common/lowlevel.c @@ -24,6 +24,7 @@ * Copyright 2013, Joyent, Inc. All rights reserved. * Copyright 2016 RackTop Systems. * Copyright (c) 2016 by Delphix. All rights reserved. + * Copyright 2017 OmniOS Community Edition (OmniOSce) Association. */ /* @@ -6274,6 +6275,42 @@ scf_pattern_match(scf_matchkey_t **htable, char *fmri, const char *legacy, } /* + * Construct an error message from a provided format string and include all + * of the matched FMRIs. + */ +static char * +scf_multiple_match_error(scf_pattern_t *pattern, const char *format) +{ + scf_match_t *match; + size_t len, off; + char *msg; + + /* + * Note that strlen(format) includes the length of '%s', which + * accounts for the terminating null byte. + */ + assert(strstr(format, "%s") != NULL); + len = strlen(format) + strlen(pattern->sp_arg); + for (match = pattern->sp_matches; match != NULL; + match = match->sm_next) + len += strlen(match->sm_key->sk_fmri) + 2; + + if ((msg = malloc(len)) == NULL) + return (NULL); + + (void) snprintf(msg, len, format, pattern->sp_arg); + off = strlen(msg); + for (match = pattern->sp_matches; match != NULL; + match = match->sm_next) { + assert(off < len); + off += snprintf(msg + off, len - off, "\t%s\n", + match->sm_key->sk_fmri); + } + + return (msg); +} + +/* * Fails with _INVALID_ARGUMENT, _HANDLE_DESTROYED, _INTERNAL (bad server * response or id in use), _NO_MEMORY, _HANDLE_MISMATCH, _CONSTRAINT_VIOLATED, * _NOT_FOUND, _NOT_BOUND, _CONNECTION_BROKEN, _NOT_SET, _DELETED, @@ -6301,8 +6338,6 @@ scf_walk_fmri(scf_handle_t *h, int argc, char **argv, int flags, ssize_t max_name_length; char *pgname = NULL; scf_walkinfo_t info; - boolean_t partial_fmri = B_FALSE; - boolean_t wildcard_fmri = B_FALSE; #ifndef NDEBUG if (flags & SCF_WALK_EXPLICIT) @@ -6510,7 +6545,6 @@ scf_walk_fmri(scf_handle_t *h, int argc, char **argv, int flags, goto error; } pattern[i].sp_type = PATTERN_EXACT; - partial_fmri = B_TRUE; /* we just iterated all instances */ continue; @@ -6535,7 +6569,6 @@ badfmri: * Prepend svc:/ to patterns which don't begin with * or * svc: or lrc:. */ - wildcard_fmri = B_TRUE; pattern[i].sp_type = PATTERN_GLOB; if (argv[i][0] == '*' || (strlen(argv[i]) >= 4 && argv[i][3] == ':')) @@ -6548,7 +6581,6 @@ badfmri: argv[i]); } } else { - partial_fmri = B_TRUE; pattern[i].sp_type = PATTERN_PARTIAL; pattern[i].sp_arg = strdup(argv[i]); } @@ -6789,44 +6821,55 @@ nolegacy: *err = UU_EXIT_FATAL; } else if (!(flags & SCF_WALK_MULTIPLE) && pattern[i].sp_matchcount > 1) { - size_t len, off; char *msg; - /* - * Construct a message with all possible FMRIs before - * passing off to error handling function. - * - * Note that strlen(scf_get_msg(...)) includes the - * length of '%s', which accounts for the terminating - * null byte. - */ - len = strlen(scf_get_msg(SCF_MSG_PATTERN_MULTIMATCH)) + - strlen(pattern[i].sp_arg); - for (match = pattern[i].sp_matches; match != NULL; - match = match->sm_next) { - len += strlen(match->sm_key->sk_fmri) + 2; - } - if ((msg = malloc(len)) == NULL) { + msg = scf_multiple_match_error(&pattern[i], + scf_get_msg(SCF_MSG_PATTERN_MULTIMATCH)); + + if (msg == NULL) { ret = SCF_ERROR_NO_MEMORY; goto error; } - /* LINTED - format argument */ - (void) snprintf(msg, len, - scf_get_msg(SCF_MSG_PATTERN_MULTIMATCH), - pattern[i].sp_arg); - off = strlen(msg); - for (match = pattern[i].sp_matches; match != NULL; - match = match->sm_next) { - off += snprintf(msg + off, len - off, "\t%s\n", - match->sm_key->sk_fmri); + errfunc(msg); + + if (err != NULL) + *err = UU_EXIT_FATAL; + + free(msg); + + /* + * Set matchcount to 0 so the callback is not + * performed for this pattern. + */ + pattern[i].sp_matchcount = 0; + + } else if ((flags & SCF_WALK_UNIPARTIAL) && + pattern[i].sp_type == PATTERN_PARTIAL && + pattern[i].sp_matchcount > 1) { + char *msg; + + msg = scf_multiple_match_error(&pattern[i], + scf_get_msg(SCF_MSG_PATTERN_MULTIPARTIAL)); + + if (msg == NULL) { + ret = SCF_ERROR_NO_MEMORY; + goto error; } errfunc(msg); + if (err != NULL) *err = UU_EXIT_FATAL; free(msg); + + /* + * Set matchcount to 0 so the callback is not + * performed for this pattern. + */ + pattern[i].sp_matchcount = 0; + } else { for (match = pattern[i].sp_matches; match != NULL; match = match->sm_next) { @@ -6837,26 +6880,6 @@ nolegacy: } } - if (flags & SCF_WALK_UNIPARTIAL && info.count > 1) { - /* - * If the SCF_WALK_UNIPARTIAL flag was passed in and we have - * more than one fmri, then this is an error if we matched - * because of a partial fmri parameter, unless we also matched - * more than one fmri because of wildcards in the parameters. - * That is, the presence of wildcards indicates that it is ok - * to match more than one fmri in this case. - * For example, a parameter of 'foo' that matches more than - * one fmri is an error, but parameters of 'foo *bar*' that - * matches more than one is fine. - */ - if (partial_fmri && !wildcard_fmri) { - errfunc(scf_get_msg(SCF_MSG_PATTERN_MULTIPARTIAL)); - if (err != NULL) - *err = UU_EXIT_FATAL; - goto error; - } - } - /* * Clear 'sk_seen' for all keys. */ @@ -6875,12 +6898,11 @@ nolegacy: scf_matchkey_t *key; /* - * Ignore patterns which didn't match anything or matched too - * many FMRIs. + * Ignore patterns which didn't match anything or + * for which the matchcount has been set to 0 due to an + * error detected above. */ - if (pattern[i].sp_matchcount == 0 || - (!(flags & SCF_WALK_MULTIPLE) && - pattern[i].sp_matchcount > 1)) + if (pattern[i].sp_matchcount == 0) continue; for (match = pattern[i].sp_matches; match != NULL; diff --git a/usr/src/man/man1m/svcadm.1m b/usr/src/man/man1m/svcadm.1m index 968095ea0e..928ba17a78 100644 --- a/usr/src/man/man1m/svcadm.1m +++ b/usr/src/man/man1m/svcadm.1m @@ -3,7 +3,7 @@ .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License. .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] -.TH SVCADM 1M "May 9, 2008" +.TH SVCADM 1M "Oct 17, 2017" .SH NAME svcadm \- manipulate service instances .SH SYNOPSIS @@ -49,14 +49,12 @@ svcadm \- manipulate service instances .fi .SH DESCRIPTION -.sp .LP \fBsvcadm\fR issues requests for actions on services executing within the service management facility (see \fBsmf\fR(5)). Actions for a service are carried out by its assigned service restarter agent. The default service restarter is \fBsvc.startd\fR (see \fBsvc.startd\fR(1M)). .SH OPTIONS -.sp .LP The following options are supported: .sp @@ -101,7 +99,6 @@ from the global zone, see \fBzones\fR(5). .SH SUBCOMMANDS .SS "Common Operations" -.sp .LP The subcommands listed below are used during the typical administration of a service instance. @@ -226,7 +223,6 @@ service instance (see \fBsmf_security\fR(5)). .RE .SS "Exceptional Operations" -.sp .LP The following subcommands are used for service development and temporary administrative manipulation. @@ -303,7 +299,6 @@ group of the \fBsvc:/system/svc/restarter:default\fR service instance (see .RE .SS "Operands" -.sp .LP The following operands are supported: .sp @@ -365,8 +360,10 @@ does not begin with "svc:", then "svc:/" is prepended. .sp .LP -If an abbreviated \fIFMRI\fR or pattern matches more than one service, a -warning message is displayed and that operand is ignored. +If an abbreviated \fIFMRI\fR matches more than one service, a warning message +is displayed and that operand is ignored. +If a pattern matches more than one service or instance, the subcommand is +applied to all matches. .SH EXAMPLES .LP \fBExample 1 \fRRestarting a Service Instance @@ -460,7 +457,6 @@ The following command restores the running services: .sp .SH EXIT STATUS -.sp .LP The following exit values are returned: .sp @@ -514,7 +510,6 @@ with the service's dependencies. .RE .SH ATTRIBUTES -.sp .LP See \fBattributes\fR(5) for descriptions of the following attributes: .sp @@ -534,13 +529,11 @@ Interface Stability See below. The interactive output is Uncommitted. The invocation and non-interactive output are Committed. .SH SEE ALSO -.sp .LP \fBsvcprop\fR(1), \fBsvcs\fR(1), \fBinetd\fR(1M), \fBinit\fR(1M), \fBsvccfg\fR(1M), \fBsvc.startd\fR(1M), \fBlibscf\fR(3LIB), \fBcontract\fR(4), \fBattributes\fR(5), \fBsmf\fR(5), \fBsmf_security\fR(5), \fBzones\fR(5) .SH NOTES -.sp .LP The amount of time \fBsvcadm\fR will spend waiting for services and their dependencies to change state is implicitly limited by their method timeouts. @@ -554,4 +547,4 @@ Attempts to synchronously enable a service which depends (directly or indirectly) on a file may fail with an exit status indicating that dependencies are unsatisfied if the caller does not have the privileges necessary to search the directory containing the file. This limitation may be removed in a future -Solaris release. +release. |