summaryrefslogtreecommitdiff
path: root/srcx
diff options
context:
space:
mode:
authorStef Walter <stef@memberwebs.com>2004-05-19 18:11:39 +0000
committerStef Walter <stef@memberwebs.com>2004-05-19 18:11:39 +0000
commit39f8d8a2c669824b38d92bfda7c28d6ae18ff2a8 (patch)
tree6fab32299261263023974385700537e2b3459ebb /srcx
parentda8619479b79290d28b2f83f045c54ba04d7663d (diff)
jkill arguments when in a jail
Diffstat (limited to 'srcx')
-rw-r--r--srcx/jkill.c99
1 files changed, 66 insertions, 33 deletions
diff --git a/srcx/jkill.c b/srcx/jkill.c
index 236a2f4..dae91d7 100644
--- a/srcx/jkill.c
+++ b/srcx/jkill.c
@@ -81,7 +81,8 @@ static void parse_jail_opts(int argc, char* argv[]);
static void parse_host_opts(int argc, char* argv[]);
static void usage();
-static void usage_jail(const char* name);
+static void usage_jail();
+static void usage_hr(const char* name);
int main(int argc, char* argv[])
{
@@ -115,7 +116,7 @@ int main(int argc, char* argv[])
else
{
- parse_host_opts(argc, argv);
+ parse_host_opts(argc, argv, 1);
argc -= optind;
argv += optind;
@@ -190,53 +191,74 @@ static void parse_jail_opts(int argc, char* argv[])
{
char* t;
int ch;
+ int ishr = 0;
t = strchr(argv[0], '/');
t = t ? t + 1 : argv[0];
+ g_verbose = 1;
+ g_force = 1;
+ g_usescripts = 1;
+
if(strcmp(t, "halt") == 0)
{
- g_verbose = 1;
- g_force = 1;
- g_usescripts = 1;
g_restart = 0;
+ ishr = 1;
}
else if(strcmp(t, "reboot") == 0)
{
- g_verbose = 1;
- g_force = 1;
- g_usescripts = 1;
g_restart = 1;
+ ishr = 1;
}
- else
+ /* Options for jkill */
+ if(!ishr)
{
- /*
- * When not named either of the above we fall through
- * and process the arguments as usual.
- */
- parse_host_opts(argc, argv);
- return;
+ while((ch = getopt(argc, argv, "rt:")) != -1)
+ {
+ switch(ch)
+ {
+ case 'r':
+ g_restart = 1;
+ break;
+
+ /* Timeout to use between kills */
+ case 't':
+ g_timeout = atoi(optarg);
+ if(g_timeout <= 0)
+ errx(2, "invalid timeout argument: %s", optarg);
+ break;
+
+ case '?':
+ default:
+ usage_jail();
+ break;
+ }
+ }
}
- while((ch = getopt(argc, argv, "dk:lnqp")) != -1)
+ /* These are the options for 'halt' and 'reboot' */
+ else
{
- switch(ch)
+ while((ch = getopt(argc, argv, "dk:lnqp")) != -1)
{
- case 'd':
- case 'k':
- case 'l':
- case 'n':
- case 'q':
- case 'p':
- warnx("the '-%c' option is not supported from inside a jail", (char)ch);
- break;
+ switch(ch)
+ {
+ case 'd':
+ case 'k':
+ case 'l':
+ case 'n':
+ case 'q':
+ case 'p':
+ warnx("the '-%c' option is not supported from inside a jail", (char)ch);
+ break;
- case '?':
- default:
- usage_jail(t);
- break;
+ case '?':
+ default:
+ usage_hr(t);
+ break;
+ }
}
}
@@ -244,10 +266,15 @@ static void parse_jail_opts(int argc, char* argv[])
argv += optind;
if(argc > 0)
- usage_jail(t);
+ {
+ if(ishr)
+ usage_hr(t);
+ else
+ usage_jail();
+ }
}
-static void parse_host_opts(int argc, char* argv[])
+static void parse_host_opts(int argc, char* argv[], int namereq)
{
int ch;
@@ -302,7 +329,7 @@ static void parse_host_opts(int argc, char* argv[])
argc -= optind;
argv += optind;
- if(argc <= 0)
+ if(namereq && argc <= 0)
usage();
}
@@ -470,7 +497,13 @@ static void usage()
exit(2);
}
-static void usage_jail(const char* name)
+static void usage_jail()
+{
+ fprintf(stderr, "usage: jkill [-r] [-t timeout]\n");
+ exit(2);
+}
+
+static void usage_hr(const char* name)
{
fprintf(stderr, "usage: %s\n", name);
exit(2);