etc/services - sync with NetBSD-8
[minix.git] / crypto / external / bsd / heimdal / dist / kcm / main.c
blobc37e7234102b178ba9ad38a840dc716ef8440516
1 /* $NetBSD: main.c,v 1.1.1.2 2014/04/24 12:45:27 pettai Exp $ */
3 /*
4 * Copyright (c) 1997-2002 Kungliga Tekniska Högskolan
5 * (Royal Institute of Technology, Stockholm, Sweden).
6 * All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the Institute nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
36 #include "kcm_locl.h"
38 __RCSID("NetBSD");
40 sig_atomic_t exit_flag = 0;
42 krb5_context kcm_context = NULL;
44 const char *service_name = "org.h5l.kcm";
46 static RETSIGTYPE
47 sigterm(int sig)
49 exit_flag = 1;
52 static RETSIGTYPE
53 sigusr1(int sig)
55 kcm_debug_ccache(kcm_context);
58 static RETSIGTYPE
59 sigusr2(int sig)
61 kcm_debug_events(kcm_context);
64 int
65 main(int argc, char **argv)
67 krb5_error_code ret;
68 setprogname(argv[0]);
70 ret = krb5_init_context(&kcm_context);
71 if (ret) {
72 errx (1, "krb5_init_context failed: %d", ret);
73 return ret;
76 kcm_configure(argc, argv);
78 #ifdef HAVE_SIGACTION
80 struct sigaction sa;
82 sa.sa_flags = 0;
83 sa.sa_handler = sigterm;
84 sigemptyset(&sa.sa_mask);
86 sigaction(SIGINT, &sa, NULL);
87 sigaction(SIGTERM, &sa, NULL);
89 sa.sa_handler = sigusr1;
90 sigaction(SIGUSR1, &sa, NULL);
92 sa.sa_handler = sigusr2;
93 sigaction(SIGUSR2, &sa, NULL);
95 sa.sa_handler = SIG_IGN;
96 sigaction(SIGPIPE, &sa, NULL);
98 #else
99 signal(SIGINT, sigterm);
100 signal(SIGTERM, sigterm);
101 signal(SIGUSR1, sigusr1);
102 signal(SIGUSR2, sigusr2);
103 signal(SIGPIPE, SIG_IGN);
104 #endif
105 #ifdef SUPPORT_DETACH
106 if (detach_from_console)
107 daemon(0, 0);
108 #endif
109 pidfile(NULL);
111 if (launchd_flag) {
112 heim_sipc mach;
113 heim_sipc_launchd_mach_init(service_name, kcm_service, NULL, &mach);
114 } else {
115 heim_sipc un;
116 heim_sipc_service_unix(service_name, kcm_service, NULL, &un);
119 heim_ipc_main();
121 krb5_free_context(kcm_context);
122 return 0;