From: Christian Brauner Date: Fri, 12 Jan 2018 13:11:21 +0000 (+0100) Subject: cmd: move lxc-console to API symbols only X-Git-Tag: lxc-3.0.0.beta1~36^2~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8d313ae1dd66601b60f950b0ad4962098d695b53;p=thirdparty%2Flxc.git cmd: move lxc-console to API symbols only Closes #2073. Signed-off-by: Christian Brauner --- diff --git a/src/lxc/tools/lxc_console.c b/src/lxc/tools/lxc_console.c index 876cbce58..f847811cb 100644 --- a/src/lxc/tools/lxc_console.c +++ b/src/lxc/tools/lxc_console.c @@ -39,12 +39,7 @@ #include #include "arguments.h" -#include "commands.h" -#include "error.h" -#include "log.h" -#include "lxc.h" -#include "mainloop.h" -#include "utils.h" +#include "tool_utils.h" static char etoc(const char *expr) { @@ -115,7 +110,6 @@ int main(int argc, char *argv[]) ret = lxc_log_init(&log); if (ret) return EXIT_FAILURE; - lxc_log_options_no_override(); /* REMOVE IN LXC 3.0 */ setenv("LXC_UPDATE_CONFIG_FORMAT", "1", 0); diff --git a/src/lxc/tools/tool_utils.c b/src/lxc/tools/tool_utils.c index 4b4dad0b4..00181ab65 100644 --- a/src/lxc/tools/tool_utils.c +++ b/src/lxc/tools/tool_utils.c @@ -17,7 +17,9 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#define _GNU_SOURCE #define __STDC_FORMAT_MACROS /* Required for PRIu64 to work. */ +#include #include #include #include @@ -310,6 +312,32 @@ again: return status; } +int lxc_safe_uint(const char *numstr, unsigned int *converted) +{ + char *err = NULL; + unsigned long int uli; + + while (isspace(*numstr)) + numstr++; + + if (*numstr == '-') + return -EINVAL; + + errno = 0; + uli = strtoul(numstr, &err, 0); + if (errno == ERANGE && uli == ULONG_MAX) + return -ERANGE; + + if (err == numstr || *err != '\0') + return -EINVAL; + + if (uli > UINT_MAX) + return -ERANGE; + + *converted = (unsigned int)uli; + return 0; +} + int lxc_safe_int(const char *numstr, int *converted) { char *err = NULL; diff --git a/src/lxc/tools/tool_utils.h b/src/lxc/tools/tool_utils.h index f900f037c..b122e3ea1 100644 --- a/src/lxc/tools/tool_utils.h +++ b/src/lxc/tools/tool_utils.h @@ -125,6 +125,7 @@ static inline int lxc_caps_init(void) { extern int wait_for_pid(pid_t pid); extern int lxc_wait_for_pid_status(pid_t pid); +extern int lxc_safe_uint(const char *numstr, unsigned int *converted); extern int lxc_safe_int(const char *numstr, int *converted); extern int lxc_safe_long(const char *numstr, long int *converted);