commit 5156758e212f48d2d636c7b79823ab944f73cd4f
parent e180a911724f518a08904d74f9f3102727acbfb7
Author: Connor Lane Smith <cls@lubutu.com>
Date: Fri, 10 Jun 2011 02:56:13 +0100
kill -l
Diffstat:
8 files changed, 62 insertions(+), 31 deletions(-)
diff --git a/Makefile b/Makefile
@@ -7,6 +7,7 @@ LIB = \
util/concat.o \
util/enmasse.o \
util/eprintf.o \
+ util/putword.o \
util/recurse.o \
SRC = \
diff --git a/TODO b/TODO
@@ -1,7 +1,5 @@
cksum [file...]
-cmp [-ls] file1 file2
-
comm [-123] file1 file2
cp [-r] file [name]
@@ -13,8 +11,6 @@ diff [-ru] file1 file2
id [-gnru] [user]
-kill [-s signal] [pid...]
-
mv file [name]
mv [file...] directory
diff --git a/echo.c b/echo.c
@@ -3,6 +3,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include "util.h"
int
main(int argc, char *argv[])
@@ -18,11 +19,8 @@ main(int argc, char *argv[])
default:
exit(EXIT_FAILURE);
}
- for(; optind < argc; optind++) {
- fputs(argv[optind], stdout);
- if(optind+1 < argc)
- putchar(' ');
- }
+ for(; optind < argc; optind++)
+ putword(argv[optind]);
if(!nflag)
putchar('\n');
return EXIT_SUCCESS;
diff --git a/kill.1 b/kill.1
@@ -3,8 +3,13 @@
KILL \- compare two files
.SH SYNOPSIS
.B kill
-.RB [ \-s ]
+.RB [ \-s
+.IR signal ]
.RI [ pid ...]
+.P
+.B kill
+.B -l
+.RI [ signum ]
.SH DESCRIPTION
.B kill
sends a
@@ -14,5 +19,10 @@ signal to the given processes.
.TP
.BI \-s " signal"
sends the named signal.
+.TP
+.B \-l
+lists available signals. If a
+.I signum
+is given, only the corresponding signal name will be printed.
.SH SEE ALSO
.IR kill (2)
diff --git a/kill.c b/kill.c
@@ -1,6 +1,8 @@
/* See LICENSE file for copyright and license details. */
-#include <stdlib.h>
#include <signal.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
#include <strings.h>
#include <unistd.h>
#include "util.h"
@@ -21,12 +23,16 @@ struct {
int
main(int argc, char *argv[])
{
+ bool lflag = false;
char c, *end;
int i, sig = SIGTERM;
pid_t pid;
- while((c = getopt(argc, argv, "s:")) != -1)
+ while((c = getopt(argc, argv, "ls:")) != -1)
switch(c) {
+ case 'l':
+ lflag = true;
+ break;
case 's':
for(i = 0; i < LEN(sigs); i++)
if(!strcasecmp(optarg, sigs[i].name)) {
@@ -39,7 +45,24 @@ main(int argc, char *argv[])
default:
exit(EXIT_FAILURE);
}
- for(; optind < argc; optind++) {
+ if(lflag) {
+ if(optind == argc-1) {
+ sig = strtol(argv[optind], &end, 0);
+ if(*end != '\0')
+ eprintf("%s: not a number\n", argv[optind]);
+ }
+ else if(optind == argc)
+ sig = 0;
+ else
+ eprintf("usage: %s [-s signal] [pid...]\n"
+ " %s -l [signum]\n", argv[0], argv[0]);
+
+ for(i = 0; i < LEN(sigs); i++)
+ if(sigs[i].sig == sig || sig == 0)
+ putword(sigs[i].name);
+ putchar('\n');
+ }
+ else for(; optind < argc; optind++) {
pid = strtol(argv[optind], &end, 0);
if(*end != '\0')
eprintf("%s: not a number\n", argv[optind]);
diff --git a/uname.c b/uname.c
@@ -6,8 +6,6 @@
#include <sys/utsname.h>
#include "util.h"
-static void print(const char *);
-
int
main(int argc, char *argv[])
{
@@ -46,26 +44,15 @@ main(int argc, char *argv[])
eprintf("uname:");
if(sflag || !(nflag || rflag || vflag || mflag))
- print(u.sysname);
+ putword(u.sysname);
if(nflag)
- print(u.nodename);
+ putword(u.nodename);
if(rflag)
- print(u.release);
+ putword(u.release);
if(vflag)
- print(u.version);
+ putword(u.version);
if(mflag)
- print(u.machine);
+ putword(u.machine);
putchar('\n');
return EXIT_SUCCESS;
}
-
-void
-print(const char *s)
-{
- static bool first = true;
-
- if(!first)
- putchar(' ');
- fputs(s, stdout);
- first = false;
-}
diff --git a/util.h b/util.h
@@ -5,4 +5,5 @@
char *agetcwd(void);
void enmasse(int, char **, int (*)(const char *, const char *));
void eprintf(const char *, ...);
+void putword(const char *);
void recurse(const char *, void (*)(const char *));
diff --git a/util/putword.c b/util/putword.c
@@ -0,0 +1,15 @@
+/* See LICENSE file for copyright and license details. */
+#include <stdbool.h>
+#include <stdio.h>
+#include "../util.h"
+
+void
+putword(const char *s)
+{
+ static bool first = true;
+
+ if(!first)
+ putchar(' ');
+ fputs(s, stdout);
+ first = false;
+}