1 #include <sys/svrctl.h>
10 static void usage(void);
17 static char *bin_name
;
19 int main (int argc
, char *argv
[])
22 endpoint_t proc_e
= NONE
;
23 struct sysgetenv sysgetenv
;
25 char *to_whom
, *operation
, *what
, *value
;
29 if (argc
< 4 || argc
> 5) usage();
31 fprintf(stderr
, "You have to be root to run this utility\n");
35 /* Make some parameters lower case to ease comparing */
39 for (i
= 0; i
< strlen(to_whom
); ++i
) to_whom
[i
] = tolower(to_whom
[i
]);
40 for (i
= 0; i
< strlen(operation
); ++i
) operation
[i
] = tolower(operation
[i
]);
41 for (i
= 0; i
< strlen(what
); ++i
) what
[i
] = tolower(what
[i
]);
43 if (!strncmp(to_whom
, VFS
, strlen(VFS
)+1)) proc_e
= VFS_PROC_NR
;
44 else if (!strncmp(to_whom
, PM
, strlen(PM
)+1)) proc_e
= PM_PROC_NR
;
48 sysgetenv
.keylen
= strlen(what
) + 1;
50 if (!strncmp(operation
, SET
, strlen(SET
)+1)) {
51 if (argc
!= 5) usage();
53 sysgetenv
.val
= value
;
54 sysgetenv
.vallen
= strlen(value
) + 1;
56 if (proc_e
== VFS_PROC_NR
)
58 else if (proc_e
== PM_PROC_NR
)
64 m
.m2_p1
= (char *) &sysgetenv
;
65 r
= _syscall(proc_e
, SVRCTL
, &m
);
68 fprintf(stderr
, "invalid parameter: %s\n", what
);
69 else if (errno
== EINVAL
)
70 fprintf(stderr
, "invalid value: %s\n", value
);
76 } else if (!strncmp(operation
, GET
, strlen(GET
)+1)) {
77 char get_param_buffer
[4096];
79 memset(get_param_buffer
, '\0', sizeof(get_param_buffer
));
80 sysgetenv
.val
= get_param_buffer
;
81 sysgetenv
.vallen
= sizeof(get_param_buffer
) - 1;
83 if (proc_e
== VFS_PROC_NR
)
85 else if (proc_e
== PM_PROC_NR
)
91 m
.m2_p1
= (char *) &sysgetenv
;
92 r
= _syscall(proc_e
, SVRCTL
, &m
);
95 fprintf(stderr
, "invalid parameter: %s\n", what
);
100 if (sysgetenv
.vallen
> 0) {
101 get_param_buffer
[sysgetenv
.vallen
] = '\0';
102 printf("%s\n", get_param_buffer
);
105 return(EXIT_SUCCESS
);
109 return(EXIT_FAILURE
);
114 fprintf(stderr
, "Usage:\n");
115 fprintf(stderr
, " %s <vfs|pm> set <request> <value>\n", bin_name
);
116 fprintf(stderr
, " %s <vfs|pm> get <request>\n", bin_name
);