// Did we recognize this option?
if (!opt) {
if (gof->noerror) return 1;
- error_exit("Unknown option %s", gof->arg);
+ help_exit("Unknown option %s", gof->arg);
}
// Might enabling this switch off something else?
if (opt == bad || !(i & toys.optflags)) continue;
if (toys.optflags & bad->dex[2]) break;
}
- error_exit("No '%c' with '%c'", opt->c, bad->c);
+ help_exit("No '%c' with '%c'", opt->c, bad->c);
}
// Does this option take an argument?
char *s = "Missing argument to ";
struct longopts *lo;
- if (opt->c != -1) error_exit("%s-%c", s, opt->c);
+ if (opt->c != -1) help_exit("%s-%c", s, opt->c);
for (lo = gof->longopts; lo->opt != opt; lo = lo->next);
- error_exit("%s--%.*s", s, lo->len, lo->str);
+ help_exit("%s--%.*s", s, lo->len, lo->str);
}
if (type == ':') *(opt->arg) = (long)arg;
} else if (type == '#' || type == '-') {
long l = atolx(arg);
if (type == '-' && !ispunct(*arg)) l*=-1;
- if (l < opt->val[0].l) error_exit("-%c < %ld", opt->c, opt->val[0].l);
- if (l > opt->val[1].l) error_exit("-%c > %ld", opt->c, opt->val[1].l);
+ if (l < opt->val[0].l) help_exit("-%c < %ld", opt->c, opt->val[0].l);
+ if (l > opt->val[1].l) help_exit("-%c > %ld", opt->c, opt->val[1].l);
*(opt->arg) = l;
} else if (CFG_TOYBOX_FLOAT && type == '.') {
*f = strtod(arg, &arg);
if (opt->val[0].l != LONG_MIN && *f < opt->val[0].f)
- error_exit("-%c < %lf", opt->c, (double)opt->val[0].f);
+ help_exit("-%c < %lf", opt->c, (double)opt->val[0].f);
if (opt->val[1].l != LONG_MAX && *f > opt->val[1].f)
- error_exit("-%c > %lf", opt->c, (double)opt->val[1].f);
+ help_exit("-%c > %lf", opt->c, (double)opt->val[1].f);
}
if (!gof->nodash_now) gof->arg = "";
// Option parsing is a two stage process: parse the option string into
// a struct opts list, then use that list to process argv[];
- toys.exithelp++;
// Allocate memory for optargs
saveflags = 0;
while (toys.argv[saveflags++]);
// Sanity check
if (toys.optc<gof.minargs)
- error_exit("Need%s %d argument%s", letters[!!(gof.minargs-1)],
+ help_exit("Need%s %d argument%s", letters[!!(gof.minargs-1)],
gof.minargs, letters[!(gof.minargs-1)]);
if (toys.optc>gof.maxargs)
- error_exit("Max %d argument%s", gof.maxargs, letters[!(gof.maxargs-1)]);
+ help_exit("Max %d argument%s", gof.maxargs, letters[!(gof.maxargs-1)]);
if (gof.requires && !(gof.requires & toys.optflags)) {
struct opts *req;
char needs[32], *s = needs;
if (req->flags & 1) *(s++) = req->c;
*s = 0;
- error_exit("Needs %s-%s", s[1] ? "one of " : "", needs);
+ help_exit("Needs %s-%s", s[1] ? "one of " : "", needs);
}
- toys.exithelp = 0;
if (CFG_TOYBOX_FREE) {
llist_traverse(gof.opts, free);
#include "toys.h"
#if !CFG_TOYBOX_HELP
-void show_help(void) {;}
+void show_help(FILE *out) {;}
#else
#include "generated/help.h"
#include "generated/newtoys.h"
;
-void show_help(void)
+void show_help(FILE *out)
{
int i = toys.which-toy_list;
char *s;
i = toy_find(++s)-toy_list;
}
- fprintf(toys.exithelp ? stderr : stdout, "%s", s);
+ fprintf(out, "%s", s);
}
#endif
if (msg) vfprintf(stderr, msg, va);
else s+=2;
if (err) fprintf(stderr, s, strerror(err));
- putc('\n', stderr);
+ if (msg || err) putc('\n', stderr);
if (!toys.exitval) toys.exitval++;
}
+// These functions don't collapse together because of the va_stuff.
+
void error_msg(char *msg, ...)
{
va_list va;
{
va_list va;
- if (CFG_TOYBOX_HELP && toys.exithelp) show_help();
+ va_start(va, msg);
+ verror_msg(msg, 0, va);
+ va_end(va);
+
+ xexit();
+}
+
+// Exit with an error message after showing help text.
+void help_exit(char *msg, ...)
+{
+ va_list va;
+
+ if (CFG_TOYBOX_HELP) show_help(stderr);
va_start(va, msg);
verror_msg(msg, 0, va);
// help.c
-void show_help(void);
+void show_help(FILE *out);
// xwrap.c
void xstrncpy(char *dest, char *src, size_t size);
void error_msg(char *msg, ...) printf_format;
void perror_msg(char *msg, ...) printf_format;
void error_exit(char *msg, ...) printf_format noreturn;
+void help_exit(char *msg, ...) printf_format noreturn;
void perror_exit(char *msg, ...) printf_format noreturn;
ssize_t readall(int fd, void *buf, size_t len);
ssize_t writeall(int fd, void *buf, size_t len);
if (CFG_TOYBOX_HELP_DASHDASH && argv[1] && !strcmp(argv[1], "--help")) {
if (CFG_TOYBOX && toys.which == toy_list && toys.argv[2])
if (!(toys.which = toy_find(toys.argv[2]))) return;
- show_help();
+ show_help(stdout);
xexit();
}
} else if (CFG_TOYBOX_DEBUG && uid && which != toy_list)
error_msg("Not installed suid root");
- if ((which->flags & TOYFLAG_NEEDROOT) && euid) {
- toys.exithelp++;
- error_exit("Not root");
- }
+ if ((which->flags & TOYFLAG_NEEDROOT) && euid) help_exit("Not root");
}
// Free old toys contents (to be reentrant), but leave rebound if any
// Humor toys.h
struct toy_context toys;
char libbuf[4096], toybuf[4096];
-void show_help(void) {;}
+void show_help(FILE *out) {;}
void toy_exec(char *argv[]) {;}
// Parse config files into data structures.
unsigned optflags; // Command line option flags from get_optflags()
int exitval; // Value error_exit feeds to exit()
int optc; // Count of optargs
- int exithelp; // Should error_exit print a usage message first?
int old_umask; // Old umask preserved by TOYFLAG_UMASK
int toycount; // Total number of commands in this build
int signal; // generic_signal() records what signal it saw here
}
}
- if (!(toys.optflags & FLAG_l) && !toys.optc) {
- toys.exithelp++;
- error_exit("no name");
- }
+ if (!(toys.optflags & FLAG_l) && !toys.optc) help_exit("no name");
TT.cur_pid = getpid();
char **ss;
long long val = 0;
- if (!toys.optflags) {
- toys.exithelp = 1;
- error_exit("need --option");
- }
+ if (!toys.optflags) help_exit("need --option");
for (ss = toys.optargs; *ss; ss++) {
int fd = xopen(*ss, O_RDONLY), i;
xprintf("<a name=\"%s\"><h1>%s</h1><blockquote><pre>\n", t->name, t->name);
toys.which = t;
- show_help();
+ show_help(stdout);
if (toys.optflags & FLAG_h) xprintf("</blockquote></pre>\n");
}
-// The simple help is just toys.which = toy_find("name"); show_help();
+// The simple help is just toys.which = toy_find("name"); show_help(stdout);
// But iterating through html output and all commands is a big more
void help_main(void)
p = ptr = toybuf;
}
}
- if (!sock->sa_family || !argv[1]) {
- toys.exithelp++;
- error_exit("bad hw '%s'", *argv);
- }
+ if (!sock->sa_family || !argv[1]) help_exit("bad hw '%s'", *argv);
hw_addr = *++argv;
// Parse and verify address.
} ifre6;
int plen, fd6 = xsocket(AF_INET6, SOCK_DGRAM, 0);
- if (!argv[1]) {
- toys.exithelp++;
- error_exit("%s", *argv);
- }
+ if (!argv[1]) help_exit("%s", *argv);
plen = get_addrinfo(argv[1], AF_INET6, &ifre6.addr);
if (plen < 0) plen = 128;
break;
}
- if (i == sizeof(try)/sizeof(*try)) {
- toys.exithelp++;
- error_exit("bad argument '%s'", *argv);
- }
+ if (i == sizeof(try)/sizeof(*try)) help_exit("bad argument '%s'", *argv);
}
close(TT.sockfd);
}
} else {
char *file = (toys.optflags & (FLAG_d|FLAG_c)) ? NULL : toys.optargs[1];
- if (!toys.optc || (file && toys.optc != 2)) {
- toys.exithelp++;
- perror_exit("needs %d arg%s", 1+!!file, file ? "s" : "");
- }
+ if (!toys.optc || (file && toys.optc != 2))
+ help_exit("needs %d arg%s", 1+!!file, file ? "s" : "");
for (s = toys.optargs; *s; s++) {
loopback_setup(*s, file);
if (file) break;
unsigned char vflag, recursive;
} chattr;
-static inline void chattr_help(void)
-{
- toys.exithelp++;
- error_exit("Invalid Argument");
-}
-
// Set file flags on a Linux second extended file system.
static inline int ext2_setflag(int fd, struct stat *sb, unsigned long flag)
{
for (; ptr->name; ptr++)
if (ptr->opt == ch) return ptr->flag;
- chattr_help(); // if no match found then Show help
- return 0; // silent warning.
+ help_exit("bad '%c'", ch);
}
// Parse command line argument and fill the chattr structure.
errno = 0;
arg = *(*argv += 1);
- if (!arg) chattr_help();
+ if (!arg) help_exit("bad -v");
if (*arg == '-') perror_exit("Invalid Number '%s'", arg);
chattr.version = strtoul(arg, &endptr, 0);
if (errno || *endptr) perror_exit("bad version '%s'", arg);
memset(&chattr, 0, sizeof(struct _chattr));
parse_cmdline_arg(&argv);
- if (!*argv) chattr_help();
+ if (!*argv) help_exit("no file");
if (chattr.set && (chattr.add || chattr.rm))
- error_exit("'=' is incompatible with '-' and '+'");
- if (chattr.rm & chattr.add) error_exit("Can't set and unset same flag.");
+ error_exit("no '=' with '-' or '+'");
+ if (chattr.rm & chattr.add) error_exit("set/unset same flag");
if (!(chattr.add || chattr.rm || chattr.set || chattr.vflag))
- error_exit(("Must use '-v', '=', '-' or '+'"));
+ error_exit("need '-v', '=', '-' or '+'");
for (; *argv; argv++) dirtree_read(*argv, update_attr);
toys.exitval = 0; //always set success at this point.
}
// The argument parsing logic can't make "<2" conditional on other
// arguments like -f and -l, so we do it by hand here.
- if (toys.optflags&FLAG_f) {
- if (toys.optc) toys.exithelp++;
- } else if (!(toys.optflags&(FLAG_l|FLAG_L)) && toys.optc!=2) toys.exithelp++;
-
- if (toys.exithelp) error_exit("Argument count wrong");
+ if ((toys.optflags&FLAG_f) ? toys.optc :
+ (!(toys.optflags&(FLAG_l|FLAG_L)) && toys.optc!=2))
+ help_exit("Argument count wrong");
if (TT.filename) pollfds[0].fd = xopen(TT.filename, O_RDWR);
else {
if (strcmp(t->cmd, *toys.optargs)) continue;
toys.optargs++, toys.optc--;
- if (toys.optc < t->nargs) {
- toys.exithelp++;
- error_exit("check args");
- }
+ if (toys.optc < t->nargs) help_exit("check args");
t->f(toys.optargs);
toys.optargs += t->nargs;
toys.optc -= t->nargs;
break;
}
- if (i == ARRAY_LEN(cc)) {
- toys.exithelp++;
- error_exit("invalid option '%s'", *toys.optargs);
- }
+ if (i == ARRAY_LEN(cc)) help_exit("invalid option '%s'", *toys.optargs);
}
xclose(TT.sockfd);
}
if (!toys.optc) {
if (!FLAG_elr) {
- if (toys.optflags & FLAG_u) {
- toys.exithelp++;
- error_exit("file name must be specified for replace");
- }
+ if (toys.optflags & FLAG_u)
+ help_exit("file name must be specified for replace");
do_replace(pwd->pw_name);
}
else if (toys.optflags & FLAG_e) do_edit(pwd);
else if (toys.optflags & FLAG_l) do_list(pwd->pw_name);
else if (toys.optflags & FLAG_r) do_remove(pwd->pw_name);
} else {
- if (FLAG_elr) {
- toys.exithelp++;
- error_exit("no arguments permitted after this option");
- }
+ if (FLAG_elr) help_exit("no arguments permitted after this option");
do_replace(pwd->pw_name);
}
if (!(toys.optflags & FLAG_c)) free(TT.cdir);
while (*toys.optargs) {
if (!(arg = strchr(*toys.optargs, '='))) error_exit("unknown arg %s", *toys.optargs);
*arg++ = '\0';
- if (!*arg) {
- toys.exithelp = 1;
- error_exit("");
- }
+ if (!*arg) help_exit(0);
key.name = *toys.optargs;
if (!(res = bsearch(&key, operands, ARRAY_LEN(operands), sizeof(struct pair),
comp))) error_exit("unknown arg %s", key.name);
if (ioctl(dev_fd, BLKSSZGET, &arg) == 0) g_sect_size = arg;
if (toys.optflags & FLAG_b) {
if (TT.sect_sz != 512 && TT.sect_sz != 1024 && TT.sect_sz != 2048 &&
- TT.sect_sz != 4096) {
- toys.exithelp++;
- error_exit("bad sector size");
+ TT.sect_sz != 4096)
+ {
+ help_exit("bad sector size");
}
g_sect_size = TT.sect_sz;
}
toys.exitval = 0;
return;
} else {
- if (!toys.optc || toys.optc > 1 ) {
- toys.exitval = toys.exithelp = 1;
- show_help();
- return;
- }
+ if (toys.optc != 1) help_exit(stdout);
if (read_mbr(toys.optargs[0], 1)) return;
while (1) {
xputc('\n');
struct group *grp = NULL;
char *entry = NULL;
- if (toys.optflags && toys.optc == 2) {
- toys.exithelp = 1;
- error_exit("options, user and group can't be together");
- }
+ if (toys.optflags && toys.optc == 2)
+ help_exit("options, user and group can't be together");
if (toys.optc == 2) { //add user to group
//toys.optargs[0]- user, toys.optargs[1] - group
return NULL;
}
-static void iphelp(void)
-{
- toys.exithelp = 1;
- error_exit(NULL);
-}
-
static void send_nlmesg(int type, int flags, int family,
void *buf, int blen)
{
for (; *argv; argv++) {
int param, proto;
- if ((idx = substring_to_idx(*argv++, vlan_optlist)) == -1) iphelp();
+ if ((idx = substring_to_idx(*argv++, vlan_optlist)) == -1) help_exit(0);
switch (idx) {
case 0: // ARG_id
- if (!*argv) iphelp();
+ if (!*argv) help_exit(0);
param = atolx(*argv);
add_string_to_rtattr(n, size, IFLA_VLAN_ID, ¶m, sizeof(param));
break;
case 1: // ARG_protocol
if (!*argv) error_exit("Invalid vlan id.");
- if ((idx = substring_to_idx(*argv, vlan_protolist)) == -1) iphelp();
+ if ((idx = substring_to_idx(*argv, vlan_protolist)) == -1) help_exit(0);
if (!idx) proto = ETH_P_8021Q; // PROTO_8021Q - 0
else if (idx == 1) proto = 0x88A8; // ETH Protocol - 8021AD
// IFLA VLAN PROTOCOL - 5
break;
case 2: // ARG_reorder_hdr
case 3: // ARG_gvrp
- if ((param = substring_to_idx(*argv, on_off)) == -1) iphelp();
+ if ((param = substring_to_idx(*argv, on_off)) == -1) help_exit(0);
flags.mask |= (idx -1); // VLAN FLAG REORDER Header
flags.flags &= ~(idx -1); // VLAN FLAG REORDER Header
fd = xsocket(AF_INET, SOCK_DGRAM, 0);
xioctl(fd, SIOCGIFINDEX, &req);
for (++argv; *argv;) {
- if ((idx = substring_to_idx(*argv++, cmd_objectlist)) == -1) iphelp();
+ if ((idx = substring_to_idx(*argv++, cmd_objectlist)) == -1) help_exit(0);
switch(idx) {
case 0:
flags |= IFF_UP; break;
case 2:
case 3:
case 4:
- if (!*argv) iphelp();
+ if (!*argv) help_exit(0);
else if (!strcmp(*argv, "on")) {
if (idx == 2) {
masks &= ~case_flags[idx-2];
masks |= case_flags[idx-2];
flags |= case_flags[idx-2];
} else masks &= ~case_flags[idx-2];
- } else iphelp();
+ } else help_exit(0);
++argv;
break;
case 5:
{"set", 1}, {"show", 2}, {"list", 2}, {"lst", 2}, {NULL,-1}};
if (!*argv) idx = 2;
- else if ((idx = substring_to_idx(*argv++, cmd_objectlist)) == -1) iphelp();
+ else if ((idx = substring_to_idx(*argv++, cmd_objectlist)) == -1)
+ help_exit(0);
ipcmd = cmdobjlist[idx];
return ipcmd(argv);
}
TT.is_addr++;
if (!*argv) idx = 1;
- else if ((idx = substring_to_idx(*argv++, cmd_objectlist)) == -1) iphelp();
+ else if ((idx = substring_to_idx(*argv++, cmd_objectlist)) == -1)
+ help_exit(0);
ipcmd = cmdobjlist[idx];
return ipcmd(argv);
struct arglist ip_aflist[] = {{"inet", AF_INET},
{"inet6", AF_INET6}, {"link", AF_PACKET}, {NULL, -1}};
- if (!*++optargv) iphelp();
+ if (!*++optargv) help_exit(0);
if ((TT.addressfamily = string_to_idx(*optargv, ip_aflist)) == -1)
error_exit("wrong family '%s'", *optargv);
}
case 2:
TT.stats++;
break;
- default: iphelp();
+ default: help_exit(0);
break; // unreachable code.
}
}
struct arglist ip_objectlist[] = { {"address", 0}, {"link", 1},
{"route", 2}, {"rule", 3}, {"tunnel", 4}, {"tunl", 4}, {NULL, -1}};
- if ((idx = substring_to_idx(*optargv, ip_objectlist)) == -1) iphelp();
+ if ((idx = substring_to_idx(*optargv, ip_objectlist)) == -1) help_exit(0);
ipcmd = cmdobjlist[idx];
toys.exitval = ipcmd(++optargv);
- } else iphelp();
+ } else help_exit(0);
} else {
struct arglist ip_objectlist[] = { {"ipaddr", 0}, {"iplink", 1},
{"iproute", 2}, {"iprule", 3}, {"iptunnel", 4}, {NULL, -1}};
if ((idx = string_to_idx(toys.which->name, ip_objectlist)) == -1)
- iphelp();
+ help_exit(0);
ipcmd = cmdobjlist[idx];
toys.exitval = ipcmd(optargv);
}
for (tmp = TT.qid; tmp; tmp = tmp->next) do_ipcrm(0, 2, tmp->arg);
for (tmp = TT.skey; tmp; tmp = tmp->next) do_ipcrm(1, 3, tmp->arg);
for (tmp = TT.sid; tmp; tmp = tmp->next) do_ipcrm(0, 3, tmp->arg);
- if (toys.optc) {
- toys.exithelp++;
- error_exit("unknown argument: %s", *toys.optargs);
- }
+ if (toys.optc) help_exit("unknown argument: %s", *toys.optargs);
}
}
if (flag(m)) show_shm_id();
else if (flag(s)) show_sem_id();
else if (flag(q)) show_msg_id();
- else {
- toys.exithelp++;
- error_exit(NULL);
- }
+ else help_exit(0);
return;
}
if ((toys.optc < 1) && (((flags & FLAG_r) && (flags & FLAG_l))
||(!((flags & FLAG_r)||(flags & FLAG_l)))))
{
- toys.exithelp++;
- error_exit("bad syntax");
+ help_exit("bad syntax");
}
// Check for -r flag without arg if yes then do auto remove.
if ((flags & FLAG_r) && !toys.optc) {
error_exit("Unknown signal '%s'", arg);
} else signum = SIGTERM;
}
- if (!(flag_chk(FLAG_s) || flag_chk(FLAG_P)) && !*toys.optargs) {
- toys.exithelp++;
- error_exit("missing argument");
- }
- if (*(toys.optargs+1) && !(flag_chk(FLAG_s) || flag_chk(FLAG_P))) {
- toys.exithelp++;
- error_exit("max argument > 1");
- }
+ if (!(flag_chk(FLAG_s) || flag_chk(FLAG_P)) && !*toys.optargs)
+ help_exit("missing argument");
+ if (*(toys.optargs+1) && !(flag_chk(FLAG_s) || flag_chk(FLAG_P)))
+ help_exit("max argument > 1");
if (*toys.optargs) { /* compile regular expression(PATTERN) */
if ((eval = regcomp(&rp, *toys.optargs, REG_EXTENDED | REG_NOSUB)) != 0) {
char errbuf[256];
#define INVALID_ADDR 0xffffffffUL
#define IPV6_ADDR_LEN 40 //32 + 7 (':') + 1 ('\0')
-#define TEST_ARGV(argv) if (!*argv) show_route_help()
+#define TEST_ARGV(argv) if (!*argv) help_exit(0)
struct _arglist {
char *arg;
{ NULL, 0 }
};
-// display help info and exit.
-static void show_route_help(void)
-{
- toys.exithelp = 1;
- error_exit("Invalid Argument");
-}
-
// to get the host name from the given ip.
static int get_hostname(char *ipstr, struct sockaddr_in *sockin)
{
//when adding a network route, the netmask to be used.
struct sockaddr sock;
unsigned int addr_mask = (((struct sockaddr_in *)&((rt)->rt_genmask))->sin_addr.s_addr);
- if (addr_mask) show_route_help();
+ if (addr_mask) help_exit("dup netmask");
argv++;
TEST_ARGV(argv);
*netmask = *argv;
argv++;
} else if (ishost < 0) perror_exit("resolving '%s'", *argv);
else perror_exit("gateway '%s' is a NETWORK", *argv);
- } else show_route_help();
+ } else help_exit("dup gw");
} else if (!strcmp(*argv, "mss")) {
//set the TCP Maximum Segment Size for connections over this route.
argv++;
} else if (!strcmp(*argv, "reinstate")) {
rt->rt_flags |= RTF_REINSTATE;
argv++;
- } else show_route_help(); //No match found; exit form the application.
+ } else help_exit("no '%s'", *argv); //No match found; exit form the application.
}//end of while loop.
if (!rt->rt_dev && (rt->rt_flags & RTF_REJECT)) rt->rt_dev = (char *)"lo";
int is_net_or_host = 0, sokfd, arg2_action;
int action = get_action(&argv, arglist1); //verify the arg for add/del.
- if (!action || !*argv) show_route_help();
+ if (!action || !*argv) help_exit("setroute");
arg2_action = get_action(&argv, arglist2); //verify the arg for -net or -host
- if (!*argv) show_route_help();
+ if (!*argv) help_exit("setroute");
memset(&rt, 0, sizeof(struct rtentry));
targetip = *argv++;
rt->rtmsg_flags |= RTF_GATEWAY;
argv++;
} else perror_exit("resolving '%s'", *argv);
- } else show_route_help();
+ } else help_exit(0);
} else if (!strcmp(*argv, "dev")) {
argv++;
TEST_ARGV(argv);
} else if (!strcmp(*argv, "dyn")) {
rt->rtmsg_flags |= RTF_DYNAMIC;
argv++;
- } else show_route_help();
+ } else help_exit(0);
}//end of while loop.
}
char *targetip;
int sockfd, action = get_action(&argv, arglist1);
- if (!action || !*argv) show_route_help();
+ if (!action || !*argv) help_exit(0);
memset(&sock_in6, 0, sizeof(struct sockaddr_in6));
memset(&rt, 0, sizeof(struct in6_rtmsg));
targetip = *argv++;
if (action == 1) xioctl(sockfd, SIOCADDRT, &rt);
else xioctl(sockfd, SIOCDELRT, &rt);
xclose(sockfd);
- } else show_route_help();
+ } else help_exit(0);
}
/*
if (!*toys.optargs) {
if (!strcmp(TT.family, "inet")) display_routes();
else if (!strcmp(TT.family, "inet6")) display_routes6();
- else show_route_help();
+ else help_exit(0);
return;
}//End of if statement.
char *buf = toybuf;
memset(&srcaddr, 0, sizeof(srcaddr));
- if (getsockname(0, (struct sockaddr *)&srcaddr, &socklen)) {
- toys.exithelp = 1;
- error_exit(NULL);
- }
+ if (getsockname(0, (struct sockaddr *)&srcaddr, &socklen)) help_exit(0);
if (TT.user) TT.pw = xgetpwnam(TT.user);
if (*toys.optargs) xchroot(*toys.optargs);
// Act like groupadd?
if (toys.optc == 2) {
- if (toys.optflags) {
- toys.exithelp = 1;
- error_exit("options with USER GROUP");
- }
+ if (toys.optflags) help_exit("options with USER GROUP");
xexec((char *[]){"groupadd", toys.optargs[0], toys.optargs[1], 0});
}
} else {
// "<1" in optstr wouldn't cover this because "-SIGNAL"
- if (!*args) {
- toys.exithelp++;
- error_exit("missing argument");
- }
+ if (!*args) help_exit("missing argument");
while (*args) {
char *arg = *(args++);
name.</p></li>
<li><p>int <b>optc</b> - Optarg count, equivalent to argc but for
optargs[].<p></li>
-<li><p>int <b>exithelp</b> - Whether error_exit() should print a usage message
-via help_main() before exiting. (True during option parsing, defaults to
-false afterwards.)</p></li>
</ul>
<a name="toy_union" />