diff options
author | Russ Allbery <rra@stanford.edu> | 2012-02-22 12:19:56 -0800 |
---|---|---|
committer | Russ Allbery <rra@stanford.edu> | 2012-02-22 13:07:53 -0800 |
commit | 4b821c7bd2e9df4b4cf4a79641b694fa0d04ec7a (patch) | |
tree | 29cb6a3cb4ea0aa1bfb0cde111f343b9ab568c0a /php | |
parent | e31f08ad2f80f5808a19e042cab9663239c08b84 (diff) |
Add timeout support in PHP bindings, remove remctl_output warning
The PHP bindings no longer output a PHP warning if remctl_output
fails. This was inconsistent with the other API calls (remctl_open
and remctl_command can also fail but didn't result in warnings), may
be expected and handled by the caller, and made testing difficult.
Change-Id: I70c489a9c5e4debd2211e015af9144befe27b58f
Diffstat (limited to 'php')
-rw-r--r-- | php/README | 15 | ||||
-rw-r--r-- | php/php_remctl.c | 33 | ||||
-rw-r--r-- | php/php_remctl.h.in | 2 | ||||
-rw-r--r-- | php/tests/006.phpt | 47 |
4 files changed, 91 insertions, 6 deletions
@@ -137,6 +137,21 @@ FULL INTERFACE remctl_open() calls on the same object. Returns true on success, false on failure. + remctl_set_timeout(TIMEOUT) + Sets the timeout for connections and commands to TIMEOUT, which + should be an integer number of seconds. TIMEOUT may be 0 to clear a + timeout that was previously set. All subsequent operations on this + object will be subject to this timeout, including open() if called + prior to calling open(). Returns true on success and false on + failure. Failure is only possible if TIMEOUT is malformed. + + The timeout is a timeout on network activity from the server, not on + a complete operation. So, for example, a timeout of ten seconds + just requires that the server send some data every ten seconds. If + the server sends only tiny amounts of data at a time, the complete + operation could take much longer than ten seconds without triggering + the timeout. + remctl_open(CONNECTION, HOSTNAME[, PORT[, PRINCIPAL]]) Connect to HOSTNAME on port PORT using PRINCIPAL as the remote server's principal for authentication. If PORT is omitted or 0, use diff --git a/php/php_remctl.c b/php/php_remctl.c index f917343..6ba2cb9 100644 --- a/php/php_remctl.c +++ b/php/php_remctl.c @@ -6,7 +6,7 @@ * * Originally written by Andrew Mortensen <admorten@umich.edu>, 2008 * Copyright 2008 Andrew Mortensen <admorten@umich.edu> - * Copyright 2008, 2011 + * Copyright 2008, 2011, 2012 * The Board of Trustees of the Leland Stanford Junior University * * See LICENSE for licensing terms. @@ -20,6 +20,7 @@ #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> +#include <time.h> #include <client/remctl.h> @@ -33,6 +34,7 @@ static zend_function_entry remctl_functions[] = { ZEND_FE(remctl_new, NULL) ZEND_FE(remctl_set_ccache, NULL) ZEND_FE(remctl_set_source_ip, NULL) + ZEND_FE(remctl_set_timeout, NULL) ZEND_FE(remctl_open, NULL) ZEND_FE(remctl_close, NULL) ZEND_FE(remctl_command, NULL) @@ -265,6 +267,30 @@ ZEND_FUNCTION(remctl_set_source_ip) /* + * Set the timeout for subsequent operations. + */ +ZEND_FUNCTION(remctl_set_timeout) +{ + struct remctl *r; + zval *zrem; + long timeout; + int status; + + status = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &zrem, + &timeout); + if (status == FAILURE) { + zend_error(E_WARNING, "remctl_set_timeout: invalid parameters\n"); + RETURN_FALSE; + } + ZEND_FETCH_RESOURCE(r, struct remctl *, &zrem, -1, PHP_REMCTL_RES_NAME, + le_remctl_internal); + if (!remctl_set_timeout(r, timeout)) + RETURN_FALSE; + RETURN_TRUE; +} + + +/* * Open a connection to the remote host. Only the host parameter is required; * the rest are optional. PHP may require something be passed in for * principal, but the empty string is taken to mean "use the library default." @@ -401,11 +427,8 @@ ZEND_FUNCTION(remctl_output) /* Get the output token. */ output = remctl_output(r); - if (output == NULL) { - zend_error(E_WARNING, "remctl_output: error reading from server: %s", - remctl_error(r)); + if (output == NULL) RETURN_NULL(); - } /* * Populate an object with the output results. return_value is defined diff --git a/php/php_remctl.h.in b/php/php_remctl.h.in index 895435b..026fcd3 100644 --- a/php/php_remctl.h.in +++ b/php/php_remctl.h.in @@ -3,7 +3,7 @@ * * Originally written by Andrew Mortensen <admorten@umich.edu>, 2008 * Copyright 2008 Andrew Mortensen <admorten@umich.edu> - * Copyright 2008, 2011 + * Copyright 2008, 2011, 2012 * The Board of Trustees of the Leland Stanford Junior University * * See LICENSE for licensing terms. diff --git a/php/tests/006.phpt b/php/tests/006.phpt new file mode 100644 index 0000000..ba60368 --- /dev/null +++ b/php/tests/006.phpt @@ -0,0 +1,47 @@ +--TEST-- +Check setting a timeout for operations +--ENV-- +KRB5CCNAME=remctl-test.cache +LD_LIBRARY_PATH=../client/.libs +--SKIPIF-- +<?php + if (!file_exists("remctl-test.pid")) + echo "skip remctld not running"; +?> +--FILE-- +<?php + $fh = fopen("remctl-test.princ", "r"); + $principal = rtrim(fread($fh, filesize("remctl-test.princ"))); + $r = remctl_new(); + if ($r == null) { + echo "remctl_new failed\n"; + exit(2); + } + echo "Created object\n"; + if (!remctl_set_timeout($r, 1)) { + echo "remctl_set_timeout failed\n"; + exit(2); + } + if (!remctl_open($r, "127.0.0.1", 14373, $principal)) { + echo "remctl_open failed\n"; + exit(2); + } + $args = array("test", "sleep"); + if (!remctl_command($r, $args)) { + echo "remctl_command failed\n"; + exit(2); + } + echo "Sent sleep command\n"; + $output = remctl_output($r); + if (!$output) { + echo "output is correctly empty\n"; + } + $error = remctl_error($r); + echo "Error: $error\n"; + remctl_close($r); +?> +--EXPECT-- +Created object +Sent sleep command +output is correctly empty +Error: error receiving token: timed out |