Remove building with NOCRYPTO option
[minix.git] / minix / commands / svrctl / svrctl.c
blobe9c2280de361e7bc53c77a41d56e508678cc5c7d
1 #define _MINIX_SYSTEM 1
3 #include <sys/svrctl.h>
4 #include <sys/types.h>
5 #include <ctype.h>
6 #include <lib.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <unistd.h>
12 static void usage(void);
14 #define VFS "vfs"
15 #define PM "pm"
16 #define SET "set"
17 #define GET "get"
19 static char *bin_name;
21 int main (int argc, char *argv[])
23 unsigned long param;
24 endpoint_t proc_e = NONE;
25 struct sysgetenv sysgetenv;
26 char *to_whom, *operation, *what, *value;
27 unsigned i;
29 bin_name = argv[0];
30 if (argc < 4 || argc > 5) usage();
31 if (geteuid() != 0) {
32 fprintf(stderr, "You have to be root to run this utility\n");
33 exit(EXIT_FAILURE);
36 /* Make some parameters lower case to ease comparing */
37 to_whom = argv[1];
38 operation = argv[2];
39 what = argv[3];
40 for (i = 0; i < strlen(to_whom); ++i) to_whom[i] = tolower(to_whom[i]);
41 for (i = 0; i < strlen(operation); ++i) operation[i] = tolower(operation[i]);
42 for (i = 0; i < strlen(what); ++i) what[i] = tolower(what[i]);
44 if (!strncmp(to_whom, VFS, strlen(VFS)+1)) proc_e = VFS_PROC_NR;
45 else if (!strncmp(to_whom, PM, strlen(PM)+1)) proc_e = PM_PROC_NR;
46 else usage();
48 sysgetenv.key = what;
49 sysgetenv.keylen = strlen(what) + 1;
51 if (!strncmp(operation, SET, strlen(SET)+1)) {
52 if (argc != 5) usage();
53 value = argv[4];
54 sysgetenv.val = value;
55 sysgetenv.vallen = strlen(value) + 1;
57 if (proc_e == VFS_PROC_NR)
58 param = VFSSETPARAM;
59 else if (proc_e == PM_PROC_NR)
60 param = PMSETPARAM;
61 else
62 usage();
64 if (svrctl(param, &sysgetenv) != 0) {
65 if (errno == ESRCH)
66 fprintf(stderr, "invalid parameter: %s\n", what);
67 else if (errno == EINVAL)
68 fprintf(stderr, "invalid value: %s\n", value);
69 else
70 perror("");
71 exit(EXIT_FAILURE);
73 return(EXIT_SUCCESS);
74 } else if (!strncmp(operation, GET, strlen(GET)+1)) {
75 char get_param_buffer[4096];
77 memset(get_param_buffer, '\0', sizeof(get_param_buffer));
78 sysgetenv.val = get_param_buffer;
79 sysgetenv.vallen = sizeof(get_param_buffer) - 1;
81 if (proc_e == VFS_PROC_NR)
82 param = VFSGETPARAM;
83 else if (proc_e == PM_PROC_NR)
84 param = PMGETPARAM;
85 else
86 usage();
88 if (svrctl(param, &sysgetenv) != 0) {
89 if (errno == ESRCH)
90 fprintf(stderr, "invalid parameter: %s\n", what);
91 else
92 perror("");
93 return(EXIT_FAILURE);
94 } else {
95 if (sysgetenv.vallen > 0) {
96 get_param_buffer[sysgetenv.vallen] = '\0';
97 printf("%s\n", get_param_buffer);
100 return(EXIT_SUCCESS);
101 } else
102 usage();
104 return(EXIT_FAILURE);
107 static void usage()
109 fprintf(stderr, "Usage:\n");
110 fprintf(stderr, " %s <vfs|pm> set <request> <value>\n", bin_name);
111 fprintf(stderr, " %s <vfs|pm> get <request>\n", bin_name);
112 exit(EXIT_FAILURE);