4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
36 #define ILL_ARG_EX_CLASS_DESC "java/lang/IllegalArgumentException"
37 #define THROWABLE_CLASS_DESC "java/lang/Throwable"
39 #define CLASS_FIELD_DESC(class_desc) "L" class_desc ";"
42 * syslog(3c) ident string
44 static char jsyslog_ident
[32];
47 * Log the given message with the given severity.
50 JNIEXPORT
void JNICALL
51 Java_com_sun_solaris_service_logging_SyslogHandler_syslog(JNIEnv
*env
,
52 jclass clazz
, jint severity
, jstring messageObj
)
56 if (messageObj
== NULL
) {
57 jclass exceptionClass
;
59 if (!(exceptionClass
= (*env
)->FindClass(env
,
60 ILL_ARG_EX_CLASS_DESC
)))
61 return; /* exception thrown */
62 (*env
)->Throw(env
, (*env
)->NewObject(env
, exceptionClass
,
63 (*env
)->GetStaticMethodID(env
, exceptionClass
, "<init>",
64 "()" CLASS_FIELD_DESC(THROWABLE_CLASS_DESC
))));
68 if (!(message
= (*env
)->GetStringUTFChars(env
, messageObj
, NULL
)))
69 return; /* exception thrown */
70 syslog(severity
, "%s", message
);
71 (*env
)->ReleaseStringUTFChars(env
, messageObj
, message
);
78 JNIEXPORT
void JNICALL
79 Java_com_sun_solaris_service_logging_SyslogHandler_openlog(JNIEnv
*env
,
80 jclass clazz
, jstring identObj
, jint logopt
, jint facility
)
84 if (identObj
== NULL
) {
85 jclass exceptionClass
;
87 if (!(exceptionClass
= (*env
)->FindClass(env
,
88 ILL_ARG_EX_CLASS_DESC
)))
89 return; /* exception thrown */
90 (*env
)->Throw(env
, (*env
)->NewObject(env
, exceptionClass
,
91 (*env
)->GetStaticMethodID(env
, exceptionClass
, "<init>",
92 "()" CLASS_FIELD_DESC(THROWABLE_CLASS_DESC
))));
96 if (!(ident
= (*env
)->GetStringUTFChars(env
, identObj
, NULL
)))
97 return; /* exception thrown */
98 (void) strlcpy(jsyslog_ident
, ident
, sizeof (jsyslog_ident
));
99 openlog(jsyslog_ident
, logopt
, facility
);
101 (*env
)->ReleaseStringUTFChars(env
, identObj
, ident
);
105 * Invoke closelog(3c).
108 JNIEXPORT
void JNICALL
109 Java_com_sun_solaris_service_logging_SyslogHandler_closelog(JNIEnv
*env
,