31 #include <sys/types.h>
39 #include "xbps_api_impl.h"
42 pfcexec(
struct xbps_handle *xhp,
const char *file,
const char **argv)
54 if (strcmp(xhp->
rootdir,
"/")) {
55 if (geteuid() == 0 && access(
"bin/sh", X_OK) == 0) {
56 if (chroot(xhp->
rootdir) == 0) {
62 (void)execv(file, __UNCONST(argv));
69 while (waitpid(child, &status, 0) < 0) {
74 if (!WIFEXITED(status))
77 return WEXITSTATUS(status);
81 vfcexec(
struct xbps_handle *xhp,
const char *arg, va_list ap)
84 size_t argv_size, argc;
88 if ((argv = malloc(argv_size *
sizeof(*argv))) == NULL) {
97 if (argc == argv_size) {
99 argv = realloc(argv, argv_size *
sizeof(*argv));
106 arg = va_arg(ap,
const char *);
109 }
while (arg != NULL);
111 retval = pfcexec(xhp, argv[0], argv);
118 xbps_file_exec(
struct xbps_handle *xhp,
const char *arg, ...)
124 result = vfcexec(xhp, arg, ap);