diff mbox

infiniband-diags: Remove Red Hat-ism.

Message ID 1354566498-8364-1-git-send-email-jonstanley@gmail.com (mailing list archive)
State Rejected, archived
Delegated to: Ira Weiny
Headers show

Commit Message

Jon Stanley Dec. 3, 2012, 8:28 p.m. UTC
Future release of Fedora are going to remove /etc/sysconfig/network
which we source to get $HOSTNAME. Bash (and sh) set $HOSTNAME in
the shell by default, so we should be safe to use that here. This
adds the benefit of working across multiple distributions if that
is required in the future.

Related: rhbz881917

Signed-off-by: Jon Stanley <jonstanley@gmail.com>
Cc: Doug Ledford <dledford@redhat.com>
Cc: Ira Weiny <weiny2@llnl.gov>
---
 scripts/set_nodedesc.sh |    3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)

Comments

Jason Gunthorpe Dec. 3, 2012, 10:35 p.m. UTC | #1
On Mon, Dec 03, 2012 at 03:28:18PM -0500, Jon Stanley wrote:
> Future release of Fedora are going to remove /etc/sysconfig/network
> which we source to get $HOSTNAME. Bash (and sh) set $HOSTNAME in
> the shell by default, so we should be safe to use that here. This
> adds the benefit of working across multiple distributions if that
> is required in the future.

This looks like it is a bashism (ie dash does not do this), so you
should update the #! to use /bin/bash not /bin/sh...

$ HOSTNAME= /bin/dash 
\h{\u}\w#echo $HOSTNAME

\h{\u}\w#

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Jon Stanley Dec. 4, 2012, 1:40 p.m. UTC | #2
On Mon, Dec 3, 2012 at 5:35 PM, Jason Gunthorpe
<jgunthorpe@obsidianresearch.com> wrote:

> This looks like it is a bashism (ie dash does not do this), so you
> should update the #! to use /bin/bash not /bin/sh...

But Garrett just committed something a few days ago to remove
bash-isms, and I'd hate to reintroduce one for this trivial thing.
More specifically, here's what's going to happen in Fedora-land, and
isn't in RHEL6:

The /etc/sysconfig/network file goes away, and is replaced (for our
purposes) with /etc/hostname ,which contains the short name of the
hostname. The way I figure it, we can get the hostname one of a few
ways here:

1) Blindly trust that the set hostname is correct (i.e. what the
hostname(1) command returns is what we should be using)
2) Read /etc/hostname in a subshell (the HOSTNAME= no longer exists,
so it can't be sourced)
3) Fall back on /etc/sysconfig/network if we don't find /etc/hostname
if we go with 2.

Thoughts?
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Garrett Cooper Dec. 4, 2012, 4:31 p.m. UTC | #3
On Tue, Dec 4, 2012 at 5:40 AM, Jon Stanley <jonstanley@gmail.com> wrote:
> On Mon, Dec 3, 2012 at 5:35 PM, Jason Gunthorpe
> <jgunthorpe@obsidianresearch.com> wrote:
>
>> This looks like it is a bashism (ie dash does not do this), so you
>> should update the #! to use /bin/bash not /bin/sh...
>
> But Garrett just committed something a few days ago to remove
> bash-isms, and I'd hate to reintroduce one for this trivial thing.
> More specifically, here's what's going to happen in Fedora-land, and
> isn't in RHEL6:
>
> The /etc/sysconfig/network file goes away, and is replaced (for our
> purposes) with /etc/hostname ,which contains the short name of the
> hostname. The way I figure it, we can get the hostname one of a few
> ways here:
>
> 1) Blindly trust that the set hostname is correct (i.e. what the
> hostname(1) command returns is what we should be using)
> 2) Read /etc/hostname in a subshell (the HOSTNAME= no longer exists,
> so it can't be sourced)
> 3) Fall back on /etc/sysconfig/network if we don't find /etc/hostname
> if we go with 2.
>
> Thoughts?

Calling ``newname=$(hostname)`` would be better (assuming that the
network was setup enough where one could get this information).
Thanks!
-Garrett
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Garrett Cooper Dec. 4, 2012, 4:33 p.m. UTC | #4
On Mon, Dec 3, 2012 at 2:35 PM, Jason Gunthorpe
<jgunthorpe@obsidianresearch.com> wrote:
> On Mon, Dec 03, 2012 at 03:28:18PM -0500, Jon Stanley wrote:
>> Future release of Fedora are going to remove /etc/sysconfig/network
>> which we source to get $HOSTNAME. Bash (and sh) set $HOSTNAME in
>> the shell by default, so we should be safe to use that here. This
>> adds the benefit of working across multiple distributions if that
>> is required in the future.
>
> This looks like it is a bashism (ie dash does not do this), so you
> should update the #! to use /bin/bash not /bin/sh...
>
> $ HOSTNAME= /bin/dash
> \h{\u}\w#echo $HOSTNAME
>
> \h{\u}\w#

    Good catch! I forgot about this important subtlety between bash
and the rest of the bourne shells (I'll need to verify that I didn't
leave any "dangling bashisms" in my last patch).
Thanks!
-Garrett

$ set
BASH=/usr/local/bin/bash
BLOCKSIZE=K
EDITOR=vim
ENV=/usr/home/gcooper/.shrc
HOME=/usr/home/gcooper
IFS='
'
LOGNAME=gcooper
MAIL=/var/mail/gcooper
OPTIND=1
P4CLIENT=gcooper-bayonetta
P4PORT=perforce.freebsd.org:1666
P4USER=gcooper
PAGER=more
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/usr/home/gcooper/bin
PPID=9754
PS1='$ '
PS2='> '
PS4='+ '
PWD=/usr/home/gcooper
SHELL=/bin/sh
SHLVL=1
SSH_CLIENT='192.168.20.1 45753 22'
SSH_CONNECTION='192.168.20.1 45753 192.168.20.2 22'
SSH_TTY=/dev/pts/10
TERM=screen
USER=gcooper
_=set
$ bash -c set
BASH=/usr/local/bin/bash
BASHOPTS=cmdhist:colonbreakswords:extquote:force_fignore:hostcomplete:interactive_comments:progcomp:promptvars:sourcepath
BASH_ALIASES=()
BASH_ARGC=()
BASH_ARGV=()
BASH_CMDS=()
BASH_EXECUTION_STRING=set
BASH_LINENO=()
BASH_SOURCE=()
BASH_VERSINFO=([0]="4" [1]="2" [2]="37" [3]="0" [4]="release"
[5]="amd64-portbld-freebsd9.1")
BASH_VERSION='4.2.37(0)-release'
BLOCKSIZE=K
DIRSTACK=()
EDITOR=vim
ENV=/usr/home/gcooper/.shrc
EUID=1000
GROUPS=()
HOME=/usr/home/gcooper
HOSTNAME=bayonetta.local
HOSTTYPE=amd64
IFS=$' \t\n'
LOGNAME=gcooper
MACHTYPE=amd64-portbld-freebsd9.1
MAIL=/var/mail/gcooper
OPTERR=1
OPTIND=1
OSTYPE=freebsd9.1
P4CLIENT=gcooper-bayonetta
P4PORT=perforce.freebsd.org:1666
P4USER=gcooper
PAGER=more
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/usr/home/gcooper/bin
PPID=9758
PS4='+ '
PWD=/usr/home/gcooper
SHELL=/usr/local/bin/bash
SHELLOPTS=braceexpand:hashall:interactive-comments
SHLVL=2
SSH_CLIENT='192.168.20.1 45753 22'
SSH_CONNECTION='192.168.20.1 45753 192.168.20.2 22'
SSH_TTY=/dev/pts/10
TERM=screen
UID=1000
USER=gcooper
_=set
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Jason Gunthorpe Dec. 4, 2012, 6:11 p.m. UTC | #5
On Tue, Dec 04, 2012 at 08:31:19AM -0800, Garrett Cooper wrote:

> Calling ``newname=$(hostname)`` would be better (assuming that the
> network was setup enough where one could get this information).

Calling hostname is always preferred to mucking about with files in
/etc/. hostname never requires the network, hostname -f might
sometimes.

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Garrett Cooper Dec. 4, 2012, 7:48 p.m. UTC | #6
On Tue, Dec 4, 2012 at 10:11 AM, Jason Gunthorpe
<jgunthorpe@obsidianresearch.com> wrote:
> On Tue, Dec 04, 2012 at 08:31:19AM -0800, Garrett Cooper wrote:
>
>> Calling ``newname=$(hostname)`` would be better (assuming that the
>> network was setup enough where one could get this information).
>
> Calling hostname is always preferred to mucking about with files in
> /etc/. hostname never requires the network, hostname -f might
> sometimes.

Yes, but OSes don't set the hostname until a little later on in the
boot process (FreeBSD for instance), depending upon how the system was
first booted and the host's network configuration (DHCP*/SLAAC/etc).
That's more of what I was driving at when I said "assuming that the
network was setup enough where one could get this information".

Thanks,
-Garrett
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Ira Weiny Feb. 13, 2013, 10:11 p.m. UTC | #7
On Tue, 4 Dec 2012 11:48:18 -0800
Garrett Cooper <yanegomi@gmail.com> wrote:

> On Tue, Dec 4, 2012 at 10:11 AM, Jason Gunthorpe
> <jgunthorpe@obsidianresearch.com> wrote:
> > On Tue, Dec 04, 2012 at 08:31:19AM -0800, Garrett Cooper wrote:
> >
> >> Calling ``newname=$(hostname)`` would be better (assuming that the
> >> network was setup enough where one could get this information).
> >
> > Calling hostname is always preferred to mucking about with files in
> > /etc/. hostname never requires the network, hostname -f might
> > sometimes.
> 
> Yes, but OSes don't set the hostname until a little later on in the
> boot process (FreeBSD for instance), depending upon how the system was
> first booted and the host's network configuration (DHCP*/SLAAC/etc).
> That's more of what I was driving at when I said "assuming that the
> network was setup enough where one could get this information".

set_nodedesc.sh was deprecated and moved to a compat build a while ago.

As such I think the best thing to do is use hostname as Jason says and call it good.  I believe that users attempting to set the NodeDescription within boot scripts can do so with the sysfs files.

Jon I would accept a patch if you would like to redo this one but I am going to reject the patch as it stands.

Thanks,
Ira

> 
> Thanks,
> -Garrett
> --
> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/scripts/set_nodedesc.sh b/scripts/set_nodedesc.sh
index 1e42ac8..3d2e406 100755
--- a/scripts/set_nodedesc.sh
+++ b/scripts/set_nodedesc.sh
@@ -1,8 +1,5 @@ 
 #!/bin/sh
 
-if [ -f /etc/sysconfig/network ]; then
-. /etc/sysconfig/network
-fi
 
 ib_sysfs="/sys/class/infiniband"
 newname="$HOSTNAME"