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