diff --git a/configs/hostname b/configs/hostname new file mode 100644 index 0000000..2fbb50c --- /dev/null +++ b/configs/hostname @@ -0,0 +1 @@ +localhost diff --git a/configs/rc.init b/configs/rc.init old mode 100644 new mode 100755 index 16482d2..1c28b6e --- a/configs/rc.init +++ b/configs/rc.init @@ -1,9 +1,12 @@ #!/bin/sh -echo "Mounting.." +echo "Mounting..." mount -o nosuid,noexec,nodev -t proc proc /proc mount -o nosuid,noexec,nodev -t sysfs sysfs /sys mount -o gid=5,mode=0620 -t devtmpfs /dev mount -o nosuid,noexec,nodev,mode=0777 -t tmpfs /tmp +echo "Setuping hostname..." +hostname -c /etc/hostname + echo "Starting shell..." -sh +env TERM="vt100" sh diff --git a/configs/rc.poweroff b/configs/rc.poweroff old mode 100644 new mode 100755 diff --git a/src/coreutils/nl/nl.c b/src/coreutils/nl/nl.c index 1a1fb22..68df9b9 100644 --- a/src/coreutils/nl/nl.c +++ b/src/coreutils/nl/nl.c @@ -30,7 +30,8 @@ int nl(const char *path) { fprintf(stdout, "%*s\t%s", w_flag, " ", buf); } - free(buf); + if (buf != NULL) + free(buf); if (strcmp(path, "-")) fclose(fp); diff --git a/src/findutils/grep/build.sh b/src/findutils/grep/build.sh new file mode 100755 index 0000000..6d8974b --- /dev/null +++ b/src/findutils/grep/build.sh @@ -0,0 +1,3 @@ +#!/bin/sh +project_dir=$(pwd) +echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC diff --git a/src/findutils/grep/grep.c b/src/findutils/grep/grep.c new file mode 100644 index 0000000..11da139 --- /dev/null +++ b/src/findutils/grep/grep.c @@ -0,0 +1,20 @@ +#include +#include +#include +#include "recurse.h" + +int main(int argc, char **argv) { + int opt; + while ((opt = getopt(argc, argv, "R")) != -1) { + switch (opt) { + default: + printf("grep [pattern1 pattern2...]\n\t[-R Recursive]\n"); + return 0; + } + } + + argc -= optind; + argv += optind; + return 0; +} + diff --git a/src/networking/hostname/hostname.c b/src/networking/hostname/hostname.c index 9c60f40..f787a66 100644 --- a/src/networking/hostname/hostname.c +++ b/src/networking/hostname/hostname.c @@ -1,18 +1,55 @@ #include #include +#include #include #include #include -int main(const int argc, const char **argv) { - if (argv[argc - 1][0] == '-') { - printf("hostname [hostname Set new hostname]\n"); - return 0; +void readcfg(const char *cfg, char *buf, size_t len) { + FILE *fp = fopen(cfg, "r"); + if (fp == NULL) { + fprintf(stderr, "hostname: %s\n", strerror(errno)); + exit(1); } + fgets(buf, len, fp); + + /* Remove \n from string */ + *(strrchr(buf, '\n')) = '\0'; + + fclose(fp); +} + +int main(int argc, char **argv) { + char hostname[HOST_NAME_MAX + 1]; + char *newhost = NULL; + int config = 0; + + int opt; + while ((opt = getopt(argc, argv, "c:")) != -1) { + switch (opt) { + case 'c': + readcfg(optarg, hostname, sizeof(hostname)); + + config = 1; + newhost = hostname; + break; + + default: + printf("hostname [hostname]\n\t[-c CONFIG Use config file]\n"); + return 0; + } + } + + argc -= optind; + argv += optind; + + if (newhost == NULL) + newhost = argv[0]; + /* Set hostname */ - if (argc == 2) { - if (sethostname(argv[argc - 1], strlen(argv[argc - 1])) < 0) { + if (argc == 1 || config) { + if (sethostname(newhost, strlen(newhost)) < 0) { fprintf(stderr, "hostname: %s\n", strerror(errno)); return 1; } @@ -20,8 +57,7 @@ int main(const int argc, const char **argv) { return 0; } - /* Get info */ - char hostname[HOST_NAME_MAX + 1]; + /* Get hostname */ if (gethostname(hostname, sizeof(hostname)) < 0) { fprintf(stderr, "hostname: %s\n", strerror(errno)); return 1; diff --git a/src/sysutils-linux/mount/mount.c b/src/sysutils-linux/mount/mount.c index e0203b5..70a85e1 100644 --- a/src/sysutils-linux/mount/mount.c +++ b/src/sysutils-linux/mount/mount.c @@ -36,7 +36,9 @@ int parse_fstab(void) { // ret = 1; } - free(buf); + if (buf != NULL) + free(buf); + fclose(fp); return ret; }