xref: /titanic_52/usr/src/contrib/ast/src/lib/libcmd/uname.c (revision 906afcb89d0412cc073b95c2d701a804a8cdb62c)
1*906afcb8SAndy Fiddaman /***********************************************************************
2*906afcb8SAndy Fiddaman *                                                                      *
3*906afcb8SAndy Fiddaman *               This software is part of the ast package               *
4*906afcb8SAndy Fiddaman *          Copyright (c) 1992-2012 AT&T Intellectual Property          *
5*906afcb8SAndy Fiddaman *                      and is licensed under the                       *
6*906afcb8SAndy Fiddaman *                 Eclipse Public License, Version 1.0                  *
7*906afcb8SAndy Fiddaman *                    by AT&T Intellectual Property                     *
8*906afcb8SAndy Fiddaman *                                                                      *
9*906afcb8SAndy Fiddaman *                A copy of the License is available at                 *
10*906afcb8SAndy Fiddaman *          http://www.eclipse.org/org/documents/epl-v10.html           *
11*906afcb8SAndy Fiddaman *         (with md5 checksum b35adb5213ca9657e911e9befb180842)         *
12*906afcb8SAndy Fiddaman *                                                                      *
13*906afcb8SAndy Fiddaman *              Information and Software Systems Research               *
14*906afcb8SAndy Fiddaman *                            AT&T Research                             *
15*906afcb8SAndy Fiddaman *                           Florham Park NJ                            *
16*906afcb8SAndy Fiddaman *                                                                      *
17*906afcb8SAndy Fiddaman *                 Glenn Fowler <gsf@research.att.com>                  *
18*906afcb8SAndy Fiddaman *                  David Korn <dgk@research.att.com>                   *
19*906afcb8SAndy Fiddaman *                                                                      *
20*906afcb8SAndy Fiddaman ***********************************************************************/
21*906afcb8SAndy Fiddaman #pragma prototyped
22*906afcb8SAndy Fiddaman /*
23*906afcb8SAndy Fiddaman  * David Korn
24*906afcb8SAndy Fiddaman  * Glenn Fowler
25*906afcb8SAndy Fiddaman  * AT&T Research
26*906afcb8SAndy Fiddaman  *
27*906afcb8SAndy Fiddaman  * uname
28*906afcb8SAndy Fiddaman  */
29*906afcb8SAndy Fiddaman 
30*906afcb8SAndy Fiddaman static const char usage[] =
31*906afcb8SAndy Fiddaman "[-?\n@(#)$Id: uname (AT&T Research) 2007-04-19 $\n]"
32*906afcb8SAndy Fiddaman USAGE_LICENSE
33*906afcb8SAndy Fiddaman "[+NAME?uname - identify the current system ]"
34*906afcb8SAndy Fiddaman "[+DESCRIPTION?By default \buname\b writes the operating system name to"
35*906afcb8SAndy Fiddaman "	standard output. When options are specified, one or more"
36*906afcb8SAndy Fiddaman "	system characteristics are written to standard output, space"
37*906afcb8SAndy Fiddaman "	separated, on a single line. When more than one option is specified"
38*906afcb8SAndy Fiddaman "	the output is in the order specfied by the \b-A\b option below."
39*906afcb8SAndy Fiddaman "	Unsupported option values are listed as \a[option]]\a. If any unknown"
40*906afcb8SAndy Fiddaman "	options are specified then the local \b/usr/bin/uname\b is called.]"
41*906afcb8SAndy Fiddaman "[+?If any \aname\a operands are specified then the \bsysinfo\b(2) values"
42*906afcb8SAndy Fiddaman "	for each \aname\a are listed, separated by space, on one line."
43*906afcb8SAndy Fiddaman "	\bgetconf\b(1), a pre-existing \astandard\a interface, provides"
44*906afcb8SAndy Fiddaman "	access to the same information; vendors should spend more time"
45*906afcb8SAndy Fiddaman "	using standards than inventing them.]"
46*906afcb8SAndy Fiddaman "[+?Selected information is printed in the same order as the options below.]"
47*906afcb8SAndy Fiddaman "[a:all?Equivalent to \b-snrvmpio\b.]"
48*906afcb8SAndy Fiddaman "[s:system|sysname|kernel-name?The detailed kernel name. This is the default.]"
49*906afcb8SAndy Fiddaman "[n:nodename?The hostname or nodename.]"
50*906afcb8SAndy Fiddaman "[r:release|kernel-release?The kernel release level.]"
51*906afcb8SAndy Fiddaman "[v:version|kernel-version?The kernel version level.]"
52*906afcb8SAndy Fiddaman "[m:machine?The name of the hardware type the system is running on.]"
53*906afcb8SAndy Fiddaman "[p:processor?The name of the processor instruction set architecture.]"
54*906afcb8SAndy Fiddaman "[i:implementation|platform|hardware-platform?The hardware implementation;"
55*906afcb8SAndy Fiddaman "	this is \b--host-id\b on some systems.]"
56*906afcb8SAndy Fiddaman "[o:operating-system?The generic operating system name.]"
57*906afcb8SAndy Fiddaman "[h:host-id|id?The host id in hex.]"
58*906afcb8SAndy Fiddaman "[d:domain?The domain name returned by \agetdomainname\a(2).]"
59*906afcb8SAndy Fiddaman "[R:extended-release?The extended release name.]"
60*906afcb8SAndy Fiddaman "[A:everything?Equivalent to \b-snrvmpiohdR\b.]"
61*906afcb8SAndy Fiddaman "[f:list?List all \bsysinfo\b(2) names and values, one per line.]"
62*906afcb8SAndy Fiddaman "[S:sethost?Set the hostname or nodename to \aname\a. No output is"
63*906afcb8SAndy Fiddaman "	written to standard output.]:[name]"
64*906afcb8SAndy Fiddaman "\n"
65*906afcb8SAndy Fiddaman "\n[ name ... ]\n"
66*906afcb8SAndy Fiddaman "\n"
67*906afcb8SAndy Fiddaman "[+SEE ALSO?\bhostname\b(1), \bgetconf\b(1), \buname\b(2),"
68*906afcb8SAndy Fiddaman "	\bsysconf\b(2), \bsysinfo\b(2)]"
69*906afcb8SAndy Fiddaman ;
70*906afcb8SAndy Fiddaman 
71*906afcb8SAndy Fiddaman #if defined(__STDPP__directive) && defined(__STDPP__hide)
72*906afcb8SAndy Fiddaman __STDPP__directive pragma pp:hide getdomainname gethostid gethostname sethostname
73*906afcb8SAndy Fiddaman #else
74*906afcb8SAndy Fiddaman #define getdomainname	______getdomainname
75*906afcb8SAndy Fiddaman #define gethostid	______gethostid
76*906afcb8SAndy Fiddaman #define gethostname	______gethostname
77*906afcb8SAndy Fiddaman #define sethostname	______sethostname
78*906afcb8SAndy Fiddaman #endif
79*906afcb8SAndy Fiddaman 
80*906afcb8SAndy Fiddaman #include <cmd.h>
81*906afcb8SAndy Fiddaman #include <ctype.h>
82*906afcb8SAndy Fiddaman #include <proc.h>
83*906afcb8SAndy Fiddaman 
84*906afcb8SAndy Fiddaman #include "FEATURE/utsname"
85*906afcb8SAndy Fiddaman 
86*906afcb8SAndy Fiddaman #define MAXHOSTNAME	64
87*906afcb8SAndy Fiddaman 
88*906afcb8SAndy Fiddaman #if _lib_uname && _sys_utsname
89*906afcb8SAndy Fiddaman 
90*906afcb8SAndy Fiddaman #include <sys/utsname.h>
91*906afcb8SAndy Fiddaman 
92*906afcb8SAndy Fiddaman #endif
93*906afcb8SAndy Fiddaman 
94*906afcb8SAndy Fiddaman #if defined(__STDPP__directive) && defined(__STDPP__hide)
95*906afcb8SAndy Fiddaman __STDPP__directive pragma pp:nohide getdomainname gethostid gethostname sethostname
96*906afcb8SAndy Fiddaman #else
97*906afcb8SAndy Fiddaman #undef	getdomainname
98*906afcb8SAndy Fiddaman #undef	gethostid
99*906afcb8SAndy Fiddaman #undef	gethostname
100*906afcb8SAndy Fiddaman #undef	sethostname
101*906afcb8SAndy Fiddaman #endif
102*906afcb8SAndy Fiddaman 
103*906afcb8SAndy Fiddaman #if _lib_getdomainname
104*906afcb8SAndy Fiddaman extern int	getdomainname(char*, size_t);
105*906afcb8SAndy Fiddaman #endif
106*906afcb8SAndy Fiddaman #if _lib_gethostid
107*906afcb8SAndy Fiddaman extern long	gethostid(void);
108*906afcb8SAndy Fiddaman #endif
109*906afcb8SAndy Fiddaman #if _lib_gethostname
110*906afcb8SAndy Fiddaman extern int	gethostname(char*, size_t);
111*906afcb8SAndy Fiddaman #endif
112*906afcb8SAndy Fiddaman #if _lib_sethostname
113*906afcb8SAndy Fiddaman extern int	sethostname(const char*, size_t);
114*906afcb8SAndy Fiddaman #endif
115*906afcb8SAndy Fiddaman 
116*906afcb8SAndy Fiddaman #ifndef HOSTTYPE
117*906afcb8SAndy Fiddaman #define HOSTTYPE	"unknown"
118*906afcb8SAndy Fiddaman #endif
119*906afcb8SAndy Fiddaman 
120*906afcb8SAndy Fiddaman static const char	hosttype[] = HOSTTYPE;
121*906afcb8SAndy Fiddaman 
122*906afcb8SAndy Fiddaman #if !_lib_uname || !_sys_utsname
123*906afcb8SAndy Fiddaman 
124*906afcb8SAndy Fiddaman #if defined(__STDPP__)
125*906afcb8SAndy Fiddaman #define SYSNAME		#(getprd machine)
126*906afcb8SAndy Fiddaman #define RELEASE		#(getprd release)
127*906afcb8SAndy Fiddaman #define VERSION		#(getprd version)
128*906afcb8SAndy Fiddaman #define MACHINE		#(getprd architecture)
129*906afcb8SAndy Fiddaman #else
130*906afcb8SAndy Fiddaman #define SYSNAME		""
131*906afcb8SAndy Fiddaman #define RELEASE		""
132*906afcb8SAndy Fiddaman #define VERSION		""
133*906afcb8SAndy Fiddaman #define MACHINE		""
134*906afcb8SAndy Fiddaman #endif
135*906afcb8SAndy Fiddaman 
136*906afcb8SAndy Fiddaman struct utsname
137*906afcb8SAndy Fiddaman {
138*906afcb8SAndy Fiddaman 	char*	sysname;
139*906afcb8SAndy Fiddaman 	char	nodename[MAXHOSTNAME];
140*906afcb8SAndy Fiddaman 	char*	release;
141*906afcb8SAndy Fiddaman 	char*	version;
142*906afcb8SAndy Fiddaman 	char*	machine;
143*906afcb8SAndy Fiddaman };
144*906afcb8SAndy Fiddaman 
145*906afcb8SAndy Fiddaman int
146*906afcb8SAndy Fiddaman uname(register struct utsname* ut)
147*906afcb8SAndy Fiddaman {
148*906afcb8SAndy Fiddaman #ifdef HOSTTYPE
149*906afcb8SAndy Fiddaman 	char*		sys = 0;
150*906afcb8SAndy Fiddaman 	char*		arch = 0;
151*906afcb8SAndy Fiddaman 
152*906afcb8SAndy Fiddaman 	if (*hosttype)
153*906afcb8SAndy Fiddaman 	{
154*906afcb8SAndy Fiddaman 		static char	buf[sizeof(hosttype)];
155*906afcb8SAndy Fiddaman 
156*906afcb8SAndy Fiddaman 		strcpy(buf, hosttype);
157*906afcb8SAndy Fiddaman 		sys = buf;
158*906afcb8SAndy Fiddaman 		if (arch = strchr(sys, '.'))
159*906afcb8SAndy Fiddaman 		{
160*906afcb8SAndy Fiddaman 			*arch++ = 0;
161*906afcb8SAndy Fiddaman 			if (!*arch)
162*906afcb8SAndy Fiddaman 				arch = 0;
163*906afcb8SAndy Fiddaman 		}
164*906afcb8SAndy Fiddaman 		if (!*sys)
165*906afcb8SAndy Fiddaman 			sys = 0;
166*906afcb8SAndy Fiddaman 	}
167*906afcb8SAndy Fiddaman #endif
168*906afcb8SAndy Fiddaman #ifdef _lib_gethostname
169*906afcb8SAndy Fiddaman 	if (gethostname(ut->nodename, sizeof(ut->nodename) - 1))
170*906afcb8SAndy Fiddaman 		return -1;
171*906afcb8SAndy Fiddaman #else
172*906afcb8SAndy Fiddaman 	strncpy(ut->nodename, "local", sizeof(ut->nodename) - 1);
173*906afcb8SAndy Fiddaman #endif
174*906afcb8SAndy Fiddaman #ifdef HOSTTYPE
175*906afcb8SAndy Fiddaman 	if (!(ut->sysname = sys))
176*906afcb8SAndy Fiddaman #endif
177*906afcb8SAndy Fiddaman 	if (!*(ut->sysname = SYSNAME))
178*906afcb8SAndy Fiddaman 		ut->sysname = ut->nodename;
179*906afcb8SAndy Fiddaman #ifdef HOSTTYPE
180*906afcb8SAndy Fiddaman 	if (!(ut->machine = arch))
181*906afcb8SAndy Fiddaman #endif
182*906afcb8SAndy Fiddaman 	ut->machine = MACHINE;
183*906afcb8SAndy Fiddaman 	ut->release = RELEASE;
184*906afcb8SAndy Fiddaman 	ut->version = VERSION;
185*906afcb8SAndy Fiddaman 	return 0;
186*906afcb8SAndy Fiddaman }
187*906afcb8SAndy Fiddaman 
188*906afcb8SAndy Fiddaman #endif
189*906afcb8SAndy Fiddaman 
190*906afcb8SAndy Fiddaman #define OPT_system		(1<<0)
191*906afcb8SAndy Fiddaman #define OPT_nodename		(1<<1)
192*906afcb8SAndy Fiddaman #define OPT_release		(1<<2)
193*906afcb8SAndy Fiddaman #define OPT_version		(1<<3)
194*906afcb8SAndy Fiddaman #define OPT_machine		(1<<4)
195*906afcb8SAndy Fiddaman #define OPT_processor		(1<<5)
196*906afcb8SAndy Fiddaman 
197*906afcb8SAndy Fiddaman #define OPT_STANDARD		6
198*906afcb8SAndy Fiddaman 
199*906afcb8SAndy Fiddaman #define OPT_implementation	(1<<6)
200*906afcb8SAndy Fiddaman #define OPT_operating_system	(1<<7)
201*906afcb8SAndy Fiddaman 
202*906afcb8SAndy Fiddaman #define OPT_ALL			8
203*906afcb8SAndy Fiddaman 
204*906afcb8SAndy Fiddaman #define OPT_hostid		(1<<8)
205*906afcb8SAndy Fiddaman #define OPT_vendor		(1<<9)
206*906afcb8SAndy Fiddaman #define OPT_domain		(1<<10)
207*906afcb8SAndy Fiddaman #define OPT_machine_type	(1<<11)
208*906afcb8SAndy Fiddaman #define OPT_base		(1<<12)
209*906afcb8SAndy Fiddaman #define OPT_extended_release	(1<<13)
210*906afcb8SAndy Fiddaman #define OPT_extra		(1<<14)
211*906afcb8SAndy Fiddaman 
212*906afcb8SAndy Fiddaman #define OPT_TOTAL		15
213*906afcb8SAndy Fiddaman 
214*906afcb8SAndy Fiddaman #define OPT_all			(1L<<29)
215*906afcb8SAndy Fiddaman #define OPT_total		(1L<<30)
216*906afcb8SAndy Fiddaman #define OPT_standard		((1<<OPT_STANDARD)-1)
217*906afcb8SAndy Fiddaman 
218*906afcb8SAndy Fiddaman #ifndef MACHINE
219*906afcb8SAndy Fiddaman #if defined(__STDPP__)
220*906afcb8SAndy Fiddaman #define MACHINE			#(getprd architecture)
221*906afcb8SAndy Fiddaman #else
222*906afcb8SAndy Fiddaman #define MACHINE			""
223*906afcb8SAndy Fiddaman #endif
224*906afcb8SAndy Fiddaman #endif
225*906afcb8SAndy Fiddaman 
226*906afcb8SAndy Fiddaman #ifndef HOSTTYPE
227*906afcb8SAndy Fiddaman #define HOSTTYPE		"unknown"
228*906afcb8SAndy Fiddaman #endif
229*906afcb8SAndy Fiddaman 
230*906afcb8SAndy Fiddaman #define extra(m)        do \
231*906afcb8SAndy Fiddaman 			{ \
232*906afcb8SAndy Fiddaman 				if ((char*)&ut.m[sizeof(ut.m)] > last) \
233*906afcb8SAndy Fiddaman 					last = (char*)&ut.m[sizeof(ut.m)]; \
234*906afcb8SAndy Fiddaman 			} while(0)
235*906afcb8SAndy Fiddaman 
236*906afcb8SAndy Fiddaman #define output(f,v,u)	do \
237*906afcb8SAndy Fiddaman 			{ \
238*906afcb8SAndy Fiddaman 				if ((flags&(f))&&(*(v)||(flags&(OPT_all|OPT_total))==OPT_all&&((f)&OPT_standard)||!(flags&(OPT_all|OPT_total)))) \
239*906afcb8SAndy Fiddaman 				{ \
240*906afcb8SAndy Fiddaman 					if (sep) \
241*906afcb8SAndy Fiddaman 						sfputc(sfstdout, ' '); \
242*906afcb8SAndy Fiddaman 					else \
243*906afcb8SAndy Fiddaman 						sep = 1; \
244*906afcb8SAndy Fiddaman 					if (*(v)) \
245*906afcb8SAndy Fiddaman 						sfputr(sfstdout, v, -1); \
246*906afcb8SAndy Fiddaman 					else \
247*906afcb8SAndy Fiddaman 						sfprintf(sfstdout, "[%s]", u); \
248*906afcb8SAndy Fiddaman 				} \
249*906afcb8SAndy Fiddaman 			} while (0)
250*906afcb8SAndy Fiddaman 
251*906afcb8SAndy Fiddaman int
252*906afcb8SAndy Fiddaman b_uname(int argc, char** argv, Shbltin_t* context)
253*906afcb8SAndy Fiddaman {
254*906afcb8SAndy Fiddaman 	register long	flags = 0;
255*906afcb8SAndy Fiddaman 	register int	sep = 0;
256*906afcb8SAndy Fiddaman 	register int	n;
257*906afcb8SAndy Fiddaman 	register char*	s;
258*906afcb8SAndy Fiddaman 	char*		t;
259*906afcb8SAndy Fiddaman 	char*		e;
260*906afcb8SAndy Fiddaman 	char*		sethost = 0;
261*906afcb8SAndy Fiddaman 	int		list = 0;
262*906afcb8SAndy Fiddaman 	struct utsname	ut;
263*906afcb8SAndy Fiddaman 	char		buf[257];
264*906afcb8SAndy Fiddaman 
265*906afcb8SAndy Fiddaman 	cmdinit(argc, argv, context, ERROR_CATALOG, 0);
266*906afcb8SAndy Fiddaman 	for (;;)
267*906afcb8SAndy Fiddaman 	{
268*906afcb8SAndy Fiddaman 		switch (optget(argv, usage))
269*906afcb8SAndy Fiddaman 		{
270*906afcb8SAndy Fiddaman 		case 'a':
271*906afcb8SAndy Fiddaman 			flags |= OPT_all|((1L<<OPT_ALL)-1);
272*906afcb8SAndy Fiddaman 			continue;
273*906afcb8SAndy Fiddaman 		case 'b':
274*906afcb8SAndy Fiddaman 			flags |= OPT_base;
275*906afcb8SAndy Fiddaman 			continue;
276*906afcb8SAndy Fiddaman 		case 'c':
277*906afcb8SAndy Fiddaman 			flags |= OPT_vendor;
278*906afcb8SAndy Fiddaman 			continue;
279*906afcb8SAndy Fiddaman 		case 'd':
280*906afcb8SAndy Fiddaman 			flags |= OPT_domain;
281*906afcb8SAndy Fiddaman 			continue;
282*906afcb8SAndy Fiddaman 		case 'f':
283*906afcb8SAndy Fiddaman 			list = 1;
284*906afcb8SAndy Fiddaman 			continue;
285*906afcb8SAndy Fiddaman 		case 'h':
286*906afcb8SAndy Fiddaman 			flags |= OPT_hostid;
287*906afcb8SAndy Fiddaman 			continue;
288*906afcb8SAndy Fiddaman 		case 'i':
289*906afcb8SAndy Fiddaman 			flags |= OPT_implementation;
290*906afcb8SAndy Fiddaman 			continue;
291*906afcb8SAndy Fiddaman 		case 'm':
292*906afcb8SAndy Fiddaman 			flags |= OPT_machine;
293*906afcb8SAndy Fiddaman 			continue;
294*906afcb8SAndy Fiddaman 		case 'n':
295*906afcb8SAndy Fiddaman 			flags |= OPT_nodename;
296*906afcb8SAndy Fiddaman 			continue;
297*906afcb8SAndy Fiddaman 		case 'o':
298*906afcb8SAndy Fiddaman 			flags |= OPT_operating_system;
299*906afcb8SAndy Fiddaman 			continue;
300*906afcb8SAndy Fiddaman 		case 'p':
301*906afcb8SAndy Fiddaman 			flags |= OPT_processor;
302*906afcb8SAndy Fiddaman 			continue;
303*906afcb8SAndy Fiddaman 		case 'r':
304*906afcb8SAndy Fiddaman 			flags |= OPT_release;
305*906afcb8SAndy Fiddaman 			continue;
306*906afcb8SAndy Fiddaman 		case 's':
307*906afcb8SAndy Fiddaman 			flags |= OPT_system;
308*906afcb8SAndy Fiddaman 			continue;
309*906afcb8SAndy Fiddaman 		case 't':
310*906afcb8SAndy Fiddaman 			flags |= OPT_machine_type;
311*906afcb8SAndy Fiddaman 			continue;
312*906afcb8SAndy Fiddaman 		case 'v':
313*906afcb8SAndy Fiddaman 			flags |= OPT_version;
314*906afcb8SAndy Fiddaman 			continue;
315*906afcb8SAndy Fiddaman 		case 'x':
316*906afcb8SAndy Fiddaman 			flags |= OPT_extra;
317*906afcb8SAndy Fiddaman 			continue;
318*906afcb8SAndy Fiddaman 		case 'A':
319*906afcb8SAndy Fiddaman 			flags |= OPT_total|((1L<<OPT_TOTAL)-1);
320*906afcb8SAndy Fiddaman 			continue;
321*906afcb8SAndy Fiddaman 		case 'R':
322*906afcb8SAndy Fiddaman 			flags |= OPT_extended_release;
323*906afcb8SAndy Fiddaman 			continue;
324*906afcb8SAndy Fiddaman 		case 'S':
325*906afcb8SAndy Fiddaman 			sethost = opt_info.arg;
326*906afcb8SAndy Fiddaman 			continue;
327*906afcb8SAndy Fiddaman 		case ':':
328*906afcb8SAndy Fiddaman 			s = "/usr/bin/uname";
329*906afcb8SAndy Fiddaman 			if (!streq(argv[0], s) && (!eaccess(s, X_OK) || !eaccess(s+=4, X_OK)))
330*906afcb8SAndy Fiddaman 			{
331*906afcb8SAndy Fiddaman 				argv[0] = s;
332*906afcb8SAndy Fiddaman 				return sh_run(context, argc, argv);
333*906afcb8SAndy Fiddaman 			}
334*906afcb8SAndy Fiddaman 			error(2, "%s", opt_info.arg);
335*906afcb8SAndy Fiddaman 			break;
336*906afcb8SAndy Fiddaman 		case '?':
337*906afcb8SAndy Fiddaman 			error(ERROR_usage(2), "%s", opt_info.arg);
338*906afcb8SAndy Fiddaman 			break;
339*906afcb8SAndy Fiddaman 		}
340*906afcb8SAndy Fiddaman 		break;
341*906afcb8SAndy Fiddaman 	}
342*906afcb8SAndy Fiddaman 	argv += opt_info.index;
343*906afcb8SAndy Fiddaman 	if (error_info.errors || *argv && (flags || sethost) || sethost && flags)
344*906afcb8SAndy Fiddaman 		error(ERROR_usage(2), "%s", optusage(NiL));
345*906afcb8SAndy Fiddaman 	if (sethost)
346*906afcb8SAndy Fiddaman 	{
347*906afcb8SAndy Fiddaman #if _lib_sethostname
348*906afcb8SAndy Fiddaman 		if (sethostname(sethost, strlen(sethost) + 1))
349*906afcb8SAndy Fiddaman #else
350*906afcb8SAndy Fiddaman #ifdef	ENOSYS
351*906afcb8SAndy Fiddaman 		errno = ENOSYS;
352*906afcb8SAndy Fiddaman #else
353*906afcb8SAndy Fiddaman 		errno = EPERM;
354*906afcb8SAndy Fiddaman #endif
355*906afcb8SAndy Fiddaman #endif
356*906afcb8SAndy Fiddaman 		error(ERROR_system(1), "%s: cannot set host name", sethost);
357*906afcb8SAndy Fiddaman 	}
358*906afcb8SAndy Fiddaman 	else if (list)
359*906afcb8SAndy Fiddaman 		astconflist(sfstdout, NiL, ASTCONF_base|ASTCONF_defined|ASTCONF_lower|ASTCONF_quote|ASTCONF_matchcall, "CS|SI");
360*906afcb8SAndy Fiddaman 	else if (*argv)
361*906afcb8SAndy Fiddaman 	{
362*906afcb8SAndy Fiddaman 		e = &buf[sizeof(buf)-1];
363*906afcb8SAndy Fiddaman 		while (s = *argv++)
364*906afcb8SAndy Fiddaman 		{
365*906afcb8SAndy Fiddaman 			t = buf;
366*906afcb8SAndy Fiddaman 			*t++ = 'C';
367*906afcb8SAndy Fiddaman 			*t++ = 'S';
368*906afcb8SAndy Fiddaman 			*t++ = '_';
369*906afcb8SAndy Fiddaman 			while (t < e && (n = *s++))
370*906afcb8SAndy Fiddaman 				*t++ = islower(n) ? toupper(n) : n;
371*906afcb8SAndy Fiddaman 			*t = 0;
372*906afcb8SAndy Fiddaman 			sfprintf(sfstdout, "%s%c", *(t = astconf(buf, NiL, NiL)) ? t : *(t = astconf(buf+3, NiL, NiL)) ? t :  "unknown", *argv ? ' ' : '\n');
373*906afcb8SAndy Fiddaman 		}
374*906afcb8SAndy Fiddaman 	}
375*906afcb8SAndy Fiddaman 	else
376*906afcb8SAndy Fiddaman 	{
377*906afcb8SAndy Fiddaman 		s = buf;
378*906afcb8SAndy Fiddaman 		if (!flags)
379*906afcb8SAndy Fiddaman 			flags = OPT_system;
380*906afcb8SAndy Fiddaman 		memzero(&ut, sizeof(ut));
381*906afcb8SAndy Fiddaman 		if (uname(&ut) < 0)
382*906afcb8SAndy Fiddaman 			error(ERROR_usage(2), "information unavailable");
383*906afcb8SAndy Fiddaman 		output(OPT_system, ut.sysname, "sysname");
384*906afcb8SAndy Fiddaman 		if (flags & OPT_nodename)
385*906afcb8SAndy Fiddaman 		{
386*906afcb8SAndy Fiddaman #if !_mem_nodeext_utsname && _lib_gethostname
387*906afcb8SAndy Fiddaman 			if (sizeof(ut.nodename) > 9 || gethostname(s, sizeof(buf)))
388*906afcb8SAndy Fiddaman #endif
389*906afcb8SAndy Fiddaman 			s = ut.nodename;
390*906afcb8SAndy Fiddaman 			output(OPT_nodename, s, "nodename");
391*906afcb8SAndy Fiddaman 		}
392*906afcb8SAndy Fiddaman 		output(OPT_release, ut.release, "release");
393*906afcb8SAndy Fiddaman 		output(OPT_version, ut.version, "version");
394*906afcb8SAndy Fiddaman 		output(OPT_machine, ut.machine, "machine");
395*906afcb8SAndy Fiddaman 		if (flags & OPT_processor)
396*906afcb8SAndy Fiddaman 		{
397*906afcb8SAndy Fiddaman 			if (!*(s = astconf("ARCHITECTURE", NiL, NiL)))
398*906afcb8SAndy Fiddaman 				s = ut.machine;
399*906afcb8SAndy Fiddaman 			output(OPT_processor, s, "processor");
400*906afcb8SAndy Fiddaman 		}
401*906afcb8SAndy Fiddaman 		if (flags & OPT_implementation)
402*906afcb8SAndy Fiddaman 		{
403*906afcb8SAndy Fiddaman 			if (!*(s = astconf("PLATFORM", NiL, NiL)) && !*(s = astconf("HW_NAME", NiL, NiL)))
404*906afcb8SAndy Fiddaman 			{
405*906afcb8SAndy Fiddaman 				if (t = strchr(hosttype, '.'))
406*906afcb8SAndy Fiddaman 					t++;
407*906afcb8SAndy Fiddaman 				else
408*906afcb8SAndy Fiddaman 					t = (char*)hosttype;
409*906afcb8SAndy Fiddaman 				strncpy(s = buf, t, sizeof(buf) - 1);
410*906afcb8SAndy Fiddaman 			}
411*906afcb8SAndy Fiddaman 			output(OPT_implementation, s, "implementation");
412*906afcb8SAndy Fiddaman 		}
413*906afcb8SAndy Fiddaman 		if (flags & OPT_operating_system)
414*906afcb8SAndy Fiddaman 		{
415*906afcb8SAndy Fiddaman 			s = astconf("OPERATING_SYSTEM", NiL, NiL);
416*906afcb8SAndy Fiddaman 			if (!*s)
417*906afcb8SAndy Fiddaman #ifdef _UNAME_os_DEFAULT
418*906afcb8SAndy Fiddaman 				s = _UNAME_os_DEFAULT;
419*906afcb8SAndy Fiddaman #else
420*906afcb8SAndy Fiddaman 				s = ut.sysname;
421*906afcb8SAndy Fiddaman #endif
422*906afcb8SAndy Fiddaman 			output(OPT_operating_system, s, "operating-system");
423*906afcb8SAndy Fiddaman 		}
424*906afcb8SAndy Fiddaman 		if (flags & OPT_extended_release)
425*906afcb8SAndy Fiddaman 		{
426*906afcb8SAndy Fiddaman 			s = astconf("RELEASE", NiL, NiL);
427*906afcb8SAndy Fiddaman 			output(OPT_extended_release, s, "extended-release");
428*906afcb8SAndy Fiddaman 		}
429*906afcb8SAndy Fiddaman #if _mem_idnumber_utsname
430*906afcb8SAndy Fiddaman 		output(OPT_hostid, ut.idnumber, "hostid");
431*906afcb8SAndy Fiddaman #else
432*906afcb8SAndy Fiddaman 		if (flags & OPT_hostid)
433*906afcb8SAndy Fiddaman 		{
434*906afcb8SAndy Fiddaman 			if (!*(s = astconf("HW_SERIAL", NiL, NiL)))
435*906afcb8SAndy Fiddaman #if _lib_gethostid
436*906afcb8SAndy Fiddaman 				sfsprintf(s = buf, sizeof(buf), "%08x", gethostid());
437*906afcb8SAndy Fiddaman #else
438*906afcb8SAndy Fiddaman 				{/*NOP*/};
439*906afcb8SAndy Fiddaman #endif
440*906afcb8SAndy Fiddaman 			output(OPT_hostid, s, "hostid");
441*906afcb8SAndy Fiddaman 		}
442*906afcb8SAndy Fiddaman #endif
443*906afcb8SAndy Fiddaman 		if (flags & OPT_vendor)
444*906afcb8SAndy Fiddaman 		{
445*906afcb8SAndy Fiddaman 			s = astconf("HW_PROVIDER", NiL, NiL);
446*906afcb8SAndy Fiddaman 			output(OPT_vendor, s, "vendor");
447*906afcb8SAndy Fiddaman 		}
448*906afcb8SAndy Fiddaman 		if (flags & OPT_domain)
449*906afcb8SAndy Fiddaman 		{
450*906afcb8SAndy Fiddaman 			if (!*(s = astconf("SRPC_DOMAIN", NiL, NiL)))
451*906afcb8SAndy Fiddaman #if _lib_getdomainname
452*906afcb8SAndy Fiddaman 				getdomainname(s, sizeof(buf));
453*906afcb8SAndy Fiddaman #else
454*906afcb8SAndy Fiddaman 				{/*NOP*/};
455*906afcb8SAndy Fiddaman #endif
456*906afcb8SAndy Fiddaman 			output(OPT_domain, s, "domain");
457*906afcb8SAndy Fiddaman 		}
458*906afcb8SAndy Fiddaman #if _mem_m_type_utsname
459*906afcb8SAndy Fiddaman 		s = ut.m_type;
460*906afcb8SAndy Fiddaman #else
461*906afcb8SAndy Fiddaman 		s = astconf("MACHINE", NiL, NiL);
462*906afcb8SAndy Fiddaman #endif
463*906afcb8SAndy Fiddaman 		output(OPT_machine_type, s, "m_type");
464*906afcb8SAndy Fiddaman #if _mem_base_rel_utsname
465*906afcb8SAndy Fiddaman 		s = ut.base_rel;
466*906afcb8SAndy Fiddaman #else
467*906afcb8SAndy Fiddaman 		s = astconf("BASE", NiL, NiL);
468*906afcb8SAndy Fiddaman #endif
469*906afcb8SAndy Fiddaman 		output(OPT_base, s, "base_rel");
470*906afcb8SAndy Fiddaman 		if (flags & OPT_extra)
471*906afcb8SAndy Fiddaman 		{
472*906afcb8SAndy Fiddaman 			char*	last = (char*)&ut;
473*906afcb8SAndy Fiddaman 
474*906afcb8SAndy Fiddaman 			extra(sysname);
475*906afcb8SAndy Fiddaman 			extra(nodename);
476*906afcb8SAndy Fiddaman 			extra(release);
477*906afcb8SAndy Fiddaman 			extra(version);
478*906afcb8SAndy Fiddaman 			extra(machine);
479*906afcb8SAndy Fiddaman #if _mem_idnumber_utsname
480*906afcb8SAndy Fiddaman 			extra(idnumber);
481*906afcb8SAndy Fiddaman #endif
482*906afcb8SAndy Fiddaman #if _mem_m_type_utsname
483*906afcb8SAndy Fiddaman 			extra(m_type);
484*906afcb8SAndy Fiddaman #endif
485*906afcb8SAndy Fiddaman #if _mem_base_rel_utsname
486*906afcb8SAndy Fiddaman 			extra(base_rel);
487*906afcb8SAndy Fiddaman #endif
488*906afcb8SAndy Fiddaman 			if (last < ((char*)(&ut + 1)))
489*906afcb8SAndy Fiddaman 			{
490*906afcb8SAndy Fiddaman 				s = t = last;
491*906afcb8SAndy Fiddaman 				while (s < (char*)(&ut + 1))
492*906afcb8SAndy Fiddaman 				{
493*906afcb8SAndy Fiddaman 					if (!(n = *s++))
494*906afcb8SAndy Fiddaman 					{
495*906afcb8SAndy Fiddaman 						if ((s - t) > 1)
496*906afcb8SAndy Fiddaman 						{
497*906afcb8SAndy Fiddaman 							if (sep)
498*906afcb8SAndy Fiddaman 								sfputc(sfstdout, ' ');
499*906afcb8SAndy Fiddaman 							else
500*906afcb8SAndy Fiddaman 								sep = 1;
501*906afcb8SAndy Fiddaman 							sfputr(sfstdout, t, -1);
502*906afcb8SAndy Fiddaman 						}
503*906afcb8SAndy Fiddaman 						t = s;
504*906afcb8SAndy Fiddaman 					}
505*906afcb8SAndy Fiddaman 					else if (!isprint(n))
506*906afcb8SAndy Fiddaman 						break;
507*906afcb8SAndy Fiddaman 				}
508*906afcb8SAndy Fiddaman 			}
509*906afcb8SAndy Fiddaman 		}
510*906afcb8SAndy Fiddaman 		if (sep)
511*906afcb8SAndy Fiddaman 			sfputc(sfstdout, '\n');
512*906afcb8SAndy Fiddaman 	}
513*906afcb8SAndy Fiddaman 	return error_info.errors;
514*906afcb8SAndy Fiddaman }
515