Revision a2febf9a
Added by Stephen Beaver over 9 years ago
src/etc/inc/pkg-utils.inc | ||
---|---|---|
6 | 6 |
This file contains various functions used by the pfSense package system. |
7 | 7 |
HISTORY |
8 | 8 |
$Id$ |
9 |
|
|
10 |
Copyright (C) 2010 Ermal Luçi |
|
11 |
Copyright (C) 2005-2006 Colin Smith (ethethlay@gmail.com) |
|
12 |
All rights reserved. |
|
13 |
Redistribution and use in source and binary forms, with or without |
|
14 |
modification, are permitted provided that the following conditions are met: |
|
15 |
|
|
16 |
1. Redistributions of source code must retain the above copyright notice, |
|
17 |
this list of conditions and the following disclaimer. |
|
18 |
|
|
19 |
2. Redistributions in binary form must reproduce the above copyright |
|
20 |
notice, this list of conditions and the following disclaimer in the |
|
21 |
documentation and/or other materials provided with the distribution. |
|
22 |
|
|
23 |
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, |
|
24 |
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY |
|
25 |
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
|
26 |
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, |
|
27 |
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
28 |
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
29 |
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
30 |
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
31 |
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
32 |
POSSIBILITY OF SUCH DAMAGE. |
|
33 |
|
|
9 |
*/ |
|
10 |
/* ==================================================================== |
|
11 |
* Copyright (c) 2004-2015 Electric Sheep Fencing, LLC. All rights reserved. |
|
12 |
* Copyright (c) 2004, 2005 Scott Ullrich |
|
13 |
* Copyright (c) 2005-2006 Colin Smith (ethethlay@gmail.com) |
|
14 |
* |
|
15 |
* Redistribution and use in source and binary forms, with or without modification, |
|
16 |
* are permitted provided that the following conditions are met: |
|
17 |
* |
|
18 |
* 1. Redistributions of source code must retain the above copyright notice, |
|
19 |
* this list of conditions and the following disclaimer. |
|
20 |
* |
|
21 |
* 2. Redistributions in binary form must reproduce the above copyright |
|
22 |
* notice, this list of conditions and the following disclaimer in |
|
23 |
* the documentation and/or other materials provided with the |
|
24 |
* distribution. |
|
25 |
* |
|
26 |
* 3. All advertising materials mentioning features or use of this software |
|
27 |
* must display the following acknowledgment: |
|
28 |
* "This product includes software developed by the pfSense Project |
|
29 |
* for use in the pfSense software distribution. (http://www.pfsense.org/). |
|
30 |
* |
|
31 |
* 4. The names "pfSense" and "pfSense Project" must not be used to |
|
32 |
* endorse or promote products derived from this software without |
|
33 |
* prior written permission. For written permission, please contact |
|
34 |
* coreteam@pfsense.org. |
|
35 |
* |
|
36 |
* 5. Products derived from this software may not be called "pfSense" |
|
37 |
* nor may "pfSense" appear in their names without prior written |
|
38 |
* permission of the Electric Sheep Fencing, LLC. |
|
39 |
* |
|
40 |
* 6. Redistributions of any form whatsoever must retain the following |
|
41 |
* acknowledgment: |
|
42 |
* |
|
43 |
* "This product includes software developed by the pfSense Project |
|
44 |
* for use in the pfSense software distribution (http://www.pfsense.org/). |
|
45 |
* |
|
46 |
* THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY |
|
47 |
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
48 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
49 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR |
|
50 |
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
51 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
|
52 |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
53 |
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|
54 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
|
55 |
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
56 |
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
|
57 |
* OF THE POSSIBILITY OF SUCH DAMAGE. |
|
58 |
* |
|
59 |
* ==================================================================== |
|
60 |
* |
|
34 | 61 |
*/ |
35 |
|
|
36 | 62 |
/* |
37 |
pfSense_BUILDER_BINARIES: /usr/bin/cd /usr/bin/tar /usr/sbin/fifolog_create /bin/chmod
|
|
63 |
pfSense_BUILDER_BINARIES: /usr/bin/cd /usr/bin/tar /usr/sbin/fifolog_create /bin/chmod
|
|
38 | 64 |
pfSense_BUILDER_BINARIES: /usr/sbin/pkg_add /usr/sbin/pkg_info /usr/sbin/pkg_delete /bin/rm |
39 |
pfSense_MODULE: pkg
|
|
65 |
pfSense_MODULE: pkg
|
|
40 | 66 |
*/ |
41 | 67 |
|
42 | 68 |
require_once("globals.inc"); |
... | ... | |
111 | 137 |
|
112 | 138 |
$descriptorspec = array( |
113 | 139 |
1 => array("pipe", "w"), /* stdout */ |
114 |
2 => array("pipe", "w") /* stderr */
|
|
140 |
2 => array("pipe", "w") /* stderr */
|
|
115 | 141 |
); |
116 | 142 |
|
117 | 143 |
pkg_debug("pkg_call(): {$params}\n"); |
... | ... | |
127 | 153 |
/* XXX: should be a tunnable? */ |
128 | 154 |
$timeout = 300; // seconds |
129 | 155 |
$error_log = ''; |
156 |
$started = time(); |
|
157 |
$maxwaittime = 10; // Number of seconds to wait for a response fromteh pacakge we are calling |
|
130 | 158 |
|
131 | 159 |
do { |
132 | 160 |
$write = array(); |
... | ... | |
151 | 179 |
} |
152 | 180 |
} |
153 | 181 |
} |
182 |
|
|
154 | 183 |
$status = proc_get_status($process); |
184 |
|
|
185 |
$now = time(); |
|
186 |
|
|
187 |
if(($now - $started) >= $maxwaittime) { |
|
188 |
$rc = -1; |
|
189 |
proc_terminate($process); |
|
190 |
break; |
|
191 |
} |
|
192 |
|
|
155 | 193 |
} while ($status['running']); |
194 |
|
|
156 | 195 |
fclose($pipes[1]); |
157 | 196 |
fclose($pipes[2]); |
158 | 197 |
proc_close($process); |
159 | 198 |
|
160 |
$rc = $status['exitcode']; |
|
199 |
if(!isset($rc)) { |
|
200 |
$rc = $status['exitcode']; |
|
201 |
} |
|
161 | 202 |
|
162 | 203 |
pkg_debug("pkg_call(): rc = {$rc}\n"); |
163 | 204 |
if ($rc == 0) { |
... | ... | |
169 | 210 |
$static_output .= "\n\n" . sprintf(gettext("ERROR!!! An error occurred on pkg execution (rc = %d) with parameters '%s':"), $rc, $params) . "\n" . $error_log; |
170 | 211 |
update_output_window($static_output); |
171 | 212 |
} |
213 |
|
|
172 | 214 |
return false; |
173 | 215 |
} |
174 | 216 |
|
... | ... | |
201 | 243 |
|
202 | 244 |
$descriptorspec = array( |
203 | 245 |
1 => array("pipe", "w"), /* stdout */ |
204 |
2 => array("pipe", "w") /* stderr */
|
|
246 |
2 => array("pipe", "w") /* stderr */
|
|
205 | 247 |
); |
206 | 248 |
|
207 | 249 |
pkg_debug("pkg_exec(): {$params}\n"); |
... | ... | |
281 | 323 |
|
282 | 324 |
foreach ($config['installedpackages']['package'] as $idx => $pkg) { |
283 | 325 |
if ($pkg['name'] == $package_name || |
284 |
get_package_internal_name($pkg) == $package_name) {
|
|
326 |
get_package_internal_name($pkg) == $package_name) {
|
|
285 | 327 |
return $idx; |
286 | 328 |
} |
287 | 329 |
} |
... | ... | |
304 | 346 |
} |
305 | 347 |
} |
306 | 348 |
|
307 |
/* Get information about packages */
|
|
349 |
// Get information about packages.
|
|
308 | 350 |
function get_pkg_info($pkgs = 'all', $info = 'all') { |
309 | 351 |
global $g, $static_output, $input_errors; |
310 | 352 |
|
... | ... | |
315 | 357 |
$pkgs = $g['pkg_prefix']; |
316 | 358 |
} |
317 | 359 |
|
360 |
|
|
318 | 361 |
/* Make sure repo metadata is up2date */ |
319 | 362 |
$static_output .= "\n" . gettext("Updating package repository metadada...") . "\n"; |
320 | 363 |
update_status($static_output); |
364 |
|
|
321 | 365 |
if (!pkg_call("update")) { |
322 | 366 |
$input_errors[] = gettext("ERROR: An error occurred when updating packages repository. Aborting...") . "\n"; |
323 | 367 |
$static_output .= "\n" . gettext("ERROR: An error occurred when updating packages repository. Aborting...") . "\n"; |
... | ... | |
325 | 369 |
return array(); |
326 | 370 |
} |
327 | 371 |
|
372 |
|
|
328 | 373 |
$rc = pkg_exec("search -U --raw-format json-compact " . $pkgs, $out, $err); |
329 | 374 |
|
330 | 375 |
if ($rc != 0) { |
... | ... | |
435 | 480 |
} |
436 | 481 |
|
437 | 482 |
if (!is_array($config['installedpackages']['package'][$pkg_id])) { |
438 |
return; // No package belongs to the pkg_id passed to this function.
|
|
483 |
return; // No package belongs to the pkg_id passed to this function.
|
|
439 | 484 |
} |
440 | 485 |
|
441 | 486 |
$package =& $config['installedpackages']['package'][$pkg_id]; |
... | ... | |
595 | 640 |
update_output_window($static_output); |
596 | 641 |
/* modify system files */ |
597 | 642 |
|
598 |
/* if a require exists, include it. this will
|
|
599 |
* show us where an error exists in a package
|
|
600 |
* instead of making us blindly guess
|
|
643 |
/* if a require exists, include it. this will |
|
644 |
* show us where an error exists in a package |
|
645 |
* instead of making us blindly guess |
|
601 | 646 |
*/ |
602 | 647 |
$missing_include = false; |
603 | 648 |
if ($pkg_config['include_file'] <> "") { |
... | ... | |
813 | 858 |
} |
814 | 859 |
/* |
815 | 860 |
* XXX: Otherwise inclusion of config.inc again invalidates actions taken. |
816 |
* Same is done during installation.
|
|
861 |
* Same is done during installation. |
|
817 | 862 |
*/ |
818 | 863 |
write_config("Intermediate config write during package removal for {$package_name}."); |
819 | 864 |
|
820 | 865 |
/* |
821 |
* If a require exists, include it. this will
|
|
866 |
* If a require exists, include it. this will
|
|
822 | 867 |
* show us where an error exists in a package |
823 | 868 |
* instead of making us blindly guess |
824 | 869 |
*/ |
Also available in: Unified diff
Partial fix for #5263
Added timeout to pkg_call function to prevent GUI lockup when beta.pfsense.org is not available