kernel: ~Stack can grow now (upto 4MB)
[meinos.git] / apps / rc / helper.c
blobb5eb1829d4d41144205aef3f6d8ed874a2affe5d
1 /*
2 meinOS - A unix-like x86 microkernel operating system
3 Copyright (C) 2008 Janosch Gräf <janosch.graef@gmx.net>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include <rpc.h>
20 #include <stdio.h>
21 #include <unistd.h>
23 #include "helper.h"
25 int get_runlevel(void) {
26 return rpc_call("init_get_runlevel",0);
29 int str_to_runlevel(const char *str) {
30 if (str[0]==0) return -1;
31 if (str[1]!=0) return -1;
32 char chr = str[0];
34 if (chr>='0' && chr<'7') return chr-'0';
35 else return -1;
38 char *rcd_path(int runlevel) {
39 static char *path = "/etc/init.d/rcX.d\n";
40 path[14] = '0'+runlevel;
41 return path;
44 void parse_rc_script(rc_script_t *script,const char *dir,const char *file) {
45 char *name;
46 asprintf(&(script->path),"%s/%s",dir,file);
47 script->priority = strtoul(file+1,&name,10);
48 script->name = strdup(name);
51 int compare_rc_script(const void *vscript1,const void *vscript2) {
52 const rc_script_t *script1 = vscript1;
53 const rc_script_t *script2 = vscript2;
55 if (script1->name==NULL) return 1;
56 else if (script2->name==NULL) return -1;
57 else return script1->priority-script2->priority;
60 int make_rc_symlink(const char *name,int runlevel,int priority,char prefix) {
61 char *link;
62 char *target;
64 asprintf(&link,"%s/%c%02d%s",rcd_path(runlevel),prefix,priority,name);
65 asprintf(&target,"/etc/init.d/%s",name);
67 int ret = symlink(target,link);
69 free(link);
70 free(target);
72 return ret;