This commit is contained in:
Your Name 2024-07-09 11:02:46 +03:00
parent 7a048f8787
commit f8dd7660ae
143 changed files with 74 additions and 248 deletions

0
bin/.gitignore vendored Executable file → Normal file
View File

View File

@ -1,36 +1,6 @@
#!/bin/sh #!/bin/sh
if [ -z $PROJECT_DIR ]; then
PROJECT_DIR=$(pwd)
fi
if [ -z $CFLAGS ]; then for i in $(ls src); do
CFLAGS="-pedantic -s -Os -Wall -Wextra -D_GNU_SOURCE -D_DEFAULT_SOURCE -D_BSD_SOURCE" echo "CC $i"
fi cc -s -Os -Wextra -Wall -pedantic -I. -Iinclude src/$i -o bin/$(basename $i .c)
if [ -z $CC ]; then
CC=cc
fi
if [ -z $projects ]; then
projects="editors sysutils-linux init console-tools coreutils findutils networking loginutils procps"
fi
#Compile
for project in $projects; do
echo "Chdir" $project
for p in src/$project/*; do
echo " * Makeing" $p
for i in $p; do
cd $PROJECT_DIR/$i
echo " * Compile" $i
chmod -v +x build.sh
env CC=$CC CFLAGS="$CFLAGS -I$PROJECT_DIR -I$PROJECT_DIR/include/libmu" OUTPUT="$PROJECT_DIR"/bin/ ./build.sh
cd $PROJECT_DIR
done
echo -ne "\n"
done
done done
chmod -vR a+x bin/

View File

@ -2,7 +2,7 @@
#define _CONFIG_H #define _CONFIG_H
/* (cat tee wc xargs rev split cp) text buffer */ /* (cat tee wc xargs rev split cp) text buffer */
#define BUF_SIZE 1024 * 1024 #define BUF_SIZE 512 * 512
#ifdef _SHRED_C #ifdef _SHRED_C
/* source of random (shred) */ /* source of random (shred) */

View File

@ -14,6 +14,7 @@
struct mu_proc { struct mu_proc {
/* from status */ /* from status */
char prog[PATH_MAX + 1];
uid_t uid; uid_t uid;
gid_t gid; gid_t gid;
@ -82,7 +83,10 @@ int mu_proc_status(const char *prog_name, const pid_t pid, struct mu_proc *proc_
val++; val++;
/* Write values */ /* Write values */
if (!strncmp(token, "Uid", 3)) if (!strncmp(token, "Name", 4))
strcpy(proc_s->prog, val);
else if (!strncmp(token, "Uid", 3))
proc_s->uid = strtoul(val, 0L, 10); proc_s->uid = strtoul(val, 0L, 10);
else if (!strncmp(token, "Gid", 3)) else if (!strncmp(token, "Gid", 3))

View File

@ -8,7 +8,6 @@
#include "get_stat.h" #include "get_stat.h"
int mu_recurse(const char *restrict prog_name, int link_flag, const char *restrict path, void *restrict arg, int (*file_act)(const char *path, void *p), int (*dir_act)(const char *path, void *p)) { int mu_recurse(const char *restrict prog_name, int link_flag, const char *restrict path, void *restrict arg, int (*file_act)(const char *path, void *p), int (*dir_act)(const char *path, void *p)) {
struct stat sb; struct stat sb;
if (mu_get_stats(prog_name, link_flag, path, &sb)) if (mu_get_stats(prog_name, link_flag, path, &sb))
return 1; return 1;

View File

@ -5,7 +5,7 @@
#include <stdlib.h> #include <stdlib.h>
char s_flag; char s_flag;
int compare(FILE *fp1, FILE *fp2) { int compare(FILE *fp1, FILE *fp2, const char *s1, const char *s2) {
if (fp1 == fp2) if (fp1 == fp2)
return 0; return 0;
@ -18,7 +18,17 @@ int compare(FILE *fp1, FILE *fp2) {
ch1 = getc(fp1); ch1 = getc(fp1);
ch2 = getc(fp2); ch2 = getc(fp2);
if (ch1 != ch2) { if (ch1 == EOF) {
printf("EOF on %s\n", s1);
return 1;
}
else if (ch2 == EOF) {
printf("EOF on %s\n", s2);
return 1;
}
else if (ch1 != ch2) {
if (!s_flag) if (!s_flag)
printf("files differ at byte %zu and line %zu\n", byte, lines); printf("files differ at byte %zu and line %zu\n", byte, lines);
@ -52,7 +62,7 @@ FILE *file_open(const char *path) {
FILE *fp = fopen(path, "r"); FILE *fp = fopen(path, "r");
if (fp == NULL) { if (fp == NULL) {
fprintf(stderr, "cmp: %s\n", strerror(errno)); fprintf(stderr, "cmp: %s\n", strerror(errno));
exit(1); return NULL;
} }
return fp; return fp;
@ -82,6 +92,9 @@ int main(int argc, char **argv) {
FILE *fp1 = NULL; FILE *fp1 = NULL;
FILE *fp2 = stdin; FILE *fp2 = stdin;
char *s1 = "-";
char *s2 = "-";
switch (argc) { switch (argc) {
case 4: case 4:
skip2 = parse_int(argv[3]); skip2 = parse_int(argv[3]);
@ -92,11 +105,21 @@ int main(int argc, char **argv) {
/* fallthrough */ /* fallthrough */
case 2: case 2:
s2 = argv[1];
fp2 = file_open(argv[1]); fp2 = file_open(argv[1]);
if (fp2 == NULL)
exit(1);
/* fallthrough */ /* fallthrough */
case 1: case 1:
s1 = argv[0];
fp1 = file_open(argv[0]); fp1 = file_open(argv[0]);
if (fp1 == NULL) {
fclose(fp2);
exit(1);
}
break; break;
default: default:
@ -118,7 +141,7 @@ int main(int argc, char **argv) {
return 1; return 1;
} }
int ret = compare(fp1, fp2); int ret = compare(fp1, fp2, s1, s2);
fclose(fp1); fclose(fp1);
fclose(fp2); fclose(fp2);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,2 +0,0 @@
#!/bin/sh
kill -s USR1 1

View File

@ -1,2 +0,0 @@
#!/bin/sh
kill -s USR2 1

View File

@ -5,6 +5,7 @@
#include <signal.h> #include <signal.h>
#include <dirent.h> #include <dirent.h>
#include <unistd.h> #include <unistd.h>
#include "proc_parser.h"
typedef struct { typedef struct {
const char *name; const char *name;
@ -58,11 +59,12 @@ int my_kill(pid_t pid, int signal) {
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
unsigned int a_flag = 0; char a_flag = 0;
char n_flag = 0;
int signal = SIGTERM; int signal = SIGTERM;
int opt; int opt;
while ((opt = getopt(argc, argv, "s:la")) != -1) { while ((opt = getopt(argc, argv, "s:lan")) != -1) {
switch (opt) { switch (opt) {
case 'l': case 'l':
for (size_t i = 0; i < sizeof(signals) / sizeof(signals[0]); i++) for (size_t i = 0; i < sizeof(signals) / sizeof(signals[0]); i++)
@ -78,8 +80,12 @@ int main(int argc, char **argv) {
a_flag = 1; a_flag = 1;
break; break;
case 'n':
n_flag = 1;
break;
default: default:
printf("kill [lsa] [pid1 pid2...]\n\t-s SIG\n\t-l List all signals\n\t-a Kill all process\n"); printf("kill [lsan] [pid1 pid2/str1...]\n\t-s SIG\n\t-l List all signals\n\t-a Kill all process\n\t-n STR kill processes by name\n");
return 0; return 0;
} }
} }
@ -87,9 +93,14 @@ int main(int argc, char **argv) {
argv += optind; argv += optind;
argc -= optind; argc -= optind;
if ((n_flag || !a_flag) && argc == 0) {
fprintf(stderr, "kill: missing operands\n");
return 1;
}
int ret = 0; int ret = 0;
if (a_flag) { if (a_flag || n_flag) {
DIR *dp = opendir("/proc"); DIR *dp = opendir("/proc");
if (dp == NULL) { if (dp == NULL) {
fprintf(stderr, "kill: /proc: %s\n", strerror(errno)); fprintf(stderr, "kill: /proc: %s\n", strerror(errno));
@ -100,24 +111,38 @@ int main(int argc, char **argv) {
struct dirent *ep; struct dirent *ep;
while ((ep = readdir(dp)) != NULL) { while ((ep = readdir(dp)) != NULL) {
pid_t pid = atoi(ep->d_name); pid_t pid = strtoul(ep->d_name, 0L, 10);
if (pid == 0 || pid == my_pid) if (pid == 0)
continue; continue;
if (my_kill(pid, signal)) if (n_flag) {
ret = 1; struct mu_proc proc;
if (mu_proc_parser("kill", pid, &proc))
ret = 1;
for (int i = 0; i < argc; i++) {
if (!strcmp(proc.prog, argv[i]))
if (my_kill(pid, signal))
ret = 1;
}
}
else if (a_flag) {
if (pid == my_pid)
continue;
if (my_kill(pid, signal))
ret = 1;
}
} }
closedir(dp); closedir(dp);
} }
else { else {
for (int i = 0; i < argc; i++) { for (int i = 0; i < argc; i++)
pid_t pid = atoi(argv[i]); if (my_kill(strtoul(argv[i], 0L, 10), signal))
if (my_kill(pid, signal))
ret = 1; ret = 1;
}
} }
return ret; return ret;

View File

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

View File

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

View File

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

View File

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

Some files were not shown because too many files have changed in this diff Show More