|
Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com |
/bin/hostname options/arguments
From: Przemyslaw Nowaczyk (p_nowaczyk
o2.pl)
Date: Thu Mar 09 2006 - 03:57:47 CST
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
hi,
I've got a question about hostname arguments.. the hostname(1) says:
"hostname - set *or* print name of current host system" so as I understand it
something like: 'hostname -s new_name' shouldn't be allowed right? becouse we
acctually don't know what to do (set or print, assuming we're running root)..
if I'm right - here's a diff to change that behavior (with some KNF fixups)..
if not - sorry for spamming..
Index: hostname.c
===================================================================
RCS file: /cvs/src/bin/hostname/hostname.c,v
retrieving revision 1.7
diff -u -r1.7 hostname.c
--- hostname.c 2003/06/02 23:32:08 1.7
+++ hostname.c 2006/03/09 09:44:12

-52,15 +52,13 
#include <string.h>
#include <unistd.h>
-extern char *__progname;
+__dead void usage(void);
-void usage(void);
-
int
main(int argc, char *argv[])
{
- int ch, sflag;
- char *p, hostname[MAXHOSTNAMELEN];
+ int ch, sflag;
+ char *p, hostname[MAXHOSTNAMELEN];
sflag = 0;
while ((ch = getopt(argc, argv, "s")) != -1)

-70,6 +68,7 
break;
default:
usage();
+ /* NOTREACHED */
}
argc -= optind;
argv += optind;

-78,6 +77,8 
usage();
if (*argv) {
+ if (sflag)
+ usage();
if (sethostname(*argv, strlen(*argv)))
err(1, "sethostname");
} else {

-93,6 +94,8 
void
usage(void)
{
+ extern char *__progname;
+
(void)fprintf(stderr, "usage: %s [-s] [name-of-host]\n", __progname);
exit(1);
}
and one more thing.. if I'm right, shouldn't the usage args look like
usage: hostname [-s | name-of-host]?
--
Przemyslaw Nowaczyk <p_nowaczyk
o2.pl>
CS student
Poznan University of Technology
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]