forked from Imagelibrary/rtems
2007-12-22 Chris Johns <chrisj@rtems.org>
* configure.ac: fixed bug that always enabled strict order mutexes. * score/inline/rtems/score/coremutex.inl: Fixed coding standard. * score/src/coremutex.c: Add the holder's thread to the lock_mutex list if the mutex is initialised locked. * libnetworking/rtems/rtems_glue.c: Changed semaphore error message to show the error is an rtems-net error. * libmisc/monitor/mon-network.c: Removed warnings. * telnetd/icmds.c: Changed shell_* to rtems_shell_*. * score/Makefile.am: Fixed typo that stopped 'make tags' working. * libmisc/shell/err.c, libmisc/shell/err.h, libmisc/shell/errx.c, libmisc/shell/extern-cp.h, libmisc/shell/fts.c, libmisc/shell/fts.h, libmisc/shell/main_cp.c, libmisc/shell/utils-cp.c, libmisc/shell/verr.c, libmisc/shell/verrx.c, libmisc/shell/vwarn.c, libmisc/shell/vwarnx.c, libmisc/shell/warn.c, libmisc/shell/warnx.c: New. Ported from BSD. * libmisc/shell/shellconfig.h: Add the cp command. * libmisc/Makefile.am: Add the new files to the shell. * libmisc/shell/shell.c, libmisc/shell/shell.h: Add scripting support. * libblock/src/flashdisk.c: Fixed disk drive count size setting bug.
This commit is contained in:
@@ -1,3 +1,29 @@
|
||||
2007-12-22 Chris Johns <chrisj@rtems.org>
|
||||
|
||||
* configure.ac: fixed bug that always enabled strict order
|
||||
mutexes.
|
||||
* score/inline/rtems/score/coremutex.inl: Fixed coding standard.
|
||||
* score/src/coremutex.c: Add the holder's thread to the lock_mutex
|
||||
list if the mutex is initialised locked.
|
||||
* libnetworking/rtems/rtems_glue.c: Changed semaphore error
|
||||
message to show the error is an rtems-net error.
|
||||
* libmisc/monitor/mon-network.c: Removed warnings.
|
||||
* telnetd/icmds.c: Changed shell_* to rtems_shell_*.
|
||||
* score/Makefile.am: Fixed typo that stopped 'make tags' working.
|
||||
* libmisc/shell/err.c, libmisc/shell/err.h, libmisc/shell/errx.c,
|
||||
libmisc/shell/extern-cp.h, libmisc/shell/fts.c,
|
||||
libmisc/shell/fts.h, libmisc/shell/main_cp.c,
|
||||
libmisc/shell/utils-cp.c, libmisc/shell/verr.c,
|
||||
libmisc/shell/verrx.c, libmisc/shell/vwarn.c,
|
||||
libmisc/shell/vwarnx.c, libmisc/shell/warn.c,
|
||||
libmisc/shell/warnx.c: New. Ported from BSD.
|
||||
* libmisc/shell/shellconfig.h: Add the cp command.
|
||||
* libmisc/Makefile.am: Add the new files to the shell.
|
||||
* libmisc/shell/shell.c, libmisc/shell/shell.h: Add scripting
|
||||
support.
|
||||
* libblock/src/flashdisk.c: Fixed disk drive count size setting
|
||||
bug.
|
||||
|
||||
2007-12-21 Xi Yang <hiyangxi@gmail.com>
|
||||
|
||||
* rtems/src/semtranslatereturncode.c: Add support for proper stacking
|
||||
|
||||
@@ -234,7 +234,7 @@ RTEMS_CPUOPT([__RTEMS_DO_NOT_INLINE_CORE_MUTEX_SEIZE__],
|
||||
|
||||
## This gives the same behavior as 4.8 and older
|
||||
RTEMS_CPUOPT([__STRICT_ORDER_MUTEX__],
|
||||
[test x"${ENABLE_STRICT_ORDER_MUTEX}"=x"1"],
|
||||
[test x"${ENABLE_STRICT_ORDER_MUTEX}"= x"1"],
|
||||
[1],
|
||||
[disable strict order mutex]
|
||||
)
|
||||
|
||||
@@ -2002,7 +2002,7 @@ rtems_fdisk_read (rtems_flashdisk* fd, blkdev_request* req)
|
||||
|
||||
/**
|
||||
* Flash disk WRITE request handler. This primitive copies data from
|
||||
* supplied buffer to RAM disk and invoke the callout function to inform
|
||||
* supplied buffer to flash disk and invoke the callout function to inform
|
||||
* upper layer that writing is completed.
|
||||
*
|
||||
* @param req Pointers to the WRITE block device request info.
|
||||
@@ -2340,6 +2340,8 @@ rtems_fdisk_ioctl (dev_t dev, uint32_t req, void* argp)
|
||||
/**
|
||||
* Flash disk device driver initialization.
|
||||
*
|
||||
* @todo Memory clean up on error is really badly handled.
|
||||
*
|
||||
* @param major Flash disk major device number.
|
||||
* @param minor Minor device number, not applicable.
|
||||
* @param arg Initialization argument, not applicable.
|
||||
@@ -2419,7 +2421,7 @@ rtems_fdisk_initialize (rtems_device_major_number major,
|
||||
if (!fd->blocks)
|
||||
return RTEMS_NO_MEMORY;
|
||||
|
||||
fd->block_count = blocks;
|
||||
fd->block_count = blocks;
|
||||
|
||||
fd->devices = calloc (c->device_count, sizeof (rtems_fdisk_device_ctl));
|
||||
if (!fd->devices)
|
||||
@@ -2471,9 +2473,9 @@ rtems_fdisk_initialize (rtems_device_major_number major,
|
||||
if (ret)
|
||||
rtems_fdisk_error ("compacting of disk failed: %s (%d)",
|
||||
strerror (ret), ret);
|
||||
|
||||
rtems_flashdisk_count = rtems_flashdisk_configuration_size;
|
||||
}
|
||||
|
||||
rtems_flashdisk_count = rtems_flashdisk_configuration_size;
|
||||
|
||||
return RTEMS_SUCCESSFUL;
|
||||
}
|
||||
|
||||
@@ -68,10 +68,11 @@ if LIBNETWORKING
|
||||
shell_mount_fs = shell/main_mount_ftp.c shell/main_mount_nfs.c \
|
||||
shell/main_mount_tftp.c
|
||||
endif
|
||||
libshell_a_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)/shell
|
||||
libshell_a_SOURCES = shell/cat_file.c shell/cmds.c shell/internal.h \
|
||||
shell/main_alias.c shell/main_cat.c shell/main_cd.c \
|
||||
shell/main_chdir.c shell/main_chmod.c shell/main_chroot.c \
|
||||
shell/main_cpuuse.c shell/main_date.c shell/main_dir.c \
|
||||
shell/main_cp.c shell/main_cpuuse.c shell/main_date.c shell/main_dir.c \
|
||||
shell/main_exit.c shell/main_help.c shell/main_id.c \
|
||||
shell/main_logoff.c shell/main_ls.c shell/main_mallocinfo.c \
|
||||
shell/main_mdump.c shell/main_medit.c shell/main_mfill.c \
|
||||
@@ -82,7 +83,10 @@ libshell_a_SOURCES = shell/cat_file.c shell/cmds.c shell/internal.h \
|
||||
shell/main_tty.c shell/main_umask.c shell/main_unmount.c \
|
||||
shell/main_blksync.c shell/main_whoami.c shell/shell.c \
|
||||
shell/shell_cmdset.c shell/shellconfig.c shell/shellconfig.h \
|
||||
shell/shell.h shell/shell_makeargs.c shell/str2int.c shell/write_file.c
|
||||
shell/shell.h shell/shell_makeargs.c shell/str2int.c shell/write_file.c \
|
||||
shell/utils-cp.c shell/err.c shell/errx.c shell/verr.c shell/verrx.c \
|
||||
shell/vwarn.c shell/vwarnx.c shell/warn.c shell/warnx.c \
|
||||
shell/fts.c
|
||||
endif
|
||||
|
||||
EXTRA_DIST += shell/README
|
||||
|
||||
@@ -326,7 +326,10 @@ void mon_route(int argc, char *argv[], uint32_t command_arg,
|
||||
flags |= RTF_HOST;
|
||||
}
|
||||
|
||||
rc = rtems_bsdnet_rtrequest(cmd, &dst, &gw, &netmask, flags, NULL);
|
||||
rc = rtems_bsdnet_rtrequest(cmd,
|
||||
(struct sockaddr*) &dst,
|
||||
(struct sockaddr*) &gw,
|
||||
(struct sockaddr*) &netmask, flags, NULL);
|
||||
if (rc < 0) {
|
||||
printf("Error adding route\n");
|
||||
}
|
||||
|
||||
60
cpukit/libmisc/shell/err.c
Normal file
60
cpukit/libmisc/shell/err.c
Normal file
@@ -0,0 +1,60 @@
|
||||
/* $NetBSD: err.c,v 1.25 2005/09/13 13:51:50 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)err.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: err.c,v 1.25 2005/09/13 13:51:50 christos Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <err.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(err, _err)
|
||||
#endif
|
||||
|
||||
__dead void
|
||||
err(jmp_buf* exit_jmp, int eval, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
verr(exit_jmp, eval, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
84
cpukit/libmisc/shell/err.h
Normal file
84
cpukit/libmisc/shell/err.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/* $NetBSD: err.h,v 1.14 2005/02/03 04:39:32 perry Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)err.h 8.1 (Berkeley) 6/2/93
|
||||
*/
|
||||
|
||||
#ifndef _ERR_H_
|
||||
#define _ERR_H_
|
||||
|
||||
/*
|
||||
* Don't use va_list in the err/warn prototypes. Va_list is typedef'd in two
|
||||
* places (<machine/varargs.h> and <machine/stdarg.h>), so if we include one
|
||||
* of them here we may collide with the utility's includes. It's unreasonable
|
||||
* for utilities to have to include one of them to include err.h, so we get
|
||||
* _BSD_VA_LIST_ from <machine/ansi.h> and use it.
|
||||
*/
|
||||
#include <machine/ansi.h>
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#include <stdarg.h>
|
||||
#define _BSD_VA_LIST_ va_list
|
||||
|
||||
#define __dead
|
||||
|
||||
#define err rtems_shell_err
|
||||
#define verr rtems_shell_verr
|
||||
#define errx rtems_shell_errx
|
||||
#define verrx rtems_shell_verrx
|
||||
#define warn rtems_shell_warn
|
||||
#define vwarn rtems_shell_vwarn
|
||||
#define warnx rtems_shell_warnx
|
||||
#define vwarnx rtems_shell_vwarnx
|
||||
|
||||
#include <setjmp.h>
|
||||
|
||||
extern jmp_buf rtems_shell_bsd_exit_recover;
|
||||
|
||||
__BEGIN_DECLS
|
||||
__dead void err(jmp_buf*, int, const char *, ...)
|
||||
__attribute__((__noreturn__, __format__(__printf__, 3, 4)));
|
||||
__dead void verr(jmp_buf*, int, const char *, _BSD_VA_LIST_)
|
||||
__attribute__((__noreturn__, __format__(__printf__, 3, 0)));
|
||||
__dead void errx(jmp_buf*, int, const char *, ...)
|
||||
__attribute__((__noreturn__, __format__(__printf__, 3, 4)));
|
||||
__dead void verrx(jmp_buf*, int, const char *, _BSD_VA_LIST_)
|
||||
__attribute__((__noreturn__, __format__(__printf__, 3, 0)));
|
||||
void warn(const char *, ...)
|
||||
__attribute__((__format__(__printf__, 1, 2)));
|
||||
void vwarn(const char *, _BSD_VA_LIST_)
|
||||
__attribute__((__format__(__printf__, 1, 0)));
|
||||
void warnx(const char *, ...)
|
||||
__attribute__((__format__(__printf__, 1, 2)));
|
||||
void vwarnx(const char *, _BSD_VA_LIST_)
|
||||
__attribute__((__format__(__printf__, 1, 0)));
|
||||
__END_DECLS
|
||||
|
||||
#endif /* !_ERR_H_ */
|
||||
60
cpukit/libmisc/shell/errx.c
Normal file
60
cpukit/libmisc/shell/errx.c
Normal file
@@ -0,0 +1,60 @@
|
||||
/* $NetBSD: errx.c,v 1.13 2005/09/13 13:51:50 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)err.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: errx.c,v 1.13 2005/09/13 13:51:50 christos Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <err.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(errx, _errx)
|
||||
#endif
|
||||
|
||||
__dead void
|
||||
errx(jmp_buf* exit_jmp, int eval, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
verrx(exit_jmp, eval, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
87
cpukit/libmisc/shell/extern-cp.h
Normal file
87
cpukit/libmisc/shell/extern-cp.h
Normal file
@@ -0,0 +1,87 @@
|
||||
/* $NetBSD: extern.h,v 1.12 2005/10/15 18:22:18 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)extern.h 8.2 (Berkeley) 4/1/94
|
||||
*/
|
||||
|
||||
#ifndef _EXTERN_CP_H_
|
||||
#define _EXTERN_CP_H_
|
||||
|
||||
#define PATH_T RTEMS_SHELL_CP_PATH_T
|
||||
|
||||
typedef struct {
|
||||
char *p_end; /* pointer to NULL at end of path */
|
||||
char *target_end; /* pointer to end of target base */
|
||||
char p_path[MAXPATHLEN + 1]; /* pointer to the start of a path */
|
||||
} PATH_T;
|
||||
|
||||
#include <setjmp.h>
|
||||
|
||||
typedef struct {
|
||||
PATH_T to;
|
||||
uid_t myuid;
|
||||
int Rflag, fflag, iflag, pflag, rflag, vflag, Nflag;
|
||||
mode_t myumask;
|
||||
jmp_buf exit_jmp;
|
||||
} rtems_shell_cp_globals;
|
||||
|
||||
#define to cp_globals->to
|
||||
#define myuid cp_globals->myuid
|
||||
#define Rflag cp_globals->Rflag
|
||||
#define fflag cp_globals->fflag
|
||||
#define iflag cp_globals->iflag
|
||||
#define pflag cp_globals->pflag
|
||||
#define rflag cp_globals->rflag
|
||||
#define vflag cp_globals->vflag
|
||||
#define Nflag cp_globals->Nflag
|
||||
#define myumask cp_globals->myumask
|
||||
#define exit_jump &(cp_globals->exit_jmp)
|
||||
|
||||
#define copy_fifo rtems_shell_cp_copy_fifo
|
||||
#define copy_file rtems_shell_cp_copy_file
|
||||
#define copy_link rtems_shell_cp_copy_link
|
||||
#define copy_special rtems_shell_cp_copy_special
|
||||
#define set_utimes rtems_shell_cp_set_utimes
|
||||
#define setfile rtems_shell_cp_setfile
|
||||
#define usage rtems_shell_cp_usage
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
int copy_fifo(rtems_shell_cp_globals* cp_globals, struct stat *, int);
|
||||
int copy_file(rtems_shell_cp_globals* cp_globals, FTSENT *, int);
|
||||
int copy_link(rtems_shell_cp_globals* cp_globals, FTSENT *, int);
|
||||
int copy_special(rtems_shell_cp_globals* cp_globals, struct stat *, int);
|
||||
int set_utimes(const char *, struct stat *);
|
||||
int setfile(rtems_shell_cp_globals* cp_globals, struct stat *, int);
|
||||
void usage();
|
||||
__END_DECLS
|
||||
|
||||
#endif /* !_EXTERN_H_ */
|
||||
1193
cpukit/libmisc/shell/fts.c
Normal file
1193
cpukit/libmisc/shell/fts.c
Normal file
File diff suppressed because it is too large
Load Diff
146
cpukit/libmisc/shell/fts.h
Normal file
146
cpukit/libmisc/shell/fts.h
Normal file
@@ -0,0 +1,146 @@
|
||||
/* $NetBSD: fts.h,v 1.14 2005/09/13 01:44:32 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)fts.h 8.3 (Berkeley) 8/14/94
|
||||
*/
|
||||
|
||||
#ifndef _FTS_H_
|
||||
#define _FTS_H_
|
||||
|
||||
#ifndef __fts_stat_t
|
||||
#define __fts_stat_t struct stat
|
||||
#endif
|
||||
#ifndef __fts_nlink_t
|
||||
#define __fts_nlink_t nlink_t
|
||||
#endif
|
||||
#ifndef __fts_ino_t
|
||||
#define __fts_ino_t ino_t
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
struct _ftsent *fts_cur; /* current node */
|
||||
struct _ftsent *fts_child; /* linked list of children */
|
||||
struct _ftsent **fts_array; /* sort array */
|
||||
dev_t fts_dev; /* starting device # */
|
||||
char *fts_path; /* path for this descent */
|
||||
int fts_rfd; /* fd for root */
|
||||
u_int fts_pathlen; /* sizeof(path) */
|
||||
u_int fts_nitems; /* elements in the sort array */
|
||||
int (*fts_compar) /* compare function */
|
||||
(const struct _ftsent **, const struct _ftsent **);
|
||||
|
||||
#define FTS_COMFOLLOW 0x001 /* follow command line symlinks */
|
||||
#define FTS_LOGICAL 0x002 /* logical walk */
|
||||
#define FTS_NOCHDIR 0x004 /* don't change directories */
|
||||
#define FTS_NOSTAT 0x008 /* don't get stat info */
|
||||
#define FTS_PHYSICAL 0x010 /* physical walk */
|
||||
#define FTS_SEEDOT 0x020 /* return dot and dot-dot */
|
||||
#define FTS_XDEV 0x040 /* don't cross devices */
|
||||
#define FTS_WHITEOUT 0x080 /* return whiteout information */
|
||||
#define FTS_OPTIONMASK 0x0ff /* valid user option mask */
|
||||
|
||||
#define FTS_NAMEONLY 0x100 /* (private) child names only */
|
||||
#define FTS_STOP 0x200 /* (private) unrecoverable error */
|
||||
int fts_options; /* fts_open options, global flags */
|
||||
} FTS;
|
||||
|
||||
typedef struct _ftsent {
|
||||
struct _ftsent *fts_cycle; /* cycle node */
|
||||
struct _ftsent *fts_parent; /* parent directory */
|
||||
struct _ftsent *fts_link; /* next file in directory */
|
||||
long fts_number; /* local numeric value */
|
||||
void *fts_pointer; /* local address value */
|
||||
char *fts_accpath; /* access path */
|
||||
char *fts_path; /* root path */
|
||||
int fts_errno; /* errno for this node */
|
||||
int fts_symfd; /* fd for symlink */
|
||||
u_short fts_pathlen; /* strlen(fts_path) */
|
||||
u_short fts_namelen; /* strlen(fts_name) */
|
||||
|
||||
__fts_ino_t fts_ino; /* inode */
|
||||
dev_t fts_dev; /* device */
|
||||
__fts_nlink_t fts_nlink; /* link count */
|
||||
|
||||
#define FTS_ROOTPARENTLEVEL -1
|
||||
#define FTS_ROOTLEVEL 0
|
||||
short fts_level; /* depth (-1 to N) */
|
||||
|
||||
#define FTS_D 1 /* preorder directory */
|
||||
#define FTS_DC 2 /* directory that causes cycles */
|
||||
#define FTS_DEFAULT 3 /* none of the above */
|
||||
#define FTS_DNR 4 /* unreadable directory */
|
||||
#define FTS_DOT 5 /* dot or dot-dot */
|
||||
#define FTS_DP 6 /* postorder directory */
|
||||
#define FTS_ERR 7 /* error; errno is set */
|
||||
#define FTS_F 8 /* regular file */
|
||||
#define FTS_INIT 9 /* initialized only */
|
||||
#define FTS_NS 10 /* stat(2) failed */
|
||||
#define FTS_NSOK 11 /* no stat(2) requested */
|
||||
#define FTS_SL 12 /* symbolic link */
|
||||
#define FTS_SLNONE 13 /* symbolic link without target */
|
||||
#define FTS_W 14 /* whiteout object */
|
||||
u_short fts_info; /* user flags for FTSENT structure */
|
||||
|
||||
#define FTS_DONTCHDIR 0x01 /* don't chdir .. to the parent */
|
||||
#define FTS_SYMFOLLOW 0x02 /* followed a symlink to get here */
|
||||
#define FTS_ISW 0x04 /* this is a whiteout object */
|
||||
u_short fts_flags; /* private flags for FTSENT structure */
|
||||
|
||||
#define FTS_AGAIN 1 /* read node again */
|
||||
#define FTS_FOLLOW 2 /* follow symbolic link */
|
||||
#define FTS_NOINSTR 3 /* no instructions */
|
||||
#define FTS_SKIP 4 /* discard node */
|
||||
u_short fts_instr; /* fts_set() instructions */
|
||||
|
||||
__fts_stat_t *fts_statp; /* stat(2) information */
|
||||
char fts_name[1]; /* file name */
|
||||
} FTSENT;
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#define __RENAME(n)
|
||||
#define fts_children rtems_shell_fts_children
|
||||
#define fts_close rtems_shell_fts_close
|
||||
#define fts_open rtems_shell_fts_open
|
||||
#define fts_read rtems_shell_fts_read
|
||||
#define fts_set rtems_shell_fts_set
|
||||
|
||||
__BEGIN_DECLS
|
||||
#ifndef __LIBC12_SOURCE__
|
||||
FTSENT *fts_children(FTS *, int) __RENAME(__fts_children30);
|
||||
int fts_close(FTS *) __RENAME(__fts_close30);
|
||||
FTS *fts_open(char * const *, int,
|
||||
int (*)(const FTSENT **, const FTSENT **)) __RENAME(__fts_open30);
|
||||
FTSENT *fts_read(FTS *) __RENAME(__fts_read30);
|
||||
int fts_set(FTS *, FTSENT *, int) __RENAME(__fts_set30);
|
||||
#endif
|
||||
__END_DECLS
|
||||
|
||||
#endif /* !_FTS_H_ */
|
||||
531
cpukit/libmisc/shell/main_cp.c
Normal file
531
cpukit/libmisc/shell/main_cp.c
Normal file
@@ -0,0 +1,531 @@
|
||||
/* $NetBSD: cp.c,v 1.39 2005/10/24 12:59:07 kleink Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* David Hitz of Auspex Systems Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
#ifndef lint
|
||||
__COPYRIGHT(
|
||||
"@(#) Copyright (c) 1988, 1993, 1994\n\
|
||||
The Regents of the University of California. All rights reserved.\n");
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)cp.c 8.5 (Berkeley) 4/29/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: cp.c,v 1.39 2005/10/24 12:59:07 kleink Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
#endif
|
||||
/*
|
||||
* Cp copies source files to target files.
|
||||
*
|
||||
* The global PATH_T structure "to" always contains the path to the
|
||||
* current target file. Since fts(3) does not change directories,
|
||||
* this path can be either absolute or dot-relative.
|
||||
*
|
||||
* The basic algorithm is to initialize "to" and use fts(3) to traverse
|
||||
* the file hierarchy rooted in the argument list. A trivial case is the
|
||||
* case of 'cp file1 file2'. The more interesting case is the case of
|
||||
* 'cp file1 file2 ... fileN dir' where the hierarchy is traversed and the
|
||||
* path (relative to the root of the traversal) is appended to dir (stored
|
||||
* in "to") to form the final target path.
|
||||
*/
|
||||
|
||||
#include <rtems.h>
|
||||
#include <rtems/shell.h>
|
||||
#include <rtems/shellconfig.h>
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fts.h>
|
||||
#include <locale.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "extern-cp.h"
|
||||
|
||||
#define STRIP_TRAILING_SLASH(p) { \
|
||||
while ((p).p_end > (p).p_path + 1 && (p).p_end[-1] == '/') \
|
||||
*--(p).p_end = '\0'; \
|
||||
}
|
||||
|
||||
static char empty[] = "";
|
||||
|
||||
enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE };
|
||||
|
||||
static int main_cp(rtems_shell_cp_globals* cp_globals, int, char *[]);
|
||||
static int copy(rtems_shell_cp_globals* cp_globals, char *[], enum op, int);
|
||||
static int mastercmp(const FTSENT **, const FTSENT **);
|
||||
|
||||
void
|
||||
rtems_shell_cp_exit (rtems_shell_cp_globals* cp_global, int code)
|
||||
{
|
||||
longjmp (cp_global->exit_jmp, 1);
|
||||
}
|
||||
|
||||
int
|
||||
rtems_shell_main_cp(int argc, char *argv[])
|
||||
{
|
||||
rtems_shell_cp_globals cp_globals;
|
||||
memset (&cp_globals, 0, sizeof (cp_globals));
|
||||
if (setjmp (cp_globals.exit_jmp) == 0)
|
||||
return main_cp (&cp_globals, argc, argv);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
main_cp(rtems_shell_cp_globals* cp_globals, int argc, char *argv[])
|
||||
{
|
||||
struct stat to_stat, tmp_stat;
|
||||
enum op type;
|
||||
int Hflag, Lflag, Pflag, ch, fts_options, r;
|
||||
char *target;
|
||||
|
||||
to.p_end = to.p_path;
|
||||
to.target_end = empty;
|
||||
|
||||
(void)setlocale(LC_ALL, "");
|
||||
|
||||
Hflag = Lflag = Pflag = Rflag = 0;
|
||||
while ((ch = getopt(argc, argv, "HLNPRfiprv")) != -1)
|
||||
switch (ch) {
|
||||
case 'H':
|
||||
Hflag = 1;
|
||||
Lflag = Pflag = 0;
|
||||
break;
|
||||
case 'L':
|
||||
Lflag = 1;
|
||||
Hflag = Pflag = 0;
|
||||
break;
|
||||
case 'N':
|
||||
Nflag = 1;
|
||||
break;
|
||||
case 'P':
|
||||
Pflag = 1;
|
||||
Hflag = Lflag = 0;
|
||||
break;
|
||||
case 'R':
|
||||
Rflag = 1;
|
||||
break;
|
||||
case 'f':
|
||||
fflag = 1;
|
||||
iflag = 0;
|
||||
break;
|
||||
case 'i':
|
||||
iflag = isatty(fileno(stdin));
|
||||
fflag = 0;
|
||||
break;
|
||||
case 'p':
|
||||
pflag = 1;
|
||||
break;
|
||||
case 'r':
|
||||
rflag = 1;
|
||||
break;
|
||||
case 'v':
|
||||
vflag = 1;
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (argc < 2)
|
||||
usage();
|
||||
|
||||
fts_options = FTS_NOCHDIR | FTS_PHYSICAL;
|
||||
if (rflag) {
|
||||
if (Rflag) {
|
||||
errx(exit_jump, EXIT_FAILURE,
|
||||
"the -R and -r options may not be specified together.");
|
||||
/* NOTREACHED */
|
||||
}
|
||||
if (Hflag || Lflag || Pflag) {
|
||||
errx(exit_jump, EXIT_FAILURE,
|
||||
"the -H, -L, and -P options may not be specified with the -r option.");
|
||||
/* NOTREACHED */
|
||||
}
|
||||
fts_options &= ~FTS_PHYSICAL;
|
||||
fts_options |= FTS_LOGICAL;
|
||||
}
|
||||
if (Rflag) {
|
||||
if (Hflag)
|
||||
fts_options |= FTS_COMFOLLOW;
|
||||
if (Lflag) {
|
||||
fts_options &= ~FTS_PHYSICAL;
|
||||
fts_options |= FTS_LOGICAL;
|
||||
}
|
||||
} else {
|
||||
fts_options &= ~FTS_PHYSICAL;
|
||||
fts_options |= FTS_LOGICAL | FTS_COMFOLLOW;
|
||||
}
|
||||
|
||||
myuid = getuid();
|
||||
|
||||
/* Copy the umask for explicit mode setting. */
|
||||
myumask = umask(0);
|
||||
(void)umask(myumask);
|
||||
|
||||
/* Save the target base in "to". */
|
||||
target = argv[--argc];
|
||||
if (strlen(target) > MAXPATHLEN) {
|
||||
errx(exit_jump, EXIT_FAILURE, "%s: name too long", target);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
(void)strcpy(to.p_path, target);
|
||||
to.p_end = to.p_path + strlen(to.p_path);
|
||||
STRIP_TRAILING_SLASH(to);
|
||||
to.target_end = to.p_end;
|
||||
|
||||
/* Set end of argument list for fts(3). */
|
||||
argv[argc] = NULL;
|
||||
|
||||
/*
|
||||
* Cp has two distinct cases:
|
||||
*
|
||||
* cp [-R] source target
|
||||
* cp [-R] source1 ... sourceN directory
|
||||
*
|
||||
* In both cases, source can be either a file or a directory.
|
||||
*
|
||||
* In (1), the target becomes a copy of the source. That is, if the
|
||||
* source is a file, the target will be a file, and likewise for
|
||||
* directories.
|
||||
*
|
||||
* In (2), the real target is not directory, but "directory/source".
|
||||
*/
|
||||
r = stat(to.p_path, &to_stat);
|
||||
if (r == -1 && errno != ENOENT) {
|
||||
err(exit_jump, EXIT_FAILURE, "%s", to.p_path);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
if (r == -1 || !S_ISDIR(to_stat.st_mode)) {
|
||||
/*
|
||||
* Case (1). Target is not a directory.
|
||||
*/
|
||||
if (argc > 1)
|
||||
usage();
|
||||
/*
|
||||
* Need to detect the case:
|
||||
* cp -R dir foo
|
||||
* Where dir is a directory and foo does not exist, where
|
||||
* we want pathname concatenations turned on but not for
|
||||
* the initial mkdir().
|
||||
*/
|
||||
if (r == -1) {
|
||||
if (rflag || (Rflag && (Lflag || Hflag)))
|
||||
r = stat(*argv, &tmp_stat);
|
||||
else
|
||||
r = lstat(*argv, &tmp_stat);
|
||||
if (r == -1) {
|
||||
err(exit_jump, EXIT_FAILURE, "%s", *argv);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
if (S_ISDIR(tmp_stat.st_mode) && (Rflag || rflag))
|
||||
type = DIR_TO_DNE;
|
||||
else
|
||||
type = FILE_TO_FILE;
|
||||
} else
|
||||
type = FILE_TO_FILE;
|
||||
} else {
|
||||
/*
|
||||
* Case (2). Target is a directory.
|
||||
*/
|
||||
type = FILE_TO_DIR;
|
||||
}
|
||||
|
||||
return copy(cp_globals, argv, type, fts_options);
|
||||
}
|
||||
|
||||
int
|
||||
copy(rtems_shell_cp_globals* cp_globals,
|
||||
char *argv[], enum op type, int fts_options)
|
||||
{
|
||||
struct stat to_stat;
|
||||
FTS *ftsp;
|
||||
FTSENT *curr;
|
||||
int base, dne, rval;
|
||||
size_t nlen;
|
||||
char *p, *tmp;
|
||||
|
||||
base = 0; /* XXX gcc -Wuninitialized (see comment below) */
|
||||
|
||||
if ((ftsp = fts_open(argv, fts_options, mastercmp)) == NULL)
|
||||
err(exit_jump, EXIT_FAILURE, "%s", argv[0]);
|
||||
/* NOTREACHED */
|
||||
for (rval = 0; (curr = fts_read(ftsp)) != NULL;) {
|
||||
switch (curr->fts_info) {
|
||||
case FTS_NS:
|
||||
case FTS_DNR:
|
||||
case FTS_ERR:
|
||||
warnx("%s: %s", curr->fts_path,
|
||||
strerror(curr->fts_errno));
|
||||
rval = 1;
|
||||
continue;
|
||||
case FTS_DC: /* Warn, continue. */
|
||||
warnx("%s: directory causes a cycle", curr->fts_path);
|
||||
rval = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* If we are in case (2) or (3) above, we need to append the
|
||||
* source name to the target name.
|
||||
*/
|
||||
if (type != FILE_TO_FILE) {
|
||||
if ((curr->fts_namelen +
|
||||
to.target_end - to.p_path + 1) > MAXPATHLEN) {
|
||||
warnx("%s/%s: name too long (not copied)",
|
||||
to.p_path, curr->fts_name);
|
||||
rval = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* Need to remember the roots of traversals to create
|
||||
* correct pathnames. If there's a directory being
|
||||
* copied to a non-existent directory, e.g.
|
||||
* cp -R a/dir noexist
|
||||
* the resulting path name should be noexist/foo, not
|
||||
* noexist/dir/foo (where foo is a file in dir), which
|
||||
* is the case where the target exists.
|
||||
*
|
||||
* Also, check for "..". This is for correct path
|
||||
* concatentation for paths ending in "..", e.g.
|
||||
* cp -R .. /tmp
|
||||
* Paths ending in ".." are changed to ".". This is
|
||||
* tricky, but seems the easiest way to fix the problem.
|
||||
*
|
||||
* XXX
|
||||
* Since the first level MUST be FTS_ROOTLEVEL, base
|
||||
* is always initialized.
|
||||
*/
|
||||
if (curr->fts_level == FTS_ROOTLEVEL) {
|
||||
if (type != DIR_TO_DNE) {
|
||||
p = strrchr(curr->fts_path, '/');
|
||||
base = (p == NULL) ? 0 :
|
||||
(int)(p - curr->fts_path + 1);
|
||||
|
||||
if (!strcmp(&curr->fts_path[base],
|
||||
".."))
|
||||
base += 1;
|
||||
} else
|
||||
base = curr->fts_pathlen;
|
||||
}
|
||||
|
||||
p = &curr->fts_path[base];
|
||||
nlen = curr->fts_pathlen - base;
|
||||
|
||||
tmp = to.target_end;
|
||||
if (*p != '/' && *(tmp - 1) != '/')
|
||||
*tmp++ = '/';
|
||||
*tmp = 0;
|
||||
|
||||
(void)strncat(tmp, p, nlen);
|
||||
to.p_end = tmp + nlen;
|
||||
*to.p_end = 0;
|
||||
STRIP_TRAILING_SLASH(to);
|
||||
}
|
||||
|
||||
/* Not an error but need to remember it happened */
|
||||
if (stat(to.p_path, &to_stat) == -1)
|
||||
dne = 1;
|
||||
else {
|
||||
if (to_stat.st_dev == curr->fts_statp->st_dev &&
|
||||
to_stat.st_ino == curr->fts_statp->st_ino) {
|
||||
warnx("%s and %s are identical (not copied).",
|
||||
to.p_path, curr->fts_path);
|
||||
rval = 1;
|
||||
if (S_ISDIR(curr->fts_statp->st_mode))
|
||||
(void)fts_set(ftsp, curr, FTS_SKIP);
|
||||
continue;
|
||||
}
|
||||
if (!S_ISDIR(curr->fts_statp->st_mode) &&
|
||||
S_ISDIR(to_stat.st_mode)) {
|
||||
warnx("cannot overwrite directory %s with non-directory %s",
|
||||
to.p_path, curr->fts_path);
|
||||
rval = 1;
|
||||
continue;
|
||||
}
|
||||
dne = 0;
|
||||
}
|
||||
|
||||
switch (curr->fts_statp->st_mode & S_IFMT) {
|
||||
case S_IFLNK:
|
||||
/* Catch special case of a non dangling symlink */
|
||||
if((fts_options & FTS_LOGICAL) ||
|
||||
((fts_options & FTS_COMFOLLOW) && curr->fts_level == 0)) {
|
||||
if (copy_file(cp_globals, curr, dne))
|
||||
rval = 1;
|
||||
} else {
|
||||
if (copy_link(cp_globals, curr, !dne))
|
||||
rval = 1;
|
||||
}
|
||||
break;
|
||||
case S_IFDIR:
|
||||
if (!Rflag && !rflag) {
|
||||
if (curr->fts_info == FTS_D)
|
||||
warnx("%s is a directory (not copied).",
|
||||
curr->fts_path);
|
||||
(void)fts_set(ftsp, curr, FTS_SKIP);
|
||||
rval = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Directories get noticed twice:
|
||||
* In the first pass, create it if needed.
|
||||
* In the second pass, after the children have been copied,
|
||||
* set the permissions.
|
||||
*/
|
||||
if (curr->fts_info == FTS_D) /* First pass */
|
||||
{
|
||||
/*
|
||||
* If the directory doesn't exist, create the new
|
||||
* one with the from file mode plus owner RWX bits,
|
||||
* modified by the umask. Trade-off between being
|
||||
* able to write the directory (if from directory is
|
||||
* 555) and not causing a permissions race. If the
|
||||
* umask blocks owner writes, we fail..
|
||||
*/
|
||||
if (dne) {
|
||||
if (mkdir(to.p_path,
|
||||
curr->fts_statp->st_mode | S_IRWXU) < 0)
|
||||
err(exit_jump, EXIT_FAILURE, "%s",
|
||||
to.p_path);
|
||||
/* NOTREACHED */
|
||||
} else if (!S_ISDIR(to_stat.st_mode)) {
|
||||
errno = ENOTDIR;
|
||||
err(exit_jump, EXIT_FAILURE, "%s",
|
||||
to.p_path);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
}
|
||||
else if (curr->fts_info == FTS_DP) /* Second pass */
|
||||
{
|
||||
/*
|
||||
* If not -p and directory didn't exist, set it to be
|
||||
* the same as the from directory, umodified by the
|
||||
* umask; arguably wrong, but it's been that way
|
||||
* forever.
|
||||
*/
|
||||
if (pflag && setfile(cp_globals, curr->fts_statp, 0))
|
||||
rval = 1;
|
||||
else if (dne)
|
||||
(void)chmod(to.p_path,
|
||||
curr->fts_statp->st_mode);
|
||||
}
|
||||
else
|
||||
{
|
||||
warnx("directory %s encountered when not expected.",
|
||||
curr->fts_path);
|
||||
rval = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
case S_IFBLK:
|
||||
case S_IFCHR:
|
||||
if (Rflag) {
|
||||
if (copy_special(cp_globals, curr->fts_statp, !dne))
|
||||
rval = 1;
|
||||
} else
|
||||
if (copy_file(cp_globals, curr, dne))
|
||||
rval = 1;
|
||||
break;
|
||||
case S_IFIFO:
|
||||
if (Rflag) {
|
||||
if (copy_fifo(cp_globals, curr->fts_statp, !dne))
|
||||
rval = 1;
|
||||
} else
|
||||
if (copy_file(cp_globals, curr, dne))
|
||||
rval = 1;
|
||||
break;
|
||||
default:
|
||||
if (copy_file(cp_globals, curr, dne))
|
||||
rval = 1;
|
||||
break;
|
||||
}
|
||||
if (vflag && !rval)
|
||||
(void)printf("%s -> %s\n", curr->fts_path, to.p_path);
|
||||
}
|
||||
if (errno) {
|
||||
err(exit_jump, EXIT_FAILURE, "fts_read");
|
||||
/* NOTREACHED */
|
||||
}
|
||||
return (rval);
|
||||
}
|
||||
|
||||
/*
|
||||
* mastercmp --
|
||||
* The comparison function for the copy order. The order is to copy
|
||||
* non-directory files before directory files. The reason for this
|
||||
* is because files tend to be in the same cylinder group as their
|
||||
* parent directory, whereas directories tend not to be. Copying the
|
||||
* files first reduces seeking.
|
||||
*/
|
||||
int
|
||||
mastercmp(const FTSENT **a, const FTSENT **b)
|
||||
{
|
||||
int a_info, b_info;
|
||||
|
||||
a_info = (*a)->fts_info;
|
||||
if (a_info == FTS_ERR || a_info == FTS_NS || a_info == FTS_DNR)
|
||||
return (0);
|
||||
b_info = (*b)->fts_info;
|
||||
if (b_info == FTS_ERR || b_info == FTS_NS || b_info == FTS_DNR)
|
||||
return (0);
|
||||
if (a_info == FTS_D)
|
||||
return (-1);
|
||||
if (b_info == FTS_D)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
rtems_shell_cmd_t rtems_shell_CP_Command = {
|
||||
"cp", /* name */
|
||||
"cp [-R [-H | -L | -P]] [-f | -i] [-pv] src target # copy", /* usage */
|
||||
"files", /* topic */
|
||||
rtems_shell_main_cp, /* command */
|
||||
NULL, /* alias */
|
||||
NULL /* next */
|
||||
};
|
||||
@@ -43,6 +43,14 @@ rtems_shell_nfs_mounter (const char* device,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (rpcUdpInit () < 0)
|
||||
{
|
||||
fprintf (stdout, "error: initialising RPC\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
nfsInit (0, 0);
|
||||
|
||||
uidhost = strdup (device);
|
||||
path = strchr (uidhost, ':');
|
||||
*path = '\0';
|
||||
@@ -56,7 +64,7 @@ rtems_shell_nfs_mounter (const char* device,
|
||||
}
|
||||
|
||||
rtems_shell_filesystems_t rtems_shell_Mount_NFS = {
|
||||
name: "ftp",
|
||||
name: "nfs",
|
||||
driver_needed: 1,
|
||||
fs_ops: NULL,
|
||||
mounter: rtems_shell_nfs_mounter
|
||||
|
||||
@@ -51,27 +51,28 @@ rtems_shell_env_t *rtems_shell_init_env(
|
||||
{
|
||||
rtems_shell_env_t *shell_env;
|
||||
|
||||
if (rtems_global_shell_env.magic != 0x600D600d) {
|
||||
rtems_global_shell_env.magic = 0x600D600d;
|
||||
rtems_global_shell_env.devname = "";
|
||||
rtems_global_shell_env.taskname = "GLOBAL";
|
||||
rtems_global_shell_env.tcflag = 0;
|
||||
rtems_global_shell_env.exit_shell = 0;
|
||||
rtems_global_shell_env.forever = TRUE;
|
||||
rtems_global_shell_env.input = 0;
|
||||
rtems_global_shell_env.output = 0;
|
||||
rtems_global_shell_env.output_append = 0;
|
||||
}
|
||||
|
||||
shell_env = shell_env_arg;
|
||||
|
||||
if ( !shell_env ) {
|
||||
shell_env = malloc(sizeof(rtems_shell_env_t));
|
||||
if ( !shell_env )
|
||||
return NULL;
|
||||
*shell_env = rtems_global_shell_env;
|
||||
shell_env->taskname = NULL;
|
||||
}
|
||||
|
||||
if (rtems_global_shell_env.magic != 0x600D600d) {
|
||||
rtems_global_shell_env.magic = 0x600D600d;
|
||||
rtems_global_shell_env.devname = "";
|
||||
rtems_global_shell_env.taskname = "GLOBAL";
|
||||
rtems_global_shell_env.tcflag = 0;
|
||||
rtems_global_shell_env.exit_shell = 0;
|
||||
rtems_global_shell_env.forever = TRUE;
|
||||
}
|
||||
|
||||
*shell_env = rtems_global_shell_env;
|
||||
shell_env->taskname = NULL;
|
||||
shell_env->forever = FALSE;
|
||||
|
||||
return shell_env;
|
||||
}
|
||||
|
||||
@@ -344,10 +345,12 @@ void rtems_shell_print_env(
|
||||
|
||||
rtems_task rtems_shell_task(rtems_task_argument task_argument)
|
||||
{
|
||||
rtems_shell_env_t * shell_env = (rtems_shell_env_t*) task_argument;
|
||||
|
||||
rtems_shell_main_loop( shell_env );
|
||||
rtems_task_delete( RTEMS_SELF );
|
||||
rtems_shell_env_t *shell_env = (rtems_shell_env_t*) task_argument;
|
||||
rtems_id wake_on_end = shell_env->wake_on_end;
|
||||
rtems_shell_main_loop( shell_env );
|
||||
if (wake_on_end != RTEMS_INVALID_ID)
|
||||
rtems_event_send (wake_on_end, RTEMS_EVENT_1);
|
||||
rtems_task_delete( RTEMS_SELF );
|
||||
}
|
||||
|
||||
#define RTEMS_SHELL_MAXIMUM_ARGUMENTS 128
|
||||
@@ -365,14 +368,20 @@ rtems_boolean rtems_shell_main_loop(
|
||||
char last_cmd[256]; /* to repeat 'r' */
|
||||
int argc;
|
||||
char *argv[RTEMS_SHELL_MAXIMUM_ARGUMENTS];
|
||||
rtems_boolean result = TRUE;
|
||||
rtems_boolean input_file = FALSE;
|
||||
int line = 0;
|
||||
|
||||
rtems_shell_initialize_command_set();
|
||||
|
||||
shell_env =
|
||||
rtems_current_shell_env = rtems_shell_init_env( shell_env_arg );
|
||||
|
||||
/*
|
||||
* @todo chrisj
|
||||
* Remove the use of task variables. Chnage to have a single
|
||||
* Remove the use of task variables. Change to have a single
|
||||
* allocation per shell and then set into a notepad register
|
||||
* in the TCP. Provide a function to return the pointer.
|
||||
* in the TCB. Provide a function to return the pointer.
|
||||
* Task variables are a virus to embedded systems software.
|
||||
*/
|
||||
sc = rtems_task_variable_add(RTEMS_SELF,(void*)&rtems_current_shell_env,free);
|
||||
@@ -381,76 +390,127 @@ rtems_boolean rtems_shell_main_loop(
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
shell_env =
|
||||
rtems_current_shell_env = rtems_shell_init_env( shell_env_arg );
|
||||
|
||||
setuid(0);
|
||||
setgid(0);
|
||||
rtems_current_user_env->euid =
|
||||
rtems_current_user_env->egid = 0;
|
||||
|
||||
setvbuf(stdin,NULL,_IONBF,0); /* Not buffered*/
|
||||
/* make a raw terminal,Linux Manuals */
|
||||
if (tcgetattr(fileno(stdin), &term) >= 0) {
|
||||
term.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
|
||||
term.c_oflag &= ~OPOST;
|
||||
term.c_oflag |= (OPOST|ONLCR); /* But with cr+nl on output */
|
||||
term.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
|
||||
if (shell_env->tcflag)
|
||||
term.c_cflag = shell_env->tcflag;
|
||||
term.c_cflag |= CLOCAL | CREAD;
|
||||
term.c_cc[VMIN] = 1;
|
||||
term.c_cc[VTIME] = 0;
|
||||
if (tcsetattr (fileno(stdin), TCSADRAIN, &term) < 0) {
|
||||
fprintf(stderr,
|
||||
"shell:cannot set terminal attributes(%s)\n",shell_env->devname);
|
||||
fileno(stdout);
|
||||
|
||||
if (strcmp(shell_env->output, "stdout") != 0) {
|
||||
if (strcmp(shell_env->output, "stderr") == 0) {
|
||||
stdout = stderr;
|
||||
} else if (strcmp(shell_env->output, "/dev/null") == 0) {
|
||||
fclose (stdout);
|
||||
} else {
|
||||
FILE *output = fopen(shell_env_arg->output,
|
||||
shell_env_arg->output_append ? "a" : "w");
|
||||
if (!output) {
|
||||
fprintf(stderr, "shell: open output %s failed: %s\n",
|
||||
shell_env_arg->output, strerror(errno));
|
||||
return FALSE;
|
||||
}
|
||||
stdout = output;
|
||||
}
|
||||
setvbuf(stdout,NULL,_IONBF,0); /* Not buffered*/
|
||||
}
|
||||
|
||||
if (strcmp(shell_env_arg->input, "stdin") != 0) {
|
||||
FILE *input = fopen(shell_env_arg->input, "r");
|
||||
if (!input) {
|
||||
fprintf(stderr, "shell: open input %s failed: %s\n",
|
||||
shell_env_arg->input, strerror(errno));
|
||||
return FALSE;
|
||||
}
|
||||
stdin = input;
|
||||
shell_env->forever = FALSE;
|
||||
input_file = TRUE;
|
||||
}
|
||||
else {
|
||||
/* make a raw terminal,Linux Manuals */
|
||||
if (tcgetattr(fileno(stdin), &term) >= 0) {
|
||||
term.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
|
||||
term.c_oflag &= ~OPOST;
|
||||
term.c_oflag |= (OPOST|ONLCR); /* But with cr+nl on output */
|
||||
term.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
|
||||
if (shell_env->tcflag)
|
||||
term.c_cflag = shell_env->tcflag;
|
||||
term.c_cflag |= CLOCAL | CREAD;
|
||||
term.c_cc[VMIN] = 1;
|
||||
term.c_cc[VTIME] = 0;
|
||||
if (tcsetattr (fileno(stdin), TCSADRAIN, &term) < 0) {
|
||||
fprintf(stderr,
|
||||
"shell:cannot set terminal attributes(%s)\n",shell_env->devname);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setvbuf(stdin,NULL,_IONBF,0); /* Not buffered*/
|
||||
setvbuf(stdout,NULL,_IONBF,0); /* Not buffered*/
|
||||
|
||||
rtems_shell_initialize_command_set();
|
||||
do {
|
||||
/* Set again root user and root filesystem, side effect of set_priv..*/
|
||||
sc = rtems_libio_set_private_env();
|
||||
if (sc != RTEMS_SUCCESSFUL) {
|
||||
rtems_error(sc,"rtems_libio_set_private_env():");
|
||||
return FALSE;
|
||||
result = FALSE;
|
||||
break;
|
||||
}
|
||||
if (!rtems_shell_login(stdin,stdout)) {
|
||||
rtems_shell_cat_file(stdout,"/etc/motd");
|
||||
if (input_file || !rtems_shell_login(stdin,stdout)) {
|
||||
const char *c;
|
||||
strcpy(last_cmd,"");
|
||||
strcpy(cmd,"");
|
||||
printf("\n"
|
||||
"RTEMS SHELL (Ver.1.0-FRC):%s. "__DATE__". 'help' to list commands.\n",
|
||||
shell_env->devname);
|
||||
if (!input_file) {
|
||||
rtems_shell_cat_file(stdout,"/etc/motd");
|
||||
fprintf(stdout, "\n"
|
||||
"RTEMS SHELL (Ver.1.0-FRC):%s. " \
|
||||
__DATE__". 'help' to list commands.\n",
|
||||
shell_env->devname);
|
||||
}
|
||||
chdir("/"); /* XXX: chdir to getpwent homedir */
|
||||
shell_env->exit_shell = FALSE;
|
||||
for (;;) {
|
||||
/* Prompt section */
|
||||
/* XXX: show_prompt user adjustable */
|
||||
getcwd(curdir,sizeof(curdir));
|
||||
printf( "%s%s[%s] %c ",
|
||||
((shell_env->taskname) ? shell_env->taskname : ""),
|
||||
((shell_env->taskname) ? " " : ""),
|
||||
curdir,
|
||||
geteuid()?'$':'#'
|
||||
);
|
||||
if (!input_file) {
|
||||
/* XXX: show_prompt user adjustable */
|
||||
getcwd(curdir,sizeof(curdir));
|
||||
fprintf(stdout, "%s%s[%s] %c ",
|
||||
((shell_env->taskname) ? shell_env->taskname : ""),
|
||||
((shell_env->taskname) ? " " : ""),
|
||||
curdir,
|
||||
geteuid()?'$':'#');
|
||||
}
|
||||
|
||||
/* getcmd section */
|
||||
if (!rtems_shell_scanline(cmd,sizeof(cmd),stdin,stdout)) {
|
||||
break; /*EOF*/
|
||||
}
|
||||
|
||||
line++;
|
||||
|
||||
/* evaluate cmd section */
|
||||
c = cmd;
|
||||
while (*c) {
|
||||
if (!isblank(*c))
|
||||
break;
|
||||
c++;
|
||||
}
|
||||
|
||||
if (*c == '\0') /* empty line */
|
||||
continue;
|
||||
if (*c == '#') /* comment character */
|
||||
continue;
|
||||
|
||||
if (!strcmp(cmd,"e")) { /* edit last command */
|
||||
strcpy(cmd,last_cmd);
|
||||
continue;
|
||||
} else if (!strcmp(cmd,"r")) { /* repeat last command */
|
||||
strcpy(cmd,last_cmd);
|
||||
} else if (!strcmp(cmd,"bye")) { /* exit to telnetd */
|
||||
printf("Shell exiting\n" );
|
||||
return TRUE;
|
||||
} else if (!strcmp(cmd,"exit")) { /* exit application */
|
||||
printf("System shutting down at user request\n" );
|
||||
} else if (!strcmp(cmd,"bye") || !strcmp(cmd,"exit")) {
|
||||
fprintf(stdout, "Shell exiting\n" );
|
||||
break;
|
||||
} else if (!strcmp(cmd,"shutdown")) { /* exit application */
|
||||
fprintf(stdout, "System shutting down at user request\n" );
|
||||
exit(0);
|
||||
} else if (!strcmp(cmd,"")) { /* only for get a new prompt */
|
||||
strcpy(last_cmd,cmd);
|
||||
@@ -469,7 +529,7 @@ rtems_boolean rtems_shell_main_loop(
|
||||
if ( argv[0] == NULL ) {
|
||||
shell_env->errorlevel = -1;
|
||||
} else if ( shell_cmd == NULL ) {
|
||||
printf("shell:%s command not found\n", argv[0]);
|
||||
fprintf(stdout, "shell:%s command not found\n", argv[0]);
|
||||
shell_env->errorlevel = -1;
|
||||
} else {
|
||||
shell_env->errorlevel = shell_cmd->command(argc, argv);
|
||||
@@ -482,22 +542,25 @@ rtems_boolean rtems_shell_main_loop(
|
||||
strcpy(last_cmd, cmd);
|
||||
cmd[0] = 0;
|
||||
}
|
||||
printf("\nGoodbye from RTEMS SHELL :-(\n");
|
||||
fflush( stdout );
|
||||
fflush( stderr );
|
||||
}
|
||||
} while (shell_env->forever);
|
||||
return TRUE;
|
||||
} while (result && shell_env->forever);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------- */
|
||||
rtems_status_code rtems_shell_init (
|
||||
static rtems_status_code rtems_shell_run (
|
||||
char *task_name,
|
||||
uint32_t task_stacksize,
|
||||
rtems_task_priority task_priority,
|
||||
char *devname,
|
||||
tcflag_t tcflag,
|
||||
int forever
|
||||
int forever,
|
||||
const char* input,
|
||||
const char* output,
|
||||
int output_append,
|
||||
rtems_id wake_on_end
|
||||
)
|
||||
{
|
||||
rtems_id task_id;
|
||||
@@ -526,15 +589,67 @@ rtems_status_code rtems_shell_init (
|
||||
|
||||
shell_env = rtems_shell_init_env( NULL );
|
||||
if ( !shell_env ) {
|
||||
rtems_error(sc,"allocating shell_env %s in shell_init()",task_name);
|
||||
rtems_error(RTEMS_NO_MEMORY,
|
||||
"allocating shell_env %s in shell_init()",task_name);
|
||||
return RTEMS_NO_MEMORY;
|
||||
}
|
||||
shell_env->devname = devname;
|
||||
shell_env->taskname = task_name;
|
||||
shell_env->tcflag = tcflag;
|
||||
shell_env->exit_shell = FALSE;
|
||||
shell_env->forever = forever;
|
||||
shell_env->devname = devname;
|
||||
shell_env->taskname = task_name;
|
||||
shell_env->tcflag = tcflag;
|
||||
shell_env->exit_shell = FALSE;
|
||||
shell_env->forever = forever;
|
||||
shell_env->input = strdup (input);
|
||||
shell_env->output = strdup (output);
|
||||
shell_env->output_append = output_append;
|
||||
shell_env->wake_on_end = wake_on_end;
|
||||
|
||||
return rtems_task_start(task_id, rtems_shell_task,
|
||||
(rtems_task_argument) shell_env);
|
||||
}
|
||||
|
||||
rtems_status_code rtems_shell_init (
|
||||
char *task_name,
|
||||
uint32_t task_stacksize,
|
||||
rtems_task_priority task_priority,
|
||||
char *devname,
|
||||
tcflag_t tcflag,
|
||||
int forever
|
||||
)
|
||||
{
|
||||
return rtems_shell_run (task_name, task_stacksize, task_priority,
|
||||
devname, tcflag, forever,
|
||||
"stdin", "stdout", 0, RTEMS_INVALID_ID);
|
||||
}
|
||||
|
||||
rtems_status_code rtems_shell_script (
|
||||
char *task_name,
|
||||
uint32_t task_stacksize,
|
||||
rtems_task_priority task_priority,
|
||||
const char* input,
|
||||
const char* output,
|
||||
int output_append,
|
||||
int wait
|
||||
)
|
||||
{
|
||||
rtems_id current_task = RTEMS_INVALID_ID;
|
||||
rtems_status_code sc;
|
||||
|
||||
if (wait) {
|
||||
sc = rtems_task_ident (RTEMS_SELF, RTEMS_LOCAL, ¤t_task);
|
||||
if (sc != RTEMS_SUCCESSFUL)
|
||||
return sc;
|
||||
}
|
||||
|
||||
sc = rtems_shell_run (task_name, task_stacksize, task_priority,
|
||||
NULL, 0, 0, input, output, output_append,
|
||||
current_task);
|
||||
if (sc != RTEMS_SUCCESSFUL)
|
||||
return sc;
|
||||
|
||||
if (wait) {
|
||||
rtems_event_set out;
|
||||
sc = rtems_event_receive (RTEMS_EVENT_1, RTEMS_WAIT, 0, &out);
|
||||
}
|
||||
|
||||
return sc;
|
||||
}
|
||||
|
||||
@@ -101,6 +101,29 @@ rtems_status_code rtems_shell_init(
|
||||
int forever
|
||||
);
|
||||
|
||||
/**
|
||||
* Run a shell script creating a shell tasks to execute the command under.
|
||||
*
|
||||
* @param task_name Name of the shell task.
|
||||
* @param task_stacksize The size of the stack. If 0 the default size is used.
|
||||
* @param task_priority The priority the shell runs at.
|
||||
* @param input The file of commands. Can be 'stdin' to use stdin.
|
||||
* @param output The output file to write commands to. Can be 'stdout',
|
||||
* 'stderr' or '/dev/null'.
|
||||
* @param output_append Append the output to the file or truncate the file.
|
||||
* Create if it does not exist.
|
||||
* @param wait Wait for the script to finish.
|
||||
*/
|
||||
rtems_status_code rtems_shell_script(
|
||||
char *task_name,
|
||||
uint32_t task_stacksize, /*0 default*/
|
||||
rtems_task_priority task_priority,
|
||||
const char *input,
|
||||
const char *output,
|
||||
int output_append,
|
||||
int wait
|
||||
);
|
||||
|
||||
/*
|
||||
* Things that are useful to external entities developing commands and plugging
|
||||
* them in.
|
||||
@@ -117,6 +140,10 @@ typedef struct {
|
||||
int forever ; /* repeat login */
|
||||
int errorlevel;
|
||||
uintptr_t mdump_addr;
|
||||
const char* input;
|
||||
const char* output;
|
||||
int output_append;
|
||||
rtems_id wake_on_end;
|
||||
} rtems_shell_env_t;
|
||||
|
||||
rtems_boolean rtems_shell_main_loop(
|
||||
|
||||
@@ -34,6 +34,7 @@ extern rtems_shell_cmd_t rtems_shell_ID_Command;
|
||||
extern rtems_shell_cmd_t rtems_shell_TTY_Command;
|
||||
extern rtems_shell_cmd_t rtems_shell_WHOAMI_Command;
|
||||
|
||||
extern rtems_shell_cmd_t rtems_shell_CP_Command;
|
||||
extern rtems_shell_cmd_t rtems_shell_PWD_Command;
|
||||
extern rtems_shell_cmd_t rtems_shell_LS_Command;
|
||||
extern rtems_shell_cmd_t rtems_shell_CHDIR_Command;
|
||||
@@ -192,6 +193,11 @@ extern rtems_shell_filesystems_t *rtems_shell_Mount_filesystems[];
|
||||
/*
|
||||
* File and directory commands
|
||||
*/
|
||||
#if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
|
||||
!defined(CONFIGURE_SHELL_NO_COMMAND_CP)) || \
|
||||
defined(CONFIGURE_SHELL_COMMAND_CP)
|
||||
&rtems_shell_CP_Command,
|
||||
#endif
|
||||
#if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
|
||||
!defined(CONFIGURE_SHELL_NO_COMMAND_PWD)) || \
|
||||
defined(CONFIGURE_SHELL_COMMAND_PWD)
|
||||
|
||||
350
cpukit/libmisc/shell/utils-cp.c
Normal file
350
cpukit/libmisc/shell/utils-cp.c
Normal file
@@ -0,0 +1,350 @@
|
||||
/* $NetBSD: utils.c,v 1.29 2005/10/15 18:22:18 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if 0
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)utils.c 8.3 (Berkeley) 4/1/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: utils.c,v 1.29 2005/10/15 18:22:18 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/utime.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <fts.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "extern-cp.h"
|
||||
|
||||
#define lchmod chmod
|
||||
#define lchown chown
|
||||
|
||||
int
|
||||
set_utimes(const char *file, struct stat *fs)
|
||||
{
|
||||
struct utimbuf tv;
|
||||
|
||||
tv.actime = fs->st_atime;
|
||||
tv.modtime = fs->st_mtime;
|
||||
|
||||
if (utime(file, &tv)) {
|
||||
warn("lutimes: %s", file);
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
copy_file(rtems_shell_cp_globals* cp_globals, FTSENT *entp, int dne)
|
||||
{
|
||||
static char buf[MAXBSIZE];
|
||||
struct stat to_stat, *fs;
|
||||
int ch, checkch, from_fd, rcount, rval, to_fd, wcount;
|
||||
|
||||
if ((from_fd = open(entp->fts_path, O_RDONLY, 0)) == -1) {
|
||||
warn("%s", entp->fts_path);
|
||||
return (1);
|
||||
}
|
||||
|
||||
fs = entp->fts_statp;
|
||||
|
||||
/*
|
||||
* If the file exists and we're interactive, verify with the user.
|
||||
* If the file DNE, set the mode to be the from file, minus setuid
|
||||
* bits, modified by the umask; arguably wrong, but it makes copying
|
||||
* executables work right and it's been that way forever. (The
|
||||
* other choice is 666 or'ed with the execute bits on the from file
|
||||
* modified by the umask.)
|
||||
*/
|
||||
if (!dne) {
|
||||
if (iflag) {
|
||||
(void)fprintf(stderr, "overwrite %s? ", to.p_path);
|
||||
checkch = ch = getchar();
|
||||
while (ch != '\n' && ch != EOF)
|
||||
ch = getchar();
|
||||
if (checkch != 'y' && checkch != 'Y') {
|
||||
(void)close(from_fd);
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
/* overwrite existing destination file name */
|
||||
to_fd = open(to.p_path, O_WRONLY | O_TRUNC, 0);
|
||||
} else
|
||||
to_fd = open(to.p_path, O_WRONLY | O_TRUNC | O_CREAT,
|
||||
fs->st_mode & ~(S_ISUID | S_ISGID));
|
||||
|
||||
if (to_fd == -1 && fflag) {
|
||||
/*
|
||||
* attempt to remove existing destination file name and
|
||||
* create a new file
|
||||
*/
|
||||
(void)unlink(to.p_path);
|
||||
to_fd = open(to.p_path, O_WRONLY | O_TRUNC | O_CREAT,
|
||||
fs->st_mode & ~(S_ISUID | S_ISGID));
|
||||
}
|
||||
|
||||
if (to_fd == -1) {
|
||||
warn("%s", to.p_path);
|
||||
(void)close(from_fd);
|
||||
return (1);
|
||||
}
|
||||
|
||||
rval = 0;
|
||||
|
||||
/*
|
||||
* There's no reason to do anything other than close the file
|
||||
* now if it's empty, so let's not bother.
|
||||
*/
|
||||
|
||||
if (fs->st_size) {
|
||||
|
||||
/*
|
||||
* Mmap and write if less than 8M (the limit is so
|
||||
* we don't totally trash memory on big files).
|
||||
* This is really a minor hack, but it wins some CPU back.
|
||||
*/
|
||||
#if 0
|
||||
if (fs->st_size <= 8 * 1048576) {
|
||||
size_t fsize = (size_t)fs->st_size;
|
||||
p = mmap(NULL, fsize, PROT_READ, MAP_FILE|MAP_SHARED,
|
||||
from_fd, (off_t)0);
|
||||
if (p == MAP_FAILED) {
|
||||
goto mmap_failed;
|
||||
} else {
|
||||
(void) madvise(p, (size_t)fs->st_size,
|
||||
MADV_SEQUENTIAL);
|
||||
if (write(to_fd, p, fsize) !=
|
||||
fs->st_size) {
|
||||
warn("%s", to.p_path);
|
||||
rval = 1;
|
||||
}
|
||||
if (munmap(p, fsize) < 0) {
|
||||
warn("%s", entp->fts_path);
|
||||
rval = 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
mmap_failed:
|
||||
#endif
|
||||
{
|
||||
while ((rcount = read(from_fd, buf, MAXBSIZE)) > 0) {
|
||||
wcount = write(to_fd, buf, (size_t)rcount);
|
||||
if (rcount != wcount || wcount == -1) {
|
||||
warn("%s", to.p_path);
|
||||
rval = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (rcount < 0) {
|
||||
warn("%s", entp->fts_path);
|
||||
rval = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rval == 1) {
|
||||
(void)close(from_fd);
|
||||
(void)close(to_fd);
|
||||
return (1);
|
||||
}
|
||||
|
||||
if (pflag && setfile(cp_globals, fs, to_fd))
|
||||
rval = 1;
|
||||
/*
|
||||
* If the source was setuid or setgid, lose the bits unless the
|
||||
* copy is owned by the same user and group.
|
||||
*/
|
||||
#define RETAINBITS \
|
||||
(S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO)
|
||||
else if (fs->st_mode & (S_ISUID | S_ISGID) && fs->st_uid == myuid) {
|
||||
if (fstat(to_fd, &to_stat)) {
|
||||
warn("%s", to.p_path);
|
||||
rval = 1;
|
||||
} else if (fs->st_gid == to_stat.st_gid &&
|
||||
fchmod(to_fd, fs->st_mode & RETAINBITS & ~myumask)) {
|
||||
warn("%s", to.p_path);
|
||||
rval = 1;
|
||||
}
|
||||
}
|
||||
(void)close(from_fd);
|
||||
if (close(to_fd)) {
|
||||
warn("%s", to.p_path);
|
||||
rval = 1;
|
||||
}
|
||||
/* set the mod/access times now after close of the fd */
|
||||
if (pflag && set_utimes(to.p_path, fs)) {
|
||||
rval = 1;
|
||||
}
|
||||
return (rval);
|
||||
}
|
||||
|
||||
int
|
||||
copy_link(rtems_shell_cp_globals* cp_globals, FTSENT *p, int exists)
|
||||
{
|
||||
int len;
|
||||
char target[MAXPATHLEN];
|
||||
|
||||
if ((len = readlink(p->fts_path, target, sizeof(target)-1)) == -1) {
|
||||
warn("readlink: %s", p->fts_path);
|
||||
return (1);
|
||||
}
|
||||
target[len] = '\0';
|
||||
if (exists && unlink(to.p_path)) {
|
||||
warn("unlink: %s", to.p_path);
|
||||
return (1);
|
||||
}
|
||||
if (symlink(target, to.p_path)) {
|
||||
warn("symlink: %s", target);
|
||||
return (1);
|
||||
}
|
||||
return (pflag ? setfile(cp_globals, p->fts_statp, 0) : 0);
|
||||
}
|
||||
|
||||
int
|
||||
copy_fifo(rtems_shell_cp_globals* cp_globals, struct stat *from_stat, int exists)
|
||||
{
|
||||
if (exists && unlink(to.p_path)) {
|
||||
warn("unlink: %s", to.p_path);
|
||||
return (1);
|
||||
}
|
||||
if (mkfifo(to.p_path, from_stat->st_mode)) {
|
||||
warn("mkfifo: %s", to.p_path);
|
||||
return (1);
|
||||
}
|
||||
return (pflag ? setfile(cp_globals, from_stat, 0) : 0);
|
||||
}
|
||||
|
||||
int
|
||||
copy_special(rtems_shell_cp_globals* cp_globals, struct stat *from_stat, int exists)
|
||||
{
|
||||
if (exists && unlink(to.p_path)) {
|
||||
warn("unlink: %s", to.p_path);
|
||||
return (1);
|
||||
}
|
||||
if (mknod(to.p_path, from_stat->st_mode, from_stat->st_rdev)) {
|
||||
warn("mknod: %s", to.p_path);
|
||||
return (1);
|
||||
}
|
||||
return (pflag ? setfile(cp_globals, from_stat, 0) : 0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Function: setfile
|
||||
*
|
||||
* Purpose:
|
||||
* Set the owner/group/permissions for the "to" file to the information
|
||||
* in the stat structure. If fd is zero, also call set_utimes() to set
|
||||
* the mod/access times. If fd is non-zero, the caller must do a utimes
|
||||
* itself after close(fd).
|
||||
*/
|
||||
#define st_flags st_mode
|
||||
|
||||
int
|
||||
setfile(rtems_shell_cp_globals* cp_globals, struct stat *fs, int fd)
|
||||
{
|
||||
int rval, islink;
|
||||
|
||||
rval = 0;
|
||||
islink = S_ISLNK(fs->st_mode);
|
||||
fs->st_mode &= S_ISUID | S_ISGID | S_IRWXU | S_IRWXG | S_IRWXO;
|
||||
|
||||
/*
|
||||
* Changing the ownership probably won't succeed, unless we're root
|
||||
* or POSIX_CHOWN_RESTRICTED is not set. Set uid/gid before setting
|
||||
* the mode; current BSD behavior is to remove all setuid bits on
|
||||
* chown. If chown fails, lose setuid/setgid bits.
|
||||
*/
|
||||
#if 0
|
||||
if (fd ? fchown(fd, fs->st_uid, fs->st_gid) :
|
||||
lchown(to.p_path, fs->st_uid, fs->st_gid)) {
|
||||
#endif
|
||||
if (lchown(to.p_path, fs->st_uid, fs->st_gid)) {
|
||||
if (errno != EPERM) {
|
||||
warn("chown: %s", to.p_path);
|
||||
rval = 1;
|
||||
}
|
||||
fs->st_mode &= ~(S_ISUID | S_ISGID);
|
||||
}
|
||||
if (fd ? fchmod(fd, fs->st_mode) : lchmod(to.p_path, fs->st_mode)) {
|
||||
warn("chmod: %s", to.p_path);
|
||||
rval = 1;
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (!islink && !Nflag) {
|
||||
unsigned long fflags = fs->st_flags;
|
||||
/*
|
||||
* XXX
|
||||
* NFS doesn't support chflags; ignore errors unless
|
||||
* there's reason to believe we're losing bits.
|
||||
* (Note, this still won't be right if the server
|
||||
* supports flags and we were trying to *remove* flags
|
||||
* on a file that we copied, i.e., that we didn't create.)
|
||||
*/
|
||||
errno = 0;
|
||||
if ((fd ? fchflags(fd, fflags) :
|
||||
chflags(to.p_path, fflags)) == -1)
|
||||
if (errno != EOPNOTSUPP || fs->st_flags != 0) {
|
||||
warn("chflags: %s", to.p_path);
|
||||
rval = 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/* if fd is non-zero, caller must call set_utimes() after close() */
|
||||
if (fd == 0 && set_utimes(to.p_path, fs))
|
||||
rval = 1;
|
||||
return (rval);
|
||||
}
|
||||
|
||||
void
|
||||
usage(void)
|
||||
{
|
||||
(void)fprintf(stderr,
|
||||
"usage: %s [-R [-H | -L | -P]] [-f | -i] [-pv] src target\n"
|
||||
" %s [-R [-H | -L | -P]] [-f | -i] [-pv] src1 ... srcN directory\n",
|
||||
"cp", "cp");
|
||||
}
|
||||
71
cpukit/libmisc/shell/verr.c
Normal file
71
cpukit/libmisc/shell/verr.c
Normal file
@@ -0,0 +1,71 @@
|
||||
/* $NetBSD: verr.c,v 1.13 2005/09/13 01:44:09 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)err.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: verr.c,v 1.13 2005/09/13 01:44:09 christos Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(verr, _verr)
|
||||
#endif
|
||||
|
||||
__dead void
|
||||
verr(jmp_buf* exit_jmp, int eval, const char *fmt, _BSD_VA_LIST_ ap)
|
||||
{
|
||||
int sverrno;
|
||||
|
||||
sverrno = errno;
|
||||
#if 0
|
||||
(void)fprintf(stderr, "%s: ", getprogname());
|
||||
#endif
|
||||
if (fmt != NULL) {
|
||||
(void)vfprintf(stdout, fmt, ap);
|
||||
(void)fprintf(stdout, ": ");
|
||||
}
|
||||
(void)fprintf(stdout, "%s\n", strerror(sverrno));
|
||||
longjmp (*exit_jmp, 1);
|
||||
}
|
||||
64
cpukit/libmisc/shell/verrx.c
Normal file
64
cpukit/libmisc/shell/verrx.c
Normal file
@@ -0,0 +1,64 @@
|
||||
/* $NetBSD: verrx.c,v 1.13 2005/09/13 01:44:09 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)err.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: verrx.c,v 1.13 2005/09/13 01:44:09 christos Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <err.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(verrx, _verrx)
|
||||
#endif
|
||||
|
||||
__dead void
|
||||
verrx(jmp_buf* exit_jmp, int eval, const char *fmt, _BSD_VA_LIST_ ap)
|
||||
{
|
||||
#if 0
|
||||
(void)fprintf(stderr, "%s: ", getprogname());
|
||||
#endif
|
||||
if (fmt != NULL)
|
||||
(void)vfprintf(stdout, fmt, ap);
|
||||
(void)fprintf(stdout, "\n");
|
||||
longjmp (*exit_jmp, 1);
|
||||
}
|
||||
70
cpukit/libmisc/shell/vwarn.c
Normal file
70
cpukit/libmisc/shell/vwarn.c
Normal file
@@ -0,0 +1,70 @@
|
||||
/* $NetBSD: vwarn.c,v 1.13 2005/09/13 01:44:09 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)err.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: vwarn.c,v 1.13 2005/09/13 01:44:09 christos Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(vwarn, _vwarn)
|
||||
#endif
|
||||
|
||||
void
|
||||
vwarn(const char *fmt, _BSD_VA_LIST_ ap)
|
||||
{
|
||||
int sverrno;
|
||||
|
||||
sverrno = errno;
|
||||
#if 0
|
||||
(void)fprintf(stderr, "%s: ", getprogname());
|
||||
#endif
|
||||
if (fmt != NULL) {
|
||||
(void)vfprintf(stdout, fmt, ap);
|
||||
(void)fprintf(stdout, ": ");
|
||||
}
|
||||
(void)fprintf(stdout, "%s\n", strerror(sverrno));
|
||||
}
|
||||
63
cpukit/libmisc/shell/vwarnx.c
Normal file
63
cpukit/libmisc/shell/vwarnx.c
Normal file
@@ -0,0 +1,63 @@
|
||||
/* $NetBSD: vwarnx.c,v 1.13 2005/09/13 01:44:09 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)err.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: vwarnx.c,v 1.13 2005/09/13 01:44:09 christos Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <err.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(vwarnx, _vwarnx)
|
||||
#endif
|
||||
|
||||
void
|
||||
vwarnx(const char *fmt, _BSD_VA_LIST_ ap)
|
||||
{
|
||||
#if 0
|
||||
(void)fprintf(stderr, "%s: ", getprogname());
|
||||
#endif
|
||||
if (fmt != NULL)
|
||||
(void)vfprintf(stdout, fmt, ap);
|
||||
(void)fprintf(stdout, "\n");
|
||||
}
|
||||
60
cpukit/libmisc/shell/warn.c
Normal file
60
cpukit/libmisc/shell/warn.c
Normal file
@@ -0,0 +1,60 @@
|
||||
/* $NetBSD: warn.c,v 1.13 2005/09/13 13:51:50 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)err.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: warn.c,v 1.13 2005/09/13 13:51:50 christos Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <err.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(warn, _warn)
|
||||
#endif
|
||||
|
||||
void
|
||||
warn(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
vwarn(fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
60
cpukit/libmisc/shell/warnx.c
Normal file
60
cpukit/libmisc/shell/warnx.c
Normal file
@@ -0,0 +1,60 @@
|
||||
/* $NetBSD: warnx.c,v 1.13 2005/09/13 13:51:50 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)err.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: warnx.c,v 1.13 2005/09/13 13:51:50 christos Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <err.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(warnx, _warnx)
|
||||
#endif
|
||||
|
||||
void
|
||||
warnx(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
vwarnx(fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
@@ -311,13 +311,15 @@ rtems_bsdnet_semaphore_obtain (void)
|
||||
level
|
||||
);
|
||||
if (_Thread_Executing->Wait.return_code)
|
||||
rtems_panic ("Can't obtain network semaphore\n");
|
||||
rtems_panic ("rtems-net: can't obtain network sema: %d\n",
|
||||
_Thread_Executing->Wait.return_code);
|
||||
#else
|
||||
rtems_status_code sc;
|
||||
|
||||
sc = rtems_semaphore_obtain (networkSemaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
|
||||
if (sc != RTEMS_SUCCESSFUL)
|
||||
rtems_panic ("Can't obtain network semaphore: `%s'\n", rtems_status_text (sc));
|
||||
rtems_panic ("rtems-net: can't obtain network semaphore: `%s'\n",
|
||||
rtems_status_text (sc));
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -338,13 +340,14 @@ rtems_bsdnet_semaphore_release (void)
|
||||
);
|
||||
_Thread_Enable_dispatch();
|
||||
if (i)
|
||||
rtems_panic ("Can't release network semaphore\n");
|
||||
rtems_panic ("rtems-net: can't release network sema: %i\n");
|
||||
#else
|
||||
rtems_status_code sc;
|
||||
|
||||
sc = rtems_semaphore_release (networkSemaphore);
|
||||
if (sc != RTEMS_SUCCESSFUL)
|
||||
rtems_panic ("Can't release network semaphore: `%s'\n", rtems_status_text (sc));
|
||||
rtems_panic ("rtems-net: can't release network semaphore: `%s'\n",
|
||||
rtems_status_text (sc));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ libscore_a_SOURCES += src/heap.c src/heapallocate.c src/heapextend.c \
|
||||
libscore_a_SOURCES += src/object.c src/objectallocate.c \
|
||||
src/objectclearname.c src/objectcomparenameraw.c \
|
||||
src/objectcomparenamestring.c src/objectcopynameraw.c \
|
||||
src/objectcopynamestring.c \ src/objectextendinformation.c \
|
||||
src/objectcopynamestring.c src/objectextendinformation.c \
|
||||
src/objectfree.c src/objectget.c src/objectgetisr.c src/objectgetnext.c \
|
||||
src/objectinitializeinformation.c src/objectnametoid.c \
|
||||
src/objectshrinkinformation.c src/objectgetnoprotection.c \
|
||||
|
||||
@@ -141,7 +141,8 @@ RTEMS_INLINE_ROUTINE int _CORE_mutex_Seize_interrupt_trylock_body(
|
||||
_CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) ){
|
||||
|
||||
#ifdef __STRICT_ORDER_MUTEX__
|
||||
_Chain_Prepend_unprotected(&executing->lock_mutex,&the_mutex->queue.lock_queue);
|
||||
_Chain_Prepend_unprotected( &executing->lock_mutex,
|
||||
&the_mutex->queue.lock_queue );
|
||||
the_mutex->queue.priority_before = executing->current_priority;
|
||||
#endif
|
||||
|
||||
|
||||
@@ -64,6 +64,13 @@ void _CORE_mutex_Initialize(
|
||||
the_mutex->holder_id = _Thread_Executing->Object.id;
|
||||
if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ||
|
||||
_CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) )
|
||||
|
||||
#ifdef __STRICT_ORDER_MUTEX__
|
||||
_Chain_Prepend_unprotected( &executing->lock_mutex,
|
||||
&the_mutex->queue.lock_queue );
|
||||
the_mutex->queue.priority_before = executing->current_priority;
|
||||
#endif
|
||||
|
||||
_Thread_Executing->resource_count++;
|
||||
} else {
|
||||
the_mutex->nest_count = 0;
|
||||
|
||||
@@ -54,11 +54,11 @@ static int main_udp(int argc,char * argv[]) {
|
||||
/*+++++++++++++++++++++++++++++++++++++++++++++*/
|
||||
|
||||
void _rtems_telnetd_register_icmds(void) {
|
||||
shell_add_cmd("inet" ,"net","inet routes" ,main_inet);
|
||||
shell_add_cmd("mbuf" ,"net","mbuf stats" ,main_mbuf);
|
||||
shell_add_cmd("if" ,"net","if stats" ,main_if );
|
||||
shell_add_cmd("ip" ,"net","ip stats" ,main_ip );
|
||||
shell_add_cmd("icmp" ,"net","icmp stats" ,main_icmp);
|
||||
shell_add_cmd("tcp" ,"net","tcp stats" ,main_tcp );
|
||||
shell_add_cmd("udp" ,"net","udp stats" ,main_udp );
|
||||
rtems_shell_add_cmd("inet" ,"net","inet routes" ,main_inet);
|
||||
rtems_shell_add_cmd("mbuf" ,"net","mbuf stats" ,main_mbuf);
|
||||
rtems_shell_add_cmd("if" ,"net","if stats" ,main_if );
|
||||
rtems_shell_add_cmd("ip" ,"net","ip stats" ,main_ip );
|
||||
rtems_shell_add_cmd("icmp" ,"net","icmp stats" ,main_icmp);
|
||||
rtems_shell_add_cmd("tcp" ,"net","tcp stats" ,main_tcp );
|
||||
rtems_shell_add_cmd("udp" ,"net","udp stats" ,main_udp );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user