.
This commit is contained in:
parent
31133309c2
commit
b701e39fbb
@ -5,7 +5,7 @@
|
||||
#include <errno.h>
|
||||
|
||||
int main(const int argc, const char **argv) {
|
||||
if (argc <= 2) {
|
||||
if (argc < 3) {
|
||||
printf("chroot [dir] [\"command arg\"]\n");
|
||||
return 0;
|
||||
}
|
||||
@ -16,6 +16,8 @@ int main(const int argc, const char **argv) {
|
||||
}
|
||||
|
||||
chdir("/");
|
||||
for (int i = 2; i < argc; i++)
|
||||
for (int i = 1; i < argc; i++)
|
||||
system(argv[i]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -21,11 +21,20 @@ char *make_path(const char *src, const char *dst) {
|
||||
return full_path;
|
||||
}
|
||||
|
||||
int write_buffer(int ifd, int ofd) {
|
||||
int write_buffer(int ifd, int ofd, const char *dst) {
|
||||
off_t len = lseek(ifd, 0, SEEK_END);
|
||||
if (len < 0)
|
||||
return 1;
|
||||
|
||||
else if (len == 0) {
|
||||
int fd = open(dst, O_CREAT | O_RDONLY, 0666);
|
||||
if (fd < 0)
|
||||
return 1;
|
||||
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ftruncate(ofd, len) < 0)
|
||||
return 1;
|
||||
|
||||
@ -57,7 +66,7 @@ int copy(const char *src, const char *dst) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (write_buffer(ifd, ofd))
|
||||
if (write_buffer(ifd, ofd, dst))
|
||||
fprintf(stderr, "cp: (%s %s) %s\n", src, dst, strerror(errno));
|
||||
|
||||
close(ifd);
|
||||
|
Loading…
Reference in New Issue
Block a user