int answer_version(struct cinit_answer *asr) { asr->ret = CINIT_ASW_OK; cinit_cp_data(asr->data, VERSION); return 1; }
//void svc_start(struct listitem *li, int strict) void svc_start(struct listitem *li) { char buf[CINIT_DATA_LEN]; struct timespec ts; int delay = 0; /* FIXME: to be calculated by waitpid status, if respawing */ /* first update status before forking ! */ if(li->status & CINIT_ST_SH_ONCE) li->status = CINIT_ST_ONCE_RUN; else li->status = CINIT_ST_RESPAWNING; /* set start time */ li->start = time(NULL); /* * FIXME: All cleanup must go here close(fds); reset signals reset env? * FIXME: Add logging possibility to here open (0,1,2) to other processes, * if specified */ /* * BUG: the following child may return _before_ the fork returns in the * parent. Thus this pid may not be registered. And that's the reason why * we need the global svc_lock! */ li->pid = fork(); /********************** parent ************************/ if(li->pid > 0) { printf("%s is at %d\n", li->abs_path, li->pid); return; } /********************** Error ************************/ if(li->pid < 0) { svc_report_status(li->abs_path, MSG_SVC_FORK, strerror(errno)); svc_set_status(li, CINIT_ST_BAD_ERR); return; } /********************** Client / fork() ************************/ /* * sleep, if necesseray */ if(delay) { ts.tv_sec = delay; ts.tv_nsec = 0; /* * FIXME: also report value; int2char */ printf("Delay: %d\n", delay); svc_report_status(li->abs_path, MSG_SVC_SLEEP, NULL); /* * do not need to check for errors, because we can continue anyway */ /* * WRONG: FIXME: look whether to sleep again */ nanosleep(&ts, NULL); } svc_report_status(li->abs_path, MSG_SVC_START, NULL); cinit_cp_data(buf, li->abs_path); if(!path_append(buf, C_ON)) return; /* * Check for existence */ li->status = file_exists(buf); if(li->status == FE_NOT) { svc_report_status(li->abs_path, "Nothing to execute :-)", NULL); _exit(0); /* nothing there? fine! */ } if(li->status == FE_FILE) { /* FIXME: I guess this a) does nothing b) should do more than only signals */ set_signals(SIGSTAGE_CLIENT); execute_sth(buf); } else { /* any kind of error, reported by file_exists already */ _exit(1); } }