/*1* Copyright (c) 1997-2002 Kungliga Tekniska Högskolan2* (Royal Institute of Technology, Stockholm, Sweden).3* All rights reserved.4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8*9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11*12* 2. Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in the14* documentation and/or other materials provided with the distribution.15*16* 3. Neither the name of the Institute nor the names of its contributors17* may be used to endorse or promote products derived from this software18* without specific prior written permission.19*20* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND21* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE22* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE23* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE24* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL25* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS26* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)27* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT28* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY29* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF30* SUCH DAMAGE.31*/3233#include "kcm_locl.h"3435RCSID("$Id$");3637sig_atomic_t exit_flag = 0;3839krb5_context kcm_context = NULL;4041const char *service_name = "org.h5l.kcm";4243static RETSIGTYPE44sigterm(int sig)45{46exit_flag = 1;47}4849static RETSIGTYPE50sigusr1(int sig)51{52kcm_debug_ccache(kcm_context);53}5455static RETSIGTYPE56sigusr2(int sig)57{58kcm_debug_events(kcm_context);59}6061int62main(int argc, char **argv)63{64krb5_error_code ret;65setprogname(argv[0]);6667ret = krb5_init_context(&kcm_context);68if (ret) {69errx (1, "krb5_init_context failed: %d", ret);70return ret;71}7273kcm_configure(argc, argv);7475#ifdef HAVE_SIGACTION76{77struct sigaction sa;7879sa.sa_flags = 0;80sa.sa_handler = sigterm;81sigemptyset(&sa.sa_mask);8283sigaction(SIGINT, &sa, NULL);84sigaction(SIGTERM, &sa, NULL);8586sa.sa_handler = sigusr1;87sigaction(SIGUSR1, &sa, NULL);8889sa.sa_handler = sigusr2;90sigaction(SIGUSR2, &sa, NULL);9192sa.sa_handler = SIG_IGN;93sigaction(SIGPIPE, &sa, NULL);94}95#else96signal(SIGINT, sigterm);97signal(SIGTERM, sigterm);98signal(SIGUSR1, sigusr1);99signal(SIGUSR2, sigusr2);100signal(SIGPIPE, SIG_IGN);101#endif102#ifdef SUPPORT_DETACH103if (detach_from_console)104daemon(0, 0);105#endif106pidfile(NULL);107108if (launchd_flag) {109heim_sipc mach;110heim_sipc_launchd_mach_init(service_name, kcm_service, NULL, &mach);111} else {112heim_sipc un;113heim_sipc_service_unix(service_name, kcm_service, NULL, &un);114}115116heim_ipc_main();117118krb5_free_context(kcm_context);119return 0;120}121122123