diff options
author | jamie <jamie@FreeBSD.org> | 2012-02-08 23:51:46 +0000 |
---|---|---|
committer | jamie <jamie@FreeBSD.org> | 2012-02-08 23:51:46 +0000 |
commit | a85d762796e36a664734574599d8854c54db7479 (patch) | |
tree | ab97c1c8fcd8613191432f5b22d123b1306595ff /usr.sbin/jail/jail.c | |
parent | 7fb1cfc351e28fde87dc1b4a11d8b72a5d9ca797 (diff) | |
download | FreeBSD-src-a85d762796e36a664734574599d8854c54db7479.zip FreeBSD-src-a85d762796e36a664734574599d8854c54db7479.tar.gz |
Improvements in error messages:
Some errors printed the jail name for unnamed (command line) jails.
Attempting to create an already-existing jail from the command line
returned with no error (even for non-root) due to bad logic in
start_state.
Ignore kvm_proc errors, which are typically caused by permission
problems. Instead, stop ignoring permission errors when removing
a jail (but continue to silently ignore other errors, i.e. the
jail no longer existing). This makes non-root attempts at removing
a jail give a clearer error message.
Diffstat (limited to 'usr.sbin/jail/jail.c')
-rw-r--r-- | usr.sbin/jail/jail.c | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/usr.sbin/jail/jail.c b/usr.sbin/jail/jail.c index 513a3b8..227280f 100644 --- a/usr.sbin/jail/jail.c +++ b/usr.sbin/jail/jail.c @@ -62,6 +62,8 @@ static void clear_persist(struct cfjail *j); static int update_jail(struct cfjail *j); static int rdtun_params(struct cfjail *j, int dofail); static void running_jid(struct cfjail *j, int dflag); +static void jail_quoted_warnx(const struct cfjail *j, const char *name_msg, + const char *noname_msg); static int jailparam_set_note(const struct cfjail *j, struct jailparam *jp, unsigned njp, int flags); static void print_jail(FILE *fp, struct cfjail *j, int oldcl); @@ -317,10 +319,10 @@ main(int argc, char **argv) error = 0; if (op == JF_STOP) { for (i = 0; i < argc; i++) - if (start_state(argv[i], op, Rflag) < 0) + if (start_state(argv[i], docf, op, Rflag) < 0) error = 1; } else { - if (start_state(docf ? argv[0] : NULL, op, 0) < 0) + if (start_state(argv[0], docf, op, 0) < 0) exit(1); } @@ -376,7 +378,8 @@ main(int argc, char **argv) break; case JF_SET_RESTART: if (j->jid < 0) { - warnx("\"%s\" not found", j->name); + jail_quoted_warnx(j, "not found", + "no jail specified"); failed(j); continue; } @@ -396,7 +399,8 @@ main(int argc, char **argv) if (j->comparam == NULL) { if (j->jid > 0 && !(j->flags & (JF_DEPEND | JF_WILD))) { - warnx("\"%s\" already exists", j->name); + jail_quoted_warnx(j, "already exists", + NULL); failed(j); continue; } @@ -420,7 +424,8 @@ main(int argc, char **argv) case JF_SET: if (j->jid < 0 && !(j->flags & JF_DEPEND)) { - warnx("\"%s\" not found", j->name); + jail_quoted_warnx(j, "not found", + "no jail specified"); failed(j); continue; } @@ -444,8 +449,8 @@ main(int argc, char **argv) if (j->jid < 0) { if (!(j->flags & (JF_DEPEND | JF_WILD)) && verbose >= 0) - warnx("\"%s\" not found", - j->name); + jail_quoted_warnx(j, + "not found", NULL); goto jail_remove_done; } j->comparam = stopcommands; @@ -834,6 +839,19 @@ running_jid(struct cfjail *j, int dflag) j->jid = jail_get(jiov, 2, dflag ? JAIL_DYING : 0); } +static void +jail_quoted_warnx(const struct cfjail *j, const char *name_msg, + const char *noname_msg) +{ + const char *pval; + + if ((pval = j->name) || (pval = string_param(j->intparams[KP_JID])) || + (pval = string_param(j->intparams[KP_NAME]))) + warnx("\"%s\" %s", pval, name_msg); + else + warnx("%s", noname_msg); +} + /* * Set jail parameters and possible print them out. */ |