fixed
This commit is contained in:
parent
7a048f8787
commit
f8dd7660ae
0
bin/.gitignore
vendored
Executable file → Normal file
0
bin/.gitignore
vendored
Executable file → Normal file
36
build.sh
36
build.sh
@ -1,36 +1,6 @@
|
||||
#!/bin/sh
|
||||
if [ -z $PROJECT_DIR ]; then
|
||||
PROJECT_DIR=$(pwd)
|
||||
fi
|
||||
|
||||
if [ -z $CFLAGS ]; then
|
||||
CFLAGS="-pedantic -s -Os -Wall -Wextra -D_GNU_SOURCE -D_DEFAULT_SOURCE -D_BSD_SOURCE"
|
||||
fi
|
||||
|
||||
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
|
||||
for i in $(ls src); do
|
||||
echo "CC $i"
|
||||
cc -s -Os -Wextra -Wall -pedantic -I. -Iinclude src/$i -o bin/$(basename $i .c)
|
||||
done
|
||||
|
||||
chmod -vR a+x bin/
|
||||
|
2
config.h
2
config.h
@ -2,7 +2,7 @@
|
||||
#define _CONFIG_H
|
||||
|
||||
/* (cat tee wc xargs rev split cp) text buffer */
|
||||
#define BUF_SIZE 1024 * 1024
|
||||
#define BUF_SIZE 512 * 512
|
||||
|
||||
#ifdef _SHRED_C
|
||||
/* source of random (shred) */
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
struct mu_proc {
|
||||
/* from status */
|
||||
char prog[PATH_MAX + 1];
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
|
||||
@ -82,7 +83,10 @@ int mu_proc_status(const char *prog_name, const pid_t pid, struct mu_proc *proc_
|
||||
val++;
|
||||
|
||||
/* 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);
|
||||
|
||||
else if (!strncmp(token, "Gid", 3))
|
@ -8,7 +8,6 @@
|
||||
#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)) {
|
||||
|
||||
struct stat sb;
|
||||
if (mu_get_stats(prog_name, link_flag, path, &sb))
|
||||
return 1;
|
@ -5,7 +5,7 @@
|
||||
#include <stdlib.h>
|
||||
char s_flag;
|
||||
|
||||
int compare(FILE *fp1, FILE *fp2) {
|
||||
int compare(FILE *fp1, FILE *fp2, const char *s1, const char *s2) {
|
||||
if (fp1 == fp2)
|
||||
return 0;
|
||||
|
||||
@ -18,7 +18,17 @@ int compare(FILE *fp1, FILE *fp2) {
|
||||
ch1 = getc(fp1);
|
||||
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)
|
||||
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");
|
||||
if (fp == NULL) {
|
||||
fprintf(stderr, "cmp: %s\n", strerror(errno));
|
||||
exit(1);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return fp;
|
||||
@ -82,6 +92,9 @@ int main(int argc, char **argv) {
|
||||
FILE *fp1 = NULL;
|
||||
FILE *fp2 = stdin;
|
||||
|
||||
char *s1 = "-";
|
||||
char *s2 = "-";
|
||||
|
||||
switch (argc) {
|
||||
case 4:
|
||||
skip2 = parse_int(argv[3]);
|
||||
@ -92,11 +105,21 @@ int main(int argc, char **argv) {
|
||||
/* fallthrough */
|
||||
|
||||
case 2:
|
||||
s2 = argv[1];
|
||||
fp2 = file_open(argv[1]);
|
||||
if (fp2 == NULL)
|
||||
exit(1);
|
||||
|
||||
/* fallthrough */
|
||||
|
||||
case 1:
|
||||
s1 = argv[0];
|
||||
fp1 = file_open(argv[0]);
|
||||
if (fp1 == NULL) {
|
||||
fclose(fp2);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -118,7 +141,7 @@ int main(int argc, char **argv) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ret = compare(fp1, fp2);
|
||||
int ret = compare(fp1, fp2, s1, s2);
|
||||
fclose(fp1);
|
||||
fclose(fp2);
|
||||
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
3
src/coreutils/env/build.sh
vendored
3
src/coreutils/env/build.sh
vendored
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo *.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
@ -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
|
@ -1,2 +0,0 @@
|
||||
#!/bin/sh
|
||||
kill -s USR1 1
|
@ -1,2 +0,0 @@
|
||||
#!/bin/sh
|
||||
kill -s USR2 1
|
@ -5,6 +5,7 @@
|
||||
#include <signal.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#include "proc_parser.h"
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
@ -58,11 +59,12 @@ int my_kill(pid_t pid, int signal) {
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
unsigned int a_flag = 0;
|
||||
char a_flag = 0;
|
||||
char n_flag = 0;
|
||||
int signal = SIGTERM;
|
||||
|
||||
int opt;
|
||||
while ((opt = getopt(argc, argv, "s:la")) != -1) {
|
||||
while ((opt = getopt(argc, argv, "s:lan")) != -1) {
|
||||
switch (opt) {
|
||||
case 'l':
|
||||
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;
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
n_flag = 1;
|
||||
break;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -87,9 +93,14 @@ int main(int argc, char **argv) {
|
||||
argv += optind;
|
||||
argc -= optind;
|
||||
|
||||
if ((n_flag || !a_flag) && argc == 0) {
|
||||
fprintf(stderr, "kill: missing operands\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ret = 0;
|
||||
|
||||
if (a_flag) {
|
||||
if (a_flag || n_flag) {
|
||||
DIR *dp = opendir("/proc");
|
||||
if (dp == NULL) {
|
||||
fprintf(stderr, "kill: /proc: %s\n", strerror(errno));
|
||||
@ -100,24 +111,38 @@ int main(int argc, char **argv) {
|
||||
|
||||
struct dirent *ep;
|
||||
while ((ep = readdir(dp)) != NULL) {
|
||||
pid_t pid = atoi(ep->d_name);
|
||||
if (pid == 0 || pid == my_pid)
|
||||
pid_t pid = strtoul(ep->d_name, 0L, 10);
|
||||
if (pid == 0)
|
||||
continue;
|
||||
|
||||
if (my_kill(pid, signal))
|
||||
ret = 1;
|
||||
if (n_flag) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
else {
|
||||
for (int i = 0; i < argc; i++) {
|
||||
pid_t pid = atoi(argv[i]);
|
||||
if (my_kill(pid, signal))
|
||||
for (int i = 0; i < argc; i++)
|
||||
if (my_kill(strtoul(argv[i], 0L, 10), signal))
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC -lcrypt
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC -lcrypt
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC -lcrypt
|
@ -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
Loading…
Reference in New Issue
Block a user