diff options
author | meem <none@none> | 2005-09-09 21:00:44 -0700 |
---|---|---|
committer | meem <none@none> | 2005-09-09 21:00:44 -0700 |
commit | 4b908718db419b27633010608bf691c20684c0e2 (patch) | |
tree | 7ac239f32940cc95c5aef491b38ef7677e31deee | |
parent | a135774b1295d1921bc186802675ec11220d6d27 (diff) | |
download | illumos-joyent-4b908718db419b27633010608bf691c20684c0e2.tar.gz |
6269723 gcc and if_mpadm don't get along
6273892 gcc and cmd/streams don't get along
6312414 cmd/streams/strcmd should be cstyle-clean, lint-clean, and linted nightly
6312419 if_mpadm should be lint-clean and linted nightly
-rw-r--r-- | usr/src/Makefile.lint | 1 | ||||
-rw-r--r-- | usr/src/cmd/cmd-inet/usr.sbin/Makefile | 3 | ||||
-rw-r--r-- | usr/src/cmd/cmd-inet/usr.sbin/if_mpadm.c | 64 | ||||
-rw-r--r-- | usr/src/cmd/streams/strcmd/Makefile | 11 | ||||
-rw-r--r-- | usr/src/cmd/streams/strcmd/strchg.c | 351 | ||||
-rw-r--r-- | usr/src/cmd/streams/strcmd/strconf.c | 177 |
6 files changed, 293 insertions, 314 deletions
diff --git a/usr/src/Makefile.lint b/usr/src/Makefile.lint index eac3e63f7e..64b5f838b0 100644 --- a/usr/src/Makefile.lint +++ b/usr/src/Makefile.lint @@ -235,6 +235,7 @@ COMMON_SUBDIRS = \ cmd/split \ cmd/ssh \ cmd/stat \ + cmd/streams/strcmd \ cmd/strings \ cmd/su \ cmd/sulogin \ diff --git a/usr/src/cmd/cmd-inet/usr.sbin/Makefile b/usr/src/cmd/cmd-inet/usr.sbin/Makefile index fcf7f574b1..457e94cea6 100644 --- a/usr/src/cmd/cmd-inet/usr.sbin/Makefile +++ b/usr/src/cmd/cmd-inet/usr.sbin/Makefile @@ -80,7 +80,7 @@ MSGSUBDIRS= bootconfchk htable ifconfig in.ftpd in.routed in.talkd \ # lint-clean. LINTCLEAN= 6to4relay arp ikeadm in.rlogind in.rshd in.telnetd in.tftpd \ ipaddrsel ipsecalgs ipseckey ipsecconf route routeadm \ - in.rarpd $(SYNCPROG) + in.rarpd if_mpadm $(SYNCPROG) # Likewise, as subdirs get lint-clean, add them here. Once # they're all clean, replace the dependency of the lint target # with SUBDIRS. Also (sigh) deal with the commented-out build lines @@ -239,6 +239,7 @@ lint: $(LINTSUBDIRS) -I$(SRC)/lib/gss_mechs/mech_krb5/include \ -I$(SRC)/lib/pam_modules/krb5 \ in.telnetd.c $(LDLIBS) -lbsm -lpam -lsocket -lnsl + $(LINT.c) if_mpadm.c $(LDLIBS) -lsocket -lnsl -lipmp $(LINT.c) ipaddrsel.c $(LDLIBS) -lsocket -lnsl $(LINT.c) ipsecalgs.c $(LDLIBS) -lsocket -lnsl -lipsecutil $(LINT.c) ipsecconf.c $(LDLIBS) -lsocket -lnsl -lipsecutil diff --git a/usr/src/cmd/cmd-inet/usr.sbin/if_mpadm.c b/usr/src/cmd/cmd-inet/usr.sbin/if_mpadm.c index fc703c7b2e..d4874135fd 100644 --- a/usr/src/cmd/cmd-inet/usr.sbin/if_mpadm.c +++ b/usr/src/cmd/cmd-inet/usr.sbin/if_mpadm.c @@ -20,7 +20,7 @@ * CDDL HEADER END */ /* - * Copyright 2000-2003 Sun Microsystems, Inc. All rights reserved. + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -54,7 +54,7 @@ static boolean_t offline_set(char *ifname); static void usage() { - fprintf(stderr, "Usage : if_mpadm [-d | -r] <interface_name>\n"); + (void) fprintf(stderr, "Usage : if_mpadm [-d | -r] <interface_name>\n"); } static void @@ -88,6 +88,7 @@ print_mpathd_error_msg(uint32_t error) } } +int main(int argc, char **argv) { char *ifname; @@ -105,8 +106,8 @@ main(int argc, char **argv) ifname = optarg; cmd = MI_OFFLINE; if (offline_set(ifname)) { - fprintf(stderr, gettext("Interface already " - "offlined\n")); + (void) fprintf(stderr, gettext("Interface " + "already offlined\n")); exit(1); } break; @@ -114,7 +115,7 @@ main(int argc, char **argv) ifname = optarg; cmd = MI_UNDO_OFFLINE; if (!offline_set(ifname)) { - fprintf(stderr, gettext("Interface not " + (void) fprintf(stderr, gettext("Interface not " "offlined\n")); exit(1); } @@ -208,8 +209,9 @@ send_cmd(int cmd, char *ifname) if (s == -1) { s = connect_to_mpathd(AF_INET6); if (s == -1) { - fprintf(stderr, gettext("Cannot establish " - "communication with in.mpathd.\n")); + (void) fprintf(stderr, gettext("Cannot " + "establish communication with " + "in.mpathd.\n")); exit(1); } } @@ -225,7 +227,7 @@ send_cmd(int cmd, char *ifname) /* errno is set only when ret is -1 */ if (ret == -1) perror("write"); - fprintf(stderr, gettext("Failed to " + (void) fprintf(stderr, gettext("Failed to " "successfully send command to " "in.mpathd.\n")); exit(1); @@ -241,14 +243,14 @@ send_cmd(int cmd, char *ifname) /* errno is set only when ret is -1 */ if (ret == -1) perror("write"); - fprintf(stderr, gettext("Failed to " + (void) fprintf(stderr, gettext("Failed to " "successfully send command to " "in.mpathd.\n")); exit(1); } break; default : - fprintf(stderr, "Unknown command \n"); + (void) fprintf(stderr, "Unknown command \n"); exit(1); } @@ -258,8 +260,8 @@ send_cmd(int cmd, char *ifname) /* errno is set only when ret is -1 */ if (ret == -1) perror("read"); - fprintf(stderr, gettext("Failed to successfully read " - "result from in.mpathd.\n")); + (void) fprintf(stderr, gettext("Failed to successfully " + "read result from in.mpathd.\n")); exit(1); } if (me.me_mpathd_error == 0) { @@ -268,7 +270,8 @@ send_cmd(int cmd, char *ifname) * We retried at least once. Tell the user * that things succeeded now. */ - fprintf(stderr, gettext("Retry Successful.\n")); + (void) fprintf(stderr, + gettext("Retry Successful.\n")); } return; /* Successful */ } @@ -277,7 +280,8 @@ send_cmd(int cmd, char *ifname) if (me.me_sys_error == EAGAIN) { (void) close(s); (void) sleep(1); - fprintf(stderr, gettext("Retrying ...\n")); + (void) fprintf(stderr, + gettext("Retrying ...\n")); continue; /* Retry */ } errno = me.me_sys_error; @@ -292,7 +296,8 @@ send_cmd(int cmd, char *ifname) * times and did not succeed. Let the user try it again * later. */ - fprintf(stderr, gettext("Device busy. Retry the operation later.\n")); + (void) fprintf(stderr, + gettext("Device busy. Retry the operation later.\n")); exit(1); } @@ -317,8 +322,8 @@ do_offline(char *ifname) * Verify whether IFF_OFFLINE is not set as a sanity check. */ if (!offline_set(ifname)) { - fprintf(stderr, gettext("Operation failed : in.mpathd has " - "not set IFF_OFFLINE on %s\n"), ifname); + (void) fprintf(stderr, gettext("Operation failed : in.mpathd " + "has not set IFF_OFFLINE on %s\n"), ifname); exit(1); } /* @@ -349,7 +354,7 @@ do_offline(char *ifname) } numifs = lifn.lifn_count; - buf = (char *)calloc(numifs, sizeof (struct lifreq)); + buf = calloc(numifs, sizeof (struct lifreq)); if (buf == NULL) { perror("calloc"); exit(1); @@ -382,8 +387,8 @@ do_offline(char *ifname) else ret = if_down(ifsock_v6, &lifr); if (ret != 0) { - fprintf(stderr, gettext("Bringing down the " - "interfaces failed.\n")); + (void) fprintf(stderr, gettext("Bringing down " + "the interfaces failed.\n")); exit(1); } } @@ -411,8 +416,8 @@ undo_offline(char *ifname) * Verify whether IFF_OFFLINE is set as a sanity check. */ if (offline_set(ifname)) { - fprintf(stderr, gettext("Operation failed : in.mpathd has " - "not cleared IFF_OFFLINE on %s\n"), ifname); + (void) fprintf(stderr, gettext("Operation failed : in.mpathd " + "has not cleared IFF_OFFLINE on %s\n"), ifname); exit(1); } /* @@ -443,7 +448,7 @@ undo_offline(char *ifname) } numifs = lifn.lifn_count; - buf = (char *)calloc(numifs, sizeof (struct lifreq)); + buf = calloc(numifs, sizeof (struct lifreq)); if (buf == NULL) { perror("calloc"); exit(1); @@ -477,8 +482,8 @@ undo_offline(char *ifname) else ret = if_up(ifsock_v6, &lifr); if (ret != 0) { - fprintf(stderr, gettext("Bringing up the " - "interfaces failed.\n")); + (void) fprintf(stderr, gettext("Bringing up " + "the interfaces failed.\n")); exit(1); } } @@ -577,8 +582,8 @@ if_down(int ifsock, struct lifreq *lifr) /* IFF_OFFLINE was set to start with. Is it still there ? */ if (!(lifr->lifr_flags & (IFF_OFFLINE))) { - fprintf(stderr, gettext("IFF_OFFLINE disappeared on %s\n"), - lifr->lifr_name); + (void) fprintf(stderr, gettext("IFF_OFFLINE disappeared on " + "%s\n"), lifr->lifr_name); return (-1); } lifr->lifr_flags &= ~IFF_UP; @@ -649,7 +654,7 @@ if_up(int ifsock, struct lifreq *lifr) * When a data address associated with the physical interface itself * is failed over (e.g., qfe0, rather than qfe0:1), the kernel must * fill the ipif data structure for qfe0 with a placeholder entry (the - * "replacement ipif"). Replacement ipif's cannot be brought IFF_UP + * "replacement ipif"). Replacement ipif's cannot be brought IFF_UP * (nor would it make any sense to do so), so we must be careful to * skip them; thankfully they can be easily identified since they * all have a zeroed address. @@ -659,7 +664,8 @@ if_up(int ifsock, struct lifreq *lifr) /* IFF_OFFLINE was not set to start with. Is it there ? */ if (lifr->lifr_flags & IFF_OFFLINE) { - fprintf(stderr, gettext("IFF_OFFLINE set wrongly on %s\n"), + (void) fprintf(stderr, + gettext("IFF_OFFLINE set wrongly on %s\n"), lifr->lifr_name); return (-1); } diff --git a/usr/src/cmd/streams/strcmd/Makefile b/usr/src/cmd/streams/strcmd/Makefile index f9d2d1cd4b..d286ee1246 100644 --- a/usr/src/cmd/streams/strcmd/Makefile +++ b/usr/src/cmd/streams/strcmd/Makefile @@ -19,14 +19,13 @@ # # CDDL HEADER END # +# ident "%Z%%M% %I% %E% SMI" # -#ident "%Z%%M% %I% %E% SMI" -# -# Copyright (c) 1989 by Sun Microsystems, Inc. +# Copyright 2005 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. # PROG= strchg strconf -SRCS= $(PROG:%=%.c) include ../../Makefile.cmd @@ -41,6 +40,8 @@ install: all $(ROOTPROG) clean: -lint: lint_SRCS +lint: + $(LINT.c) strchg.c + $(LINT.c) strconf.c include ../../Makefile.targ diff --git a/usr/src/cmd/streams/strcmd/strchg.c b/usr/src/cmd/streams/strcmd/strchg.c index 0d69750de0..516808d034 100644 --- a/usr/src/cmd/streams/strcmd/strchg.c +++ b/usr/src/cmd/streams/strcmd/strchg.c @@ -19,13 +19,18 @@ * * CDDL HEADER END */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ +#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.6 */ -#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.6 */ - -/* +/* * Streams Command strchg: change the configuration of the * stream associated with stdin. * @@ -54,24 +59,28 @@ */ -#include <stdio.h> -#include <sys/stropts.h> -#include <sys/termio.h> -#include <sys/types.h> -#include <sys/stat.h> +#include <stdio.h> +#include <sys/stropts.h> +#include <sys/termio.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <string.h> +#include <stdlib.h> +#include <unistd.h> -#define FALSE 0 +#define FALSE 0 #define TRUE 1 -#define SUCCESS 0 -#define FAILURE 1 +#define SUCCESS 0 +#define FAILURE 1 #define NMODULES 16 /* "reasonable" # of modules to push */ /* (can push more if you like) */ #define MAXMODULES 2048 /* max # of modules to push */ #define OPTLIST "af:h:pu:" -#define USAGE "Usage:\t%s -h module1[,module2 ... ]\n\t%s -f file\n\t%s -p [-a | -u module ]\n" +#define USAGE "Usage:\t%s -h module1[,module2 ... ]\n\t%s -f file"\ + "\n\t%s -p [-a | -u module ]\n" #define ERR_USAGE 1 /* bad invocation */ #define ERR_MODULE 2 /* bad module name(s) or too many modules */ @@ -81,29 +90,18 @@ #define ERR_PERM 6 /* not owner or superuser */ #define STDIN 0 -#define CNULL (char *)NULL -#define SAME 0 /* return from str[n]cmp if match */ -static char *Cmd_namep; /* how was it invoked? */ +static char *Cmd_namep; /* how was it invoked? */ static struct str_mlist Oldmods[NMODULES]; /* modlist for Oldlist */ static struct str_list Oldlist; /* original modules */ -extern char *strncpy(); -extern char *strtok(); -extern int getopt(); -extern unsigned short geteuid(); -extern int ioctl(); -extern int strncmp(); -extern void perror(); - -static int pop_modules(); /* pop 'n' modules */ -static int push_module(); /* push a module */ -static int more_modules(); /* increase size of mod lists */ -static void restore(); /* restore state of stdin */ - -main( argc, argv) -int argc; -char *argv[]; +static int pop_modules(int); +static int push_module(const char *); +static int more_modules(struct str_list *, int); +static void restore(int, int); + +int +main(int argc, char **argv) { char buf[BUFSIZ]; /* input buffer */ char *file_namep; /* file from -f opt */ @@ -112,8 +110,8 @@ char *argv[]; FILE *fp; /* file pointer for -f file */ - register int i; /* loop index and junk var */ - register int j; /* loop index and junk var */ + int i; /* loop index and junk var */ + int j; /* loop index and junk var */ int euid; /* effective uid */ short error; /* TRUE if usage error */ @@ -124,15 +122,11 @@ char *argv[]; short popupto; /* TRUE if -p -u module */ short push; /* TRUE if -h mod1[,mod2 ...] */ - struct str_mlist - newmods[NMODULES];/* mod list for new list */ + struct str_mlist newmods[NMODULES]; /* mod list for new list */ struct stat stats; /* stream stats */ struct str_list newlist; /* modules to be pushed */ struct termio termio; /* save state of tty */ - extern char *optarg; /* for getopt() */ - extern int optind; /* for getopt() */ - /* * init */ @@ -147,17 +141,17 @@ char *argv[]; /* * only owner and root can change stream configuration */ - if ( (euid = geteuid()) != 0 ) { - if ( fstat(0, &stats) < 0 ) { + if ((euid = geteuid()) != 0) { + if (fstat(0, &stats) < 0) { perror("fstat"); (void) fprintf(stderr, "%s: fstat of stdin failed\n", Cmd_namep); - return(ERR_STDIN); + return (ERR_STDIN); } - if ( euid != stats.st_uid ) { + if (euid != stats.st_uid) { (void) fprintf(stderr, "%s: not owner of stdin\n", Cmd_namep); - return(ERR_PERM); + return (ERR_PERM); } } @@ -166,24 +160,24 @@ char *argv[]; * parse args */ - if ( argc == 1 ) { + if (argc == 1) { (void) fprintf(stderr, USAGE, Cmd_namep, Cmd_namep, Cmd_namep); - return(ERR_USAGE); + return (ERR_USAGE); } - while ( !error && (i = getopt( argc, argv, OPTLIST)) != -1 ) { + while (!error && (i = getopt(argc, argv, OPTLIST)) != -1) { switch (i) { case 'a': /* pop All */ - if ( fromfile || popupto || push ) + if (fromfile || popupto || push) error = TRUE; else popall = TRUE; break; - case 'f': /* read from File*/ - if ( pop || push ) + case 'f': /* read from File */ + if (pop || push) error = TRUE; else { fromfile = TRUE; @@ -192,7 +186,7 @@ char *argv[]; break; case 'h': /* pusH */ - if ( fromfile || pop ) + if (fromfile || pop) error = TRUE; else { push = TRUE; @@ -201,14 +195,14 @@ char *argv[]; break; case 'p': /* poP */ - if ( fromfile || push ) + if (fromfile || push) error = TRUE; else pop = TRUE; break; case 'u': /* pop Upto */ - if ( fromfile || popall || push ) + if (fromfile || popall || push) error = TRUE; else { popupto = TRUE; @@ -219,56 +213,55 @@ char *argv[]; default: (void) fprintf(stderr, USAGE, Cmd_namep, Cmd_namep, Cmd_namep); - return(ERR_USAGE); + return (ERR_USAGE); /*NOTREACHED*/ } } - if ( error || optind < argc ) { + if (error || optind < argc) { (void) fprintf(stderr, USAGE, Cmd_namep, Cmd_namep, Cmd_namep); - return(ERR_USAGE); + return (ERR_USAGE); } - if ( !pop && ( popall || popupto ) ) { + if (!pop && (popall || popupto)) { (void) fprintf(stderr, - "%s: -p option must be used with -a or -u to pop modules\n", - Cmd_namep); + "%s: -p option must be used with -a or -u to pop modules\n", + Cmd_namep); (void) fprintf(stderr, USAGE, Cmd_namep, Cmd_namep, Cmd_namep); - return(ERR_USAGE); + return (ERR_USAGE); } /* * Save state so can restore if something goes wrong - * (If are only going to push modules, don't need to + * (If are only going to push modules, don't need to * save original module list for restore.) */ - if ( fromfile || pop ) { + if (fromfile || pop) { /* * get number of modules on stream * allocate more room if needed */ - if ( (i = ioctl(STDIN, I_LIST, (struct str_list *)NULL)) - < 0 ) { + if ((i = ioctl(STDIN, I_LIST, NULL)) < 0) { perror("I_LIST"); (void) fprintf(stderr, "%s: I_LIST ioctl failed\n", Cmd_namep); - return(ERR_STDIN); + return (ERR_STDIN); } - if ( i > Oldlist.sl_nmods ) - if ( more_modules(&Oldlist, i) != SUCCESS ) - return(ERR_MEM); + if (i > Oldlist.sl_nmods && + more_modules(&Oldlist, i) != SUCCESS) + return (ERR_MEM); /* * get list of modules on stream */ Oldlist.sl_nmods = i; - if ( ioctl(STDIN, I_LIST, &Oldlist) < 0 ) { + if (ioctl(STDIN, I_LIST, &Oldlist) < 0) { perror("I_LIST"); (void) fprintf(stderr, "%s: I_LIST ioctl failed\n", Cmd_namep); - return(ERR_STDIN); + return (ERR_STDIN); } /* @@ -277,7 +270,7 @@ char *argv[]; * if the strchg -h or -f options failed due to * specifying invalid module names for pushing */ - if (ioctl(STDIN, TCGETA, &termio) >= 0 ) + if (ioctl(STDIN, TCGETA, &termio) >= 0) is_a_tty = TRUE; } @@ -285,195 +278,192 @@ char *argv[]; /* * push modules on stream */ - if ( push ) { + if (push) { /* * pull mod names out of comma-separated list */ - for ( i = 0, modp = strtok(modnamep, ","); - modp != CNULL; ++i, modp = strtok(CNULL, ",") ) { - if ( push_module(modp) == FAILURE) { + for (i = 0, modp = strtok(modnamep, ","); + modp != NULL; ++i, modp = strtok(NULL, ",")) { + if (push_module(modp) == FAILURE) { /* pop the 'i' modules we just added */ restore(i, 0); - return(ERR_STDIN); + return (ERR_STDIN); } } - return(SUCCESS); + return (SUCCESS); } /* * read configuration from a file */ - if ( fromfile ) { + if (fromfile) { - if ( (fp = fopen(file_namep, "r")) == (FILE *)NULL ) { + if ((fp = fopen(file_namep, "r")) == NULL) { perror("fopen"); (void) fprintf(stderr, "%s: could not open file '%s'\n", Cmd_namep, file_namep); - return(ERR_OPEN); + return (ERR_OPEN); } /* * read file and construct a new strlist */ i = 0; - while ( fgets(buf, BUFSIZ, fp) != CNULL ) { + while (fgets(buf, BUFSIZ, fp) != NULL) { - if ( buf[0] == '#' ) + if (buf[0] == '#') continue; /* skip comments */ /* * skip trailing newline, trailing and leading * whitespace */ - if ( (modp = strtok(buf, " \t\n")) == CNULL ) + if ((modp = strtok(buf, " \t\n")) == NULL) continue; /* blank line */ - (void)strncpy(newlist.sl_modlist[i].l_name, - modp, FMNAMESZ); + (void) strncpy(newlist.sl_modlist[i].l_name, + modp, FMNAMESZ); ++i; - if ( (modp = strtok(CNULL, " \t\n")) != CNULL ) { + if ((modp = strtok(NULL, " \t\n")) != NULL) { /* - * bad format + * bad format * should only be one name per line */ (void) fprintf(stderr, - "%s: error on line %d in file %s: multiple module names??\n", - Cmd_namep, i, file_namep); - return(ERR_MODULE); + "%s: error on line %d in file %s: " + "multiple module names??\n", + Cmd_namep, i, file_namep); + return (ERR_MODULE); } - if ( i > newlist.sl_nmods ) - if ( more_modules(&newlist, i) != SUCCESS ) - return(ERR_MEM); + if (i > newlist.sl_nmods) + if (more_modules(&newlist, i) != SUCCESS) + return (ERR_MEM); } newlist.sl_nmods = i; /* * If an empty file, exit silently */ - if ( i == 0 ) - return(SUCCESS); + if (i == 0) + return (SUCCESS); - /* + /* * Pop all modules currently on the stream. */ - - if ( (i = pop_modules(Oldlist.sl_nmods - 1)) - != (Oldlist.sl_nmods - 1) ) { + if ((i = pop_modules(Oldlist.sl_nmods - 1)) + != (Oldlist.sl_nmods - 1)) { /* put back whatever we've popped */ restore(0, i); - return(ERR_STDIN); + return (ERR_STDIN); } /* * Push new modules */ - for ( i = newlist.sl_nmods - 1; i >= 0; --i ) { - - if ( push_module(newlist.sl_modlist[i].l_name) - == FAILURE ) { + for (i = newlist.sl_nmods - 1; i >= 0; --i) { + if (push_module(newlist.sl_modlist[i].l_name) == + FAILURE) { /* * pop whatever new modules we've pushed * then push old module list back on */ restore((newlist.sl_nmods - 1 - i), - (Oldlist.sl_nmods - 1)); + (Oldlist.sl_nmods - 1)); /* * If the stream is a tty line, at least try * to set the state to what it was before. */ - if ( is_a_tty ) { - if ( ioctl(STDIN, TCSETA, &termio) < 0 ) { - perror("TCSETA"); - (void) fprintf(stderr, - "%s: WARNING: Could not restore the states of the terminal line discipline\n", - Cmd_namep); - } + if (is_a_tty && + ioctl(STDIN, TCSETA, &termio) < 0) { + perror("TCSETA"); + (void) fprintf(stderr, + "%s: WARNING: Could not restore " + "the states of the terminal line " + "discipline\n", Cmd_namep); } - return(ERR_STDIN); + return (ERR_STDIN); } - } - return(SUCCESS); + } + return (SUCCESS); } /* end if-fromfile */ /* * pop all modules (except driver) */ - if ( popall ) { - if ( Oldlist.sl_nmods > 1 ) { - if ( (i = pop_modules(Oldlist.sl_nmods - 1)) - != (Oldlist.sl_nmods - 1) ) { + if (popall) { + if (Oldlist.sl_nmods > 1) { + if ((i = pop_modules(Oldlist.sl_nmods - 1)) != + (Oldlist.sl_nmods - 1)) { restore(0, i); - return(ERR_STDIN); + return (ERR_STDIN); } } - return(SUCCESS); + return (SUCCESS); } /* * pop up to (but not including) a module */ - if ( popupto ) { + if (popupto) { /* * check that the module is in fact on the stream */ - for ( i = 0; i < Oldlist.sl_nmods; ++i ) - if ( strncmp(Oldlist.sl_modlist[i].l_name, modnamep, - FMNAMESZ) == SAME ) + for (i = 0; i < Oldlist.sl_nmods; ++i) + if (strncmp(Oldlist.sl_modlist[i].l_name, modnamep, + FMNAMESZ) == 0) break; - if ( i == Oldlist.sl_nmods ) { + if (i == Oldlist.sl_nmods) { /* no match found */ (void) fprintf(stderr, "%s: %s not found on stream\n", Cmd_namep, modnamep); - return(ERR_MODULE); + return (ERR_MODULE); } - if ( (j = pop_modules(i)) != i ) { + if ((j = pop_modules(i)) != i) { /* put back whatever we've popped */ restore(0, j); - return(ERR_STDIN); + return (ERR_STDIN); } - return(SUCCESS); + return (SUCCESS); } /* * pop the topmost module */ - if ( pop ) { - if ( Oldlist.sl_nmods > 1 ) - if ( pop_modules(1) != 1 ) + if (pop) { + if (Oldlist.sl_nmods > 1) + if (pop_modules(1) != 1) /* no need to restore */ - return(ERR_STDIN); - return(SUCCESS); + return (ERR_STDIN); + return (SUCCESS); } - /*NOTREACHED*/ + return (SUCCESS); } -/* +/* * pop_module(n) pop 'n' modules from stream * * returns # of modules popped */ static int -pop_modules(num_modules) -int num_modules; +pop_modules(int num_modules) { + int i; - register short i; /* the ubiquitous loop variable */ - - for ( i = 0; i < num_modules; i++ ) { - if ( ioctl(STDIN, I_POP, 0) < 0 ) { + for (i = 0; i < num_modules; i++) { + if (ioctl(STDIN, I_POP, 0) < 0) { perror("I_POP"); (void) fprintf(stderr, - "%s: I_POP ioctl failed\n", Cmd_namep); - return(i); + "%s: I_POP ioctl failed\n", Cmd_namep); + return (i); } } - return(i); + return (i); } /* @@ -482,14 +472,13 @@ int num_modules; * returns SUCCESS or FAILURE */ static int -push_module(modnamep) -char *modnamep; +push_module(const char *modnamep) { - if ( ioctl(STDIN, I_PUSH, modnamep) < 0 ) { + if (ioctl(STDIN, I_PUSH, modnamep) < 0) { perror("I_PUSH"); (void) fprintf(stderr, - "%s: I_PUSH ioctl of %s failed\n", Cmd_namep, modnamep); - return(FAILURE); + "%s: I_PUSH ioctl of %s failed\n", Cmd_namep, modnamep); + return (FAILURE); } return (SUCCESS); } @@ -503,33 +492,34 @@ char *modnamep; * */ static void -restore(npop, npush) -int npop; -int npush; +restore(int npop, int npush) { - register int i; + int i; - if ( (i = pop_modules(npop)) != npop ) { + if ((i = pop_modules(npop)) != npop) { (void) fprintf(stderr, - "%s: WARNING: could not restore state of stream\n", Cmd_namep); + "%s: WARNING: could not restore state of stream\n", + Cmd_namep); return; } - if ( npush >= Oldlist.sl_nmods ) { /* "cannot" happen */ + + if (npush >= Oldlist.sl_nmods) { /* "cannot" happen */ (void) fprintf(stderr, - "%s: internal logic error in restore\n", Cmd_namep); + "%s: internal logic error in restore\n", Cmd_namep); (void) fprintf(stderr, - "%s: WARNING: could not restore state of stream\n", Cmd_namep); + "%s: WARNING: could not restore state of stream\n", + Cmd_namep); return; } - for ( i = npush - 1; i >= 0; --i ) { - if ( push_module(Oldlist.sl_modlist[i].l_name) == FAILURE ) { + + for (i = npush - 1; i >= 0; --i) { + if (push_module(Oldlist.sl_modlist[i].l_name) == FAILURE) { (void) fprintf(stderr, - "%s: WARNING: could not restore state of stream\n", - Cmd_namep); + "%s: WARNING: could not restore state of stream\n", + Cmd_namep); return; } } - return; } /* @@ -539,35 +529,30 @@ int npush; */ static int -more_modules(listp, n) -struct str_list *listp; /* streams module list */ -int n; /* # of modules */ +more_modules(struct str_list *listp, int n) { - register int i; - register struct str_mlist *modp; + int i; + struct str_mlist *modp; - extern char *calloc(); - - if ( n > MAXMODULES ) { + if (n > MAXMODULES) { (void) fprintf(stderr, - "%s: too many modules (%d) -- max is %d\n", - Cmd_namep, n, MAXMODULES); - return(FAILURE); + "%s: too many modules (%d) -- max is %d\n", + Cmd_namep, n, MAXMODULES); + return (FAILURE); } - if ( (modp = (struct str_mlist *)calloc((unsigned)n, - (unsigned)sizeof(struct str_mlist))) == (struct str_mlist *)NULL ) { + if ((modp = calloc(n, sizeof (struct str_mlist))) == NULL) { perror("calloc"); (void) fprintf(stderr, - "%s: failed to allocate space for module list\n", - Cmd_namep); - return(FAILURE); + "%s: failed to allocate space for module list\n", + Cmd_namep); + return (FAILURE); } - for ( i = 0; i < listp->sl_nmods; ++i ) + for (i = 0; i < listp->sl_nmods; ++i) (void) strncpy(modp[i].l_name, listp->sl_modlist[i].l_name, - FMNAMESZ); + FMNAMESZ); listp->sl_nmods = n; listp->sl_modlist = modp; - return(SUCCESS); + return (SUCCESS); } diff --git a/usr/src/cmd/streams/strcmd/strconf.c b/usr/src/cmd/streams/strcmd/strconf.c index 42771287b8..c666910a3c 100644 --- a/usr/src/cmd/streams/strcmd/strconf.c +++ b/usr/src/cmd/streams/strcmd/strconf.c @@ -19,12 +19,18 @@ * * CDDL HEADER END */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ +#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.5 */ -#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.5 */ -/* +/* * Streams Command strconf: display the configuration of the * stream associated with stdin. * @@ -48,15 +54,15 @@ #include <stdio.h> #include <sys/stropts.h> - -#define TRUE 1 -#define FALSE 0 +#include <string.h> +#include <stdlib.h> +#include <unistd.h> #define OPTLIST "m:t" -#define USAGE "USAGE: %s [ -m module | -t ]\n" +#define USAGE "USAGE: %s [ -m module | -t ]\n" -#define SUCCESS 0 -#define FAILURE 1 +#define SUCCESS 0 +#define FAILURE 1 #define ERR_USAGE 1 /* bad invocation */ #define ERR_MODULE 2 /* module not there */ @@ -67,134 +73,118 @@ /* (there can be more) */ #define MAXMODULES 2048 /* max # of modules */ -#define STDIN 0 -#define SAME 0 /* return from str[n]cmp if match */ - +static char *Cmd_namep; /* how was it invoked? */ +static int more_modules(struct str_list *, int); -static char *Cmd_namep; /* how was it invoked? */ - - -extern char *strcpy(); -extern int getopt(); -extern int ioctl(); -extern int strncmp(); - -static int more_modules(); /* increase size of mod list */ - -main( argc, argv) -int argc; -char *argv[]; +int +main(int argc, char **argv) { char *modp; /* ptr to module name */ - register int i; /* loop var & junk (what else?) */ - short mod_present; /* TRUE if -m module */ - short topmost; /* TRUE if -t */ - struct str_mlist - mlist[NMODULES];/* modlist for strlist */ + int i; /* loop var & junk (what else?) */ + boolean_t mod_present; /* B_TRUE if -m module */ + boolean_t topmost; /* B_TRUE if -t */ + struct str_mlist mlist[NMODULES]; /* modlist for strlist */ struct str_list strlist; /* mods on stream */ - extern char *optarg; /* for getopt() */ - extern int optind; /* for getopt() */ - /* * init */ Cmd_namep = argv[0]; - mod_present = topmost = FALSE; + mod_present = topmost = B_FALSE; strlist.sl_nmods = NMODULES; strlist.sl_modlist = mlist; /* * parse args */ - if ( argc > 1) { - while ( (i = getopt( argc, argv, OPTLIST)) != -1 ) { - switch( i) { - case 'm': /* module present ? */ - modp = optarg; - mod_present = TRUE; - break; - - case 't': /* list topmost */ - topmost = TRUE; - break; - - default: - (void) fprintf(stderr, USAGE, Cmd_namep); - return(ERR_USAGE); + if (argc > 1) { + while ((i = getopt(argc, argv, OPTLIST)) != -1) { + switch (i) { + case 'm': /* module present ? */ + modp = optarg; + mod_present = B_TRUE; + break; + + case 't': /* list topmost */ + topmost = B_TRUE; + break; + + default: + (void) fprintf(stderr, USAGE, Cmd_namep); + return (ERR_USAGE); } } - if ( optind < argc ) { + if (optind < argc) { (void) fprintf(stderr, USAGE, Cmd_namep); - return(ERR_USAGE); + return (ERR_USAGE); } } if (topmost && mod_present) { (void) fprintf(stderr, - "%s: [-t] and [-m] options cannot be used together\n", Cmd_namep); + "%s: [-t] and [-m] options cannot be used together\n", + Cmd_namep); (void) fprintf(stderr, USAGE, Cmd_namep); - return(ERR_USAGE); + return (ERR_USAGE); } /* * get number of modules on stream * allocate more room if needed */ - if ( (i = ioctl(STDIN, I_LIST, (struct str_list *)NULL)) - < 0 ) { + if ((i = ioctl(STDIN_FILENO, I_LIST, NULL)) < 0) { perror("I_LIST"); (void) fprintf(stderr, "%s: I_LIST ioctl failed\n", Cmd_namep); - return(ERR_STDIN); + return (ERR_STDIN); } - if ( i > strlist.sl_nmods ) - if ( more_modules(&strlist, i) != SUCCESS ) - return(ERR_MEM); + if (i > strlist.sl_nmods) + if (more_modules(&strlist, i) != SUCCESS) + return (ERR_MEM); /* * get list of modules on stream */ strlist.sl_nmods = i; - if ( ioctl (0, I_LIST, &strlist) < 0) { + if (ioctl(STDIN_FILENO, I_LIST, &strlist) < 0) { perror("I_LIST"); - (void) fprintf (stderr, "%s: I_LIST ioctl failed\n", Cmd_namep); - return(ERR_STDIN); + (void) fprintf(stderr, "%s: I_LIST ioctl failed\n", Cmd_namep); + return (ERR_STDIN); } /* * list topmost module */ - if ( topmost ) { - if ( strlist.sl_nmods >= 2 ) { - (void) printf("%s\n", strlist.sl_modlist[0].l_name); - return(SUCCESS); + if (topmost) { + if (strlist.sl_nmods >= 2) { + (void) puts(strlist.sl_modlist[0].l_name); + return (SUCCESS); } - return(ERR_MODULE); + return (ERR_MODULE); } /* * check if module is present */ - if ( mod_present ) { - for ( i = 0; i < strlist.sl_nmods; i++ ) { - if ( strncmp(modp, strlist.sl_modlist[i].l_name, - FMNAMESZ) == SAME ) { - (void) printf("yes\n"); - return(SUCCESS); + if (mod_present) { + for (i = 0; i < strlist.sl_nmods; i++) { + if (strncmp(modp, strlist.sl_modlist[i].l_name, + FMNAMESZ) == 0) { + (void) puts("yes"); + return (SUCCESS); } } - (void) printf("no\n"); - return(ERR_MODULE); + (void) puts("no"); + return (ERR_MODULE); } /* * print names of all modules and topmost driver on stream */ - for ( i = 0; i < strlist.sl_nmods; i++ ) - (void) printf("%s\n", strlist.sl_modlist[i].l_name); - return(SUCCESS); + for (i = 0; i < strlist.sl_nmods; i++) + (void) puts(strlist.sl_modlist[i].l_name); + return (SUCCESS); } /* @@ -204,35 +194,30 @@ char *argv[]; */ static int -more_modules(listp, n) -struct str_list *listp; /* streams module list */ -int n; /* # of modules */ +more_modules(struct str_list *listp, int n) { - register int i; - register struct str_mlist *modp; - - extern char *calloc(); + int i; + struct str_mlist *modp; - if ( n > MAXMODULES ) { + if (n > MAXMODULES) { (void) fprintf(stderr, - "%s: too many modules (%d) -- max is %d\n", - Cmd_namep, n, MAXMODULES); - return(FAILURE); + "%s: too many modules (%d) -- max is %d\n", + Cmd_namep, n, MAXMODULES); + return (FAILURE); } - if ( (modp = (struct str_mlist *)calloc((unsigned)n, - (unsigned)sizeof(struct str_mlist))) == (struct str_mlist *)NULL ) { + if ((modp = calloc(n, sizeof (struct str_mlist))) == NULL) { perror("calloc"); (void) fprintf(stderr, - "%s: failed to allocate space for module list\n", - Cmd_namep); - return(FAILURE); + "%s: failed to allocate space for module list\n", + Cmd_namep); + return (FAILURE); } - for ( i = 0; i < listp->sl_nmods; ++i ) + for (i = 0; i < listp->sl_nmods; ++i) (void) strncpy(modp[i].l_name, listp->sl_modlist[i].l_name, - FMNAMESZ); + FMNAMESZ); listp->sl_nmods = n; listp->sl_modlist = modp; - return(SUCCESS); + return (SUCCESS); } |