1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ |
---|
2 | /* |
---|
3 | * oafd: OAF CORBA dameon. |
---|
4 | * |
---|
5 | * Copyright (C) 1999, 2000 Red Hat, Inc. |
---|
6 | * Copyright (C) 1999, 2000 Eazel, Inc. |
---|
7 | * |
---|
8 | * This library is free software; you can redistribute it and/or |
---|
9 | * modify it under the terms of the GNU General Public License as |
---|
10 | * published by the Free Software Foundation; either version 2 of the |
---|
11 | * License, or (at your option) any later version. |
---|
12 | * |
---|
13 | * This library is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 | * General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with this library; if not, write to the Free Software |
---|
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
21 | * |
---|
22 | * Authors: Elliot Lee <sopwith@redhat.com>, |
---|
23 | * |
---|
24 | */ |
---|
25 | |
---|
26 | #include "config.h" |
---|
27 | #include <signal.h> |
---|
28 | #include <stdio.h> |
---|
29 | #include <sys/types.h> |
---|
30 | #include <sys/wait.h> |
---|
31 | #include <unistd.h> |
---|
32 | #include <stdlib.h> |
---|
33 | #include <string.h> |
---|
34 | |
---|
35 | #include "bonobo-activation/bonobo-activation-i18n.h" |
---|
36 | #include "bonobo-activation/bonobo-activation-private.h" |
---|
37 | |
---|
38 | #include "server.h" |
---|
39 | #include "activation-server-corba-extensions.h" |
---|
40 | |
---|
41 | static CORBA_Object |
---|
42 | od_server_activate_factory (Bonobo_ServerInfo *si, |
---|
43 | ODActivationInfo *actinfo, |
---|
44 | const Bonobo_ActivationEnvironment *environment, |
---|
45 | CORBA_Environment *ev) |
---|
46 | { |
---|
47 | Bonobo_ActivationResult *res; |
---|
48 | Bonobo_StringList selorder; |
---|
49 | Bonobo_ActivationFlags flags; |
---|
50 | CORBA_Object retval = CORBA_OBJECT_NIL; |
---|
51 | CORBA_Object factory = CORBA_OBJECT_NIL; |
---|
52 | char *requirements; |
---|
53 | |
---|
54 | memset (&selorder, 0, sizeof (Bonobo_StringList)); |
---|
55 | |
---|
56 | requirements = g_alloca (strlen (si->location_info) + sizeof ("iid == ''")); |
---|
57 | sprintf (requirements, "iid == '%s'", si->location_info); |
---|
58 | |
---|
59 | flags = ((actinfo->flags | Bonobo_ACTIVATION_FLAG_NO_LOCAL) & (~Bonobo_ACTIVATION_FLAG_PRIVATE)); |
---|
60 | |
---|
61 | res = Bonobo_ActivationContext_activateMatching ( |
---|
62 | actinfo->ac, requirements, &selorder, |
---|
63 | environment, flags, actinfo->ctx, ev); |
---|
64 | |
---|
65 | if (ev->_major != CORBA_NO_EXCEPTION) |
---|
66 | goto out; |
---|
67 | |
---|
68 | switch (res->res._d) { |
---|
69 | case Bonobo_ACTIVATION_RESULT_NONE: |
---|
70 | CORBA_free (res); |
---|
71 | goto out; |
---|
72 | break; |
---|
73 | case Bonobo_ACTIVATION_RESULT_OBJECT: |
---|
74 | factory = res->res._u.res_object; |
---|
75 | break; |
---|
76 | default: |
---|
77 | g_assert_not_reached (); |
---|
78 | break; |
---|
79 | } |
---|
80 | |
---|
81 | retval = Bonobo_GenericFactory_createObject (factory, si->iid, ev); |
---|
82 | if (ev->_major != CORBA_NO_EXCEPTION) |
---|
83 | retval = CORBA_OBJECT_NIL; |
---|
84 | |
---|
85 | CORBA_free (res); |
---|
86 | |
---|
87 | out: |
---|
88 | return retval; |
---|
89 | } |
---|
90 | |
---|
91 | /* Copied largely from goad.c, goad_server_activate_exe() */ |
---|
92 | static CORBA_Object |
---|
93 | od_server_activate_exe (Bonobo_ServerInfo *si, |
---|
94 | ODActivationInfo *actinfo, |
---|
95 | CORBA_Object od_obj, |
---|
96 | const Bonobo_ActivationEnvironment *environment, |
---|
97 | CORBA_Environment *ev) |
---|
98 | { |
---|
99 | char **args; |
---|
100 | char *extra_arg, *ctmp, *ctmp2; |
---|
101 | int fd_arg; |
---|
102 | int i; |
---|
103 | char *iorstr; |
---|
104 | CORBA_Object retval; |
---|
105 | |
---|
106 | /* Munge the args */ |
---|
107 | args = g_alloca (36 * sizeof (char *)); |
---|
108 | for (i = 0, ctmp = ctmp2 = si->location_info; i < 32; i++) { |
---|
109 | while (*ctmp2 && !g_ascii_isspace ((guchar) *ctmp2)) |
---|
110 | ctmp2++; |
---|
111 | if (!*ctmp2) |
---|
112 | break; |
---|
113 | |
---|
114 | args[i] = g_alloca (ctmp2 - ctmp + 1); |
---|
115 | strncpy (args[i], ctmp, ctmp2 - ctmp); |
---|
116 | args[i][ctmp2 - ctmp] = '\0'; |
---|
117 | |
---|
118 | ctmp = ctmp2; |
---|
119 | while (*ctmp2 && g_ascii_isspace ((guchar) *ctmp2)) |
---|
120 | ctmp2++; |
---|
121 | if (!*ctmp2) |
---|
122 | break; |
---|
123 | ctmp = ctmp2; |
---|
124 | } |
---|
125 | if (!g_ascii_isspace ((guchar) *ctmp) && i < 32) |
---|
126 | args[i++] = ctmp; |
---|
127 | |
---|
128 | extra_arg = |
---|
129 | g_alloca (strlen (si->iid) + |
---|
130 | sizeof ("--oaf-activate-iid=")); |
---|
131 | args[i++] = extra_arg; |
---|
132 | sprintf (extra_arg, "--oaf-activate-iid=%s", si->iid); |
---|
133 | |
---|
134 | fd_arg = i; |
---|
135 | extra_arg = g_alloca (sizeof ("--oaf-ior-fd=") + 10); |
---|
136 | args[i++] = "--oaf-ior-fd=%d"; |
---|
137 | |
---|
138 | |
---|
139 | iorstr = CORBA_ORB_object_to_string ( |
---|
140 | bonobo_activation_orb_get (), od_obj, ev); |
---|
141 | |
---|
142 | if (ev->_major != CORBA_NO_EXCEPTION) |
---|
143 | iorstr = NULL; |
---|
144 | |
---|
145 | if(actinfo->flags & Bonobo_ACTIVATION_FLAG_PRIVATE) { |
---|
146 | extra_arg = g_alloca (sizeof ("--oaf-private")); |
---|
147 | args[i++] = extra_arg; |
---|
148 | g_snprintf (extra_arg, sizeof ("--oaf-private"), |
---|
149 | "--oaf-private"); |
---|
150 | } |
---|
151 | |
---|
152 | args[i] = NULL; |
---|
153 | |
---|
154 | /* |
---|
155 | * We set the process group of activated servers to our process group; |
---|
156 | * this allows people to destroy all OAF servers along with oafd |
---|
157 | * if necessary |
---|
158 | */ |
---|
159 | retval = bonobo_activation_server_by_forking ( |
---|
160 | (const char **) args, TRUE, fd_arg, environment, iorstr, |
---|
161 | si->iid, bonobo_object_directory_re_check_fn, actinfo, ev); |
---|
162 | |
---|
163 | CORBA_free (iorstr); |
---|
164 | |
---|
165 | return retval; |
---|
166 | } |
---|
167 | |
---|
168 | CORBA_Object |
---|
169 | od_server_activate (Bonobo_ServerInfo *si, |
---|
170 | ODActivationInfo *actinfo, |
---|
171 | CORBA_Object od_obj, |
---|
172 | const Bonobo_ActivationEnvironment *environment, |
---|
173 | CORBA_Environment *ev) |
---|
174 | { |
---|
175 | g_return_val_if_fail (ev->_major == CORBA_NO_EXCEPTION, |
---|
176 | CORBA_OBJECT_NIL); |
---|
177 | |
---|
178 | if (!strcmp (si->server_type, "exe")) |
---|
179 | return od_server_activate_exe (si, actinfo, od_obj, environment, ev); |
---|
180 | |
---|
181 | else if (!strcmp (si->server_type, "factory")) |
---|
182 | return od_server_activate_factory (si, actinfo, environment, ev); |
---|
183 | |
---|
184 | else if (!strcmp (si->server_type, "shlib")) |
---|
185 | g_warning (_("We don't handle activating shlib objects in a remote process yet")); |
---|
186 | |
---|
187 | return CORBA_OBJECT_NIL; |
---|
188 | } |
---|