Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*************************************************************************
3 : *
4 : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : *
6 : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : *
8 : * OpenOffice.org - a multi-platform office productivity suite
9 : *
10 : * This file is part of OpenOffice.org.
11 : *
12 : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : * it under the terms of the GNU Lesser General Public License version 3
14 : * only, as published by the Free Software Foundation.
15 : *
16 : * OpenOffice.org is distributed in the hope that it will be useful,
17 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : * GNU Lesser General Public License version 3 for more details
20 : * (a copy is included in the LICENSE file that accompanied this code).
21 : *
22 : * You should have received a copy of the GNU Lesser General Public License
23 : * version 3 along with OpenOffice.org. If not, see
24 : * <http://www.openoffice.org/license.html>
25 : * for a copy of the LGPLv3 License.
26 : *
27 : ************************************************************************/
28 :
29 : #include <config_folders.h>
30 :
31 : #ifdef AIX
32 : #define _LINUX_SOURCE_COMPAT
33 : #include <sys/timer.h>
34 : #undef _LINUX_SOURCE_COMPAT
35 : #endif
36 :
37 : #include <sys/types.h>
38 : #include <signal.h>
39 : #include <sys/wait.h>
40 : #include <osl/file.hxx>
41 : #include <osl/thread.h>
42 : #include <rtl/bootstrap.hxx>
43 :
44 : #include <plugin/impl.hxx>
45 :
46 :
47 0 : ::boost::shared_ptr<SysPlugData> CreateSysPlugData()
48 : {
49 0 : return ::boost::shared_ptr<SysPlugData>();
50 : }
51 :
52 0 : UnxPluginComm::UnxPluginComm(
53 : const OUString& /*mimetype*/,
54 : const OUString& library,
55 : XLIB_Window aParent,
56 : int nDescriptor1,
57 : int nDescriptor2
58 : ) :
59 0 : PluginComm( OUStringToOString( library, osl_getThreadTextEncoding() ), false ),
60 : PluginConnector( nDescriptor2 ),
61 0 : m_nCommPID( 0 )
62 : {
63 0 : OString path;
64 0 : if (!getPluginappPath(&path))
65 : {
66 : SAL_WARN("extensions.plugin", "cannot construct path to pluginapp.bin");
67 0 : return;
68 : }
69 :
70 : char pDesc[32];
71 : char pWindow[32];
72 0 : sprintf( pWindow, "%d", (int)aParent );
73 0 : sprintf( pDesc, "%d", nDescriptor1 );
74 0 : OString aLib(OUStringToOString(library, osl_getThreadTextEncoding()));
75 :
76 : char const* pArgs[5];
77 0 : pArgs[0] = path.getStr();
78 0 : pArgs[1] = pDesc;
79 0 : pArgs[2] = aLib.getStr();
80 0 : pArgs[3] = pWindow;
81 0 : pArgs[4] = NULL;
82 :
83 : SAL_INFO(
84 : "extensions.plugin",
85 : "try to launch: " << pArgs[0] << " " << pArgs[1] << " " << pArgs[2]
86 : << " " << pArgs[3] << ", descriptors are " << nDescriptor1 << ", "
87 : << nDescriptor2);
88 :
89 0 : pid_t pid = fork();
90 0 : if( pid == 0 )
91 : {
92 0 : execvp( pArgs[0], const_cast< char ** >(pArgs) );
93 : SAL_WARN("extensions.plugin", "could not exec " << pArgs[0]);
94 0 : _exit(255);
95 : }
96 :
97 0 : if( pid == -1 )
98 : {
99 : SAL_WARN("extensions.plugin", "fork failed");
100 0 : return;
101 : }
102 :
103 0 : m_nCommPID = pid;
104 : // wait for pluginapp.bin to start up
105 0 : if( ! WaitForMessage( 5000 ) )
106 : {
107 : SAL_WARN(
108 : "extensions.plugin",
109 : "timeout on command: " << pArgs[0] << " " << pArgs[1] << " "
110 : << pArgs[2] << " " << pArgs[3]);
111 0 : invalidate();
112 : }
113 : else
114 : {
115 0 : MediatorMessage* pMessage = GetNextMessage( sal_True );
116 : Respond( pMessage->m_nID,
117 : const_cast<char*>("init ack"),8,
118 0 : NULL );
119 0 : delete pMessage;
120 0 : NPP_Initialize();
121 0 : }
122 : }
123 :
124 0 : UnxPluginComm::~UnxPluginComm()
125 : {
126 0 : NPP_Shutdown();
127 0 : if( m_nCommPID != 0 )
128 : {
129 0 : int status = 16777216;
130 0 : pid_t nExit = waitpid( m_nCommPID, &status, WUNTRACED );
131 : SAL_INFO(
132 : "extensions.plugin",
133 : "child " << nExit << " (plugin app child " << m_nCommPID
134 : << ") exited with status " << WEXITSTATUS(status));
135 : }
136 0 : }
137 :
138 0 : bool UnxPluginComm::getPluginappPath(OString * path) {
139 : OSL_ASSERT(path != NULL);
140 0 : OUString p("$BRAND_BASE_DIR/" LIBO_LIBEXEC_FOLDER "/pluginapp.bin");
141 0 : rtl::Bootstrap::expandMacros(p);
142 : return
143 0 : (osl::FileBase::getSystemPathFromFileURL(p, p) ==
144 0 : osl::FileBase::E_None) &&
145 : p.convertToString(
146 0 : path, osl_getThreadTextEncoding(),
147 : (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR |
148 0 : RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR));
149 : }
150 :
151 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|