bin/68062: standalone repeat(1) command

Cyrille Lefevre cyrille.lefevre at laposte.net
Thu Jun 17 23:10:36 GMT 2004


>Number:         68062
>Category:       bin
>Synopsis:       standalone repeat(1) command
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jun 17 23:10:26 GMT 2004
>Closed-Date:
>Last-Modified:
>Originator:     Cyrille Lefevre
>Release:        FreeBSD 5.2-CURRENT i386
>Organization:
ACME
>Environment:
System: FreeBSD gits 5.2-CURRENT FreeBSD 5.2-CURRENT #29: Mon May 31 01:35:59 CEST 2004 root at gits:/disk3/freebsd/current/obj/disk3/freebsd/current/src/sys/CUSTOM i386
>Description:
	the standalone repeat(1) utility inpired from the csh(1) one.
>How-To-Repeat:
	repeat 3 sync
>Fix:
Index: Makefile
===================================================================
RCS file: /home/ncvs/src/share/man/man1/Makefile,v
retrieving revision 1.17
diff -u -I$Id.*$ -I$.+BSD.*$ -r1.17 Makefile
--- Makefile	20 Jan 2004 10:27:22 -0000	1.17
+++ Makefile	17 Jun 2004 22:22:34 -0000
@@ -61,7 +61,6 @@
 	builtin.1 read.1 \
 	builtin.1 readonly.1 \
 	builtin.1 rehash.1 \
-	builtin.1 repeat.1 \
 	builtin.1 sched.1 \
 	builtin.1 set.1 \
 	builtin.1 setenv.1 \

# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	usr.bin/repeat/Makefile
#	usr.bin/repeat/repeat.1
#	usr.bin/repeat/repeat.c
#
echo x - usr.bin/repeat/Makefile
sed 's/^X//' >usr.bin/repeat/Makefile << 'END-of-usr.bin/repeat/Makefile'
X# $FreeBSD$
X
XPROG=	repeat
XWARNS?=	6
X
X.include <bsd.prog.mk>
END-of-usr.bin/repeat/Makefile
echo x - usr.bin/repeat/repeat.1
sed 's/^X//' >usr.bin/repeat/repeat.1 << 'END-of-usr.bin/repeat/repeat.1'
X.\" Copyright (c) 2004
X.\"	The Regents of the University of California.  All rights reserved.
X.\"
X.\" This code is derived from software contributed to Berkeley by
X.\" the Institute of Electrical and Electronics Engineers, Inc.
X.\"
X.\" Redistribution and use in source and binary forms, with or without
X.\" modification, are permitted provided that the following conditions
X.\" are met:
X.\" 1. Redistributions of source code must retain the above copyright
X.\"    notice, this list of conditions and the following disclaimer.
X.\" 2. Redistributions in binary form must reproduce the above copyright
X.\"    notice, this list of conditions and the following disclaimer in the
X.\"    documentation and/or other materials provided with the distribution.
X.\" 4. Neither the name of the University nor the names of its contributors
X.\"    may be used to endorse or promote products derived from this software
X.\"    without specific prior written permission.
X.\"
X.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
X.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
X.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
X.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
X.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
X.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
X.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
X.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
X.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
X.\" SUCH DAMAGE.
X.\"
X.\"     @(#)apply.1	8.2 (Berkeley) 4/4/94
X.\" From: src/usr.bin/apply/apply.1,v 1.14 2002/04/19 23:16:06 charnier Exp
X.\" $FreeBSD$
X.\"
X.Dd June 17, 2004
X.Dt REPEAT 1
X.Os
X.Sh NAME
X.Nm repeat
X.Nd repeat a command count times
X.Sh SYNOPSIS
X.Nm
X.Ar count
X.Ar command
X.Op Ar argument ...
X.Sh DESCRIPTION
XThe
X.Nm
Xutility runs the named
X.Ar command
Xwith optional
X.Ar argument ,
X.Pa count
Xtimes.
X.Sh DIAGNOSTICS
X.Ex -std
X.Sh SEE ALSO
X.Xr csh 1
X.Sh HISTORY
XThe
X.Nm
Xutility first appeared in
X.Xr csh 1 .
END-of-usr.bin/repeat/repeat.1
echo x - usr.bin/repeat/repeat.c
sed 's/^X//' >usr.bin/repeat/repeat.c << 'END-of-usr.bin/repeat/repeat.c'
X/*-
X * Copyright (c) 2004
X *	The Regents of the University of California.  All rights reserved.
X *
X * Redistribution and use in source and binary forms, with or without
X * modification, are permitted provided that the following conditions
X * are met:
X * 1. Redistributions of source code must retain the above copyright
X *    notice, this list of conditions and the following disclaimer.
X * 2. Redistributions in binary form must reproduce the above copyright
X *    notice, this list of conditions and the following disclaimer in the
X *    documentation and/or other materials provided with the distribution.
X * 4. Neither the name of the University nor the names of its contributors
X *    may be used to endorse or promote products derived from this software
X *    without specific prior written permission.
X *
X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
X * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
X * SUCH DAMAGE.
X */
X
X#include <sys/cdefs.h>
X__FBSDID("$FreeBSD$");
X
X#include <sys/types.h>
X#include <sys/wait.h>
X
X#include <err.h>
X#include <errno.h>
X#include <signal.h>
X#include <stdio.h>
X#include <stdlib.h>
X#include <unistd.h>
X
Xstatic int exec_cmd(const char *, char *const *);
Xstatic void usage(void) __dead2;
X
Xint
Xmain(int argc, char *const argv[])
X{
X	char *endp;
X	long count;
X	int rval;
X
X	if (argc < 2)
X		usage();
X
X	count = strtol(argv[1], &endp, 10);
X	if (errno == ERANGE || endp == argv[1] || *endp || count < 0)
X		errx(1, "%s: badly formed number.", argv[1]);
X
X	for (rval = 0; count > 0; count--)
X		if (exec_cmd(argv[2], &argv[2]))
X			rval = 1;
X
X	exit(rval);
X}
X
X/*
X * based on exec_shell() from apply(1).
X * exec_cmd --
X *      Execute a command using passed arguments.
X */
Xstatic int
Xexec_cmd(const char *command, char *const *argv)
X{
X	pid_t pid;
X	int omask, pstat;
X	sig_t intsave, quitsave;
X
X	if (!argv || !argv[0])           /* just checking... */
X		return(1);
X
X	omask = sigblock(sigmask(SIGCHLD));
X	switch(pid = vfork()) {
X	case -1:                        /* error */
X		err(1, "vfork");
X	case 0:                         /* child */
X		(void)sigsetmask(omask);
X		execvp(command, argv);
X		warn("%s", command);
X		_exit(1);
X	}
X	intsave = signal(SIGINT, SIG_IGN);
X	quitsave = signal(SIGQUIT, SIG_IGN);
X	pid = waitpid(pid, &pstat, 0);
X	(void)sigsetmask(omask);
X	(void)signal(SIGINT, intsave);
X	(void)signal(SIGQUIT, quitsave);
X	return(pid == -1 ? -1 : pstat);
X}
X
Xstatic void
Xusage(void)
X{
X
X	(void)fprintf(stderr, "usage: repeat count command [argument ...]\n");
X	exit(1);
X}
END-of-usr.bin/repeat/repeat.c
exit

>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list