]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
bionic: Remove custom getline, openpty and prlimit 4537/head
authorStéphane Graber <stgraber@stgraber.org>
Tue, 8 Apr 2025 14:49:13 +0000 (10:49 -0400)
committerStéphane Graber <stgraber@stgraber.org>
Tue, 8 Apr 2025 14:49:39 +0000 (10:49 -0400)
Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
src/include/getline.c [deleted file]
src/include/getline.h [deleted file]
src/include/meson.build
src/include/openpty.c [deleted file]
src/include/openpty.h [deleted file]
src/include/prlimit.c [deleted file]
src/include/prlimit.h [deleted file]
src/lxc/conf.c
src/lxc/terminal.c
src/lxc/utils.h

diff --git a/src/include/getline.c b/src/include/getline.c
deleted file mode 100644 (file)
index b1dd892..0000000
+++ /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 <sys/types.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-/*
- * 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 (file)
index cbf9db9..0000000
+++ /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 <stdio.h>
-
-#include "../lxc/compiler.h"
-
-__hidden extern ssize_t getline(char **outbuf, size_t *outsize, FILE *fp);
-
-#endif
index 7fd5d41bd138743c975fd60d4a8fd1874ddd7941..74fc43897c461ee9b72699a517d3b0a99c5e1c77 100644 (file)
@@ -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 (file)
index 6a38849..0000000
+++ /dev/null
@@ -1,136 +0,0 @@
-/* SPDX-License-Identifier: LGPL-2.1+ */
-
-#define _GNU_SOURCE
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <termios.h>
-#include <unistd.h>
-
-#if HAVE_PTY_H
-#include <pty.h>
-#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 (file)
index 6302cae..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-/* SPDX-License-Identifier: LGPL-2.1+ */
-
-#ifndef _OPENPTY_H
-#define _OPENPTY_H
-
-#include <termios.h>
-#include <sys/ioctl.h>
-
-#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 (file)
index 3718f14..0000000
+++ /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 <errno.h>
-#include <fcntl.h>
-#include <stdarg.h>
-#include <stdint.h>
-#include <unistd.h>
-#include <linux/types.h> /* __le64, __l32 ... */
-#include <sys/resource.h>
-#include <sys/syscall.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/uio.h>
-#include <sys/vfs.h>
-
-#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 (file)
index a36b795..0000000
+++ /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 <linux/resource.h>
-#include <sys/types.h>
-
-#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
index 517b7c570df99b76a1febc203edbc59bfdce8abb..6a6ee0942ce2600fef003ee9039a953a4731f4da 100644 (file)
@@ -13,6 +13,7 @@
 #include <mntent.h>
 #include <net/if.h>
 #include <netinet/in.h>
+#include <pty.h>
 #include <pwd.h>
 #include <stdarg.h>
 #include <stdbool.h>
 #include <sys/statvfs.h>
 #endif
 
-#if HAVE_OPENPTY
-#include <pty.h>
-#else
-#include "openpty.h"
-#endif
-
 #if HAVE_LIBCAP
 #include <sys/capability.h>
 #endif
 #include "strlcat.h"
 #endif
 
-#if !HAVE_PRLIMIT && HAVE_PRLIMIT64
-#include "prlimit.h"
-#endif
-
 #if !HAVE_STRLCPY
 #include "strlcpy.h"
 #endif
index 173eff6df75178586d16801204555eea73c3b3e0..d94089d6b80aebd782c00eed37b45427ddac2a99 100644 (file)
@@ -5,6 +5,7 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <pthread.h>
+#include <pty.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include "terminal.h"
 #include "utils.h"
 
-#if HAVE_OPENPTY
-#include <pty.h>
-#else
-#include "openpty.h"
-#endif
-
 #define LXC_TERMINAL_BUFFER_SIZE 1024
 
 lxc_log_define(terminal, lxc);
index 923ce8596c9fe14dcc7ae3cc326a9894af2b3b3b..0007b51a6027b0f7becaa5726a77e7e5db2956e8 100644 (file)
@@ -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);