source: trunk/ORBit2-2.14.0/src/services/name/boot.c

Last change on this file was 92, checked in by cinc, 19 years ago

Orbit2 modified for use with NOM

File size: 3.1 KB
Line 
1#include "CosNaming.h"
2#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5#ifdef HAVE_SYSLOG_H
6# include <syslog.h>
7#endif
8#include <signal.h>
9#include <popt.h>
10#include "CosNaming_impl.h"
11
12static void
13signal_handler(int signo){
14#ifdef HAVE_SYSLOG
15 syslog(LOG_ERR,"Receveived signal %d\nshutting down.", signo);
16#endif
17 switch(signo) {
18 case SIGSEGV:
19 abort();
20 default:
21 exit(1);
22 }
23}
24
25static char *opt_corbaloc_key = NULL;
26
27static const struct poptOption TheOptions[] = {
28 { "key", 0, POPT_ARG_STRING, &opt_corbaloc_key, 0,
29 "Respond to corbaloc requests with this object key", "string" },
30#if 0
31 ORBIT_POPT_TABLE,
32#endif
33 POPT_AUTOHELP
34 { NULL }
35};
36
37int
38main (int argc, char *argv[])
39{
40 CORBA_ORB orb;
41 CORBA_Environment ev;
42 CosNaming_NamingContext context;
43 const char* progname = "orbit-name-server";
44
45#ifdef HAVE_SYSLOG
46 openlog(progname, LOG_NDELAY | LOG_PID, LOG_DAEMON);
47 syslog(LOG_INFO,"starting");
48#endif
49
50#ifdef HAVE_SIGACTION
51 {
52 sigset_t empty_mask;
53 struct sigaction act;
54 sigemptyset(&empty_mask);
55 act.sa_handler = signal_handler;
56 act.sa_mask = empty_mask;
57 act.sa_flags = 0;
58
59 sigaction(SIGINT, &act, NULL);
60 sigaction(SIGHUP, &act, NULL);
61 sigaction(SIGSEGV, &act, NULL);
62 sigaction(SIGABRT, &act, NULL);
63
64 act.sa_handler = SIG_IGN;
65 sigaction(SIGPIPE, &act, NULL);
66 }
67#else
68 signal(SIGINT, signal_handler);
69#ifdef SIGHUP
70 signal(SIGHUP, signal_handler);
71#endif
72 signal(SIGSEGV, signal_handler);
73 signal(SIGABRT, signal_handler);
74#ifdef SIGPIPE
75 signal(SIGPIPE, SIG_IGN);
76#endif
77#endif
78
79 CORBA_exception_init (&ev);
80 orb = CORBA_ORB_init (&argc, argv, "orbit-local-orb", &ev);
81
82 {
83 poptContext pcxt;
84 int rc;
85 pcxt = poptGetContext(progname, argc, (const char**)argv,
86 TheOptions, 0);
87 if ( (rc=poptGetNextOpt(pcxt)) < -1 ) {
88 g_warning("%s: bad argument %s: %s\n",
89 progname,
90 poptBadOption(pcxt, POPT_BADOPTION_NOALIAS),
91 poptStrerror(rc));
92 exit(1);
93 }
94 if ( poptGetArg(pcxt) != 0 ) {
95 g_warning("%s: leftover arguments.\n", progname);
96 exit(1);
97 }
98 poptFreeContext(pcxt);
99 }
100
101 {
102 PortableServer_POA root_poa;
103 PortableServer_POAManager pm;
104 root_poa = (PortableServer_POA)
105 CORBA_ORB_resolve_initial_references (orb, "RootPOA", &ev);
106 context = ORBit_CosNaming_NamingContextExt_create (root_poa, &ev);
107 pm = PortableServer_POA__get_the_POAManager (root_poa, &ev);
108 PortableServer_POAManager_activate (pm, &ev);
109 CORBA_Object_release((CORBA_Object)pm, &ev);
110 CORBA_Object_release((CORBA_Object)root_poa, &ev);
111 }
112
113 {
114 CORBA_char *objstr;
115 objstr = CORBA_ORB_object_to_string (orb, context, &ev);
116 g_print ("%s\n", objstr);
117 fflush (stdout);
118 CORBA_free(objstr);
119 }
120 if ( opt_corbaloc_key ) {
121 CORBA_sequence_CORBA_octet okey;
122 okey._length = strlen(opt_corbaloc_key);
123 okey._buffer = opt_corbaloc_key;
124 ORBit_ORB_forw_bind(orb, &okey, context, &ev);
125 }
126
127
128 CORBA_ORB_run (orb, &ev);
129
130 /* Don't release until done (dont know why) */
131 CORBA_Object_release (context, &ev);
132
133#ifdef HAVE_SYSLOG
134 syslog(LOG_INFO, "exiting");
135#endif
136 return 0;
137}
Note: See TracBrowser for help on using the repository browser.