ia64/xen-unstable

view tools/vtpm_manager/manager/vtpmd.c @ 8977:f84d5cdd9895

Clean up segment selector fixup and validation.

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Thu Feb 23 14:43:45 2006 +0100 (2006-02-23)
parents 2d00d405ef9f
children 72ef14e79cc0
line source
1 // ===================================================================
2 //
3 // Copyright (c) 2005, Intel Corp.
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions
8 // are met:
9 //
10 // * Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 // * Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following
14 // disclaimer in the documentation and/or other materials provided
15 // with the distribution.
16 // * Neither the name of Intel Corporation nor the names of its
17 // contributors may be used to endorse or promote products derived
18 // from this software without specific prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31 // OF THE POSSIBILITY OF SUCH DAMAGE.
32 // ===================================================================
33 //
34 // vtpmd.c
35 //
36 // Application
37 //
38 // ===================================================================
40 #include <stdio.h>
41 #include <signal.h>
42 #include <sys/types.h>
43 #include <unistd.h>
44 #include "vtpm_manager.h"
45 #include "vtpmpriv.h"
46 #include "tcg.h"
47 #include "log.h"
49 #ifndef VTPM_MULTI_VM
50 #include <pthread.h>
51 #endif
53 void signal_handler(int reason) {
54 #ifndef VTPM_MULTI_VM
56 if (pthread_equal(pthread_self(), vtpm_globals->master_pid)) {
57 vtpmloginfo(VTPM_LOG_VTPM, "VTPM Manager shutting down for signal %d.\n", reason);
58 } else {
59 // For old Linux Thread machines, signals are delivered to each thread. Deal with them.
60 vtpmloginfo(VTPM_LOG_VTPM, "Child shutting down\n");
61 pthread_exit(NULL);
62 }
63 #endif
64 VTPM_Stop_Service();
65 exit(-1);
66 }
68 struct sigaction ctl_c_handler;
70 int main(int argc, char **argv) {
72 vtpmloginfo(VTPM_LOG_VTPM, "Starting VTPM.\n");
74 if (VTPM_Init_Service() != TPM_SUCCESS) {
75 vtpmlogerror(VTPM_LOG_VTPM, "Closing vtpmd due to error during startup.\n");
76 return -1;
77 }
79 ctl_c_handler.sa_handler = signal_handler;
80 sigemptyset(&ctl_c_handler.sa_mask);
81 ctl_c_handler.sa_flags = 0;
83 if (sigaction(SIGINT, &ctl_c_handler, NULL) == -1)
84 vtpmlogerror(VTPM_LOG_VTPM, "Could not install SIGINT handler. Ctl+break will not stop service gently.\n");
86 // For easier debuggin with gdb
87 if (sigaction(SIGHUP, &ctl_c_handler, NULL) == -1)
88 vtpmlogerror(VTPM_LOG_VTPM, "Could not install SIGHUP handler. Ctl+break will not stop service gently.\n");
90 #ifdef VTPM_MULTI_VM
91 TPM_RESULT status = VTPM_Service_Handler();
93 if (status != TPM_SUCCESS)
94 vtpmlogerror(VTPM_LOG_VTPM, "VTPM Manager exited with status %s. It never should exit.\n", tpm_get_error_name(status));
96 return -1;
97 #else
98 sigset_t sig_mask;
100 sigemptyset(&sig_mask);
101 sigaddset(&sig_mask, SIGPIPE);
102 sigprocmask(SIG_BLOCK, &sig_mask, NULL);
103 //pthread_mutex_init(&vtpm_globals->dmi_mutex, NULL);
104 pthread_t be_thread, dmi_thread;
105 int betype_be, dmitype_dmi;
107 vtpm_globals->master_pid = pthread_self();
109 betype_be = BE_LISTENER_THREAD;
110 if (pthread_create(&be_thread, NULL, VTPM_Service_Handler, &betype_be) != 0) {
111 vtpmlogerror(VTPM_LOG_VTPM, "Failed to launch BE Thread.\n");
112 exit(-1);
113 }
115 dmitype_dmi = DMI_LISTENER_THREAD;
116 if (pthread_create(&dmi_thread, NULL, VTPM_Service_Handler, &dmitype_dmi) != 0) {
117 vtpmlogerror(VTPM_LOG_VTPM, "Failed to launch DMI Thread.\n");
118 exit(-1);
119 }
121 //Join the other threads until exit time.
122 pthread_join(be_thread, NULL);
123 pthread_join(dmi_thread, NULL);
124 #endif
126 vtpmlogerror(VTPM_LOG_VTPM, "VTPM Manager shut down unexpectedly.\n");
128 VTPM_Stop_Service();
129 return 0;
130 }