Skip to content

Commit

Permalink
improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
niaow committed Dec 31, 2017
1 parent 168690b commit 7fee949
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 7 deletions.
17 changes: 11 additions & 6 deletions src/linitd.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,18 +533,23 @@ void cmd_start(struct conn *c, char *args) {
} else {
struct service *svc = findService(args);
if(svc != NULL) { //service already started
if(setNotify(svc, c)) {
fprintf(stderr, "Failed to set conn %d to be notified about %s\n", c->fd, args);\
if(!setNotify(svc, c)) {
fprintf(stderr, "Failed to set conn %d to be notified about %s\n", c->fd, args);
close_conn(c);
goto end;
}
//format: "notify %s %s", args, status
char not[] = "notify ";
char *status = statestr(svc->state);
char ntxt[strlen(not) + strlen(args) + strlen(status) + 1];
memcpy(ntxt, not, strlen(not));
memcpy(ntxt + strlen(not), args, strlen(args));
memcpy(ntxt + strlen(not) + strlen(args), status, strlen(status));
char ntxt[strlen(not) + strlen(args) + strlen(status) + 2];
char *nt = ntxt;
strcpy(nt, not);
nt += strlen(not);
strcpy(nt, args);
nt += strlen(args);
*nt = ' ';
nt++;
strcpy(nt, status);
struct buf dat = { .dat = ntxt, .len = strlen(ntxt) + 1 };
if(notify(c, svc, dat) != notify_success) {
fprintf(stderr, "Failed to notify conn %d about the state of %s\n", c->fd, args);
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/init.d/login.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/etc/rc.common

depends() {
dep printk
dep pre welcome
}

start() {
Expand Down
19 changes: 19 additions & 0 deletions src/scripts/init.d/pre.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/etc/rc.common

#Pre-boot targets

depends() {
if [ -d /etc/rc.d/pre ]; then
dep $(ls /etc/rc.d/pre)
fi
}

enable() {
if [ ! -d /etc/rc.d/pre ]; then
mkdir /etc/rc.d/pre
fi
}

disable() {
rm -r /etc/rc.d/pre
}
9 changes: 9 additions & 0 deletions src/scripts/init.d/printk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,12 @@
start() {
echo 0 > /proc/sys/kernel/printk
}

enable() {
/etc/init.d/pre enable
ln -s /etc/init.d/$this /etc/rc.d/pre/$this
}

disable() {
rm /etc/rc.d/pre/$this
}
9 changes: 9 additions & 0 deletions src/scripts/init.d/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/etc/rc.common

depends() {
dep pre
}

start() {
echo 123
}
4 changes: 4 additions & 0 deletions src/scripts/init.d/welcome.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/etc/rc.common

depends() {
dep pre
}

start() {
echo Hello!
}

0 comments on commit 7fee949

Please sign in to comment.