Changeset View
Changeset View
Standalone View
Standalone View
sbin/route/route.c
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | |||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/file.h> | #include <sys/file.h> | ||||
#include <sys/socket.h> | #include <sys/socket.h> | ||||
#include <sys/ioctl.h> | #include <sys/ioctl.h> | ||||
#ifdef JAIL | |||||
#include <sys/jail.h> | |||||
#endif | |||||
#include <sys/sysctl.h> | #include <sys/sysctl.h> | ||||
#include <sys/types.h> | #include <sys/types.h> | ||||
#include <sys/queue.h> | #include <sys/queue.h> | ||||
#include <net/if.h> | #include <net/if.h> | ||||
#include <net/route.h> | #include <net/route.h> | ||||
#include <net/if_dl.h> | #include <net/if_dl.h> | ||||
#include <netinet/in.h> | #include <netinet/in.h> | ||||
▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | stopit(int sig __unused) | ||||
stop_read = 1; | stop_read = 1; | ||||
} | } | ||||
static void | static void | ||||
usage(const char *cp) | usage(const char *cp) | ||||
{ | { | ||||
if (cp != NULL) | if (cp != NULL) | ||||
warnx("bad keyword: %s", cp); | warnx("bad keyword: %s", cp); | ||||
errx(EX_USAGE, "usage: route [-46dnqtv] command [[modifiers] args]"); | errx(EX_USAGE, "usage: route [-j jail] [-46dnqtv] command [[modifiers] args]"); | ||||
/* NOTREACHED */ | /* NOTREACHED */ | ||||
} | } | ||||
int | int | ||||
main(int argc, char **argv) | main(int argc, char **argv) | ||||
{ | { | ||||
int ch; | int ch; | ||||
#ifdef JAIL | |||||
int jid; | |||||
#endif | |||||
size_t len; | size_t len; | ||||
if (argc < 2) | if (argc < 2) | ||||
usage(NULL); | usage(NULL); | ||||
while ((ch = getopt(argc, argv, "46nqdtv")) != -1) | while ((ch = getopt(argc, argv, "46nqdtv")) != -1) | ||||
switch(ch) { | switch(ch) { | ||||
case '4': | case '4': | ||||
Show All 22 Lines | case 'v': | ||||
verbose = 1; | verbose = 1; | ||||
break; | break; | ||||
case 't': | case 't': | ||||
tflag = 1; | tflag = 1; | ||||
break; | break; | ||||
case 'd': | case 'd': | ||||
debugonly = 1; | debugonly = 1; | ||||
break; | break; | ||||
case 'j': | |||||
#ifdef JAIL | |||||
if (optarg == NULL) | |||||
usage(NULL); | |||||
jid = jail_getid(optarg); | |||||
melifaro: I'd rather save the parameter here and explicitly call some jail_attach wrapper later. This… | |||||
if (jid == -1) | |||||
Done Inline ActionsDo we need usejail at all? melifaro: Do we need usejail at all? | |||||
Done Inline ActionsIt reads to me like initialising jail_name to NULL and replacing if (usejail) with if (jail_name != NULL) would make the usejail variable superfluous. Splitting a pointer and its validity into two variables like this (jail_name and usejail) introduces the potential for contradiction if only one of the two is updated. If this split is required for something I would like to see them stored together in a struct { char *, bool } instead of destructured into two variables. crest_freebsd_rlwinm.de: It reads to me like initialising `jail_name` to NULL and replacing `if (usejail)` with `if… | |||||
errx(1, "Jail not found"); | |||||
if (jail_attach(jid) != 0) | |||||
errx(1, "Cannot attach to jail"); | |||||
#else | |||||
errx(1, "Jail support is not compiled in"); | |||||
#endif | |||||
case '?': | case '?': | ||||
default: | default: | ||||
usage(NULL); | usage(NULL); | ||||
} | } | ||||
argc -= optind; | argc -= optind; | ||||
argv += optind; | argv += optind; | ||||
pid = getpid(); | pid = getpid(); | ||||
▲ Show 20 Lines • Show All 1,761 Lines • Show Last 20 Lines |
I'd rather save the parameter here and explicitly call some jail_attach wrapper later. This will help keep argument parsing and business logic split, hopefully maintaining the same level of readability