This commit is contained in:
Your Name 2023-12-25 19:10:44 +03:00
parent 9563cf2009
commit 0cbd2c4ed0
8 changed files with 78 additions and 12 deletions

1
configs/hostname Normal file
View File

@ -0,0 +1 @@
localhost

7
configs/rc.init Normal file → Executable file
View File

@ -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

0
configs/rc.poweroff Normal file → Executable file
View File

View File

@ -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);

3
src/findutils/grep/build.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

20
src/findutils/grep/grep.c Normal file
View File

@ -0,0 +1,20 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#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;
}

View File

@ -1,18 +1,55 @@
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <unistd.h>
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;

View File

@ -36,7 +36,9 @@ int parse_fstab(void) {
// ret = 1;
}
free(buf);
if (buf != NULL)
free(buf);
fclose(fp);
return ret;
}