diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2014-09-19 15:01:58 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2014-09-19 15:01:58 +0000 |
commit | 54b6467013bfbdb3ee606961c02fbff1271ca582 (patch) | |
tree | e3969743e61542979f12fca01017e67c4480eca8 /src/minutils/s6-hostname.c | |
download | s6-linux-utils-54b6467013bfbdb3ee606961c02fbff1271ca582.tar.xz |
initial commit
Diffstat (limited to 'src/minutils/s6-hostname.c')
-rw-r--r-- | src/minutils/s6-hostname.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/minutils/s6-hostname.c b/src/minutils/s6-hostname.c new file mode 100644 index 0000000..deb525b --- /dev/null +++ b/src/minutils/s6-hostname.c @@ -0,0 +1,37 @@ +/* ISC license. */ + +#ifndef _BSD_SOURCE +#define _BSD_SOURCE +#endif + +#include <unistd.h> +#include <skalibs/bytestr.h> +#include <skalibs/allreadwrite.h> +#include <skalibs/strerr2.h> +#include <skalibs/stralloc.h> +#include <skalibs/djbunix.h> + +#define USAGE "s6-hostname [ hostname ]" + +static int getit (void) +{ + stralloc sa = STRALLOC_ZERO ; + if (sagethostname(&sa) < 0) strerr_diefu1sys(111, "get hostname") ; + sa.s[sa.len++] = '\n' ; + if (allwrite(1, sa.s, sa.len) < sa.len) + strerr_diefu1sys(111, "write to stdout") ; + return 0 ; +} + +static int setit (char const *h) +{ + if (sethostname(h, str_len(h)) < 0) + strerr_diefu1sys(111, "set hostname") ; + return 0 ; +} + +int main (int argc, char const *const *argv) +{ + PROG = "s6-hostname" ; + return (argc < 2) ? getit() : setit(argv[1]) ; +} |