8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / pools / poold / libjsyslog / jsyslog.c
blob5bd119e281cce0e5293b25b1c22940964eb6d93f
1 /*
2 * CDDL HEADER START
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
7 * with the License.
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]
20 * CDDL HEADER END
23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <stddef.h>
30 #include <assert.h>
31 #include <string.h>
32 #include <syslog.h>
34 #include "jsyslog.h"
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.
49 /*ARGSUSED*/
50 JNIEXPORT void JNICALL
51 Java_com_sun_solaris_service_logging_SyslogHandler_syslog(JNIEnv *env,
52 jclass clazz, jint severity, jstring messageObj)
54 const char *message;
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))));
65 return;
68 if (!(message = (*env)->GetStringUTFChars(env, messageObj, NULL)))
69 return; /* exception thrown */
70 syslog(severity, "%s", message);
71 (*env)->ReleaseStringUTFChars(env, messageObj, message);
75 * Invoke openlog(3c).
77 /*ARGSUSED*/
78 JNIEXPORT void JNICALL
79 Java_com_sun_solaris_service_logging_SyslogHandler_openlog(JNIEnv *env,
80 jclass clazz, jstring identObj, jint logopt, jint facility)
82 const char *ident;
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))));
93 return;
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).
107 /*ARGSUSED*/
108 JNIEXPORT void JNICALL
109 Java_com_sun_solaris_service_logging_SyslogHandler_closelog(JNIEnv *env,
110 jclass clazz)
112 closelog();