File: vuname.c

package info (click to toggle)
umview 0.8.2-1.2
  • links: PTS
  • area: main
  • in suites: buster
  • size: 5,472 kB
  • sloc: ansic: 67,309; sh: 11,160; ruby: 914; makefile: 424; python: 141
file content (178 lines) | stat: -rw-r--r-- 5,237 bytes parent folder | download | duplicates (5)
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
/*   This is part of um-ViewOS
 *   The user-mode implementation of OSVIEW -- A Process with a View
 *
 *   umviewname.c 
 *   uname extension to view-os (umview)
 *   
 *   Copyright 2005 Renzo Davoli University of Bologna - Italy
 *   
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License, version 2, as
 *   published by the Free Software Foundation.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License along
 *   with this program; if not, write to the Free Software Foundation, Inc.,
 *   51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA.
 *
 *   $Id: vuname.c 1062 2012-01-30 09:00:50Z rd235 $
 *
 */   
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include <config.h>
#include <um_lib.h>

void usage()
{
	fprintf(stderr, 
			"Usage: vuname [OPTION]...\n"
			"Print certain View-OS system information.  With no OPTION, same as -s.\n"
			"\n"
			" -a, --all                print all information, in the following order,\n"
			" except omit -p and -i if unknown:\n"
			" -s, --kernel-name        print the kernel name\n"
			" -n, --nodename           print the network node hostname\n"
			" -r, --kernel-release     print the kernel release\n"
			" -v, --kernel-version     print the kernel version\n"
			" -m, --machine            print the machine hardware name\n"
			" -p, --processor          print the processor type or \"unknown\"\n"
			" -i, --hardware-platform  print the hardware platform or \"unknown\"\n"
			" -o, --operating-system   print the operating system\n"
			" -U, --serverid           print the server id\n"
			" -V, --viewid             print the view id\n"
			" -N, --viewname           print the view name\n"
			"other options\n"
			" -q, --quiet              quiet mode: silent on errors\n"
			" -x, --nouname            do not use uname when outside View-OS\n"
			"     --help     display this help and exit\n"
			"     --version  output version information and exit\n"
			"\n");
}

char flags[12];
int quiet;
int unameok=1;
struct viewinfo vi;

int main(int argc, char *argv[])
{
	int c;
	int i;
	while (1) {
		int option_index = 0;
		static struct option long_options[] = {
			{"all", 0, 0, 'a'},
			{"kernel-name", 0, 0, 's'},
			{"nodename",0,0,'n'},
			{"kernel-release",0,0,'r'},
			{"kernel-version",0,0,'v'},
			{"machine",0,0,'m'},
			{"processor",0,0,'p'},
			{"hardware-platform",0,0,'i'},
			{"operating-system",0,0,'o'},
			{"serverid",0,0,'U'},
			{"viewid",0,0,'V'},
			{"viewname",0,0,'N'},
			{"quiet",0,0,'q'},
			{"nouname",0,0,'x'},
			{"help",0,0,0x100},
			{"version",0,0,0x101},
			{0,0,0,0}
		};
		c=getopt_long(argc,argv,"asnrvmpioxqUVN",long_options,&option_index);
		if (c == -1) break;
		switch (c) {
			case 'a': flags[0]=1; break;
			case 's': flags[1]=1; break;
			case 'n': flags[2]=1; break;
			case 'r': flags[3]=1; break;
			case 'v': flags[4]=1; break;
			case 'm': flags[5]=1; break;
			case 'p': flags[6]=1; break;
			case 'i': flags[7]=1; break;
			case 'o': flags[8]=1; break;
			case 'U': flags[9]=1; break;
			case 'V': flags[10]=1; break;
			case 'N': flags[11]=1; break;
			case 'q': quiet=1; break;
			case 'x': unameok=0; break;
			case 0x100:
				usage();
				exit(0);
				break;
			case 0x101:
				printf("umviewname (View-OS project) 1.0\n"
						"Copyright (C) 2007 View-OS Team - University of Bologna\n"
						"This is free software.  You may redistribute copies of it under the terms of\n"
						"the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.\n"
						"There is NO WARRANTY, to the extent permitted by law.\n"

						"Written by Renzo Davoli\n");
				exit(0);
				break;
			default:
				usage();
				exit(1);
		}
	}
	if (argc - optind != 0) {
		usage();
		exit(1);
	}
	c=um_view_getinfo(&vi);
	if (c<0) {
		if (unameok)
			c=uname(&vi.uname);
		if (c<0) {
			if (!quiet) perror("umviewname:");
			exit (1);
		}
	} else
		unameok=0;
	for (c=i=0;i<12;i++)
		c+=flags[i];
	if (c) {
		int n=0;
#define SPACE ((n++ == 0)?"":" ")
		if(flags[0] || flags[1])
			printf("%s%s",SPACE,vi.uname.sysname);
		if(flags[0] || flags[2])
			printf("%s%s",SPACE,vi.uname.nodename);
		if(flags[0] || flags[3])
			printf("%s%s",SPACE,vi.uname.release);
		if(flags[0] || flags[4])
			printf("%s%s",SPACE,vi.uname.version);
		if(flags[0] || flags[5])
			printf("%s%s",SPACE,vi.uname.machine);
		if(flags[6])
			printf("%s%s",SPACE,"unknown");
		if(flags[7])
			printf("%s%s",SPACE,"unknown");
		if(flags[0] || flags[8]) {
			if (unameok)
				printf("%s%s",SPACE,"GNU/Linux");
			else
				printf("%s%s",SPACE,"GNU/Linux/View-OS");
		}
		if (!unameok) {
			if(flags[0] || flags[9])
				printf("%s%d",SPACE,vi.serverid);
			if(flags[0] || flags[10])
				printf("%s%lu",SPACE,vi.viewid);
			if(flags[0] || flags[11])
				printf("%s%s",SPACE,vi.viewname);
		}
		printf("\n");
	} else {
			printf("%s\n",vi.uname.sysname);
	}
	return 0;
}