Permalink
Browse files

--

  • Loading branch information...
1 parent 0f0b584 commit 54347ee8959271b0e9e5c30a30359b16f79bcc99 @yasui0906 committed Nov 28, 2011
Showing with 254 additions and 221 deletions.
  1. +25 −147 libmtn.c
  2. +4 −3 mtn.h
  3. +12 −1 mtnd.c
  4. +213 −69 mtnexec.c
  5. +0 −1 mtnexec.h
View
172 libmtn.c
@@ -101,6 +101,17 @@ int getcount(int id)
return(r);
}
+int is_empty(STR str)
+{
+ if(!str){
+ return(1);
+ }
+ if(*str == 0){
+ return(1);
+ }
+ return(0);
+}
+
int is_numeric(STR str)
{
while(*str){
@@ -3102,10 +3113,12 @@ STR modstr(STR str, char *n)
STR catstr(STR str1, STR str2)
{
int len = 1;
- len += strlen(str1);
- len += strlen(str2);
- str1 = xrealloc(str1, len);
- strcat(str1, str2);
+ len += str1 ? strlen(str1) : 0;
+ len += str2 ? strlen(str2) : 0;
+ str1 = str1 ? xrealloc(str1, len) : xcalloc(len);
+ if(str2){
+ strcat(str1, str2);
+ }
return(str1);
}
@@ -3137,6 +3150,9 @@ STR dotstr(STR str)
STR basestr(STR str)
{
char buff[PATH_MAX];
+ if(is_empty(str)){
+ return(str);
+ }
strcpy(buff, str);
return(modstr(str, basename(buff)));
}
@@ -3250,125 +3266,13 @@ STR findarg(ARG arg, STR str)
return(NULL);
}
-static STR convarg3(STR arg, MTNJOB *job)
-{
- int n;
- int m;
- STR s;
- if(!strcmp(arg, "")){
- s = joinarg(job->argl, " ");
- arg = modstr(arg, s);
- s = clrstr(s);
- }else if(!strcmp(arg, "/")){
- s = joinarg(job->argl, " ");
- s = basestr(s);
- arg = modstr(arg, s);
- s = clrstr(s);
- }else if(!strcmp(arg, ".")){
- s = joinarg(job->argl, " ");
- s = dotstr(s);
- arg = modstr(arg, s);
- s = clrstr(s);
- }else if(!strcmp(arg, "/.")){
- s = joinarg(job->argl, " ");
- s = basestr(s);
- s = dotstr(s);
- arg = modstr(arg, s);
- s = clrstr(s);
- }else if(!strcmp(arg, "H")){
- if(job->svr){
- arg = modstr(arg, job->svr->host);
- }else{
- arg = modstr(arg, "local");
- }
- }else{
- errno = 0;
- n = strtol(arg, NULL, 10);
- for(m=0;job->argl[m];m++);
- if(!errno){
- arg = modstr(arg, (n < m) ? job->argl[n] : "");
- }else{
- s = newstr("{");
- s = catstr(s, arg);
- s = catstr(s, "}");
- arg = modstr(arg, s);
- clrstr(s);
- }
- }
- return(arg);
-}
-
-static STR convarg2(STR arg, MTNJOB *job)
-{
- int i;
- STR p;
- STR q;
- STR r;
- if(!job->argl || !arg){
- return(arg);
- }
- i = 0;
- p = newstr(arg);
- while(*(p + i)){
- if(*(p + i) == '}'){
- *(p + i) = 0;
- i++;
- q = newstr(p);
- r = newstr(p + i);
- q = convarg3(q, job);
- arg = modstr(arg, q);
- arg = catstr(arg, r);
- clrstr(q);
- clrstr(r);
- break;
- }
- i++;
- }
- clrstr(p);
- return(arg);
-}
-
-STR convarg(STR arg, MTNJOB *job)
+int cntarg(ARG arg)
{
- int i;
- STR p;
- STR q;
- if(!job->argl || !arg){
- return(arg);
- }
-
- i = 0;
- p = newstr(arg);
- while(*(p + i)){
- if(*(p + i) == '{'){
- *(p + i) = 0;
- i++;
- q = newstr(p + i);
- q = convarg2(q, job);
- arg = modstr(arg, p);
- arg = catstr(arg, q);
- p = modstr(p, arg);
- q = clrstr(q);
- continue;
- }
- i++;
- }
- clrstr(p);
- return(arg);
-}
-
-ARG cpconvarg(ARG arg, MTNJOB *job)
-{
- int i;
- ARG r = newarg(0);
- if(!arg){
- return(r);
- }
- for(i=0;arg[i];i++){
- r = addarg(r, arg[i]);
- r[i] = convarg(r[i], job);
+ int i = 0;
+ if(arg){
+ for(i=0;arg[i];i++);
}
- return(r);
+ return(i);
}
static int job_flush_stdout(MTNJOB *job)
@@ -3455,29 +3359,3 @@ int job_close(MTNJOB *job)
return(0);
}
-//
-// 引数リストを展開する
-// args: 引数リスト
-// argl: 展開パラメータ
-//
-ARG cmdargs(MTNJOB *job)
-{
- int i;
- ARG cmd = newarg(0);
- if(job->args){
- for(i=0;job->args[i];i++){
- if(job->conv){
- cmd = addarg(cmd, convarg(newstr(job->args[i]), job));
- }else{
- cmd = addarg(cmd, newstr(job->args[i]));
- }
- }
- }
- if(!job->conv && job->argl){
- for(i=0;job->argl[i];i++){
- cmd = addarg(cmd, job->argl[i]);
- }
- }
- return(cmd);
-}
-
View
7 mtn.h
@@ -200,6 +200,7 @@ typedef struct mtn_context
} MTN;
/*=========================================================================*/
+int is_empty(STR str);
int is_numeric(STR str);
int is_export(MTNSVR *svr);
int is_execute(MTNSVR *svr);
@@ -271,17 +272,17 @@ STR modstr(STR str, char *n);
STR clrstr(STR str);
STR catstr(STR str1, STR str2);
ARG splitstr(STR str, STR delim);
+STR dotstr(STR str);
+STR basestr(STR str);
ARG newarg(int c);
ARG addarg(ARG arg, STR str);
ARG clrarg(ARG args);
ARG copyarg(ARG args);
STR poparg(ARG args);
-STR convarg(STR arg, MTNJOB *job);
-ARG cpconvarg(ARG arg, MTNJOB *job);
STR joinarg(ARG args, STR delim);
STR findarg(ARG arg, STR str);
-ARG cmdargs(MTNJOB *job);
+int cntarg(ARG arg);
size_t set_mtnstatus_members(MTN *mtn);
size_t set_mtnstatus_debuginfo(MTN *mtn);
View
13 mtnd.c
@@ -27,6 +27,7 @@
#include <sys/epoll.h>
#include <sys/time.h>
#include <sys/wait.h>
+#include <sched.h>
MTN *mtn;
MTND *ctx;
@@ -1167,6 +1168,7 @@ void mtnd_child_exit(MTNTASK *kt)
void mtnd_child_fork(MTNTASK *kt, MTNJOB *job)
{
+ struct sched_param schparam;
int pp[3][2];
pipe(pp[0]);
pipe(pp[1]);
@@ -1196,7 +1198,6 @@ void mtnd_child_fork(MTNTASK *kt, MTNJOB *job)
return;
}
//===== exec process =====
- setpgid(0,0);
close(0);
close(1);
close(2);
@@ -1209,6 +1210,16 @@ void mtnd_child_fork(MTNTASK *kt, MTNJOB *job)
close(pp[1][1]);
close(pp[2][0]);
close(pp[2][1]);
+
+ mtn->logtype = 0;
+ mtn->logmode = MTNLOG_STDERR;
+ if(setpgid(0, 0) == -1){
+ mtnlogger(mtn, 0, "[error] %s: setpgid %s\n", __func__, strerror(errno));
+ }
+ schparam.sched_priority = 0;
+ if(sched_setscheduler(0, SCHED_BATCH, &schparam) == -1){
+ mtnlogger(mtn, 0, "[error] %s: setscheduler %s\n", __func__, strerror(errno));
+ }
execlp("sh", "sh", "-c", job->cmd, NULL);
mtnlogger(mtn, 0, "[error] %s: %s %s\n", __func__, strerror(errno), job->cmd);
_exit(127);
Oops, something went wrong.

0 comments on commit 54347ee

Please sign in to comment.