Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2002-05-14 03:42:32 +0400
committerChristopher Faylor <me@cgf.cx>2002-05-14 03:42:32 +0400
commitef48a2cad370411ca269007026e400ba5a7abde2 (patch)
treef97284ec7f976d97cff088d01ad2e6dbda31898c /winsup/utils/kill.cc
parent6f49bfb88fd65f956cf4f83de1938c2048ab078d (diff)
* kill.cc (prog_name) New global variable.
(usage) Standardize usage output. Add descriptions. (print_version) New function. (longopts) Accomodate new version option. (opts) Ditto. (main) Ditto.
Diffstat (limited to 'winsup/utils/kill.cc')
-rw-r--r--winsup/utils/kill.cc58
1 files changed, 51 insertions, 7 deletions
diff --git a/winsup/utils/kill.cc b/winsup/utils/kill.cc
index 80758283e..f59d1e8fd 100644
--- a/winsup/utils/kill.cc
+++ b/winsup/utils/kill.cc
@@ -1,6 +1,6 @@
/* kill.cc
- Copyright 1996, 1997, 1998, 1999, 2000, 2001 Red Hat, Inc.
+ Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
This file is part of Cygwin.
@@ -18,27 +18,60 @@ details. */
#include <sys/cygwin.h>
#include <getopt.h>
+static const char version[] = "$Revision$";
+static char *prog_name;
+
static struct option longopts[] =
{
{"help", no_argument, NULL, 'h' },
{"list", optional_argument, NULL, 'l'},
{"force", no_argument, NULL, 'f'},
{"signal", required_argument, NULL, 's'},
+ {"version", no_argument, NULL, 'v'},
{NULL, 0, NULL, 0}
};
-static char opts[] = "hl::fs:";
+static char opts[] = "hl::fs:v";
extern "C" const char *strsigno (int);
static void
usage (FILE *where = stderr)
{
- fputs ("usage: kill [-signal] [-s signal] pid1 [pid2 ...]\n"
- " kill -l [signal]\n", where);
+ fprintf (where , ""
+ "Usage: %s [-f] [-signal] [-s signal] pid1 [pid2 ...]\n"
+ " %s -l [signal]\n"
+ " -f, --force force, using win32 interface if necessary\n"
+ " -l, --list print a list of signal names\n"
+ " -s, --signal send signal (use %s --list for a list)\n"
+ " -h, --help output usage information and exit\n"
+ " -v, --version output version information and exit\n"
+ "", prog_name, prog_name, prog_name);
exit (where == stderr ? 1 : 0);
}
+static void
+print_version ()
+{
+ const char *v = strchr (version, ':');
+ int len;
+ if (!v)
+ {
+ v = "?";
+ len = 1;
+ }
+ else
+ {
+ v += 2;
+ len = strchr (v, ' ') - v;
+ }
+ printf ("\
+%s (cygwin) %.*s\n\
+Process Signaller\n\
+Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.\n\
+Compiled on %s", prog_name, len, v, __DATE__);
+}
+
static int
getsig (const char *in_sig)
{
@@ -65,7 +98,7 @@ test_for_unknown_sig (int sig, const char *sigstr)
{
if (sig < 0 || sig > NSIG)
{
- fprintf (stderr, "kill: unknown signal: %s\n", sigstr);
+ fprintf (stderr, "%s: unknown signal: %s\n", prog_name, sigstr);
usage ();
exit (1);
}
@@ -111,6 +144,14 @@ main (int argc, char **argv)
char *gotsig = NULL;
int ret = 0;
+ prog_name = strrchr (argv[0], '/');
+ if (prog_name == NULL)
+ prog_name = strrchr (argv[0], '\\');
+ if (prog_name == NULL)
+ prog_name = argv[0];
+ else
+ prog_name++;
+
if (argc == 1)
usage ();
@@ -147,6 +188,9 @@ main (int argc, char **argv)
case 'h':
usage (stdout);
break;
+ case 'v':
+ print_version ();
+ break;
case '?':
if (gotsig)
usage ();
@@ -170,7 +214,7 @@ main (int argc, char **argv)
int pid = strtol (*argv, &p, 10);
if (*p != '\0')
{
- fprintf (stderr, "kill: illegal pid: %s\n", *argv);
+ fprintf (stderr, "%s: illegal pid: %s\n", prog_name, *argv);
ret = 1;
}
else if (kill (pid, sig) == 0)
@@ -183,7 +227,7 @@ main (int argc, char **argv)
else
{
char buf[1000];
- sprintf (buf, "kill %d", pid);
+ sprintf (buf, "%s %d", prog_name, pid);
perror (buf);
ret = 1;
}