Blame


1 1636f5f1 2023-08-29 thomas /*
2 1636f5f1 2023-08-29 thomas * Copyright (c) 2023 Thomas Adam <thomas@xteddy.org>
3 1636f5f1 2023-08-29 thomas *
4 1636f5f1 2023-08-29 thomas * Permission to use, copy, modify, and distribute this software for any
5 1636f5f1 2023-08-29 thomas * purpose with or without fee is hereby granted, provided that the above
6 1636f5f1 2023-08-29 thomas * copyright notice and this permission notice appear in all copies.
7 1636f5f1 2023-08-29 thomas *
8 1636f5f1 2023-08-29 thomas * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 1636f5f1 2023-08-29 thomas * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 1636f5f1 2023-08-29 thomas * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 1636f5f1 2023-08-29 thomas * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 1636f5f1 2023-08-29 thomas * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 1636f5f1 2023-08-29 thomas * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 1636f5f1 2023-08-29 thomas * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 1636f5f1 2023-08-29 thomas */
16 1636f5f1 2023-08-29 thomas
17 1636f5f1 2023-08-29 thomas #include "got_compat.h"
18 1636f5f1 2023-08-29 thomas
19 1636f5f1 2023-08-29 thomas #include <stdio.h>
20 d2c8ed98 2024-03-30 thomas #include <stdarg.h>
21 1636f5f1 2023-08-29 thomas #include <unistd.h>
22 1636f5f1 2023-08-29 thomas
23 1636f5f1 2023-08-29 thomas #include "log.h"
24 1636f5f1 2023-08-29 thomas
25 1636f5f1 2023-08-29 thomas int
26 1636f5f1 2023-08-29 thomas enter_chroot(const char *path)
27 1636f5f1 2023-08-29 thomas {
28 1636f5f1 2023-08-29 thomas log_info("chroot into %s", path);
29 1636f5f1 2023-08-29 thomas if (chroot(path) == -1)
30 1636f5f1 2023-08-29 thomas fatal("chroot");
31 1636f5f1 2023-08-29 thomas if (chdir("/") == -1)
32 1636f5f1 2023-08-29 thomas fatal("chdir(\"/\")");
33 1636f5f1 2023-08-29 thomas
34 1636f5f1 2023-08-29 thomas return 1;
35 1636f5f1 2023-08-29 thomas }