This commit is contained in:
Your Name 2023-10-22 09:22:12 +03:00
parent 671e4430be
commit 28c02fbae1
4 changed files with 15 additions and 13 deletions

View File

@ -4,20 +4,22 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
int main(const int argc, const char **argv) { int main(const int argc, char **argv) {
if (argc < 3) { if (argc < 3 || !strcmp(argv[argc - 1], "-h")) {
printf("chroot [dir] [\"command arg\"]\n"); printf("chroot [dir] [\"command arg\"]\n");
return 0; return 0;
} }
if (chroot(argv[1]) == -1) { if (chroot(argv[1]) < 0) {
fprintf(stderr, "chroot: %s\n", strerror(errno)); fprintf(stderr, "chroot: %s\n", strerror(errno));
return 1; return 1;
} }
chdir("/"); chdir("/");
for (int i = 1; i < argc; i++) if (execvp(argv[2], argv) < 0) {
system(argv[i]); fprintf(stderr, "chroot: %s\n", strerror(errno));
return 1;
}
return 0; return 0;
} }

View File

@ -31,9 +31,9 @@ int move(const char *src, const char *dst) {
} }
int main(const int argc, const char **argv) { int main(const int argc, const char **argv) {
if (argc == 2) { if (argc <= 2 || !strcmp(argv[argc - 1], "-h")) {
printf("mv: missing operand\n"); printf("mv [Src1 src2...] [Dst]\n");
return 1; return 0;
} }
for (int i = 1; i < argc - 1; i++) { for (int i = 1; i < argc - 1; i++) {

View File

@ -59,9 +59,9 @@ int rmtree(const char *path) {
} }
int main(const int argc, char **argv) { int main(const int argc, char **argv) {
if (argc == 1) { if (argc == 1 || !strcmp(argv[argc - 1], "-h")) {
printf("rm: missing operand\n"); printf("rm [src1 src2...]\n");
return 1; return 0;
} }
for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) {

View File

@ -13,8 +13,8 @@ double convert(const char *num) {
} }
int main(const int argc, const char **argv) { int main(const int argc, const char **argv) {
if (argc == 1) { if (argc == 1 || !strcmp(argv[argc - 1], "-h")) {
printf("sleep [num[m - minute / h - hour / d - days].. ] / [inf (infinity)]\n"); printf("sleep [num[m - minute / h - hour / d - days]] / [inf (infinity)]\n");
return 0; return 0;
} }