1
0
forked from pool/util-linux
util-linux/util-linux-2.12-misc_utils_hostid.patch
OBS User autobuild 32a3f13ab3 Accepting request 24460 from Base:System
Copy from Base:System/util-linux based on submit request 24460 from user msmeissn

OBS-URL: https://build.opensuse.org/request/show/24460
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/util-linux?expand=0&rev=82
2009-11-16 09:02:04 +00:00

145 lines
3.7 KiB
Diff

Index: util-linux-ng-2.16/misc-utils/hostid.1
===================================================================
--- /dev/null
+++ util-linux-ng-2.16/misc-utils/hostid.1
@@ -0,0 +1,24 @@
+.TH hostid 1
+.SH NAME
+hostid \- set or print system's host id.
+.SH SYNTAX
+.B hostid
+[\-v] [\|\fIdecimal-id\fR\|]
+.SH DESCRIPTION
+.\".NXR "hostid command"
+The
+.B hostid
+command prints the current host id number in hexadecimal and both
+decimal and hexadecimal in parenthesis if the \-v option is given.
+This numeric value is expected to be unique across all hosts
+and is normally set to resemble the host's Internet address.
+
+Only the super-user can set the hostid by giving an argument. This value is
+stored in the file /etc/hostid and need only be performed once.
+
+.SH AUTHOR
+Hostid is written by Mitch DSouza \- (m.dsouza@mrc-apu.cam.ac.uk)
+
+.SH SEE ALSO
+gethostid(2), sethostid(2)
+
Index: util-linux-ng-2.16/misc-utils/hostid.c
===================================================================
--- /dev/null
+++ util-linux-ng-2.16/misc-utils/hostid.c
@@ -0,0 +1,88 @@
+/* Program hostid. Changed on 7.10.1997 <ms@suse.de>
+ New: - Hostid 0 is not permitted.
+ - Set hostid dezimal or hexadezimal, both possible.
+ - Maximum Value for id is tested
+ - Wrong Parameters are caught
+ Nov 13 2003 - cleanup, mmj@suse.de
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+
+void usage(void);
+
+void usage()
+{
+ printf ("usage : hostid [-h] [-v] [<id>]\n\n"
+ "no options: print hostid as hexadecimal number\n"
+ "-h print this helptext\n"
+ "-v print hostid decimal and hexadecimal\n"
+ "<id> set the hostid to <id>\n\n"
+ "The id String can be specified as\n"
+ " - decimal number\n"
+ " - hexadecimal number preceded by 0x\n"
+ " - octal number preceded by 0 \n\n"
+ "Remarks:\n"
+ " - only root can set the hostid\n"
+ " - it's not possible to set the hostid to 0\n\n");
+}
+
+int main (int argc, char *argv[])
+{
+ long id;
+ int verbose = 0;
+
+ if (argc > 2) {
+ printf ("wrong arguments\n");
+ usage();
+ exit(1);
+ }
+
+ if (argc == 2 && strcmp(argv[1], "-h") == 0) {
+ usage();
+ exit(0);
+ }
+
+ if (argc == 2 && strcmp(argv[1], "-v") == 0) {
+ verbose = 1;
+ argc--;
+ argv++;
+ }
+
+ switch (argc) {
+ case 2:
+ id = strtol(argv[1], NULL, 0);
+ if (errno == ERANGE) {
+ printf ("Overflow: given string was out of range\n");
+ exit(1);
+ }
+
+ if (id == 0) {
+ printf ("value not possible: Abort\n");
+ usage();
+ exit(1);
+ }
+ if (sethostid(id) != 0) {
+ perror("sethostid");
+ exit(1);
+ }
+ break;
+
+ case 1:
+ id = gethostid();
+ if(id && verbose) {
+ printf("Hostid is %ld (0x%lx)\n", id, id);
+ } else if(id) {
+ printf("0x%lx\n", id);
+ } else {
+ printf ("Error while trying: gethostid\n");
+ exit(1);
+ }
+ break;
+ }
+
+ return 0;
+}
Index: util-linux-ng-2.16/misc-utils/Makefile.am
===================================================================
--- util-linux-ng-2.16.orig/misc-utils/Makefile.am
+++ util-linux-ng-2.16/misc-utils/Makefile.am
@@ -6,7 +6,7 @@ bin_PROGRAMS =
sbin_PROGRAMS =
usrsbin_exec_PROGRAMS =
-usrbin_exec_PROGRAMS = cal ddate logger look mcookie \
+usrbin_exec_PROGRAMS = cal ddate hostid logger look mcookie \
namei script whereis scriptreplay
EXTRA_DIST += README.cal README.ddate README.namei README.namei2
@@ -16,7 +16,7 @@ usrbin_exec_SCRIPTS = chkdupexe
CLEANFILES = chkdupexe
-dist_man_MANS = cal.1 chkdupexe.1 ddate.1 logger.1 look.1 mcookie.1 \
+dist_man_MANS = cal.1 chkdupexe.1 ddate.1 hostid.1 logger.1 look.1 mcookie.1 \
namei.1 script.1 whereis.1 scriptreplay.1
if BUILD_LIBUUID