unstack - fix ipcvecs
[minix.git] / commands / sysenv / sysenv.c
blob58cb876c17ea5886e9853efd5d9e4e0ae535728d
1 /* sysenv 1.0 - request system boot parameter Author: Kees J. Bot
2 * 23 Dec 2000
3 */
4 #define nil ((void*)0)
5 #include <minix/type.h>
6 #include <sys/types.h>
7 #include <sys/svrctl.h>
8 #include <stdarg.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <errno.h>
12 #include <string.h>
14 #define NIL ((char*)0)
16 static void tell(int fd, ...)
18 va_list ap;
19 char *s;
21 va_start(ap, fd);
22 while ((s= va_arg(ap, char *)) != NIL) {
23 (void) write(fd, s, strlen(s));
25 va_end(ap);
28 int main(int argc, char **argv)
30 struct sysgetenv sysgetenv;
31 int i;
32 int ex= 0;
33 char *e;
34 char val[1024];
36 i= 1;
37 while (i < argc && argv[i][0] == '-') {
38 char *opt= argv[i++]+1;
40 if (opt[0] == '-' && opt[1] == 0) break; /* -- */
42 if (*opt != 0) {
43 tell(2, "Usage: sysenv [name ...]\n", NIL);
44 exit(1);
48 do {
49 if (i < argc) {
50 sysgetenv.key= argv[i];
51 sysgetenv.keylen= strlen(sysgetenv.key) + 1;
52 } else {
53 sysgetenv.key= nil;
54 sysgetenv.keylen= 0;
56 sysgetenv.val= val;
57 sysgetenv.vallen= sizeof(val);
59 if (svrctl(PMGETPARAM, &sysgetenv) == -1) {
60 if (errno == ESRCH) {
61 ex |= 2;
62 } else {
63 ex |= 1;
64 tell(2, "sysenv: ", strerror(errno), "\n", NIL);
66 continue;
69 e= sysgetenv.val;
70 do {
71 e += strlen(e);
72 *e++ = '\n';
73 } while (i == argc && *e != 0);
75 if (write(1, sysgetenv.val, e - sysgetenv.val) < 0) {
76 ex |= 1;
77 tell(2, "sysenv: ", strerror(errno), "\n", NIL);
79 } while (++i < argc);
80 return ex;