summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2020-10-06 15:32:01 -0400
committerJakob Kaivo <jkk@ung.org>2020-10-06 15:32:01 -0400
commitaf043921d728f6703763f544e63a1654bdabb591 (patch)
tree9e72da719acedfd98f40bb97acd062129f15ddfe
parentca6b82f8d3a8cd96c389771bc34585b5a3a2f483 (diff)
extract kill, as it can also stand alone
-rw-r--r--.gitignore1
-rw-r--r--.gitmodules3
-rw-r--r--Makefile2
m---------kill0
-rw-r--r--kill.c97
5 files changed, 9 insertions, 94 deletions
diff --git a/.gitignore b/.gitignore
index 5f97956..dd0a122 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,7 +11,6 @@ fc
fg
getopts
jobs
-kill
newgrp
pwd
read
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..5e4c016
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "kill"]
+ path = kill
+ url = ../kill/
diff --git a/Makefile b/Makefile
index 15f5688..15f9aa0 100644
--- a/Makefile
+++ b/Makefile
@@ -21,7 +21,7 @@ OBJECTS=alias.o bg.o builtins.o cd.o command.o false.o fc.o fg.o getopts.o \
unset.o \
interactive.o parse.o init.o getopt.o \
sh.tab.o sh.yy.o
-BUILTINS=alias bg cd command false fc fg getopts jobs kill newgrp pwd read \
+BUILTINS=alias bg cd command false fc fg getopts jobs newgrp pwd read \
true ulimit umask unalias wait
all: $(UTILITY) $(L10N) $(BUILTINS)
diff --git a/kill b/kill
new file mode 160000
+Subproject 6ab59251bdbd44654abd09abb7f365cabd8cd92
diff --git a/kill.c b/kill.c
index f83c6c6..1c3d24c 100644
--- a/kill.c
+++ b/kill.c
@@ -1,7 +1,7 @@
/*
* UNG's Not GNU
*
- * Copyright (c) 2011-2017, Jakob Kaivo <jkk@ung.org>
+ * Copyright (c) 2011-2020, Jakob Kaivo <jkk@ung.org>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -18,99 +18,12 @@
*/
#include "sh.h"
-#include <ctype.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <signal.h>
-#include <unistd.h>
-
-struct {
- char *name;
- int num;
-} ksigs[] = {
- { "ABRT", SIGABRT },
- { "ALRM", SIGALRM },
- { "BUS", SIGBUS },
- { "CHLD", SIGCHLD },
- { "CONT", SIGCONT },
- { "FPE", SIGFPE },
- { "HUP", SIGHUP },
- { "ILL", SIGILL },
- { "INT", SIGINT },
- { "KILL", SIGKILL },
- { "PIPE", SIGPIPE },
- { "QUIT", SIGQUIT },
- { "SEGV", SIGSEGV },
- { "STOP", SIGSTOP },
- { "TERM", SIGTERM },
- { "TSTP", SIGTSTP },
- { "TTIN", SIGTTIN },
- { "TTOU", SIGTTOU },
- { "USR1", SIGUSR1 },
- { "USR2", SIGUSR2 },
- { "POLL", SIGPOLL },
- { "PROF", SIGPROF },
- { "SYS", SIGSYS },
- { "TRAP", SIGTRAP },
- { "URG", SIGURG },
- { "VTALRM", SIGVTALRM },
- { "XCPU", SIGXCPU },
- { "XFSZ", SIGXFSZ },
-};
-size_t nsigs = sizeof(ksigs) / sizeof(ksigs[0]);
+#define main real_kill_main
+#include "kill/kill.c"
int kill_main(int argc, char *argv[])
{
- char *signame = "TERM";
- int list = 0;
-
+ /* TODO: translate %job to pid */
opterr = 0;
- int c;
- while ((c = getopt(argc, argv, "s:l")) != -1) {
- switch (c) {
- case 's': /** send signal [signal_name] **/
- signame = optarg;
- break;
-
- case 'l':
- list = 1;
- break;
-
- default:
- if (isdigit(optopt) || isupper(optopt)) {
- signame = argv[optind];
- break;
- }
- fprintf(stderr, "kill: unknown option '-%c'\n", optopt);
- //return 1;
- }
- }
-
- if (list) {
- if (argv[optind]) {
- }
-
- for (size_t i = 0; i < nsigs; i++) {
- printf("%s%c", ksigs[i].name, i < nsigs - 1 ? ' ' : '\n');
- }
- return 0;
- }
-
- if (argc <= optind) {
- fprintf(stderr, "kill: missing operand\n");
- return 1;
- }
-
- int pid = atoi(argv[optind]);
- for (size_t i = 0; i < nsigs; i++) {
- if (!strcmp(signame, ksigs[i].name)) {
- if (kill(pid, ksigs[i].num) != 0) {
- perror("kill");
- }
- }
- }
-
- fprintf(stderr, "kill: invalid signal '%s'\n", signame);
- return 1;
+ return real_kill_main(argc, argv);
}