[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Linux hostid (Fwd) (fwd)



Forwarded message:
>From Hartmut.Schwab@IWR.Uni-Heidelberg.De Fri Feb 20 10:50:42 1998
Date: Fri, 20 Feb 98 19:39:50 +0100
From: Hartmut Schwab <Hartmut.Schwab@IWR.Uni-Heidelberg.De>
Message-Id: <9802201839.AA00757@yeti.iwr.uni-heidelberg.de>
To: hjl@gnu.org
Subject: Re: Linux hostid (Fwd)

Dear H.J.LU

on 10 Nov 1997 Mitch DSouza sent  the appended email to you. I never
got any response, but I am curiouse whether my suggested changes 
have been included in any form. Please tell me what you decided to do.

Best regards

Hartmut Schwab

----- Begin Included Message -----

>From Mitch.Dsouza@Dubai.Sun.COM Mon Nov 10 14:41:17 1997
Date: Mon, 10 Nov 1997 17:47:41 +0400 (GMT)
From: Mitch DSouza - Sun Microsystems - PTAS engineer <Mitch.Dsouza@Dubai.Sun.COM>
Subject: Re: Linux hostid (Fwd)
To: hjl@gnu.ai.mit.edu
Cc: Hartmut.Schwab@IWR.Uni-Heidelberg.De, Mitch.Dsouza@Dubai.Sun.COM
Mime-Version: 1.0

Hi,

I'm forwarding the change to H.J.Lu. He will
se the change gets int the source tree as I don't maintain it 
any longer.

Thanx
Mitch
>----------------Begin Forwarded Message----------------<

Date: Fri, 7 Nov 97 20:52:17 +0100
From: "Hartmut Schwab" <Hartmut.Schwab@IWR.Uni-Heidelberg.De>
Subject: Re: Linux hostid
To: Mitch.Dsouza@Dubai.Sun.COM, m.dsouza@mrc-apu.cam.ac.uk

Dear Mitch,

thank you for your answer. I have now two email adresses of you. I decided to 
send the email to both, so maybe you receive it twice. (Sorry)
I would like to suggest a change  in the source of hostid.c.

To explain you the reason for the change:
I tried to set a hostid of 3232251649 (0xc0a83f01)
to my system and failed. After execution of the command, my hostid was
0x7fffffff.

The reason was simply an overflow in the routine atoi() (because on my
system the result of atoi is a signed integer.) This overflow did not
stop the program. I tried to solve the problem in changing atoi to
atol. But no change, because long and int are identical.

The solution in my opinion is to use strtoul and to check for an
overflow. This has the nice side-effect, that the user can choose to
give the hostid value as a hexadecimal, octal or decimal number.
(this is true for the gcc libc. It is not true for Systems which do
not use gcc libc. If the source should be used on other systems too,
some precautions have to be done.)

Below I included your original source and the one with my suggested
changes. Please decide, whether you want to include my changes into
the source. I would be happy to give a small contribution to the
program. If you include my changes, I would like to be mentioned. 
This is the only chance I have to give a small contribution to Linux :-) 

I would also like to give some changes to the manual. But since I am
not a native English speaking person, this is the most difficult
part. Below you find a paragraph, which should give you an idea what I
mean. Please check it carefully and do some corrections on my bad
English, if you want to use it.

Best Regards and hope to hear from you again.

Hartmut Schwab

=====================================

manpage:

       Only  the super-user can set the hostid by giving an argu-
       ment. A host number starting with '0x' is considered to be a
       hexadecimal number, one starting with '0' is considered to be
       an octal number. All other values are considered to be decimal
       numbers. 
       #### This value is stored in  the  file  /etc/hostid  and
       #### need only be performed once.
       #### (I am not sure, if this is still correct.)

       #### It would also be nice, to be mentioned in the manual,
       #### when you decide to include my suggested changes.

=====================================

/* Mitch DSouza - (m.dsouza@mrc-apu.cam.ac.uk) */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <getopt.h>

void main (int argc, char **argv)
{
    int verbose = 0;

    if(argc == 2 && strcmp(argv[1], "-v") == 0) {
	verbose = 1; 
	argc--;
	argv++;
    }

    if (argc==2) {
	if (sethostid(atoi(argv[1]))!=0) {
	    perror("sethostid");
	    exit(1);
	}
    } else if (argc==1)	{
	unsigned long id = gethostid();
	
	if(id && verbose) {
	    printf("Hostid is %lu (0x%lx)\n",id,id);
	} else if(id) {
	    printf("0x%lx\n", id);
	} else {
	    printf("Usage: %s hostid_number\n",*argv);
	}
    }
    exit(0);
}

=====================================

/* Mitch DSouza - (m.dsouza@mrc-apu.cam.ac.uk) */

/* Contribution: */
/* Hartmut Schwab - (Hartmut.Schwab@IWR.Uni-Heidelberg.De) */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <getopt.h>

void main (int argc, char **argv)
{
    int verbose = 0;

    if(argc == 2 && strcmp(argv[1], "-v") == 0) {
	verbose = 1; 
	argc--;
	argv++;
    }

    if (argc==2) {
	unsigned  long id;

        errno = 0;
        id = strtoul(argv[1], 0, 0);
        if (errno == ERANGE) {
            perror("overflow");
            exit(1);
        }

	if (sethostid(id)!=0) {
	    perror("sethostid");
	    exit(1);
	}

    } else if (argc==1)	{
	unsigned long id = gethostid();
	
	if(id && verbose) {
	    printf("Hostid is %lu (0x%lx)\n",id,id);
	} else if(id) {
	    printf("0x%lx\n", id);
	} else {
	    printf("Usage: %s hostid_number\n",*argv);
	}
    }
    exit(0);
}


>----------------End Forwarded Message----------------<



----- End Included Message -----



-- 
H.J. Lu (hjl@gnu.org)


--
TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to
debian-devel-request@lists.debian.org . 
Trouble?  e-mail to templin@bucknell.edu .


Reply to: