From: Stéphane Graber Date: Tue, 8 Apr 2025 14:49:13 +0000 (-0400) Subject: bionic: Remove custom getline, openpty and prlimit X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F4537%2Fhead;p=thirdparty%2Flxc.git bionic: Remove custom getline, openpty and prlimit Signed-off-by: Stéphane Graber --- diff --git a/src/include/getline.c b/src/include/getline.c deleted file mode 100644 index b1dd8924f..000000000 --- a/src/include/getline.c +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2006 SPARTA, Inc. - * All rights reserved. - * - * This software was developed by SPARTA ISSO under SPAWAR contract - * N66001-04-C-6019 ("SEFOS"). - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include -#include - -/* - * Emulate glibc getline() via BSD fgetln(). - * Note that outsize is not changed unless memory is allocated. - */ -ssize_t -getline(char **outbuf, size_t *outsize, FILE *fp) -{ - size_t len; - char *buf; - buf = fgetln(fp, &len); - - if (buf == NULL) - return (-1); - - /* Assumes realloc() accepts NULL for ptr (C99) */ - if (*outbuf == NULL || *outsize < len + 1) { - void *tmp = realloc(*outbuf, len + 1); - if (tmp == NULL) - return (-1); - *outbuf = tmp; - *outsize = len + 1; - } - memcpy(*outbuf, buf, len); - (*outbuf)[len] = '\0'; - return (len); -} diff --git a/src/include/getline.h b/src/include/getline.h deleted file mode 100644 index cbf9db925..000000000 --- a/src/include/getline.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2006 SPARTA, Inc. - * All rights reserved. - * - * This software was developed by SPARTA ISSO under SPAWAR contract - * N66001-04-C-6019 ("SEFOS"). - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef _GETLINE_H -#define _GETLINE_H - -#include - -#include "../lxc/compiler.h" - -__hidden extern ssize_t getline(char **outbuf, size_t *outsize, FILE *fp); - -#endif diff --git a/src/include/meson.build b/src/include/meson.build index 7fd5d41bd..74fc43897 100644 --- a/src/include/meson.build +++ b/src/include/meson.build @@ -8,12 +8,6 @@ netns_ifaddrs_sources = files( 'netns_ifaddrs.c', 'netns_ifaddrs.h') -if srcconf.get('HAVE_GETLINE') == 0 - include_sources += files( - 'getline.c', - 'getline.h') -endif - if srcconf.get('HAVE_FEXECVE') == 0 include_sources += files( 'fexecve.c', @@ -44,15 +38,3 @@ if srcconf.get('HAVE_STRCHRNUL') == 0 'strchrnul.c', 'strchrnul.h') endif - -if srcconf.get('HAVE_OPENPTY') == 0 - include_sources += files( - 'openpty.c', - 'openpty.h') -endif - -if srcconf.get('HAVE_PRLIMIT') == 0 and srcconf.get('HAVE_PRLIMIT64') == 1 - include_sources += files( - 'prlimit.c', - 'prlimit.h') -endif diff --git a/src/include/openpty.c b/src/include/openpty.c deleted file mode 100644 index 6a38849ef..000000000 --- a/src/include/openpty.c +++ /dev/null @@ -1,136 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1+ */ - -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if HAVE_PTY_H -#include -#endif - -static int pts_name(int fd, char **pts, size_t buf_len) -{ - int rv; - char *buf = *pts; - - for (;;) { - char *new_buf; - - if (buf_len) { - rv = ptsname_r(fd, buf, buf_len); - - if (rv != 0 || memchr(buf, '\0', buf_len)) - /* We either got an error, or we succeeded and the - returned name fit in the buffer. */ - break; - - /* Try again with a longer buffer. */ - buf_len += buf_len; /* Double it */ - } else - /* No initial buffer; start out by mallocing one. */ - buf_len = 128; /* First time guess. */ - - if (buf != *pts) - /* We've already malloced another buffer at least once. */ - new_buf = realloc(buf, buf_len); - else - new_buf = malloc(buf_len); - if (!new_buf) { - rv = -1; - break; - } - buf = new_buf; - } - - if (rv == 0) - *pts = buf; /* Return buffer to the user. */ - else if (buf != *pts) - free(buf); /* Free what we malloced when returning an error. */ - - return rv; -} - -int __unlockpt(int fd) -{ -#ifdef TIOCSPTLCK - int unlock = 0; - - if (ioctl(fd, TIOCSPTLCK, &unlock)) { - if (errno != EINVAL) - return -1; - } -#endif - return 0; -} - -int openpty(int *ptx, int *pty, char *name, const struct termios *termp, - const struct winsize *winp) -{ - char _buf[PATH_MAX]; - char *buf = _buf; - int ptx_fd, ret = -1, pty_fd = -1; - - *buf = '\0'; - - ptx_fd = open("/dev/ptmx", O_RDWR | O_NOCTTY); - if (ptx_fd == -1) - return -1; - - if (__unlockpt(ptx_fd)) - goto on_error; - -#ifdef TIOCGPTPEER - /* Try to allocate pty_fd solely based on ptx_fd first. */ - pty_fd = ioctl(ptx_fd, TIOCGPTPEER, O_RDWR | O_NOCTTY); -#endif - if (pty_fd == -1) { - /* Fallback to path-based pty_fd allocation in case kernel doesn't - * support TIOCGPTPEER. - */ - if (pts_name(ptx_fd, &buf, sizeof(_buf))) - goto on_error; - - pty_fd = open(buf, O_RDWR | O_NOCTTY); - if (pty_fd == -1) - goto on_error; - } - - if (termp) - tcsetattr(pty_fd, TCSAFLUSH, termp); -#ifdef TIOCSWINSZ - if (winp) - ioctl(pty_fd, TIOCSWINSZ, winp); -#endif - - *ptx = ptx_fd; - *pty = pty_fd; - if (name != NULL) { - if (*buf == '\0') - if (pts_name(ptx_fd, &buf, sizeof(_buf))) - goto on_error; - - strcpy(name, buf); - } - - ret = 0; - -on_error: - if (ret == -1) { - close(ptx_fd); - - if (pty_fd != -1) - close(pty_fd); - } - - if (buf != _buf) - free(buf); - - return ret; -} diff --git a/src/include/openpty.h b/src/include/openpty.h deleted file mode 100644 index 6302caea3..000000000 --- a/src/include/openpty.h +++ /dev/null @@ -1,20 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1+ */ - -#ifndef _OPENPTY_H -#define _OPENPTY_H - -#include -#include - -#include "../lxc/memory_utils.h" - -/* - * Create pseudo tty ptx pty pair with @__name and set terminal - * attributes according to @__termp and @__winp and return handles for both - * ends in @__aptx and @__apts. - */ -__hidden extern int openpty(int *ptx, int *pty, char *name, - const struct termios *termp, - const struct winsize *winp); - -#endif diff --git a/src/include/prlimit.c b/src/include/prlimit.c deleted file mode 100644 index 3718f149b..000000000 --- a/src/include/prlimit.c +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include /* __le64, __l32 ... */ -#include -#include -#include -#include -#include -#include - -#if defined(__LP64__) -#error This code is only needed on 32-bit systems! -#endif - -#define RLIM64_INFINITY (~0ULL) - -typedef uint64_t u64; - -// There is no prlimit system call, so we need to use prlimit64. -int prlimit(pid_t pid, int resource, const struct rlimit *n32, struct rlimit *o32) -{ - struct rlimit64 n64; - if (n32 != NULL) { - n64.rlim_cur = (n32->rlim_cur == RLIM_INFINITY) - ? RLIM64_INFINITY - : n32->rlim_cur; - n64.rlim_max = (n32->rlim_max == RLIM_INFINITY) - ? RLIM64_INFINITY - : n32->rlim_max; - } - - struct rlimit64 o64; - int result = prlimit64( - pid, resource, (n32 != NULL) ? (const struct rlimit64 *)&n64 : NULL, - (o32 != NULL) ? &o64 : NULL); - - if (result != -1 && o32 != NULL) { - o32->rlim_cur = (o64.rlim_cur == RLIM64_INFINITY) - ? RLIM_INFINITY - : o64.rlim_cur; - o32->rlim_max = (o64.rlim_max == RLIM64_INFINITY) - ? RLIM_INFINITY - : o64.rlim_max; - } - - return result; -} diff --git a/src/include/prlimit.h b/src/include/prlimit.h deleted file mode 100644 index a36b79528..000000000 --- a/src/include/prlimit.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef _PRLIMIT_H -#define _PRLIMIT_H - -#include -#include - -#include "../lxc/memory_utils.h" - -#define RLIM_SAVED_CUR RLIM_INFINITY -#define RLIM_SAVED_MAX RLIM_INFINITY - -__hidden int prlimit(pid_t, int, const struct rlimit *, struct rlimit *); -__hidden int prlimit64(pid_t, int, const struct rlimit64 *, struct rlimit64 *); - -#endif diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 517b7c570..6a6ee0942 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -73,12 +74,6 @@ #include #endif -#if HAVE_OPENPTY -#include -#else -#include "openpty.h" -#endif - #if HAVE_LIBCAP #include #endif @@ -87,10 +82,6 @@ #include "strlcat.h" #endif -#if !HAVE_PRLIMIT && HAVE_PRLIMIT64 -#include "prlimit.h" -#endif - #if !HAVE_STRLCPY #include "strlcpy.h" #endif diff --git a/src/lxc/terminal.c b/src/lxc/terminal.c index 173eff6df..d94089d6b 100644 --- a/src/lxc/terminal.c +++ b/src/lxc/terminal.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -29,12 +30,6 @@ #include "terminal.h" #include "utils.h" -#if HAVE_OPENPTY -#include -#else -#include "openpty.h" -#endif - #define LXC_TERMINAL_BUFFER_SIZE 1024 lxc_log_define(terminal, lxc); diff --git a/src/lxc/utils.h b/src/lxc/utils.h index 923ce8596..0007b51a6 100644 --- a/src/lxc/utils.h +++ b/src/lxc/utils.h @@ -29,13 +29,6 @@ __hidden extern int get_u16(unsigned short *val, const char *arg, int base); __hidden extern int lxc_mkdir_p(const char *dir, mode_t mode); __hidden extern char *get_rundir(void); -/* Define getline() if missing from the C library */ -#if !HAVE_GETLINE -#if !HAVE_FGETLN -#include "getline.h" -#endif -#endif - static inline int lxc_set_cloexec(int fd) { return fcntl(fd, F_SETFD, FD_CLOEXEC);