diff options
author | as145665 <none@none> | 2007-08-01 09:39:28 -0700 |
---|---|---|
committer | as145665 <none@none> | 2007-08-01 09:39:28 -0700 |
commit | 3d63ea05cb8474d8036d3588cf8299306a994b8c (patch) | |
tree | 6999ef2c95264a88b5563aae521c2147f6a0f557 /usr | |
parent | eb7b3d20d8e5dd688cd7c5f0bc3d4469e92e1c7b (diff) | |
download | illumos-gate-3d63ea05cb8474d8036d3588cf8299306a994b8c.tar.gz |
6214247 Solaris 10_74 L1: problem when running commmands in interactive mode on solaris
6528610 xargs -p does not work in some locales
Diffstat (limited to 'usr')
-rw-r--r-- | usr/src/cmd/compress/Makefile | 26 | ||||
-rw-r--r-- | usr/src/cmd/compress/compress.c | 243 | ||||
-rw-r--r-- | usr/src/cmd/cron/Makefile | 45 | ||||
-rw-r--r-- | usr/src/cmd/cron/atq.c | 10 | ||||
-rw-r--r-- | usr/src/cmd/cron/atrm.c | 46 | ||||
-rw-r--r-- | usr/src/cmd/cron/cron.h | 8 | ||||
-rw-r--r-- | usr/src/cmd/cron/cron.xcl | 20 | ||||
-rw-r--r-- | usr/src/cmd/cron/crontab.c | 67 | ||||
-rw-r--r-- | usr/src/cmd/find/Makefile | 43 | ||||
-rw-r--r-- | usr/src/cmd/find/find.c | 45 | ||||
-rw-r--r-- | usr/src/cmd/mv/Makefile | 40 | ||||
-rw-r--r-- | usr/src/cmd/mv/mv.c | 111 | ||||
-rw-r--r-- | usr/src/cmd/mv/mv.xcl | 15 | ||||
-rw-r--r-- | usr/src/cmd/rm/Makefile | 35 | ||||
-rw-r--r-- | usr/src/cmd/rm/rm.c | 47 | ||||
-rw-r--r-- | usr/src/cmd/tar/Makefile | 19 | ||||
-rw-r--r-- | usr/src/cmd/tar/tar.c | 54 | ||||
-rw-r--r-- | usr/src/cmd/tar/tar.xcl | 92 | ||||
-rw-r--r-- | usr/src/cmd/xargs/Makefile | 24 | ||||
-rw-r--r-- | usr/src/cmd/xargs/xargs.c | 76 | ||||
-rw-r--r-- | usr/src/common/util/getresponse.c | 186 | ||||
-rw-r--r-- | usr/src/common/util/getresponse.h | 53 |
22 files changed, 803 insertions, 502 deletions
diff --git a/usr/src/cmd/compress/Makefile b/usr/src/cmd/compress/Makefile index 135dcad541..5fc1e35e42 100644 --- a/usr/src/cmd/compress/Makefile +++ b/usr/src/cmd/compress/Makefile @@ -1,10 +1,10 @@ # +# # CDDL HEADER START # # The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (the "License"). You may not use this file except in compliance -# with the License. +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. @@ -20,31 +20,45 @@ # CDDL HEADER END # # + #ident "%Z%%M% %I% %E% SMI" # -# Copyright 2005 Sun Microsystems, Inc. All rights reserved. +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # PROG= compress +SRCS= compress.c $(SRC)/common/util/getresponse.c +OBJS= compress.o getresponse.o include ../Makefile.cmd .KEEP_STATE: CFLAGS += $(CCVERBOSE) -CPPFLAGS += -D_FILE_OFFSET_BITS=64 +CPPFLAGS += -D_FILE_OFFSET_BITS=64 -I $(SRC)/common/util +LINTFLAGS += -u + LDLIBS += -lsec all: $(PROG) +%.o: $(SRC)/common/util/%.c + $(COMPILE.c) $(OUTPUT_OPTION) $< + $(POST_PROCESS_O) + +$(PROG): $(OBJS) + $(LINK.c) $(OBJS) -o $@ $(LDLIBS) + $(POST_PROCESS) + install: all $(ROOTPROG) $(RM) $(ROOTBIN)/uncompress $(ROOTBIN)/zcat $(LN) $(ROOTPROG) $(ROOTBIN)/uncompress $(LN) $(ROOTPROG) $(ROOTBIN)/zcat clean: + $(RM) $(OBJS) -lint: lint_PROG +lint: lint_SRCS include ../Makefile.targ diff --git a/usr/src/cmd/compress/compress.c b/usr/src/cmd/compress/compress.c index 03341add41..fd08c406b9 100644 --- a/usr/src/cmd/compress/compress.c +++ b/usr/src/cmd/compress/compress.c @@ -1,5 +1,5 @@ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -137,14 +137,8 @@ static char rcs_ident[] = #include <fcntl.h> #include <dirent.h> #include <aclutils.h> - -/* - * Multi-byte handling for 'y' or 'n' - */ -static char *yesstr; /* string contains int'l for "yes" */ -static char *nostr; /* string contains int'l for "yes" */ -static int ynsize = 0; /* # of (multi)bytes for "y" */ -static char *yesorno; /* int'l input for 'y' */ +#include <errno.h> +#include "getresponse.h" static int n_bits; /* number of bits/code */ static int maxbits = BITS; /* user settable max # bits/code */ @@ -342,7 +336,7 @@ main(int argc, char *argv[]) struct stat statbuf; struct stat ostatbuf; int ch; /* XCU4 */ - char *p, *yptr, *nptr; + char *p; extern int optind, optopt; extern char *optarg; int dash_count = 0; /* times "-" is on cmdline */ @@ -353,22 +347,12 @@ main(int argc, char *argv[]) #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */ #endif (void) textdomain(TEXT_DOMAIN); - /* Build multi-byte char for 'y' char */ - if ((yptr = nl_langinfo(YESSTR)) == NULL) - yptr = "y"; - - yesstr = (char *)malloc(strlen(yptr) + 1); - (void) strcpy(yesstr, yptr); - /* Build multi-byte char for 'n' char */ - if ((nptr = nl_langinfo(NOSTR)) == NULL) - nptr = "n"; - - nostr = (char *)malloc(strlen(nptr) + 1); - (void) strcpy(nostr, nptr); - /* Build multi-byte char for input char */ - yesorno = (char *)malloc((size_t)ynsize + 1); - ynsize = mblen(yesstr, strlen(yesstr)); + if (init_yes() < 0) { + (void) fprintf(stderr, gettext(ERR_MSG_INIT_YES), + strerror(errno)); + exit(1); + } /* This bg check only works for sh. */ if ((oldint = signal(SIGINT, SIG_IGN)) != SIG_IGN) { @@ -461,14 +445,14 @@ main(int argc, char *argv[]) p = optarg; if (!p) { (void) fprintf(stderr, gettext( - "Missing maxbits\n")); + "Missing maxbits\n")); Usage(); exit(1); } maxbits = strtoul(optarg, &p, 10); if (*p) { (void) fprintf(stderr, gettext( - "Missing maxbits\n")); + "Missing maxbits\n")); Usage(); exit(1); } @@ -484,7 +468,7 @@ main(int argc, char *argv[]) break; default: (void) fprintf(stderr, gettext( - "Unknown flag: '%c'\n"), optopt); + "Unknown flag: '%c'\n"), optopt); Usage(); exit(1); } @@ -497,7 +481,7 @@ main(int argc, char *argv[]) if (zcat_cmd && (Fflg | Cflg | cflg | bflg | qflg | dflg | nomagic)) { (void) fprintf(stderr, gettext( - "Invalid Option\n")); + "Invalid Option\n")); Usage(); exit(1); } @@ -517,8 +501,8 @@ main(int argc, char *argv[]) if (dash_count > 1) { (void) fprintf(stderr, - gettext("%s may only appear once in the file" - " list\n"), "\"-\""); + gettext("%s may only appear once in the file" + " list\n"), "\"-\""); exit(1); } @@ -529,8 +513,8 @@ main(int argc, char *argv[]) if (fileptr - filelist > 1 && cflg && !do_decomp) { (void) fprintf(stderr, - gettext("compress: only one file may be compressed" - " to stdout\n")); + gettext("compress: only one file may be compressed" + " to stdout\n")); exit(1); } @@ -544,13 +528,13 @@ main(int argc, char *argv[]) if ((infile = fopen("/dev/null", "r")) == NULL) { (void) fprintf(stderr, gettext("Error opening /dev/null for " - "input\n")); + "input\n")); exit(1); } if ((outfile = fopen("/dev/null", "w")) == NULL) { (void) fprintf(stderr, gettext("Error opening /dev/null for " - "output\n")); + "output\n")); exit(1); } @@ -587,12 +571,12 @@ main(int argc, char *argv[]) /* No .Z: tack one on */ if (strlcpy(tempname, *fileptr, - sizeof (tempname)) >= - sizeof (tempname)) { + sizeof (tempname)) >= + sizeof (tempname)) { (void) fprintf(stderr, gettext("%s: filename " - "too long\n"), - *fileptr); + "too long\n"), + *fileptr); perm_stat = 1; continue; } @@ -629,9 +613,9 @@ main(int argc, char *argv[]) (getc(inp) != (magic_header[1] & 0xFF))) { (void) fprintf(stderr, gettext( - "%s: not in compressed " - "format\n"), - *fileptr); + "%s: not in compressed " + "format\n"), + *fileptr); perm_stat = 1; continue; } @@ -650,11 +634,11 @@ main(int argc, char *argv[]) if (maxbits > BITS) { (void) fprintf(stderr, - gettext("%s: compressed " - "with %d bits, " - "can only handle" - " %d bits\n"), - *fileptr, maxbits, BITS); + gettext("%s: compressed " + "with %d bits, " + "can only handle" + " %d bits\n"), + *fileptr, maxbits, BITS); perm_stat = 1; continue; } @@ -664,12 +648,12 @@ main(int argc, char *argv[]) /* Generate output filename */ if (strlcpy(ofname, *fileptr, - sizeof (ofname)) >= + sizeof (ofname)) >= sizeof (ofname)) { (void) fprintf(stderr, - gettext("%s: filename " - "too long\n"), - *fileptr); + gettext("%s: filename " + "too long\n"), + *fileptr); perm_stat = 1; continue; } @@ -705,9 +689,9 @@ main(int argc, char *argv[]) if (strcmp(*fileptr + strlen(*fileptr) - 2, ".Z") == 0) { (void) fprintf(stderr, gettext( - "%s: already has .Z " - "suffix -- no change\n"), - *fileptr); + "%s: already has .Z " + "suffix -- no change\n"), + *fileptr); perm_stat = 1; continue; } @@ -750,18 +734,18 @@ main(int argc, char *argv[]) /* Generate output filename */ if (strlcpy(ofname, *fileptr, - sizeof (ofname)) >= - sizeof (ofname)) { + sizeof (ofname)) >= + sizeof (ofname)) { (void) fprintf(stderr, gettext("%s: filename " - "too long\n"), - *fileptr); + "too long\n"), + *fileptr); perm_stat = 1; continue; } if (addDotZ(ofname, - sizeof (ofname)) < 0) { + sizeof (ofname)) < 0) { perm_stat = 1; continue; } @@ -773,32 +757,25 @@ main(int argc, char *argv[]) if (!overwrite && !use_stdout) { if (stat(ofname, &ostatbuf) == 0) { - yesorno[ynsize] = (char)NULL; (void) fprintf(stderr, gettext( - "%s already exists;"), ofname); + "%s already exists;"), ofname); if (bgnd_flag == 0 && isatty(2)) { int cin; (void) fprintf(stderr, gettext( - " do you wish to overwr" - "ite %s (%s or %s)? "), - ofname, yesstr, nostr); + " do you wish to overwr" + "ite %s (%s or %s)? "), + ofname, yesstr, nostr); (void) fflush(stderr); - for (cin = 0; cin < LINE_MAX; - cin++) + for (cin = 0; cin < LINE_MAX; cin++) line[cin] = 0; (void) read(2, line, LINE_MAX); - (void) strncpy(yesorno, line, - ynsize); - if (!((strncmp(yesstr, yesorno, - ynsize) == 0) || - (yesorno[0] == 'y') || - (yesorno[0] == 'Y'))) { + if (yes_check(line) == 0) { (void) fprintf(stderr, - gettext( - "\tnot overwri" - "tten\n")); + gettext( + "\tnot overwri" + "tten\n")); continue; } } else { @@ -810,10 +787,10 @@ main(int argc, char *argv[]) */ (void) fprintf(stderr, gettext( - "%s: File exists, -f not" - " specified, and ru" - "nning in the backgro" - "und.\n"), *fileptr); + "%s: File exists, -f not" + " specified, and ru" + "nning in the backgro" + "und.\n"), *fileptr); perm_stat = 1; continue; } @@ -832,12 +809,12 @@ main(int argc, char *argv[]) precious = 0; if (!quiet) { (void) fprintf(stderr, "%s: ", - *fileptr); + *fileptr); newline_needed = 1; } } else if (!quiet && !do_decomp) { (void) fprintf(stderr, "%s: ", - *fileptr); + *fileptr); newline_needed = 1; } @@ -876,8 +853,8 @@ main(int argc, char *argv[]) if (ferror(inp) || jmpval == 2) { if (do_decomp) { (void) fprintf(stderr, gettext( - "uncompress: %s: corrupt" - " input\n"), *fileptr); + "uncompress: %s: corrupt" + " input\n"), *fileptr); } else { perror(*fileptr); } @@ -923,9 +900,9 @@ main(int argc, char *argv[]) if (!force && perm_stat == 0) { if (quiet) { (void) fprintf(stderr, gettext( - "%s: -- file " - "unchanged\n"), - *fileptr); + "%s: -- file " + "unchanged\n"), + *fileptr); } perm_stat = 2; @@ -950,7 +927,7 @@ cinterr(int hshift) { /* we have exceeded the hash table */ (void) fprintf(stderr, - "internal error: hashtable exceeded - hsize = %ld\n", hsize); + "internal error: hashtable exceeded - hsize = %ld\n", hsize); (void) fprintf(stderr, "hshift = %d, %d\n", hshift, (1 << hshift) -1); (void) fprintf(stderr, "maxbits = %d\n", maxbits); (void) fprintf(stderr, "n_bits = %d\n", n_bits); @@ -1010,7 +987,7 @@ compress() if ((putc(magic_header[0], outp) == EOF || putc(magic_header[1], outp) == EOF || putc((char)(maxbits | block_compress), - outp) == EOF) && + outp) == EOF) && ferror(outp)) { ioerror(); } @@ -1126,27 +1103,27 @@ compress() if (!quiet) { #ifdef DEBUG (void) fprintf(stderr, - "%lld chars in, %lld codes (%lld bytes) out, " - "compression factor: ", - (count_long)in_count, (count_long)out_count, - (count_long) bytes_out); + "%lld chars in, %lld codes (%lld bytes) out, " + "compression factor: ", + (count_long)in_count, (count_long)out_count, + (count_long) bytes_out); prratio(stderr, (count_long)in_count, - (count_long)bytes_out); + (count_long)bytes_out); (void) fprintf(stderr, "\n"); (void) fprintf(stderr, "\tCompression as in compact: "); prratio(stderr, - (count_long)in_count-(count_long)bytes_out, - (count_long)in_count); + (count_long)in_count-(count_long)bytes_out, + (count_long)in_count); (void) fprintf(stderr, "\n"); (void) fprintf(stderr, - "\tLargest code (of last block) was %d" - " (%d bits)\n", - free_ent - 1, n_bits); + "\tLargest code (of last block) was %d" + " (%d bits)\n", + free_ent - 1, n_bits); #else /* !DEBUG */ (void) fprintf(stderr, gettext("Compression: ")); prratio(stderr, - (count_long)in_count-(count_long)bytes_out, - (count_long)in_count); + (count_long)in_count-(count_long)bytes_out, + (count_long)in_count); #endif /* DEBUG */ } /* report if no savings */ @@ -1186,7 +1163,7 @@ output(code_int code) #ifdef DEBUG if (verbose) (void) fprintf(stderr, "%5d%c", code, - (col += 6) >= 74 ? (col = 0, '\n') : ' '); + (col += 6) >= 74 ? (col = 0, '\n') : ' '); #endif /* DEBUG */ if (code >= 0) { /* @@ -1264,7 +1241,7 @@ output(code_int code) #ifdef DEBUG if (debug) { (void) fprintf(stderr, - "\nChange to %d bits\n", n_bits); + "\nChange to %d bits\n", n_bits); col = 0; } #endif /* DEBUG */ @@ -1495,7 +1472,7 @@ printcodes() col = 0; } (void) fprintf(stderr, "%5d%c", - code, (col += 6) >= 74 ? (col = 0, '\n') : ' '); + code, (col += 6) >= 74 ? (col = 0, '\n') : ' '); } (void) putc('\n', stderr); } @@ -1525,18 +1502,18 @@ dump_tab() /* dump string table */ de_stack[--stack_top] = '\n'; de_stack[--stack_top] = '"'; stack_top = - in_stack((htabof(sorttab[i]) >> maxbits) & 0xff, - stack_top); + in_stack((htabof(sorttab[i]) >> maxbits) & 0xff, + stack_top); for (ent = htabof(sorttab[i]) & ((1 << maxbits) -1); - ent > 256; - ent = htabof(sorttab[ent]) & ((1<<maxbits)-1)) { + ent > 256; + ent = htabof(sorttab[ent]) & ((1<<maxbits)-1)) { stack_top = in_stack( - htabof(sorttab[ent]) >> maxbits, - stack_top); + htabof(sorttab[ent]) >> maxbits, + stack_top); } stack_top = in_stack(ent, stack_top); (void) fwrite(&de_stack[stack_top], 1, - STACK_SIZE - stack_top, stderr); + STACK_SIZE - stack_top, stderr); stack_top = STACK_SIZE; } } else if (!debug) { /* decompressing */ @@ -1546,20 +1523,20 @@ dump_tab() /* dump string table */ c = tab_suffixof(ent); if (isascii(c) && isprint(c)) (void) fprintf(stderr, "%5d: %5d/'%c' \"", - ent, tab_prefixof(ent), c); + ent, tab_prefixof(ent), c); else (void) fprintf(stderr, "%5d: %5d/\\%03o \"", - ent, tab_prefixof(ent), c); + ent, tab_prefixof(ent), c); de_stack[--stack_top] = '\n'; de_stack[--stack_top] = '"'; for (; ent != NULL; - ent = (ent >= FIRST ? tab_prefixof(ent) : - NULL)) { + ent = (ent >= FIRST ? tab_prefixof(ent) : + NULL)) { stack_top = in_stack(tab_suffixof(ent), - stack_top); + stack_top); } (void) fwrite(&de_stack[stack_top], 1, - STACK_SIZE - stack_top, stderr); + STACK_SIZE - stack_top, stderr); stack_top = STACK_SIZE; } } @@ -1617,12 +1594,12 @@ copystat(char *ifname, struct stat *ifstat, char *ofname) perror(ifname); return; } else if ((ifstat->st_mode & - S_IFMT /* 0170000 */) != S_IFREG /* 0100000 */) { + S_IFMT /* 0170000 */) != S_IFREG /* 0100000 */) { if (quiet) { (void) fprintf(stderr, "%s: ", ifname); } (void) fprintf(stderr, gettext( - " -- not a regular file: unchanged")); + " -- not a regular file: unchanged")); newline_needed = 1; perm_stat = 1; } else if (ifstat->st_nlink > 1) { @@ -1630,22 +1607,22 @@ copystat(char *ifname, struct stat *ifstat, char *ofname) (void) fprintf(stderr, "%s: ", ifname); } (void) fprintf(stderr, gettext( - " -- has %d other links: unchanged"), - (uint_t)ifstat->st_nlink - 1); + " -- has %d other links: unchanged"), + (uint_t)ifstat->st_nlink - 1); newline_needed = 1; perm_stat = 1; } else if (didnt_shrink && !force) { /* No compression: remove file.Z */ if (!quiet) { (void) fprintf(stderr, gettext( - " -- file unchanged")); + " -- file unchanged")); newline_needed = 1; } } else if ((pathconf(ifname, _PC_XATTR_EXISTS) == 1) && - (mv_xattrs(ifname, ofname, 0) < 0)) { + (mv_xattrs(ifname, ofname, 0) < 0)) { (void) fprintf(stderr, gettext( - "%s: -- cannot preserve extended attributes, " - "file unchanged"), ifname); + "%s: -- cannot preserve extended attributes, " + "file unchanged"), ifname); newline_needed = 1; /* Move attributes back ... */ (void) mv_xattrs(ofname, ifname, 1); @@ -1682,7 +1659,7 @@ copystat(char *ifname, struct stat *ifstat, char *ofname) perror(ifname); if (!quiet) { (void) fprintf(stderr, gettext( - " -- replaced with %s"), ofname); + " -- replaced with %s"), ofname); newline_needed = 1; } return; /* Successful return */ @@ -1729,7 +1706,7 @@ cl_block(count_long in_count) /* table clear for block compress */ #ifdef DEBUG if (debug) { (void) fprintf(stderr, "count: %lld, ratio: ", - (count_long)in_count); + (count_long)in_count); prratio(stderr, (count_long)in_count, (count_long)bytes_out); (void) fprintf(stderr, "\n"); } @@ -1808,7 +1785,7 @@ prratio(FILE *stream, count_long num, count_long den) q = -q; } (void) fprintf(stream, "%d%s%02d%%", q / 100, - localeconv()->decimal_point, q % 100); + localeconv()->decimal_point, q % 100); } static void @@ -1872,8 +1849,8 @@ addDotZ(char *fn, size_t fnsize) if ((strlen(local_basename(fn)) + 2) > (size_t)max_name) { (void) fprintf(stderr, - gettext("%s: filename too long to tack on .Z:" - " %s\n"), progname, fn); + gettext("%s: filename too long to tack on .Z:" + " %s\n"), progname, fn); return (-1); } @@ -1881,15 +1858,15 @@ addDotZ(char *fn, size_t fnsize) if ((strlen(fn) + 2) > (size_t)max_path - 1) { (void) fprintf(stderr, - gettext("%s: Pathname too long to tack on .Z:" - " %s\n"), progname, fn); + gettext("%s: Pathname too long to tack on .Z:" + " %s\n"), progname, fn); return (-1); } if (strlcat(fn, ".Z", fnsize) >= fnsize) { (void) fprintf(stderr, - gettext("%s: Buffer overflow adding .Z to %s\n"), - progname, fn); + gettext("%s: Buffer overflow adding .Z to %s\n"), + progname, fn); return (-1); } diff --git a/usr/src/cmd/cron/Makefile b/usr/src/cmd/cron/Makefile index 12970e35d0..8fcc9f240d 100644 --- a/usr/src/cmd/cron/Makefile +++ b/usr/src/cmd/cron/Makefile @@ -19,7 +19,7 @@ # CDDL HEADER END # # -# Copyright 2006 Sun Microsystems, Inc. All rights reserved. +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "%Z%%M% %I% %E% SMI" @@ -34,7 +34,7 @@ MANIFEST = cron.xml ROOTMANIFESTDIR = $(ROOTSVCSYSTEM) ROOTMETHOD = $(ROOTLIBSVCMETHOD)/svc-cron -CPPFLAGS += -D_FILE_OFFSET_BITS=64 +CPPFLAGS += -D_FILE_OFFSET_BITS=64 -I $(SRC)/common/util ROOTVAR = $(ROOT)/var @@ -54,8 +54,9 @@ SCRIPT = batch XPG4SCRIPT = batch.xpg4 POFILE= $(PROG1)_cmd.po -POFILES= at.po crontab.po funcs.po batch.po -XGETFLAGS= -a -x $(PROG1).xcl +POFILES1= at.po crontab.po funcs.po batch.po +POFILES= $(POFILES1) atrm.po +$(POFILES1) := XGETFLAGS= -a -x $(PROG1).xcl ROOTDIRS = $(ROOTSPCRON) $(ROOTCROND) \ $(ROOTCRONTABS) $(ROOTATJOBS) @@ -68,15 +69,19 @@ ROOTPROG = $(PROG1:%=$(ROOTUSRSBIN)/%) $(PROG2:%=$(ROOTBIN)/%) \ ROOTSYMLINK = $(ROOTLIBCRON) $(ROOTETC)/cron +GETRESPSRC= $(SRC)/common/util/getresponse.c +GETRESPOBJ= getresponse.o COMMONOBJ1= permit.o COMMONOBJ2= funcs.o COMMONOBJS= $(COMMONOBJ1) $(COMMONOBJ2) CRONOBJS= cron.o elm.o ATOBJS= at.o att1.o att2.o XPG4OBJS= values-xpg4.o -ATRMOBJS= atrm.o +ATRMOBJS1= atrm.o +ATRMOBJS= $(ATRMOBJS1) $(GETRESPOBJ) ATQOBJS= atq.o -CRONTABOBJS= crontab.o +CRONTABOBJS1= crontab.o +CRONTABOBJS= $(CRONTABOBJS1) $(GETRESPOBJ) # /usr/xpg*/bin/crontab isn't linked with values-xpg*.o since it isn't # required by any specific behavior differences; this makes these @@ -97,16 +102,14 @@ crontab := POBJS = $(CRONTABOBJS) $(COMMONOBJS) crontab.xpg4 := POBJS = $(XPG4CTOBJS) $(XPG4COMMONOBJS) crontab.xpg6 := POBJS = $(XPG6CTOBJS) $(XPG6COMMONOBJS) -at.o objs.xpg4/at.o funcs.o objs.xpg4/funcs.o objs.xpg6/funcs.o permit.o \ -objs.xpg4/permit.o objs.xpg6/permit.o crontab.o objs.xpg4/crontab.o \ -objs.xpg6/crontab.o elm.o := CFLAGS += $(CCVERBOSE) +CFLAGS += $(CCVERBOSE) -NOBJS= $(CRONOBJS) $(ATOBJS) $(ATRMOBJS) $(ATQOBJS) $(CRONTABOBJS) \ +NOBJS= $(CRONOBJS) $(ATOBJS) $(ATRMOBJS1) $(ATQOBJS) $(CRONTABOBJS1) \ $(COMMONOBJS) OBJS = $(NOBJS) $(XPG4COMMONOBJS) $(XPG4ATOBJS) $(XPG4CTOBJS) \ - $(XPG6COMMONOBJS) $(XPG6CTOBJS) + $(XPG6COMMONOBJS) $(XPG6CTOBJS) $(GETRESPOBJ) -SRCS = $(NOBJS:%.o=%.c) +SRCS = $(NOBJS:%.o=%.c) $(GETRESPSRC) CLOBBERFILES += $(SCRIPT) $(XPG4SCRIPT) @@ -151,6 +154,8 @@ lint := LDLIBS += -lproject -lsecdb -lcontract -lpam $(XPG4) := CFLAGS += -DXPG4 $(XPG6) := CFLAGS += -DXPG6 +LINTFLAGS += -u + $(ROOTSVCSYSTEM)/cron.xml := OWNER = root $(ROOTSVCSYSTEM)/cron.xml := GROUP = sys $(ROOTSVCSYSTEM)/cron.xml := FILEMODE = 0444 @@ -179,13 +184,13 @@ $(XPG6) : objs.xpg6 $$(POBJS) $(LINK.c) $(POBJS) -o $@ $(LDLIBS) $(POST_PROCESS) -objs.xpg6/%.o: %.c +objs.xpg6/%.o: %.c $(COMPILE.c) -o $@ $< objs.xpg6: -@mkdir -p $@ -objs.xpg4/%.o: %.c +objs.xpg4/%.o: %.c $(COMPILE.c) -o $@ $< objs.xpg4: @@ -194,6 +199,18 @@ objs.xpg4: objs.xpg4/values-xpg4.o: ../../lib/common/common/values-xpg4.c $(COMPILE.c) -o $@ ../../lib/common/common/values-xpg4.c +%.o: $(SRC)/common/util/%.c + $(COMPILE.c) $(OUTPUT_OPTION) $< + $(POST_PROCESS_O) + +objs.xpg4/%.o: $(SRC)/common/util/%.c + $(COMPILE.c) -o $@ $< + $(POST_PROCESS_O) + +objs.xpg6/%.o: $(SRC)/common/util/%.c + $(COMPILE.c) -o $@ $< + $(POST_PROCESS_O) + att1.c : att1.y $(YACC.y) -d att1.y $(MV) y.tab.c att1.c diff --git a/usr/src/cmd/cron/atq.c b/usr/src/cmd/cron/atq.c index 4cedbb518e..37c7db3b58 100644 --- a/usr/src/cmd/cron/atq.c +++ b/usr/src/cmd/cron/atq.c @@ -1,5 +1,5 @@ /* - * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -36,6 +36,8 @@ #include <unistd.h> #include <locale.h> #include <errno.h> +#include <stdlib.h> +#include <string.h> #include "cron.h" extern char *errmsg(); @@ -131,7 +133,7 @@ main(int argc, char **argv) atabortperror("can't allocate list of users"); for (i = 0; i < argc; i++) { if ((chkauthattr(CRONADMIN_AUTH, pr.pw_name)) || - strcmp(pr.pw_name, argv[i]) == 0) { + strcmp(pr.pw_name, argv[i]) == 0) { if ((pp = getpwnam(argv[i])) == NULL) { (void) fprintf(stderr, "atq: No such user %s\n", argv[i]); @@ -204,7 +206,7 @@ main(int argc, char **argv) if (argnum != argc) c = pr.pw_name; else c = *argv; printf("no files for %s.\n", (argnum == 1) ? - c : "specified users"); + c : "specified users"); exit(0); } printqueue(uidlist, argnum); @@ -370,7 +372,6 @@ static void printdate(char *filename) { time_t jobdate; - extern time_t num(); struct tm *unpackeddate; char date[18]; /* reformatted execution date */ @@ -499,7 +500,6 @@ execution(struct dirent **d1, struct dirent **d2) char *name1, *name2; time_t time1, time2; int seq1, seq2; - extern time_t num(); name1 = (*d1)->d_name; name2 = (*d2)->d_name; diff --git a/usr/src/cmd/cron/atrm.c b/usr/src/cmd/cron/atrm.c index 54e2ffc124..f3f2d39bcd 100644 --- a/usr/src/cmd/cron/atrm.c +++ b/usr/src/cmd/cron/atrm.c @@ -1,5 +1,5 @@ /* - * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -33,12 +33,14 @@ #include <unistd.h> #include <locale.h> #include <strings.h> +#include <stdlib.h> +#include <libintl.h> #include "cron.h" +#include "getresponse.h" extern time_t num(); extern char *errmsg(); - -extern void audit_at_delete(char *, char *, int); +extern void audit_at_delete(char *, char *, int); #define SUPERUSER 0 /* is user super-user? */ #define CANTCD "can't change directory to the at directory" @@ -63,6 +65,9 @@ static void atperror2(char *msg, char *name); static void aterror(char *msg); static void powner(char *file); +int getjoblist(struct dirent ***, struct stat ***, int (*)()); +int removentry(char *, struct stat *, uid_t); + int main(int argc, char **argv) { @@ -71,7 +76,6 @@ main(int argc, char **argv) int allflag = 0; /* remove all jobs belonging to user? */ int jobexists; /* does a requested job exist? */ char *pp; - char *getuser(); struct dirent **namelist; /* names of jobs in spooling area */ struct stat **statlist; struct passwd *pwd; @@ -81,6 +85,7 @@ main(int argc, char **argv) * usage info and exit. */ (void) setlocale(LC_ALL, ""); + (void) textdomain(TEXT_DOMAIN); if (argc < 2) usage(); @@ -245,9 +250,14 @@ removentry(char *filename, struct stat *statptr, uid_t user) { struct passwd *pwd; char *pp; - char *getuser(); int r; + if (init_yes() < 0) { + (void) fprintf(stderr, gettext(ERR_MSG_INIT_YES), + strerror(errno)); + exit(1); + } + if (!fflag) printf("%s: ", filename); @@ -266,8 +276,8 @@ removentry(char *filename, struct stat *statptr, uid_t user) powner(filename); printf(") "); } - printf("remove it? "); - if (!yes()) + printf(gettext("remove it? ")); + if (yes() == 0) return (0); } @@ -326,9 +336,7 @@ getjoblist(struct dirent ***namelistp, struct stat ***statlistp, int i; struct stat *statptr; /* pointer to file stat structure */ struct stat **statlist; - extern int alphasort(); /* sort jobs by date of execution */ extern int filewanted(); /* should a file be listed in queue? */ - if (chdir(ATDIR) < 0) atabortperror(CANTCD); @@ -364,26 +372,6 @@ getjoblist(struct dirent ***namelistp, struct stat ***statlistp, return (numjobs); } - -/* - * Get answer to interactive prompts, eating all characters beyond the first - * one. If a 'y' is typed, return 1. - */ -int -yes(void) -{ - int ch; /* dummy variable */ - int ch1; /* dummy variable */ - - ch = ch1 = getchar(); - while (ch1 != '\n' && ch1 != EOF) - ch1 = getchar(); - if (isupper(ch)) - ch = tolower(ch); - return (ch == 'y'); -} - - /* * Get the full login name of a person using his/her user id. */ diff --git a/usr/src/cmd/cron/cron.h b/usr/src/cmd/cron/cron.h index fbd4f666ee..f9b8eacd46 100644 --- a/usr/src/cmd/cron/cron.h +++ b/usr/src/cmd/cron/cron.h @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -20,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 1999-2003 Sun Microsystems, Inc. All rights reserved. + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -100,6 +99,7 @@ void cron_sendmsg(char, char *, char *, char); time_t num(char **); void *xmalloc(size_t); void *xcalloc(size_t, size_t); +int ascandir(char *, struct dirent *(*[]), int (*)(), int (*)()); #ifdef __cplusplus } diff --git a/usr/src/cmd/cron/cron.xcl b/usr/src/cmd/cron/cron.xcl index facb8a8f0f..118a6403d5 100644 --- a/usr/src/cmd/cron/cron.xcl +++ b/usr/src/cmd/cron/cron.xcl @@ -2,9 +2,8 @@ # CDDL HEADER START # # The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (the "License"). You may not use this file except in compliance -# with the License. +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. @@ -19,10 +18,17 @@ # # CDDL HEADER END # +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +#ident "%Z%%M% %I% %E% SMI" + msgid "" msgid "/etc/cron.d/at.allow" msgid "/etc/cron.d/at.deny" -msgid "cklmsrf:q:t:" +msgid "cklmsrf:p:q:t:" msgid " " msgid "DATEMSK" msgid "%-5d" @@ -81,3 +87,9 @@ msgid "/usr/bin/pwd" msgid "user = %s\t%s\t%s\n" msgid "malloc" msgid "calloc" +msgid "%s/%s%d" +msgid "%1024s" +msgid "%*[^\n]\n" +msgid "cron" +msgid "vi" +msgid "solaris.jobs.admin" diff --git a/usr/src/cmd/cron/crontab.c b/usr/src/cmd/cron/crontab.c index dcf7fe27c5..f079cedf54 100644 --- a/usr/src/cmd/cron/crontab.c +++ b/usr/src/cmd/cron/crontab.c @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ @@ -47,6 +47,7 @@ #include <libintl.h> #include <security/pam_appl.h> #include "cron.h" +#include "getresponse.h" #if defined(XPG4) #define VIPATH "/usr/xpg4/bin/vi" @@ -86,8 +87,8 @@ " editing the crontab data - usually a minor typing error.\n\n" #define BADREAD "error reading your crontab file" #define ED_PROMPT \ - " Edit again, to ensure crontab information is intact (%c/%c)?\n"\ - " ('%c' will discard edits.)" + " Edit again, to ensure crontab information is intact (%s/%s)?\n"\ + " ('%s' will discard edits.)" #define NAMETOOLONG "login name too long" extern int per_errno; @@ -103,15 +104,12 @@ char *tnam; char edtemp[5+13+1]; char line[CTLINESIZE]; static char login[UNAMESIZE]; -static char yeschr; -static char nochr; -static int yes(void); -static int next_field(int, int); -static void catch(int); -static void crabort(char *); -static void cerror(char *); -static void copycron(FILE *); +static int next_field(int, int); +static void catch(int); +static void crabort(char *); +static void cerror(char *); +static void copycron(FILE *); int main(int argc, char **argv) @@ -142,8 +140,12 @@ main(int argc, char **argv) #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */ #endif (void) textdomain(TEXT_DOMAIN); - yeschr = *nl_langinfo(YESSTR); - nochr = *nl_langinfo(NOSTR); + + if (init_yes() < 0) { + (void) fprintf(stderr, gettext(ERR_MSG_INIT_YES), + strerror(errno)); + exit(1); + } while ((c = getopt(argc, argv, "elr")) != EOF) switch (c) { @@ -296,23 +298,24 @@ main(int argc, char **argv) } #endif (void) snprintf(buf, sizeof (buf), - "%s %s", editor, edtemp); + "%s %s", editor, edtemp); sleep(1); while (1) { ret = system(buf); /* sanity checks */ if ((tmpfp = fopen(edtemp, "r")) == NULL) - crabort("can't open temporary file"); + crabort("can't open temporary file"); if (fstat(fileno(tmpfp), &stbuf) < 0) - crabort("can't stat temporary file"); + crabort("can't stat temporary file"); if (stbuf.st_size == 0) - crabort("temporary file empty"); + crabort("temporary file empty"); if (omodtime == stbuf.st_mtime) { - (void) unlink(edtemp); - fprintf(stderr, gettext( - "The crontab file was not changed.\n")); - exit(1); + (void) unlink(edtemp); + fprintf(stderr, gettext( + "The crontab file was not" + " changed.\n")); + exit(1); } if ((ret) && (errno != EINTR)) { /* @@ -325,7 +328,7 @@ main(int argc, char **argv) if (isatty(fileno(stdin))) { /* Interactive */ fprintf(stdout, gettext(ED_PROMPT), - yeschr, nochr, nochr); + yesstr, nostr, nostr); fflush(stdout); if (yes()) { @@ -337,9 +340,9 @@ main(int argc, char **argv) exit(1); } } else { - /* Non-interactive, dump changes */ - (void) unlink(edtemp); - exit(1); + /* Non-interactive, dump changes */ + (void) unlink(edtemp); + exit(1); } } exit(0); @@ -547,17 +550,3 @@ char *msg; fprintf(stderr, "crontab: %s\n", gettext(msg)); exit(1); } - -static int -yes(void) -{ - int first_char; - int dummy_char; - - first_char = dummy_char = getchar(); - while ((dummy_char != '\n') && - (dummy_char != '\0') && - (dummy_char != EOF)) - dummy_char = getchar(); - return (first_char == yeschr); -} diff --git a/usr/src/cmd/find/Makefile b/usr/src/cmd/find/Makefile index d43075a5a6..dfdb210815 100644 --- a/usr/src/cmd/find/Makefile +++ b/usr/src/cmd/find/Makefile @@ -2,9 +2,8 @@ # CDDL HEADER START # # The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (the "License"). You may not use this file except in compliance -# with the License. +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. @@ -22,18 +21,23 @@ # #ident "%Z%%M% %I% %E% SMI" # -# Copyright 2005 Sun Microsystems, Inc. All rights reserved. +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # -PROG= find -XPG4PROG= find +PROG= find +XPG4PROG= find +FINDOBJS1= find.o +FINDOBJS= $(FINDOBJS1) getresponse.o +XPG4FINDOBJS= $(FINDOBJS:%.o=xpg4_%.o) +SRCS= $(FINDOBJS1:%.o=%.c) $(SRC)/common/util/getresponse.c include ../Makefile.cmd -$(XPG4) := CFLAGS += -DXPG4 -CPPFLAGS += -D_FILE_OFFSET_BITS=64 +$(XPG4) := CFLAGS += -DXPG4 +CPPFLAGS += -D_FILE_OFFSET_BITS=64 -I $(SRC)/common/util +LINTFLAGS += -u LDLIBS += -lsec .KEEP_STATE: @@ -42,8 +46,29 @@ all: $(PROG) $(XPG4) install: all $(ROOTPROG) $(ROOTXPG4PROG) +$(PROG): $(FINDOBJS) + $(LINK.c) -o $@ $(FINDOBJS) $(LDLIBS) + $(POST_PROCESS) + +$(XPG4): $(XPG4FINDOBJS) + $(LINK.c) -o $@ $(XPG4FINDOBJS) $(LDLIBS) + $(POST_PROCESS) + +%.o: $(SRC)/common/util/%.c + $(COMPILE.c) $(OUTPUT_OPTION) $< + $(POST_PROCESS_O) + +xpg4_%.o: %.c + $(COMPILE.c) -o $@ $< + $(POST_PROCESS_O) + +xpg4_%.o: $(SRC)/common/util/%.c + $(COMPILE.c) -o $@ $< + $(POST_PROCESS_O) + clean: + $(RM) $(FINDOBJS) -lint: lint_PROG +lint: lint_SRCS include ../Makefile.targ diff --git a/usr/src/cmd/find/find.c b/usr/src/cmd/find/find.c index 6895549994..e50d7c6a03 100644 --- a/usr/src/cmd/find/find.c +++ b/usr/src/cmd/find/find.c @@ -52,12 +52,12 @@ #include <locale.h> #include <string.h> #include <strings.h> -#include <libgen.h> #include <ctype.h> #include <wait.h> #include <fnmatch.h> #include <langinfo.h> #include <ftw.h> +#include "getresponse.h" #define A_DAY (long)(60*60*24) /* a day full of seconds */ #define A_MIN (long)(60) @@ -244,7 +244,7 @@ main(int argc, char **argv) cmdname = argv[0]; if (time(&now) == (time_t)(-1)) { (void) fprintf(stderr, gettext("%s: time() %s\n"), - cmdname, strerror(errno)); + cmdname, strerror(errno)); exit(1); } while ((c = getopt(argc, argv, "HL")) != -1) { @@ -304,8 +304,8 @@ main(int argc, char **argv) if (freenode == NULL) { (void) fprintf(stderr, gettext("%s: can't append -print" - " implicitly; try explicit -print option\n"), - cmdname); + " implicitly; try explicit -print option\n"), + cmdname); exit(1); } savenode = topnode; @@ -343,8 +343,8 @@ main(int argc, char **argv) */ if ((cwdpath = getcwd(NULL, PATH_MAX)) == NULL) { (void) fprintf(stderr, - gettext("%s : cannot get the current working " - "directory\n"), cmdname); + gettext("%s : cannot get the current working " + "directory\n"), cmdname); exit(1); } else free(cwdpath); @@ -391,6 +391,12 @@ int *actionp; int i; enum Command wasop = PRINT; + if (init_yes() < 0) { + (void) fprintf(stderr, gettext(ERR_MSG_INIT_YES), + strerror(errno)); + exit(1); + } + for (av = argv; *av && (argp = lookup(*av)); av++) { np->next = 0; np->action = argp->action; @@ -995,7 +1001,9 @@ ok(name, argv) char *name; char *argv[]; { - int c, yes = 0; + int c; + int i = 0; + char resp[LINE_MAX + 1]; (void) fflush(stdout); /* to flush possible `-print' */ @@ -1005,14 +1013,19 @@ char *argv[]; (void) fprintf(stderr, "< {} ... %s >? ", name); (void) fflush(stderr); - if ((c = tolower(getchar())) == *nl_langinfo(YESSTR)) - yes = 1; - while (c != '\n') + + while ((c = getchar()) != '\n') { if (c == EOF) exit(2); - else - c = getchar(); - return (yes? doexec(name, argv, NULL): 0); + if (i < LINE_MAX) + resp[i++] = c; + } + resp[i] = '\0'; + + if (yes_check(resp)) + return (doexec(name, argv, NULL)); + else + return (0); } /* @@ -1343,7 +1356,7 @@ getshell() if (((sh = getenv("SHELL")) != 0) && *sh == '/') { if (u = getuid()) { if ((u != geteuid() || getgid() != getegid()) && - !access(sh, 2)) + access(sh, 2) == 0) goto defshell; s = strrchr(sh, '/'); *s = 0; @@ -1645,8 +1658,8 @@ init_remote_fs() if ((fp = fopen(REMOTE_FS, "r")) == NULL) { (void) fprintf(stderr, - gettext("%s: Warning: can't open %s, ignored\n"), - REMOTE_FS, cmdname); + gettext("%s: Warning: can't open %s, ignored\n"), + REMOTE_FS, cmdname); /* Use default string name for NFS */ remote_fstypes[fstype_index++] = "nfs"; return; diff --git a/usr/src/cmd/mv/Makefile b/usr/src/cmd/mv/Makefile index 0225d52219..277d5b1bd1 100644 --- a/usr/src/cmd/mv/Makefile +++ b/usr/src/cmd/mv/Makefile @@ -1,10 +1,8 @@ -# # CDDL HEADER START # # The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (the "License"). You may not use this file except in compliance -# with the License. +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. @@ -20,21 +18,21 @@ # CDDL HEADER END # # -# Copyright 2005 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -# ident "%Z%%M% %I% %E% SMI" +#ident "%Z%%M% %I% %E% SMI" # -# cmd/mv/Makefile +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. # PROG= mv XPG4PROG= mv -OBJS= mv.o +OBJS1= mv.o +OBJS= $(OBJS1) getresponse.o CPFILE= cp LNFILE= ln XPG4OBJS= $(OBJS:%.o=xpg4_%.o) -SRCS= $(OBJS:%.o=%.c) +SRCS= $(OBJS1:%.o=%.c) $(SRC)/common/util/getresponse.c + ROOTLINKS= $(ROOTBIN)/$(CPFILE) $(ROOTBIN)/$(LNFILE) ROOTXPG4LINKS= $(ROOTXPG4BIN)/$(CPFILE) $(ROOTXPG4BIN)/$(LNFILE) @@ -45,10 +43,9 @@ clean $(XPG4) := OBJS += values-xpg4.o CLOBBERFILES += $(CPFILE) $(LNFILE) CFLAGS += $(CCVERBOSE) $(XPG4) := CFLAGS += -DXPG4 -LINTFLAGS += -DXPG4 +LINTFLAGS += -DXPG4 -u XGETFLAGS += -a -x mv.xcl -CPPFLAGS += -D_FILE_OFFSET_BITS=64 -LINTFLAGS += -DXPG4 +CPPFLAGS += -D_FILE_OFFSET_BITS=64 -I $(SRC)/common/util lint := LDLIBS += -lcmdutils -lavl -lsec $(PROG) := LDLIBS += $(ZLAZYLOAD) -lcmdutils -lavl -lsec $(ZNOLAZYLOAD) @@ -58,8 +55,6 @@ $(XPG4) := LDLIBS += $(ZLAZYLOAD) -lcmdutils -lavl -lsec $(ZNOLAZYLOAD) all: $(PROG) $(CPFILE) $(LNFILE) $(XPG4) - - $(PROG): $$(OBJS) $(LINK.c) -o $@ $(OBJS) $(LDLIBS) $(POST_PROCESS) @@ -68,10 +63,19 @@ $(XPG4): $$(XPG4OBJS) $(LINK.c) -o $@ $(XPG4OBJS) $(LDLIBS) $(POST_PROCESS) -xpg4_%.o: %.c +%.o: $(SRC)/common/util/%.c + $(COMPILE.c) $(OUTPUT_OPTION) $< + $(POST_PROCESS_O) + +xpg4_%.o: %.c + $(COMPILE.c) -o $@ $< + $(POST_PROCESS_O) + +xpg4_%.o: $(SRC)/common/util/%.c $(COMPILE.c) -o $@ $< + $(POST_PROCESS_O) -%values-xpg4.o: ../../lib/common/common/values-xpg4.c +%values-xpg4.o: ../../lib/common/common/values-xpg4.c $(COMPILE.c) -o $@ ../../lib/common/common/values-xpg4.c $(CPFILE): $(PROG) diff --git a/usr/src/cmd/mv/mv.c b/usr/src/cmd/mv/mv.c index 38bcb3db23..1f4d4fb23c 100644 --- a/usr/src/cmd/mv/mv.c +++ b/usr/src/cmd/mv/mv.c @@ -56,7 +56,6 @@ #include <dirent.h> #include <stdlib.h> #include <locale.h> -#include <langinfo.h> #include <stdarg.h> #include <string.h> #include <unistd.h> @@ -64,6 +63,7 @@ #include <sys/acl.h> #include <libcmdutils.h> #include <aclutils.h> +#include "getresponse.h" #define FTYPE(A) (A.st_mode) #define FMODE(A) (A.st_mode) @@ -94,7 +94,6 @@ #define SMALLFILESIZE (32*1024) /* don't use mmap on little files */ static char *dname(char *); -static int getresp(void); static int lnkfil(char *, char *); static int cpymve(char *, char *); static int chkfiles(char *, char **); @@ -115,9 +114,6 @@ static int copyattributes(char *, char *); static void timestruc_to_timeval(timestruc_t *, struct timeval *); static tree_node_t *create_tnode(dev_t, ino_t); -extern int errno; -extern char *optarg; -extern int optind, opterr; static struct stat s1, s2; static int cpy = FALSE; static int mve = FALSE; @@ -136,8 +132,6 @@ static int Pflg = 0; /* do not follow symlinks */ static int atflg = 0; static int attrsilent = 0; static int targetexists = 0; -static char yeschr[SCHAR_MAX + 2]; -static char nochr[SCHAR_MAX + 2]; static int cmdarg; /* command line argument */ static avl_tree_t *stree = NULL; /* source file inode search tree */ static acl_t *s1acl; @@ -167,9 +161,11 @@ main(int argc, char *argv[]) #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */ #endif (void) textdomain(TEXT_DOMAIN); - - (void) strncpy(yeschr, nl_langinfo(YESSTR), SCHAR_MAX + 2); - (void) strncpy(nochr, nl_langinfo(NOSTR), SCHAR_MAX + 2); + if (init_yes() < 0) { + (void) fprintf(stderr, gettext(ERR_MSG_INIT_YES), + strerror(errno)); + exit(3); + } if (EQ(cmd, "mv")) mve = TRUE; @@ -851,9 +847,9 @@ copy: attret = copyattributes(source, target); if (attret != 0 && !attrsilent) { (void) fprintf(stderr, gettext( - "%s: Failed to preserve" - " extended attributes of file" - " %s\n"), cmd, source); + "%s: Failed to preserve" + " extended attributes of file" + " %s\n"), cmd, source); } if (mve && attret != 0) { @@ -904,7 +900,7 @@ copy: } (void) fprintf(stderr, gettext("%s: %s: unknown file type 0x%x\n"), cmd, - source, (s1.st_mode & S_IFMT)); + source, (s1.st_mode & S_IFMT)); return (1); cleanup: @@ -1082,7 +1078,7 @@ chkfiles(char *source, char **to) { char *buf = (char *)NULL; int (*statf)() = (cpy && - !(Pflg || (Hflg && !cmdarg))) ? stat : lstat; + !(Pflg || (Hflg && !cmdarg))) ? stat : lstat; char *target = *to; int error; @@ -1143,7 +1139,7 @@ chkfiles(char *source, char **to) if ((buf = (char *)malloc(len)) == NULL) { (void) fprintf(stderr, gettext("%s: Insufficient memory to " - "%s %s\n "), cmd, cmd, source); + "%s %s\n "), cmd, cmd, source); exit(3); } (void) snprintf(buf, len, "%s/%s", @@ -1232,8 +1228,8 @@ chkfiles(char *source, char **to) (void) fprintf(stderr, gettext("%s: overwrite %s and override " "protection %o (%s/%s)? "), cmd, target, - FMODE(s2) & MODEBITS, yeschr, nochr); - if (getresp()) { + FMODE(s2) & MODEBITS, yesstr, nostr); + if (yes() == 0) { if (buf != NULL) free(buf); return (2); @@ -1241,8 +1237,8 @@ chkfiles(char *source, char **to) } else if (overwrite && ISREG(s2)) { (void) fprintf(stderr, gettext("%s: overwrite %s (%s/%s)? "), - cmd, target, yeschr, nochr); - if (getresp()) { + cmd, target, yesstr, nostr); + if (yes() == 0) { if (buf != NULL) free(buf); return (2); @@ -1254,8 +1250,8 @@ chkfiles(char *source, char **to) "%o (%s/%s)? "), /*CSTYLED*/ cmd, target, FMODE(s2) & MODEBITS, - yeschr, nochr); - if (getresp()) { + yesstr, nostr); + if (yes() == 0) { if (buf != NULL) free(buf); return (2); @@ -1393,35 +1389,6 @@ dname(char *name) return (name); } -static int -getresp(void) -{ - register int c, i; - char ans_buf[SCHAR_MAX + 1]; - - /* - * Get response from user. Based on - * first character, make decision. - * Discard rest of line. - */ - for (i = 0; ; i++) { - c = getchar(); - if (c == '\n' || c == 0 || c == EOF) { - ans_buf[i] = 0; - break; - } - if (i < SCHAR_MAX) - ans_buf[i] = c; - } - if (i >= SCHAR_MAX) { - i = SCHAR_MAX; - ans_buf[SCHAR_MAX] = 0; - } - if ((i == 0) | (strncmp(yeschr, ans_buf, i))) - return (1); - return (0); -} - static void usage(void) { @@ -1435,12 +1402,13 @@ usage(void) " mv [-f] [-i] f1 ... fn d1\n" " mv [-f] [-i] d1 d2\n")); } else if (lnk) { - (void) fprintf(stderr, gettext( #ifdef XPG4 + (void) fprintf(stderr, gettext( "Usage: ln [-f] [-s] f1 [f2]\n" " ln [-f] [-s] f1 ... fn d1\n" " ln [-f] -s d1 d2\n")); #else + (void) fprintf(stderr, gettext( "Usage: ln [-f] [-n] [-s] f1 [f2]\n" " ln [-f] [-n] [-s] f1 ... fn d1\n" " ln [-f] [-n] -s d1 d2\n")); @@ -1617,7 +1585,6 @@ copydir(char *source, char *target) s1save = s1; if (s1acl != NULL) { s1acl_save = acl_dup(s1acl); -#ifdef XPG4 if (s1acl_save == NULL) { (void) fprintf(stderr, gettext("%s: " "Insufficient memory to save acl" @@ -1626,6 +1593,14 @@ copydir(char *source, char *target) return (1); } +#ifdef XPG4 + else { + (void) fprintf(stderr, gettext("%s: " + "Insufficient memory to save acl" + " entry\n"), cmd); + if (pflg) + return (1); + } #endif } } @@ -1812,9 +1787,9 @@ copyattributes(char *source, char *target) if (!attrsilent) { (void) fprintf(stderr, - gettext("%s: could not retrieve stat" - " information for attribute directory" - "of file %s: "), cmd, source); + gettext("%s: could not retrieve stat" + " information for attribute directory" + "of file %s: "), cmd, source); perror(""); ++error; } @@ -1891,9 +1866,9 @@ copyattributes(char *source, char *target) if (fchmod(targetdirfd, attrdir.st_mode) == -1) { if (!attrsilent) { (void) fprintf(stderr, - gettext("%s: failed to set file mode" - " correctly on attribute directory of" - " file %s: "), cmd, target); + gettext("%s: failed to set file mode" + " correctly on attribute directory of" + " file %s: "), cmd, target); perror(""); ++error; } @@ -1920,8 +1895,8 @@ copyattributes(char *source, char *target) if (futimesat(targetdirfd, ".", times) < 0) { if (!attrsilent) { (void) fprintf(stderr, - gettext("%s: cannot set attribute times" - " for %s: "), cmd, target); + gettext("%s: cannot set attribute times" + " for %s: "), cmd, target); perror(""); ++error; } @@ -1996,8 +1971,8 @@ copyattributes(char *source, char *target) while (dp = readdir(srcdirp)) { if ((dp->d_name[0] == '.' && dp->d_name[1] == '\0') || - (dp->d_name[0] == '.' && dp->d_name[1] == '.' && - dp->d_name[2] == '\0')) + (dp->d_name[0] == '.' && dp->d_name[1] == '.' && + dp->d_name[2] == '\0')) continue; if ((srcattrfd = openat(sourcedirfd, dp->d_name, @@ -2095,8 +2070,8 @@ copyattributes(char *source, char *target) if (srcbuf == NULL) { if (!attrsilent) { (void) fprintf(stderr, - gettext("%s: could not allocate memory" - " for path buffer: "), cmd); + gettext("%s: could not allocate memory" + " for path buffer: "), cmd); perror(""); ++error; } @@ -2108,8 +2083,8 @@ copyattributes(char *source, char *target) if (targbuf == NULL) { if (!attrsilent) { (void) fprintf(stderr, - gettext("%s: could not allocate memory" - " for path buffer: "), cmd); + gettext("%s: could not allocate memory" + " for path buffer: "), cmd); perror(""); ++error; } @@ -2170,7 +2145,7 @@ copyattributes(char *source, char *target) } else { if (!attrsilent) { (void) fprintf(stderr, - gettext( + gettext( "%s: cannot set permissions of attribute" " %s for %s: "), cmd, dp->d_name, target); perror(""); diff --git a/usr/src/cmd/mv/mv.xcl b/usr/src/cmd/mv/mv.xcl index a748a2307d..76d24bd854 100644 --- a/usr/src/cmd/mv/mv.xcl +++ b/usr/src/cmd/mv/mv.xcl @@ -2,9 +2,8 @@ # CDDL HEADER START # # The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (the "License"). You may not use this file except in compliance -# with the License. +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. @@ -19,6 +18,13 @@ # # CDDL HEADER END # +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +#ident "%Z%%M% %I% %E% SMI" + msgid "" msgid "mv" msgid "ln" @@ -33,3 +39,6 @@ msgid "." msgid ".." msgid "%s: %s" msgid "%s: %s: %s" +msgid "cp" +msgid "fHiLpPrR@" +msgid "%s%s%s" diff --git a/usr/src/cmd/rm/Makefile b/usr/src/cmd/rm/Makefile index 86ae34f79b..f4e4e02ce1 100644 --- a/usr/src/cmd/rm/Makefile +++ b/usr/src/cmd/rm/Makefile @@ -25,23 +25,48 @@ # Use is subject to license terms. # -PROG= rm -XPG4PROG= rm +PROG= rm +XPG4PROG= rm +RMOBJ1= rm.o +RMOBJ= $(RMOBJ1) getresponse.o +XPG4RMOBJ= $(RMOBJ:%.o=xpg4_%.o) +SRCS= $(RMOBJ1:%.o=%.c) $(SRC)/common/util/getresponse.c include ../Makefile.cmd CFLAGS += $(CCVERBOSE) $(XPG4) := CFLAGS += -DXPG4 -CPPFLAGS += -D_FILE_OFFSET_BITS=64 - +CPPFLAGS += -D_FILE_OFFSET_BITS=64 -I $(SRC)/common/util +LINTFLAGS += -u .KEEP_STATE: all: $(PROG) $(XPG4) install: all $(ROOTPROG) $(ROOTXPG4PROG) +$(PROG): $(RMOBJ) + $(LINK.c) $(RMOBJ) -o $@ $(LDLIBS) + $(POST_PROCESS) + +$(XPG4): $(XPG4RMOBJ) + $(LINK.c) $(XPG4RMOBJ) -o $@ $(LDLIBS) + $(POST_PROCESS) + +%.o: $(SRC)/common/util/%.c + $(COMPILE.c) $(OUTPUT_OPTION) $< + $(POST_PROCESS_O) + +xpg4_%.o: %.c + $(COMPILE.c) -o $@ $< + $(POST_PROCESS_O) + +xpg4_%.o: $(SRC)/common/util/%.c + $(COMPILE.c) -o $@ $< + $(POST_PROCESS_O) + clean: + $(RM) $(RMOBJ) $(XPG4RMOBJ) -lint: lint_PROG +lint: lint_SRCS include ../Makefile.targ diff --git a/usr/src/cmd/rm/rm.c b/usr/src/cmd/rm/rm.c index 95b9cd766e..2e779280df 100644 --- a/usr/src/cmd/rm/rm.c +++ b/usr/src/cmd/rm/rm.c @@ -47,6 +47,7 @@ #include <string.h> #include <unistd.h> #include <values.h> +#include "getresponse.h" #define E_OK 010 /* make __accessat() use effective ids */ @@ -71,9 +72,6 @@ static struct dlist top = { DIR_CANTCLOSE, }; -static char yeschr[SCHAR_MAX + 2]; -static char nochr[SCHAR_MAX + 2]; - static struct dlist *cur, *rec; static int rm(const char *, struct dlist *); @@ -103,9 +101,6 @@ main(int argc, char **argv) #endif (void) textdomain(TEXT_DOMAIN); - (void) strncpy(yeschr, nl_langinfo(YESSTR), SCHAR_MAX + 1); - (void) strncpy(nochr, nl_langinfo(NOSTR), SCHAR_MAX + 1); - while ((c = getopt(argc, argv, "frRi")) != EOF) switch (c) { case 'f': @@ -161,6 +156,12 @@ main(int argc, char **argv) if (pathbuf == NULL) memerror(); + if (init_yes() < 0) { + (void) fprintf(stderr, gettext(ERR_MSG_INIT_YES), + strerror(errno)); + exit(2); + } + for (; *argv != NULL; argv++) { char *p = strrchr(*argv, '/'); if (p == NULL) @@ -371,7 +372,7 @@ rm(const char *entry, struct dlist *caller) */ if (interactive && !confirm(stderr, gettext("rm: examine files in directory %s (%s/%s)? "), - pathbuf, yeschr, nochr)) { + pathbuf, yesstr, nostr)) { return (0); } @@ -390,7 +391,7 @@ rm(const char *entry, struct dlist *caller) __accessat(caller->fd, entry, W_OK|X_OK|E_OK) != 0 && !confirm(stderr, gettext("rm: examine files in directory %s (%s/%s)? "), - pathbuf, yeschr, nochr)) { + pathbuf, yesstr, nostr)) { return (0); } #endif @@ -424,7 +425,7 @@ rm(const char *entry, struct dlist *caller) */ if (!confirm(stderr, gettext("rm: remove %s (%s/%s)? "), - pathbuf, yeschr, nochr)) { + pathbuf, yesstr, nostr)) { errcnt++; return (0); } @@ -500,7 +501,7 @@ unlinkit: */ if (interactive) { if (!confirm(stderr, gettext("rm: remove %s (%s/%s)? "), - pathbuf, yeschr, nochr)) { + pathbuf, yesstr, nostr)) { return (0); } } else if (!silent && flag == 0) { @@ -523,7 +524,7 @@ unlinkit: __accessat(caller->fd, entry, W_OK|E_OK) != 0 && !confirm(stdout, gettext("rm: %s: override protection %o (%s/%s)? "), - pathbuf, temp.st_mode & 0777, yeschr, nochr)) { + pathbuf, temp.st_mode & 0777, yesstr, nostr)) { return (0); } } @@ -564,30 +565,6 @@ unlinkit: } static int -yes(void) -{ - int i, b; - char ans[SCHAR_MAX + 1]; - - for (i = 0; ; i++) { - b = getchar(); - if (b == '\n' || b == '\0' || b == EOF) { - ans[i] = 0; - break; - } - if (i < SCHAR_MAX) - ans[i] = (char)b; - } - if (i >= SCHAR_MAX) { - i = SCHAR_MAX; - ans[SCHAR_MAX] = 0; - } - if ((i == 0) | (strncmp(yeschr, ans, i))) - return (0); - return (1); -} - -static int confirm(FILE *fp, const char *q, ...) { va_list ap; diff --git a/usr/src/cmd/tar/Makefile b/usr/src/cmd/tar/Makefile index e769a93542..a8053fb33d 100644 --- a/usr/src/cmd/tar/Makefile +++ b/usr/src/cmd/tar/Makefile @@ -19,7 +19,7 @@ # CDDL HEADER END # # -# Copyright 2006 Sun Microsystems, Inc. All rights reserved. +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "%Z%%M% %I% %E% SMI" @@ -28,12 +28,16 @@ PROG= tar DEFAULTFILES= tar.dfl +OBJS1= tar.o +OBJS= $(OBJS1) getresponse.o +SRCS= $(OBJS1:%.o=%.c) $(SRC)/common/util/getresponse.c include ../Makefile.cmd -CPPFLAGS += -D_FILE_OFFSET_BITS=64 +CPPFLAGS += -D_FILE_OFFSET_BITS=64 -I $(SRC)/common/util DCFILE= $(PROG).dc +LINTFLAGS += -u LAZYLIBS = $(ZLAZYLOAD) -ltsol $(ZNOLAZYLOAD) lint := LAZYLIBS = -ltsol LDLIBS += -lsec $(LAZYLIBS) @@ -60,9 +64,18 @@ install: all $(ROOTUSRSBINPROG) $(ROOTETCDEFAULTFILES) $(ROOTSYMLINK) $(ROOTSYMLINK): $(RM) $@; $(SYMLINK) ../sbin/$(PROG) $@ +$(PROG): $(OBJS) + $(LINK.c) $(OBJS) -o $@ $(LDLIBS) + $(POST_PROCESS) + +%.o: $(SRC)/common/util/%.c + $(COMPILE.c) $(OUTPUT_OPTION) $< + $(POST_PROCESS_O) + clean: + $(RM) $(OBJS) -lint: lint_PROG +lint: lint_SRCS $(DCFILE): $(RM) messages.po diff --git a/usr/src/cmd/tar/tar.c b/usr/src/cmd/tar/tar.c index 4fff1f030f..d68c4e0e34 100644 --- a/usr/src/cmd/tar/tar.c +++ b/usr/src/cmd/tar/tar.c @@ -69,6 +69,8 @@ #include <iconv.h> #include <assert.h> #include <aclutils.h> +#include "getresponse.h" + #if defined(__SunOS_5_6) || defined(__SunOS_5_7) extern int defcntl(); #endif @@ -447,7 +449,6 @@ static int is_prefix(char *s1, char *s2); static int response(void); static int build_dblock(const char *, const char *, const char, const int filetype, const struct stat *, const dev_t, const char *); -static wchar_t yesnoresponse(void); static unsigned int hash(char *str); #ifdef _iBCS2 @@ -657,6 +658,12 @@ main(int argc, char *argv[]) tfile = NULL; + if (init_yes() < 0) { + (void) fprintf(stderr, gettext(ERR_MSG_INIT_YES), + strerror(errno)); + exit(2); + } + /* * For XPG4 compatibility, we must be able to accept the "--" * argument normally recognized by getopt; it is used to delimit @@ -3279,15 +3286,11 @@ xsfile(int ofd) /* make sure we do extractions in order */ if (extno != 1) { /* starting in middle of file? */ - wchar_t yeschar; - wchar_t nochar; - (void) mbtowc(&yeschar, nl_langinfo(YESSTR), MB_LEN_MAX); - (void) mbtowc(&nochar, nl_langinfo(NOSTR), MB_LEN_MAX); (void) printf(gettext( "tar: first extent read is not #1\n" - "OK to read file beginning with extent #%d (%wc/%wc) ? "), - extno, yeschar, nochar); - if (yesnoresponse() != yeschar) { + "OK to read file beginning with extent #%d (%s/%s) ? "), + extno, yesstr, nostr); + if (yes() == 0) { canit: passtape(); if (close(ofd) != 0) @@ -3958,7 +3961,7 @@ checkw(char c, char *name) if (vflag) longt(&stbuf, ' '); /* do we have acl info here */ (void) fprintf(vfile, "%s: ", name); - if (response() == 'y') { + if (yes() == 1) { return (1); } return (0); @@ -5164,21 +5167,6 @@ check_prefix(char **namep, char **dirp, char **compp) *compp = component; } - -static wchar_t -yesnoresponse(void) -{ - wchar_t c; - - c = getwchar(); - if (c != '\n') - while (getwchar() != '\n') - ; - else c = 0; - return (c); -} - - /* * Return true if the object indicated by the file descriptor and type * is a tape device, false otherwise @@ -7368,7 +7356,7 @@ append_ext_attr(char *shortname, char **secinfo, int *len) * append DIR_TYPE */ (void) append_secattr(secinfo, len, 1, - "\0", DIR_TYPE); + "\0", DIR_TYPE); /* * Get and append attribute types LBL_TYPE. @@ -7831,7 +7819,7 @@ rebuild_lk_comp_path(char *str, char **namep) getzoneidbylabel(&bslabel)) == -1) { (void) fprintf(stderr, gettext("tar: can't get " - "zone ID for %s\n"), + "zone ID for %s\n"), tempbuf); return (-1); } @@ -7840,7 +7828,7 @@ rebuild_lk_comp_path(char *str, char **namep) /* Badly configured zone info */ (void) fprintf(stderr, gettext("tar: can't get " - "zonename for %s\n"), + "zonename for %s\n"), tempbuf); return (-1); } @@ -7873,8 +7861,8 @@ rebuild_lk_comp_path(char *str, char **namep) default: (void) fprintf(stderr, gettext( - "tar: error rebuilding path %s\n"), - *namep); + "tar: error rebuilding path %s\n"), + *namep); *buf = '\0'; str++; return (-1); @@ -7913,8 +7901,8 @@ check_ext_attr(char *filename) if (getlabel(filename, ¤tlabel) != 0) { (void) fprintf(stderr, gettext("tar: can't get label for " - " %s, getlabel() error: %s\n"), - filename, strerror(errno)); + " %s, getlabel() error: %s\n"), + filename, strerror(errno)); return (0); } else if ((blequal(¤tlabel, &bs_label)) == 0) { char *src_label = NULL; /* ascii label */ @@ -7923,11 +7911,11 @@ check_ext_attr(char *filename) if (bsltos(&bs_label, &src_label, 0, 0) <= 0) { (void) fprintf(stderr, gettext("tar: can't interpret requested label for" - " %s\n"), filename); + " %s\n"), filename); } else { (void) fprintf(stderr, gettext("tar: can't apply label %s to %s\n"), - src_label, filename); + src_label, filename); free(src_label); } (void) fprintf(stderr, diff --git a/usr/src/cmd/tar/tar.xcl b/usr/src/cmd/tar/tar.xcl index f5266202f5..2644eb7bea 100644 --- a/usr/src/cmd/tar/tar.xcl +++ b/usr/src/cmd/tar/tar.xcl @@ -2,9 +2,8 @@ # CDDL HEADER START # # The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (the "License"). You may not use this file except in compliance -# with the License. +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. @@ -19,6 +18,13 @@ # # CDDL HEADER END # +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +#ident "%Z%%M% %I% %E% SMI" + msgid "" msgid " %-12.12s %-4.4s " msgid " [extent #%d of %d]" @@ -75,3 +81,83 @@ msgid "w" msgid "x %s (in %d extents), %lu bytes, %luK\n" msgid "x %s, %lu bytes, " msgid "x %s, 0 bytes, " +msgid "SYSV3" +msgid "--" +msgid "%ld" +msgid "TMPDIR" +msgid "/tmp" +msgid "/PaxHeaders." +msgid "%12llo" +msgid "%8o" +msgid "%s %10ld.%9.9ld\n" +msgid "%.*s %10ld.%9.9ld\n" +msgid " " +msgid "%llu" +msgid "%lldK\n" +msgid "%s%s%s" +msgid "a %s%s%s " +msgid "%9llo" +msgid "%011llo" +msgid "+++ a %s %lldK [extent #%d of %d]\n" +msgid "%.*s" +msgid "x %s, %lld bytes, " +msgid "x %s%s%s, %lld bytes, " +msgid "x %s(A), %lld bytes, %lld tape blocks\n" +msgid "%7o" +msgid "+++ x %s [extent #%d], %lld bytes, %ldK\n" +msgid "file %.*s" +msgid "%3ld/%-3ld" +msgid " %6lld" +msgid " %s " +msgid "%07lo" +msgid "SCCS" +msgid "RCS" +msgid "core" +msgid "errs" +msgid "a.out" +msgid "%s %ld.%ld" +msgid "b[0] == '\\n'" +msgid "tar.c" +msgid "read" +msgid "write" +msgid "tar: " +msgid ": %s\n" +msgid "%.*s/%.*s" +msgid "malloc" +msgid "%.5s" +msgid "%.31s" +msgid "mtime" +msgid "SUN.devmajor" +msgid "SUN.devminor" +msgid "gid" +msgid "uid" +msgid "size" +msgid "path" +msgid "linkpath" +msgid "gname" +msgid "uname" +msgid "%06o" +msgid "%06d" +msgid "%12o" +msgid "%011o" +msgid "NULL" +msgid "%d %s=%s\n" +msgid "%9.9ld" +msgid "PATH_MAX <= 9996" +msgid "646" +msgid "UTF-8" +msgid "ISO" +msgid "1.0" +msgid "%0*d" +msgid "/dev/null" +msgid ".hdr" +msgid "%s.hdr" +msgid "/dev/null/%s" +msgid "%10d" +msgid "%7d" +msgid "/" +msgid "ADMIN_LOW [] " +msgid "ADMIN_LOW [%s]" +msgid ";;" +msgid "../" +msgid "/zone" diff --git a/usr/src/cmd/xargs/Makefile b/usr/src/cmd/xargs/Makefile index 31ca325398..e6d32e7452 100644 --- a/usr/src/cmd/xargs/Makefile +++ b/usr/src/cmd/xargs/Makefile @@ -21,28 +21,44 @@ # #ident "%Z%%M% %I% %E% SMI" # -# Copyright 2006 Sun Microsystems, Inc. All rights reserved. +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # -PROG= xargs +PROG= xargs # /usr/xpg6/bin/xargs is a symlink to /usr/bin/xargs -ROOTXPG6SYMLINK= $(ROOTXPG6BIN)/xargs +ROOTXPG6SYMLINK= $(ROOTXPG6BIN)/xargs + +OBJS1= xargs.o +OBJS= $(OBJS1) getresponse.o +SRCS= $(OBJS1:%.o=%.c) $(SRC)/common/util/getresponse.c include ../Makefile.cmd +CPPFLAGS += -I $(SRC)/common/util +LINTFLAGS += -u + .KEEP_STATE: all: $(PROG) install: all $(ROOTPROG) $(ROOTXPG6SYMLINK) +$(PROG): $(OBJS) + $(LINK.c) -o $@ $(OBJS) $(LDLIBS) + $(POST_PROCESS) + +%.o: $(SRC)/common/util/%.c + $(COMPILE.c) $(OUTPUT_OPTION) $< + $(POST_PROCESS_O) + $(ROOTXPG6SYMLINK): $(ROOTPROG) -$(RM) $@ -$(SYMLINK) ../../bin/$(PROG) $@ clean: + $(RM) $(OBJS) -lint: lint_PROG +lint: lint_SRCS include ../Makefile.targ diff --git a/usr/src/cmd/xargs/xargs.c b/usr/src/cmd/xargs/xargs.c index 5c2f6b5b8f..f390483cbe 100644 --- a/usr/src/cmd/xargs/xargs.c +++ b/usr/src/cmd/xargs/xargs.c @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -36,7 +36,6 @@ #include <fcntl.h> #include <string.h> #include <stdarg.h> -#include <libgen.h> #include <stdlib.h> #include <limits.h> #include <wchar.h> @@ -46,6 +45,7 @@ #include <poll.h> #include <errno.h> #include <stdarg.h> +#include "getresponse.h" #define HEAD 0 #define TAIL 1 @@ -94,7 +94,6 @@ static int TRACE = FALSE; static int INSERT = FALSE; static int linesize = 0; static int ibufsize = 0; -static char *yesstr; /* the string contains int'l for "yes" */ static int exitstat = 0; /* our exit status */ static int mac; /* modified argc, after parsing */ static char **mav; /* modified argv, after parsing */ @@ -137,7 +136,6 @@ static void usage(); static void parseargs(); static void saveinput(); - int main(int argc, char **argv) { @@ -149,7 +147,6 @@ main(int argc, char **argv) /* initialization */ - blank = wctype("blank"); n_inserts = 0; psave = saveargv; @@ -158,20 +155,10 @@ main(int argc, char **argv) #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */ #endif (void) textdomain(TEXT_DOMAIN); - - /* - * now we get the appropriate "yes" string for our locale. - * since this may be a multibyte character, we store the - * string which is returned. later on, when we're looking for - * a "y" in response to our prompt, we'll use the first - * multibyte character of yesstr as a comparision. - */ - initbuf = nl_langinfo(YESSTR); /* initbuf is a tmp placeholder here */ - if ((yesstr = malloc(strlen(initbuf) + 1)) == NULL) { - perror(gettext("xargs: Memory allocation failure")); + if (init_yes() < 0) { + ermsg(gettext(ERR_MSG_INIT_YES), strerror(errno)); exit(1); } - (void) strcpy(yesstr, initbuf); parseargs(argc, argv); @@ -788,51 +775,6 @@ ermsg(char *messages, ...) OK = FALSE; } - -/* - * Function: int rpmatch(char *) - * - * Description: - * - * Internationalized get yes / no answer. - * - * Inputs: - * s -> Pointer to answer to compare against. - * - * Returns: - * TRUE -> Answer was affirmative - * FALSE -> Answer was negative - */ - -static int -rpmatch(char *s) -{ - static char *default_yesexpr = "^[Yy].*"; - static char *compiled_yesexpr = (char *)NULL; - - /* Execute once to initialize */ - if (compiled_yesexpr == (char *)NULL) { - char *yesexpr; - - /* get yes expression according to current locale */ - yesexpr = nl_langinfo(YESEXPR); - /* - * If the was no expression or if there is a compile error - * use default yes expression. Anchor - */ - if ((yesexpr == (char *)NULL) || (*yesexpr == (char)NULL) || - ((compiled_yesexpr = - regcmp(yesexpr, 0)) == NULL)) - compiled_yesexpr = regcmp(default_yesexpr, 0); - } - - /* match yesexpr */ - if (regex(compiled_yesexpr, s) == NULL) { - return (FALSE); - } - return (TRUE); -} - static int echoargs() { @@ -869,7 +811,6 @@ echoargs() * of our desired y/n input. so, we see if there's any extra * input, and if there is, then we will store it. */ - saveinput(); (void) write(2, "?...", 4); /* ask the user for input */ @@ -891,14 +832,7 @@ echoargs() ; } - /* - * now we have to figure out whether the user typed an - * internationalized version of 'y' for yes. note that in some - * countries, they've gotten used to typing an ASCII 'y'! so - * even if our int'l version fails, we will check for an ASCII - * 'y', in order to be backwards compatible. - */ - return (rpmatch(reply)); + return (yes_check(reply)); } diff --git a/usr/src/common/util/getresponse.c b/usr/src/common/util/getresponse.c new file mode 100644 index 0000000000..cc838a7ab1 --- /dev/null +++ b/usr/src/common/util/getresponse.c @@ -0,0 +1,186 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <regex.h> +#include <locale.h> +#include <langinfo.h> +#include <limits.h> +#include <errno.h> +#include "getresponse.h" + +/* defaults - C locale values for yesstr, nostr, yesexpr (LC_MESSAGES) */ +#define DEFAULT_YESSTR "yes" +#define DEFAULT_NOSTR "no" +#define DEFAULT_YESEXPR "^[yY]" +#define DEFAULT_NOEXPR "^[nN]" + +#define FREE_MEM \ + if (yesstr) \ + free(yesstr); \ + if (nostr) \ + free(nostr); \ + if (yesexpr) \ + free(yesexpr); \ + if (noexpr) \ + free(noexpr) + +#define SET_DEFAULT_STRS \ + yesstr = DEFAULT_YESSTR; \ + nostr = DEFAULT_NOSTR; \ + yesexpr = DEFAULT_YESEXPR; \ + noexpr = DEFAULT_NOEXPR; + +/* variables used by getresponse functions */ +char *yesstr = NULL; +char *nostr = NULL; + +/* for regcomp()/regexec() yesexpr and noexpr */ +static regex_t preg_yes, preg_no; + +/* + * This function compiles a regular expression that is used to match an + * affirmative response from the user, and also assigns the strings used + * in the prompts that request affirmative or negative responses. The + * locale's values for YESEXPR, NOEXPR, YESSTR and NOSTR are used. + * + * If there are any problems using the locale's YESEXPR, NOEXPR, YESSTR or NOSTR + * values, default values of YESEXPR, YESSTR and NOSTR will be used + * as a fallback. The default values are the same as the C locale values. + */ +int +init_yes(void) +{ + int fallback = 0; + char *yesexpr; + char *noexpr; + + /* get yes expression and strings for yes/no prompts */ + yesstr = strdup(nl_langinfo(YESSTR)); + nostr = strdup(nl_langinfo(NOSTR)); + yesexpr = strdup(nl_langinfo(YESEXPR)); + noexpr = strdup(nl_langinfo(NOEXPR)); + + if (yesstr == NULL || nostr == NULL || + yesexpr == NULL || noexpr == NULL) { + FREE_MEM; + errno = ENOMEM; + return (-1); + } + + /* if problem with locale strings, use default values */ + if (*yesstr == '\0' || *nostr == '\0' || + *yesexpr == '\0' || *noexpr == '\0') { + FREE_MEM; + SET_DEFAULT_STRS; + fallback = 1; + } + /* Compile the yes and no expressions */ + while (regcomp(&preg_yes, yesexpr, REG_EXTENDED | REG_NOSUB) != 0 || + regcomp(&preg_no, noexpr, REG_EXTENDED | REG_NOSUB) != 0) { + if (fallback == 1) { + /* The fallback yesexpr failed, so exit */ + errno = EINVAL; + return (-1); + } + /* The locale's yesexpr or noexpr failed so use fallback */ + FREE_MEM; + SET_DEFAULT_STRS; + fallback = 1; + } + return (0); +} + +static int +yes_no(int (*func)(char *)) +{ + int i, b; + char ans[LINE_MAX + 1]; + + /* Get user's answer */ + for (i = 0; b = getchar(); i++) { + if (b == '\n' || b == '\0' || b == EOF) + break; + if (i < LINE_MAX) + ans[i] = b; + } + if (i >= LINE_MAX) + ans[LINE_MAX] = '\0'; + else + ans[i] = '\0'; + + return (func(ans)); +} + +static int +yes_no_check(char *ans, regex_t *reg1, regex_t *reg2) +{ + if (regexec(reg1, ans, 0, NULL, 0) == 0) { + if (regexec(reg2, ans, 0, NULL, 0) == 0) { + /* Both Expressions Match (reg2 conservative) */ + return (0); + } + /* Match */ + return (1); + } + return (0); +} + +/* + * yes_check() returns 1 if the input string is matched by yesexpr and is + * not matched by noexpr; otherwise yes_check() returns 0. + */ +int +yes_check(char *ans) +{ + return (yes_no_check(ans, &preg_yes, &preg_no)); +} + +/* + * no_check() returns 1 if the input string is matched by noexpr and is + * not matched by yesexpr; otherwise no_check() returns 0. + */ +int +no_check(char *ans) +{ + return (yes_no_check(ans, &preg_no, &preg_yes)); +} + +int +yes(void) +{ + return (yes_no(yes_check)); +} + +int +no(void) +{ + return (yes_no(no_check)); +} diff --git a/usr/src/common/util/getresponse.h b/usr/src/common/util/getresponse.h new file mode 100644 index 0000000000..cb63d634fa --- /dev/null +++ b/usr/src/common/util/getresponse.h @@ -0,0 +1,53 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#ifndef _UTIL_GETRESPONSE_H +#define _UTIL_GETRESPONSE_H + +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Declarations for getresponse(). + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#define ERR_MSG_INIT_YES "Error initializing international response strings: %s" + +extern char *yesstr; +extern char *nostr; +extern int init_yes(void); +extern int yes(void); +extern int yes_check(char *); +extern int no(void); +extern int no_check(char *); + +#ifdef __cplusplus +} +#endif + +#endif /* _UTIL_GETRESPONSE_H */ |