Mercurial > hg > toybox
annotate toys/lsb/hostname.c @ 674:7e846e281e38
New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
author | Rob Landley <rob@landley.net> |
---|---|
date | Mon, 08 Oct 2012 00:02:30 -0500 |
parents | 0ed044e9e5ca |
children | 786841fdb1e0 |
rev | line source |
---|---|
463 | 1 /* vi: set sw=4 ts=4: |
2 * | |
3 * hostname.c - Get/Set the hostname | |
4 * | |
5 * Copyright 2012 Andre Renaud <andre@bluewatersys.com> | |
6 * | |
656
6df4ccc0acbe
Regularize command headers, update links to standards documents.
Rob Landley <rob@landley.net>
parents:
653
diff
changeset
|
7 * http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/hostname.html |
463 | 8 |
464 | 9 USE_HOSTNAME(NEWTOY(hostname, NULL, TOYFLAG_BIN)) |
463 | 10 |
11 config HOSTNAME | |
12 bool "hostname" | |
665
0ed044e9e5ca
gethostname: Tighten up error messages slightly, switch to default "y".
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
13 default y |
463 | 14 help |
15 usage: hostname [newname] | |
16 | |
17 Get/Set the current hostname | |
18 */ | |
19 | |
674
7e846e281e38
New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents:
665
diff
changeset
|
20 #define FOR_hostname |
463 | 21 #include "toys.h" |
22 | |
23 void hostname_main(void) | |
24 { | |
25 const char *hostname = toys.optargs[0]; | |
26 if (hostname) { | |
464 | 27 if (sethostname(hostname, strlen(hostname))) |
665
0ed044e9e5ca
gethostname: Tighten up error messages slightly, switch to default "y".
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
28 perror_exit("set failed '%s'", hostname); |
463 | 29 } else { |
464 | 30 if (gethostname(toybuf, sizeof(toybuf))) |
665
0ed044e9e5ca
gethostname: Tighten up error messages slightly, switch to default "y".
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
31 perror_exit("get failed"); |
464 | 32 xputs(toybuf); |
463 | 33 } |
34 } |