History log of /freebsd-current/usr.sbin/crunch/crunchgen/crunched_main.c
Revision Date Author Comments
# f122045e 17-Apr-2024 Martin Tournoij <martin@arp242.net>

crunchgen: add --list option

"bsdbox --list" will print all tools in the binary, one per line. The
main use case for this is to make it easier to create links:

for t in $(bsdbox --list); do
ln -s bsdbox $t
done

The name --list was taken from busybox.

This just adds a new "program" with the name "--list". I don't think we
need to do real argument parsing here, and this is also how busybox does
it.

An additional minor change is that just "bsdbox" will no longer print
the binary name itself ("bsdbox" in this case). Before it would do:

% bsdbox
usage: boxlike <prog> <args> ..., where <prog> is one of:
cp ls mv bsdbox

And now just:

% bsdbox
usage: boxlike <prog> <args> ..., where <prog> is one of:
cp ls mv

And just "bsdbox" will also exit with code 0 (and print to stdout)
rather than exit with 0 and print to stderr

Example output:

% ./bsdbox
usage: bsdbox program [args ...]
bsdbox --list
program [args ...]

bsdbox combines several programs in one executable. Create a link to this
executable with the program name to run that program, or give the program
name as the first argument.

Currently defined programs:
true false tail head uname

% ./bsdbox --list
true
false
tail
head
uname

% ./bsdbox uname -a
FreeBSD freebsd 13.2-RELEASE-p4 FreeBSD 13.2-RELEASE-p4 GENERIC amd64

% ln -s bsdbox uname
% ./uname -a
FreeBSD freebsd 13.2-RELEASE-p4 FreeBSD 13.2-RELEASE-p4 GENERIC amd64

Pull Request: https://github.com/freebsd/freebsd-src/pull/894
Signed-off-by: Martin Tournoij <martin@arp242.net>
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/894


# 4d65a7c6 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

usr.sbin: Automated cleanup of cdefs and other formatting

Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by: Netflix


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 7483b9e4 10-Dec-2020 Stefan Eßer <se@FreeBSD.org>

Lift scope of buf[] to make it extend to a potential access via *basename

It can be assumed that the contents of the buffer was still allocated and
valid at the point of the out-of-scope access, so there was no security
issue in practice.

Reported by: Coverity Scan CID 1437697
MFC after: 3 days


# f7ff7baa 04-Dec-2020 Alex Richardson <arichardson@FreeBSD.org>

crunchgen: fix NULL-deref bug introduced in r364647

While porting over the local changes from CheriBSD for upstreaming, I
accidentally committed a broken version of find_entry_point(): we have to
return NULL if the value is not found instead of a value with
ep->name == NULL, since the checks in main were changed to check ep instead
of ep->name for NULL.

This only matters if the crunched tool cannot be found using normal lookup
and one of the fallback paths is used, so it's unlikely to be triggered
in rescue. However, I noticed that one of our CheriBSD test scripts was
failing to run commands under `su` on minimal disk images where all
binaries are hardlinks to a `cheribsdbox` tool generated with crunchgen.

This also updates the bootstrapping check in Makefile.inc1 to bootstrap
crunchgen up to the next version bump.

Reviewed By: kevans
Differential Revision: https://reviews.freebsd.org/D27474


# 0dcdda09 21-Sep-2020 Adrian Chadd <adrian@FreeBSD.org>

[rcorder] [crunch] Fix C function declarations to include void

This fixes a compile issue under gcc6 which complains about
legacy style C function declarations.

Differential Revision: https://reviews.freebsd.org/D26504


# fc905210 10-Sep-2020 Kyle Evans <kevans@FreeBSD.org>

crunchgen(8): fix crunched application build with WARNS=6

This was revealed by the rescue build with a patch I'm working on to default
WARNS=6 everywhere. The issues resolved were:

- Missing prototype for _crunched_${ident}_stub in the *_stub.c generated
bits
- Missing prototype for crunched_main
- Incomplete prototype for _crunched_${ident}_stub in the generated parts of
crunched_main
- Literal strings in the stub table must drop const qualifier, unless we
const'ify name
- f field in struct stub didn't have a proper prototype

Most of these issues are minor formalities and easily addressed.

I note that if my patch to eventually raise WARNS for the rescue build
lands, we'll need to bump the __FreeBSD_version requirement for
bootstrapping crunchgen and wipe out the rescue .OBJDIR if it's stale, which
we should be able to detect pretty easily from a couple of the issues that
have been fixed here.

Reviewed by: arichardson
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D26363


# 50e525e4 24-Aug-2020 Alex Richardson <arichardson@FreeBSD.org>

Correctly determine the real executable in crunched binaries

This should fix cases like su setting argv[0] to _su for /bin/sh.
Previously cheribsdbox (a crunched tool we use in CheriBSD to reduce the
size of our minimal disk images to allow loading them onto FPGAs without
waiting forever for the transfer) would complain about _su not being
compiled in, but now that we also look at AT_EXECPATH it correctly
invokes the sh tool.

Note: we use use AT_EXECPATH instead of the KERN_PROC_PATHNAME sysctl to get
the crunchgen binary name since it seems like KERN_PROC_PATHNAME just
returns the last cached path for a given hardlink.
When using `su`, instead of invoking /bin/csh this would invoke the last
used hardlink to cheribsdbox. This caused weird test failures when running
tests due to `id` being executed instead of `echo`:

$ id # id is a hardlink to /bin/cheribsdbox
$ su postgres -c 'echo 1' # su is also a hardlink
uid=1001(postgres) gid=1001(postgres) groups=1001(postgres)

Obtained from: CheriBSD

Reviewed By: emaste, brooks
Differential Revision: https://reviews.freebsd.org/D25998


# b0f558df 24-Aug-2020 Alex Richardson <arichardson@FreeBSD.org>

Re-indent crunched_main.c in preparation for D25998


# e881ec16 07-Sep-2017 Ryan Libby <rlibby@FreeBSD.org>

crunchgen: quiet -Wmissing-prototypes

Reviewed by: emaste (previous version)
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D12107


# 02c75192 26-Jun-2012 David E. O'Brien <obrien@FreeBSD.org>

Some amount of style(9)
-- function definitions, header ordering, and $FreeBSD$.


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# 5e8bbdf1 27-Oct-2007 Yaroslav Tykhiy <ytykhiy@gmail.com>

Include <stdlib.h> for the right prototype for exit(3).


# a7aebe89 27-Oct-2007 Yaroslav Tykhiy <ytykhiy@gmail.com>

Set the program name if the crunched program is selected through
argv[1] to mimic crt0 behaviour. Do the job by a direct assignment
to __progname in order to stay compatible with NetBSD, whose
setprogname() is a deliberate no-op.

The reason for this change is that some programs (usually those
imported from NetBSD) use getprogname() to distinguish between their
aliases. (See pkill aka pgrep for example.)

This change can be useful, and applicable, to NetBSD, too.


# b0c70f81 08-Aug-2002 Gregory Neil Shapiro <gshapiro@FreeBSD.org>

Apply the envp fix to the other call to main() as well.

Submitted by: Peter Edwards <pmedwards@eircom.net>


# 8f3548b2 04-Aug-2002 Gregory Neil Shapiro <gshapiro@FreeBSD.org>

Pass envp to crunched program's main() routines as some depend on it.
Note that crunchgen's stub .c programs already have the code to use it:

"int _crunched_%s_stub(int argc, char **argv, char **envp)"
"{return main(argc,argv,envp);}\" >%s_stub.c\n",

Add $FreeBSD$ to allow the commit.

Reviewed by: luigi
MFC after: 3 days


# b17e90a9 15-Sep-1997 Philippe Charnier <charnier@FreeBSD.org>

Use err(3).


# 709e8f9a 29-May-1995 Rodney W. Grimes <rgrimes@FreeBSD.org>

Remove trailing whitespace.


# 7d150b77 20-May-1995 Poul-Henning Kamp <phk@FreeBSD.org>

Added a crunched_here(char *path) function so crunched programs can find out
who they share bed and breakfast with.


# a62f0e65 24-Jun-1994 Jordan K. Hubbard <jkh@FreeBSD.org>

Just talked with James - there's another, better way to go about this.
Back out my earlier change. Note that this is just for the 1.1.5R floppies;
the 1.1.5A ones still have the work-around method (which works fine and
doesn't hurt anything, it's just kludge!).


# a47d4a46 24-Jun-1994 Jordan K. Hubbard <jkh@FreeBSD.org>

This is a kludge. Unless I make a link from sh to - (which would leave a file
called `-' lying around on the users system forever) login shells will fail.
Just special-case the handling of `-' for now until/unless I find a more
palatable solution.


# de566360 15-Jun-1994 Jordan K. Hubbard <jkh@FreeBSD.org>

This is the new crunch utility for making distribution floppies from
James da Silva. We need to integrate this before 1.1.5 so that we can
actually make the boot floppies.