+++ /dev/null
-/*
- * 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);
-}
+++ /dev/null
-/*
- * 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
'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',
'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
+++ /dev/null
-/* 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;
-}
+++ /dev/null
-/* 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
+++ /dev/null
-/*
- * 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;
-}
+++ /dev/null
-/*
- * 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
#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
#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);
__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);