a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * CDDL HEADER START
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * The contents of this file are subject to the terms of the
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Common Development and Distribution License (the "License").
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * You may not use this file except in compliance with the License.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * See the License for the specific language governing permissions
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * and limitations under the License.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * When distributing Covered Code, include this CDDL HEADER in each
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * If applicable, add the following below this CDDL HEADER, with the
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * fields enclosed by brackets "[]" replaced with your own identifying
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * information: Portions Copyright [yyyy] [name of copyright owner]
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * CDDL HEADER END
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Use is subject to license terms.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Copyright (c) 2010, Intel Corporation.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * All rights reserved.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu/* Signal handler type */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu#define ACPIHPD_PID_FILE "/var/run/acpihpd.pid" /* lock file path */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu/* Program Name */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liustatic int daemon_init(void);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liustatic void daemon_quit(int);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liustatic int acpihpd_init(void);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liustatic void acpihpd_fini(void);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liuvoid debug_print(int, const char *, ...);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* Get Program Name */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if ((g_prog_name = strrchr(argv[0], '/')) == NULL) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu switch (c) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu syslog(LOG_ERR, "unrecognized option %c.", optopt);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* Check the daemon running lock and initialize the signal */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (daemon_init() != 0) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu debug_print(0, "%s could not startup!", g_prog_name);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* Subscribe to the hotplug event */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu debug_print(0, "%s could not startup!", g_prog_name);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /*CONSTCOND*/
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (geteuid() != 0) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu debug_print(0, "must be root to execute %s", g_prog_name);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* Parent to exit. */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Create the lock file for singleton
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if ((s_pid_fd = open(ACPIHPD_PID_FILE, O_RDWR | O_CREAT, 0644)) < 0) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu debug_print(0, "another acpihpd is already running");
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu while ((ret = write(s_pid_fd, pid_str, i)) != i) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (set_sig_handler(SIGTERM, (sig_handler_t *)daemon_quit) != 0) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu debug_print(2, "could not set signal handler(SIGTERM)");
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (set_sig_handler(SIGQUIT, (sig_handler_t *)daemon_quit) != 0) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu debug_print(2, "could not set signal handler(SIGQUIT)");
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (set_sig_handler(SIGINT, (sig_handler_t *)daemon_quit) != 0) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu debug_print(2, "could not set signal handler(SIGINT)");
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu debug_print(2, "could not set signal handler(SIGCHLD)");
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu debug_print(1, "daemon quit [signal#:%d].", signo);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if ((s_acpihpd_hdl = sysevent_bind_handle(acpihpd_event)) == NULL) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu return (-1);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (sysevent_subscribe_event(s_acpihpd_hdl, EC_DR, &subclass, 1) != 0) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu return (-1);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* Inform cfgadm of the hot-plug event. */