/* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (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] * * CDDL HEADER END */ /* * Copyright 2004 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #pragma ident "%Z%%M% %I% %E% SMI" /* * bootlog() - error notification and progress reporting for * WAN boot components */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef _BOOT #include #endif static struct code pri_names[] = { "panic", BOOTLOG_EMERG, "alert", BOOTLOG_ALERT, "crit", BOOTLOG_CRIT, "warn", BOOTLOG_WARNING, "info", BOOTLOG_INFO, "debug", BOOTLOG_DEBUG, "verbose", BOOTLOG_VERBOSE, "progress", BOOTLOG_PROGRESS, "none", NOPRI, NULL, -1 }; typedef enum { BL_NO_TRANSPORT, BL_LOCAL_FILE, BL_CONSOLE, BL_HTTP, BL_HTTPS } bl_transport_t; typedef struct list_entry { char message[BOOTLOG_QS_MAX]; struct list_entry *flink; } list; #define BOOTLOG_RING_NELEM 512 static struct ringbuffer_t { int w_ptr; int r_ptr; list entries[BOOTLOG_RING_NELEM]; } ringbuffer; static FILE *bl_filehandle = NULL; static http_handle_t bl_httphandle = NULL; static url_t bl_url; static bl_transport_t bl_transport = BL_NO_TRANSPORT; static bl_transport_t openbootlog(void); static boolean_t setup_con(http_handle_t, boolean_t, boolean_t); static char *url_encode(const char *); static boolean_t sendmessage(bl_transport_t, char *, const char *, bootlog_severity_t, int); static int ptr_incr(int ptr); static int ptr_decr(int ptr); static void rb_init(struct ringbuffer_t *); static void rb_write(struct ringbuffer_t *, const char *); static int rb_read(struct ringbuffer_t *, char *); /* * Return a string representing the current time; not thread-safe. */ static const char * gettime(void) { static char timebuf[sizeof ("Tue Jan 19 03:14:07 2038\n")]; time_t curtime; if (time(&curtime) == 0) return ("