Page MenuHomeFreeBSD

/etc/rc.d/hostname: permit setting hostname if already set
ClosedPublic

Authored by feld on May 18 2015, 5:19 PM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Dec 11, 11:54 PM
Unknown Object (File)
Wed, Nov 27, 12:19 AM
Unknown Object (File)
Nov 14 2024, 9:21 AM
Unknown Object (File)
Nov 13 2024, 1:06 AM
Unknown Object (File)
Nov 12 2024, 3:48 PM
Unknown Object (File)
Nov 10 2024, 7:14 AM
Unknown Object (File)
Oct 28 2024, 12:57 PM
Unknown Object (File)
Oct 23 2024, 3:23 PM

Details

Summary

/etc/rc.d/hostname doesn't let you set your hostname if it has already
been set. Eg, if hostname was wrong on boot and you correct hostname in
/etc/rc.conf you cannot do a "service hostname start" to have the system
set it again.

It makes sense that you may want to do it this way instead of just
issuing hostname(1) so you can be sure it is parsed from rc.conf
correctly. It has been this way since at least r127345 (2004)

While here, clean up due to rclint recommendations: remove unecessary
quotes, fix ordering.

Test Plan

edit rc.conf, issue "service hostname start"

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 65
Build 65: arc lint + arc unit

Event Timeline

feld retitled this revision from to /etc/rc.d/hostname: permit setting hostname if already set.
feld updated this object.
feld edited the test plan for this revision. (Show Details)

The condition has been added by PHK in revision 4101 (20 years ago) with the comment "Don't set hostname if we already have it. (diskless)."
I wish it has been because of /etc/rc.d/diskless script. Such script has been used to set hostname on diskless installation, so rc.d/hostname has not been welcomed to overwrite the name later. rc.d/diskless has been dropped in 127347 revision. Currently no other /etc/rc.d/* script sets hostname, so conditional in /etc/rc.d/hostname can be removed with no harm AFAIK.

Patch seems to be correct and safe (as claimed in my previous comment), but comments on lines 42-43 needs to be modified to reflect the change of code.

I propose something like

# If we are not inside a jail, set the host name
# If we are inside a jail, set the host name if it is permitted.
This revision now requires changes to proceed.May 20 2015, 2:44 AM
feld edited edge metadata.

Update comments per dan's suggestion

feld added a subscriber: bapt.

Remove rclint changes per @bapt and @dteske

Nits

etc/rc.d/hostname
40

Despite what rclint may say, this belongs at the bottom like 75%+ of the other rc.d scripts (if we don't like that; we should attack rclint or change the other rc.d scripts to adhere to rclint). Here's a break-down of this particular situation w/respect to the "other rc.d scripts":

dteske@porridge.pixel8networks.com ~ $ find /etc/rc.d -type f -mindepth 1 -maxdepth 1 | xargs -rn1 awk 'BEGIN{on=0}/load_rc_config/{on=NR}END{print FILENAME,on"/"NR,at=(on*100)/NR"%",(at>75?"NEAR_END":"")}' | awk '{if(!/NEAR_END/)c++;print}END{printf "%16u/%u are not NEAR_END (%u%%)\n",c,NR,(c*100/NR)}'
/etc/rc.d/iscsid 19/20 95% NEAR_END
/etc/rc.d/bthidd 27/33 81.8182% NEAR_END
/etc/rc.d/kfd 22/23 95.6522% NEAR_END
/etc/rc.d/pppoed 32/33 96.9697% NEAR_END
/etc/rc.d/netwait 97/98 98.9796% NEAR_END
/etc/rc.d/syscons 372/374 99.4652% NEAR_END
/etc/rc.d/route6d 19/20 95% NEAR_END
/etc/rc.d/random 95/96 98.9583% NEAR_END
/etc/rc.d/rpcbind 18/19 94.7368% NEAR_END
/etc/rc.d/sppp 35/36 97.2222% NEAR_END
/etc/rc.d/mrouted 19/20 95% NEAR_END
/etc/rc.d/hostapd 31/32 96.875% NEAR_END
/etc/rc.d/NETWORKING 0/12 0%
/etc/rc.d/atm3 92/93 98.9247% NEAR_END
/etc/rc.d/apm 45/46 97.8261% NEAR_END
/etc/rc.d/nisdomain 53/54 98.1481% NEAR_END
/etc/rc.d/gptboot 76/77 98.7013% NEAR_END
/etc/rc.d/ntpd 19/53 35.8491%
/etc/rc.d/accounting 72/73 98.6301% NEAR_END
/etc/rc.d/cleartmp 59/60 98.3333% NEAR_END
/etc/rc.d/DAEMON 0/10 0%
/etc/rc.d/static_arp 73/74 98.6486% NEAR_END
/etc/rc.d/initrandom 60/61 98.3607% NEAR_END
/etc/rc.d/cron 18/23 78.2609% NEAR_END
/etc/rc.d/ipsec 58/59 98.3051% NEAR_END
/etc/rc.d/SERVERS 0/10 0%
/etc/rc.d/faith 74/75 98.6667% NEAR_END
/etc/rc.d/ypupdated 15/34 44.1176%
/etc/rc.d/kpasswdd 27/28 96.4286% NEAR_END
/etc/rc.d/rwho 17/18 94.4444% NEAR_END
/etc/rc.d/kldxref 34/35 97.1429% NEAR_END
/etc/rc.d/serial 0/168 0%
/etc/rc.d/motd 48/49 97.9592% NEAR_END
/etc/rc.d/swaplate 16/17 94.1176% NEAR_END
/etc/rc.d/resolv 39/57 68.4211%
/etc/rc.d/newsyslog 25/26 96.1538% NEAR_END
/etc/rc.d/sdpd 18/24 75% NEAR_END
/etc/rc.d/utx 16/17 94.1176% NEAR_END
/etc/rc.d/nscd 48/53 90.566% NEAR_END
/etc/rc.d/rtsold 25/26 96.1538% NEAR_END
/etc/rc.d/power_profile 63/96 65.625%
/etc/rc.d/auditd 31/32 96.875% NEAR_END
/etc/rc.d/local_unbound 90/91 98.9011% NEAR_END
/etc/rc.d/pflog 71/101 70.297%
/etc/rc.d/mroute6d 17/18 94.4444% NEAR_END
/etc/rc.d/pfsync 48/49 97.9592% NEAR_END
/etc/rc.d/ctld 21/22 95.4545% NEAR_END
/etc/rc.d/bsnmpd 16/19 84.2105% NEAR_END
/etc/rc.d/ypbind 16/36 44.4444%
/etc/rc.d/ipxrouted 18/19 94.7368% NEAR_END
/etc/rc.d/yppasswdd 16/37 43.2432%
/etc/rc.d/fsck 77/78 98.7179% NEAR_END
/etc/rc.d/sshd 86/87 98.8506% NEAR_END
/etc/rc.d/automount 30/31 96.7742% NEAR_END
/etc/rc.d/routing 403/404 99.7525% NEAR_END
/etc/rc.d/pf 15/72 20.8333%
/etc/rc.d/hastd 28/29 96.5517% NEAR_END
/etc/rc.d/dmesg 25/26 96.1538% NEAR_END
/etc/rc.d/hcsecd 19/24 79.1667% NEAR_END
/etc/rc.d/postrandom 40/41 97.561% NEAR_END
/etc/rc.d/ubthidhci 31/40 77.5% NEAR_END
/etc/rc.d/securelevel 28/29 96.5517% NEAR_END
/etc/rc.d/LOGIN 0/13 0%
/etc/rc.d/devd 40/41 97.561% NEAR_END
/etc/rc.d/mdconfig 182/194 93.8144% NEAR_END
/etc/rc.d/nfsd 16/62 25.8065%
/etc/rc.d/adjkerntz 17/18 94.4444% NEAR_END
/etc/rc.d/geli2 57/58 98.2759% NEAR_END
/etc/rc.d/quota 17/34 50%
/etc/rc.d/root 41/42 97.619% NEAR_END
/etc/rc.d/othermta 13/18 72.2222%
/etc/rc.d/ip6addrctl 122/123 99.187% NEAR_END
/etc/rc.d/bootparams 18/19 94.7368% NEAR_END
/etc/rc.d/rtadvd 71/72 98.6111% NEAR_END
/etc/rc.d/localpkg 76/77 98.7013% NEAR_END
/etc/rc.d/ipfs 50/51 98.0392% NEAR_END
/etc/rc.d/defaultroute 72/73 98.6301% NEAR_END
/etc/rc.d/hostid 102/103 99.0291% NEAR_END
/etc/rc.d/ugidfw 41/42 97.619% NEAR_END
/etc/rc.d/hostid_save 27/28 96.4286% NEAR_END
/etc/rc.d/netoptions 124/125 99.2% NEAR_END
/etc/rc.d/dumpon 68/69 98.5507% NEAR_END
/etc/rc.d/gssd 15/16 93.75% NEAR_END
/etc/rc.d/ipmon 32/33 96.9697% NEAR_END
/etc/rc.d/mixer 102/103 99.0291% NEAR_END
/etc/rc.d/virecover 64/65 98.4615% NEAR_END
/etc/rc.d/mountcritremote 78/79 98.7342% NEAR_END
/etc/rc.d/sysctl 36/37 97.2973% NEAR_END
/etc/rc.d/zvol 44/45 97.7778% NEAR_END
/etc/rc.d/mountcritlocal 53/54 98.1481% NEAR_END
/etc/rc.d/ftp-proxy 16/75 21.3333%
/etc/rc.d/bridge 92/93 98.9247% NEAR_END
/etc/rc.d/powerd 24/25 96% NEAR_END
/etc/rc.d/kadmind 27/28 96.4286% NEAR_END
/etc/rc.d/savecore 79/80 98.75% NEAR_END
/etc/rc.d/devfs 70/71 98.5915% NEAR_END
/etc/rc.d/rctl 38/39 97.4359% NEAR_END
/etc/rc.d/nfsclient 49/50 98% NEAR_END
/etc/rc.d/cleanvar 70/71 98.5915% NEAR_END
/etc/rc.d/routed 20/21 95.2381% NEAR_END
/etc/rc.d/ldconfig 82/83 98.7952% NEAR_END
/etc/rc.d/netif 257/258 99.6124% NEAR_END
/etc/rc.d/atm2 96/97 98.9691% NEAR_END
/etc/rc.d/zfs 64/65 98.4615% NEAR_END
/etc/rc.d/syslogd 72/73 98.6301% NEAR_END
/etc/rc.d/ppp 133/134 99.2537% NEAR_END
/etc/rc.d/var 40/111 36.036%
/etc/rc.d/local 35/36 97.2222% NEAR_END
/etc/rc.d/static_ndp 73/74 98.6486% NEAR_END
/etc/rc.d/archdep 44/45 97.7778% NEAR_END
/etc/rc.d/mdconfig2 212/224 94.6429% NEAR_END
/etc/rc.d/kld 52/53 98.1132% NEAR_END
/etc/rc.d/auditdistd 20/21 95.2381% NEAR_END
/etc/rc.d/bluetooth 360/365 98.6301% NEAR_END
/etc/rc.d/apmd 36/37 97.2973% NEAR_END
/etc/rc.d/hostname 80/81 98.7654% NEAR_END
/etc/rc.d/ypset 15/36 41.6667%
/etc/rc.d/stf 77/78 98.7179% NEAR_END
/etc/rc.d/sendmail 22/221 9.95475% NEAR_END
/etc/rc.d/dhclient 55/64 85.9375% NEAR_END
/etc/rc.d/ftpd 24/25 96% NEAR_END
/etc/rc.d/jail 565/569 99.297% NEAR_END
/etc/rc.d/timed 17/18 94.4444% NEAR_END
/etc/rc.d/nfscbd 17/19 89.4737% NEAR_END
/etc/rc.d/watchdogd 41/42 97.619% NEAR_END
/etc/rc.d/iscsictl 19/20 95% NEAR_END
/etc/rc.d/rarpd 18/21 85.7143% NEAR_END
/etc/rc.d/mountd 51/52 98.0769% NEAR_END
/etc/rc.d/gbde 118/119 99.1597% NEAR_END
/etc/rc.d/ntpdate 33/34 97.0588% NEAR_END
/etc/rc.d/ipnat 14/28 50%
/etc/rc.d/swap 16/17 94.1176% NEAR_END
/etc/rc.d/inetd 19/20 95% NEAR_END
/etc/rc.d/wpa_supplicant 37/46 80.4348% NEAR_END
/etc/rc.d/moused 19/72 26.3889%
/etc/rc.d/nsswitch 102/103 99.0291% NEAR_END
/etc/rc.d/bgfsck 41/42 97.619% NEAR_END
/etc/rc.d/nfsuserd 17/19 89.4737% NEAR_END
/etc/rc.d/FILESYSTEMS 0/12 0%
/etc/rc.d/msgs 0/13 0%
/etc/rc.d/atm1 175/176 99.4318% NEAR_END
/etc/rc.d/addswap 23/24 95.8333% NEAR_END
/etc/rc.d/ypserv 15/39 38.4615%
/etc/rc.d/ypxfrd 15/36 41.6667%
/etc/rc.d/mountlate 46/47 97.8723% NEAR_END
/etc/rc.d/tmp 38/71 53.5211%
/etc/rc.d/pwcheck 26/27 96.2963% NEAR_END
/etc/rc.d/abi 63/64 98.4375% NEAR_END
/etc/rc.d/lpd 26/27 96.2963% NEAR_END
/etc/rc.d/ipfilter 14/90 15.5556%
/etc/rc.d/keyserv 25/26 96.1538% NEAR_END
/etc/rc.d/geli 89/90 98.8889% NEAR_END
/etc/rc.d/ddb 27/32 84.375% NEAR_END
/etc/rc.d/natd 42/43 97.6744% NEAR_END
/etc/rc.d/lockd 30/31 96.7742% NEAR_END
/etc/rc.d/ccd 23/24 95.8333% NEAR_END
/etc/rc.d/statd 29/30 96.6667% NEAR_END
/etc/rc.d/ipfw 111/114 97.3684% NEAR_END
/etc/rc.d/amd 47/48 97.9167% NEAR_END
/etc/rc.d/rfcomm_pppd_server 121/122 99.1803% NEAR_END
/etc/rc.d/ipropd_master 39/40 97.5% NEAR_END
/etc/rc.d/automountd 18/19 94.7368% NEAR_END
/etc/rc.d/autounmountd 17/18 94.4444% NEAR_END
/etc/rc.d/ipropd_slave 31/32 96.875% NEAR_END
/etc/rc.d/kdc 26/27 96.2963% NEAR_END

27/165 are not NEAR_END (16%)
dteske edited edge metadata.

Looking good!

This revision was automatically updated to reflect the committed changes.