diff options
Diffstat (limited to 'usr/src/cmd/sgs/ar/common/main.c')
| -rw-r--r-- | usr/src/cmd/sgs/ar/common/main.c | 51 |
1 files changed, 41 insertions, 10 deletions
diff --git a/usr/src/cmd/sgs/ar/common/main.c b/usr/src/cmd/sgs/ar/common/main.c index e5667aa196..8a73d30209 100644 --- a/usr/src/cmd/sgs/ar/common/main.c +++ b/usr/src/cmd/sgs/ar/common/main.c @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ -/* All Rights Reserved */ +/* All Rights Reserved */ /* * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved. @@ -27,6 +27,7 @@ /* * Copyright (c) 2018, Joyent, Inc. + * Copyright 2021 Oxide Computer Company */ #include "inc.h" @@ -131,20 +132,12 @@ main(int argc, char **argv, char *envp[]) if (cmd_info->opt_flgs & z_FLAG) check_swap(); - if (cmd_info->comfun == NULL) { - if ((cmd_info->opt_flgs & (d_FLAG | r_FLAG | q_FLAG | - t_FLAG | p_FLAG | m_FLAG | x_FLAG)) == 0) { - (void) fprintf(stderr, MSG_INTL(MSG_USAGE_01)); - exit(1); - } - } - cmd_info->modified = (cmd_info->opt_flgs & s_FLAG); fd = getaf(cmd_info); if ((fd == -1) && (cmd_info->opt_flgs & - (d_FLAG | m_FLAG | p_FLAG | t_FLAG | x_FLAG)) || + (d_FLAG | m_FLAG | p_FLAG | s_FLAG | t_FLAG | x_FLAG)) || ((cmd_info->opt_flgs & r_FLAG) && (cmd_info->opt_flgs & (a_FLAG | b_FLAG)))) { (void) fprintf(stderr, MSG_INTL(MSG_NOT_FOUND_AR), @@ -315,6 +308,44 @@ setup(int argc, char *argv[], Cmd_info *cmd_info) cmd_info->arnam = argv[optind]; cmd_info->namv = &argv[optind+1]; cmd_info->namc = argc - optind - 1; + + /* + * GNU ar popularized the use of -s on its own which previously used to + * require another command function. As such, we don't set a command + * function when we encounter the -s flag because that might otherwise + * clobber an existing one being set and would interrupt the detection + * of multiple flags being used that way. + * + * If after processing everything, we find there's no command function + * set and the -s flag has been set, then we can finally set a command + * function. The command function for -t 'tcmd' is used in this case. It + * knows to only print out data if -t has been specified. + * + * While ar has not traditionally been very stringent about using flags + * in circumstances they aren't called for, we go ahead and check for + * that now for this newer option. + */ + if (cmd_info->comfun == NULL) { + if ((cmd_info->opt_flgs & s_FLAG) != 0) { + if ((cmd_info->opt_flgs & ~(s_FLAG | v_FLAG)) != 0) { + (void) fprintf(stderr, + MSG_INTL(MSG_USAGE_S_BAD_ARG)); + exit(1); + } + + if (cmd_info->namc > 1) { + (void) fprintf(stderr, + MSG_INTL(MSG_USAGE_S_EXTRA_AR)); + exit(1); + } + + setcom(cmd_info, tcmd); + } else if ((cmd_info->opt_flgs & (d_FLAG | r_FLAG | q_FLAG | + s_FLAG | t_FLAG | p_FLAG | m_FLAG | x_FLAG)) == 0) { + (void) fprintf(stderr, MSG_INTL(MSG_USAGE_01)); + exit(1); + } + } } |
