2 .\" Copyright (c) 2009, Sun Microsystems, Inc. All Rights Reserved.
3 .\" 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.
4 .\" 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
5 .\" the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH SYSEVENT_SUBSCRIBE_EVENT 3SYSEVENT "Jul 24, 2009"
8 sysevent_subscribe_event, sysevent_unsubscribe_event \- register or unregister
9 interest in event receipt
13 \fBcc\fR [ \fIflag\fR\&.\|.\|. ] \fIfile\fR\&.\|.\|. \fB-lsysevent\fR [ \fIlibrary\fR\&.\|.\|. ]
14 #include <libsysevent.h>
16 \fBint\fR \fBsysevent_subscribe_event\fR(\fBsysevent_handle_t *\fR\fIsysevent_hdl\fR,
17 \fBchar *\fR\fIevent_class\fR, \fBchar **\fR\fIevent_subclass_list\fR,
18 \fBint\fR \fInum_subclasses\fR);
23 \fBvoid\fR \fBsysevent_unsubscribe_event\fR(\fBsysevent_handle_t *\fR\fIsysevent_hdl\fR,
24 \fBchar *\fR\fIevent_class\fR);
31 \fB\fIevent_class\fR\fR
34 system event class string
40 \fB\fIevent_subclass_list\fR\fR
43 array of subclass strings
49 \fB\fInum_subclasses\fR\fR
52 number of subclass strings
58 \fB\fIsysevent_hdl\fR\fR
61 \fBsysevent\fR subscriber handle
67 The \fBsysevent_subscribe_event()\fR function registers the caller's interest
68 in event notifications belonging to the class \fIevent_class\fR and the
69 subclasses contained in \fIevent_subclass_list\fR. The subscriber handle
70 \fIsysevent_hdl\fR is updated with the new subscription and the calling process
71 receives event notifications from the event handler specified in
72 \fIsysevent_bind_handle\fR.
75 System events matching \fIevent_class\fR and a subclass contained in
76 \fIevent_subclass_list\fR published after the caller returns from
77 \fBsysevent_subscribe_event()\fR are guaranteed to be delivered to the calling
78 process. Matching system events published and queued prior to a call to
79 \fBsysevent_subscribe_event()\fR may be delivered to the process's event
83 The \fInum_subclasses\fR argument provides the number of subclass string
84 elements in \fIevent_subclass_list\fR.
87 A caller can use the event class \fBEC_ALL\fR to subscribe to all event classes
88 and subclasses. The event class \fBEC_SUB_ALL\fR can be used to subscribe to
89 all subclasses within a given event class.
92 Subsequent calls to \fBsysevent_subscribe_event()\fR are allowed to add
93 additional classes or subclasses. To remove an existing subscription,
94 \fBsysevent_unsubscribe_event()\fR must be used to remove the subscription.
97 The \fBsysevent_unsubscribe_event()\fR function removes the subscription
98 described by \fIevent_class\fR for \fIsysevent_hdl\fR. Event notifications
99 matching event_class will not be delivered to the calling process upon return.
102 A caller can use the event class \fBEC_ALL\fR to remove all subscriptions for
106 The library manages all subscription resources.
110 The \fBsysevent_subscribe_event()\fR function returns 0 if the subscription is
111 successful. Otherwise, \(mi1 is returned and \fBerrno\fR is set to indicate the
115 The \fBsysevent_unsubscribe_event()\fR function returns no value.
119 The \fBsysevent_subscribe_event()\fR function will fail if:
126 The calling process has an ID other than the privileged user.
135 The \fIsysevent_hdl\fR argument is an invalid \fBsysevent\fR handle.
144 There is insufficient memory available to allocate subscription resources.
149 \fBExample 1 \fRSubscribing for environmental events
153 #include <libsysevent.h>
154 #include <sys/nvpair.h>
156 static int32_t attr_int32;
158 #define CLASS1 "class1"
159 #define CLASS2 "class2"
160 #define SUBCLASS_1 "subclass_1"
161 #define SUBCLASS_2 "subclass_2"
162 #define SUBCLASS_3 "subclass_3"
163 #define MAX_SUBCLASS 3
166 event_handler(sysevent_t *ev)
171 * Special processing for events (CLASS1, SUBCLASS_1) and
172 * (CLASS2, SUBCLASS_3)
174 if ((strcmp(CLASS1, sysevent_get_class_name(ev)) == 0 &&
175 strcmp(SUBCLASS_1, sysevent_get_subclass_name(ev)) == 0) ||
176 (strcmp(CLASS2, sysevent_get_subclass_name(ev) == 0) &&
177 strcmp(SUBCLASS_3, sysevent_get_subclass(ev)) == 0)) {
178 if (sysevent_get_attr_list(ev, &nvlist) != 0)
180 if (nvlist_lookup_int32(nvlist, "my_int32_attr", &attr_int32)
184 /* Event Processing */
186 /* Event Processing */
193 main(int argc, char **argv)
195 sysevent_handle_t *shp;
196 const char *subclass_list[MAX_SUBCLASS];
198 /* Bind event handler and create subscriber handle */
199 shp = sysevent_bind_handle(event_handler);
203 /* Subscribe to all CLASS1 event notifications */
204 subclass_list[0] = EC_SUB_ALL;
205 if (sysevent_subscribe_event(shp, CLASS1, subclass_list, 1) != 0) {
206 sysevent_unbind_handle(shp);
210 /* Subscribe to CLASS2 events for subclasses: SUBCLASS_1,
211 * SUBCLASS_2 and SUBCLASS_3
213 subclass_list[0] = SUBCLASS_1;
214 subclass_list[1] = SUBCLASS_2;
215 subclass_list[2] = SUBCLASS_3;
216 if (sysevent_subscribe_event(shp, CLASS2, subclass_list,
217 MAX_SUBCLASS) != 0) {
218 sysevent_unbind_handle(shp);
232 See \fBattributes\fR(5) for descriptions of the following attributes:
240 ATTRIBUTE TYPE ATTRIBUTE VALUE
242 Interface Stability Committed
250 \fBsyseventd\fR(1M), \fBsysevent_bind_handle\fR(3SYSEVENT),
251 \fBsysevent_get_attr_list\fR(3SYSEVENT),
252 \fBsysevent_get_class_name\fR(3SYSEVENT),
253 \fBsysevent_get_vendor_name\fR(3SYSEVENT), \fBattributes\fR(5)
257 The \fBlibsysevent\fR interfaces do not work at all in non-global zones.