Skip to content

Commit

Permalink
Merge branch 'freebsd/11-stable/master' into hardened/11-stable/master
Browse files Browse the repository at this point in the history
* freebsd/11-stable/master:
  MFC r342792, r342805: Provide rc_service variable for rc service scripts
  MFC r305074-r305075, r327275, r327570: newfs_msdos updates
  • Loading branch information
opntr-auto committed Jan 15, 2019
2 parents 9ce50cc + 4ce65c9 commit 7bd1f45
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
12 changes: 12 additions & 0 deletions etc/rc.subr
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ ID="/usr/bin/id"
IDCMD="if [ -x $ID ]; then $ID -un; fi"
PS="/bin/ps -ww"
JID=0
# rc_service provides the path to the service script that we are executing.
# This is not being set here in an execution context, necessarily, so it's
# really just a reasonable guess, and it will get overwritten later if
# we are executing from some other means than direct execution by service(8)
# or manual invocation of the service script. The prime example of this is
# during system startup, all rc scripts will be invoked via /etc/rc, so
# run_rc_script will overwrite rc_service with the file being sourced.
rc_service="$0"

#
# functions
Expand Down Expand Up @@ -863,6 +871,9 @@ check_startmsgs()
# by $flags from the environment.
# This variable may be changed by the precmd method.
#
# rc_service Path to the service being executed, in case the service
# needs to re-invoke itself.
#
# rc_pid PID of command (if appropriate)
#
# rc_fast Not empty if "fast" was provided (q.v.)
Expand Down Expand Up @@ -1333,6 +1344,7 @@ run_rc_script()
required_vars
eval unset ${_arg}_cmd ${_arg}_precmd ${_arg}_postcmd

rc_service="$_file"
case "$_file" in
/etc/rc.d/*.sh) # no longer allowed in the base
warn "Ignoring old-style startup script $_file"
Expand Down
14 changes: 6 additions & 8 deletions sbin/newfs_msdos/mkfs_msdos.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ mkfs_msdos(const char *fname, const char *dtype, const struct msdos_options *op)

img = NULL;
rv = -1;
fd = fd1 = -1;

if (o.block_size && o.sectors_per_cluster) {
warnx("Cannot specify both block size and sectors per cluster");
Expand Down Expand Up @@ -315,15 +316,8 @@ mkfs_msdos(const char *fname, const char *dtype, const struct msdos_options *op)
bpb.bpbHiddenSecs = o.hidden_sectors;
if (!(o.floppy || (o.drive_heads && o.sectors_per_track &&
o.bytes_per_sector && o.size && o.hidden_sectors_set))) {
off_t delta;
getdiskinfo(fd, fname, dtype, o.hidden_sectors_set, &bpb);
bpb.bpbHugeSectors -= (o.offset / bpb.bpbBytesPerSec);
delta = bpb.bpbHugeSectors % bpb.bpbSecPerTrack;
if (delta != 0) {
warnx("trim %d sectors to adjust to a multiple of %d",
(int)delta, bpb.bpbSecPerTrack);
bpb.bpbHugeSectors -= delta;
}
if (bpb.bpbSecPerClust == 0) { /* set defaults */
if (bpb.bpbHugeSectors <= 6000) /* about 3MB -> 512 bytes */
bpb.bpbSecPerClust = 1;
Expand Down Expand Up @@ -598,7 +592,7 @@ mkfs_msdos(const char *fname, const char *dtype, const struct msdos_options *op)
bpb.bpbMedia = !bpb.bpbHiddenSecs ? 0xf0 : 0xf8;
if (fat == 32)
bpb.bpbRootClust = RESFTE;
if (bpb.bpbHiddenSecs + bpb.bpbHugeSectors <= MAXU16) {
if (bpb.bpbHugeSectors <= MAXU16) {
bpb.bpbSectors = bpb.bpbHugeSectors;
bpb.bpbHugeSectors = 0;
}
Expand Down Expand Up @@ -758,6 +752,10 @@ mkfs_msdos(const char *fname, const char *dtype, const struct msdos_options *op)
rv = 0;
done:
free(img);
if (fd != -1)
close(fd);
if (fd1 != -1)
close(fd1);

return rv;
}
Expand Down
6 changes: 4 additions & 2 deletions share/man/man8/rc.subr.8
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd February 4, 2016
.Dd January 15, 2019
.Dt RC.SUBR 8
.Os
.Sh NAME
Expand Down Expand Up @@ -764,7 +764,7 @@ The following variables are available to the methods
as well as after
.Ic run_rc_command
has completed:
.Bl -tag -width ".Va rc_flags" -offset indent
.Bl -tag -width ".Va rc_service" -offset indent
.It Va rc_arg
Argument provided to
.Ic run_rc_command ,
Expand All @@ -778,6 +778,8 @@ unless overridden by the environment variable
This variable may be changed by the
.Ar argument Ns Va _precmd
method.
.It Va rc_service
Path to the service script being executed, in case it needs to re-invoke itself.
.It Va rc_pid
PID of
.Va command
Expand Down

0 comments on commit 7bd1f45

Please sign in to comment.