Esempio n. 1
0
/*
 * This is an in-fix recursive function called before s is started to
 * stop every service that depends on s, in reverse order *or* after s
 * was started to start again every service that depends on s. The
 * action parametere controls if this function should start or stop
 * the procceses that depends on s.
 * @param s A Service_T object
 * @param action An action to do on the dependant services
 */
static void do_depend(Service_T s, const char *action) {

  Service_T child;
  
  ASSERT(s);

  for(child= servicelist; child; child= child->next) {
    
    if(child->dependantlist) {

      Dependant_T d;
    
      for(d= child->dependantlist; d; d= d->next) {

	if(IS(d->dependant, s->name)) {
	
	  if(IS(action, "start"))
	    do_start(child);
          else if(IS(action, "monitor"))
	    do_monitor(child);
	
	  do_depend(child, action);
	
	  if(IS(action, "stop"))
	    do_stop(child);
          else if(IS(action, "unmonitor"))
	    do_unmonitor(child);

	  break;

	}
      }
    }
  }
}
Esempio n. 2
0
File: control.c Progetto: hafiz/yoke
/*
 * This is an in-fix recursive function called before s is started to
 * stop every service that depends on s, in reverse order *or* after s
 * was started to start again every service that depends on s. The
 * action parametere controls if this function should start or stop
 * the procceses that depends on s.
 * @param s A Service_T object
 * @param action An action to do on the dependant services
 */
static void do_depend(Service_T s, int action) {
  Service_T child;
  
  ASSERT(s);

  for (child = servicelist; child; child = child->next) {
    if (child->dependantlist) {
      Dependant_T d;
    
      for (d = child->dependantlist; d; d = d->next) {
	if (IS(d->dependant, s->name)) {
	  if (action == ACTION_START)
	    do_start(child);
          else if (action == ACTION_MONITOR)
	    do_monitor(child);
	  do_depend(child, action);
	  if (action == ACTION_STOP)
	    do_stop(child);
          else if (action == ACTION_UNMONITOR)
	    do_unmonitor(child);
	  break;
	}
      }
    }
  }
}
Esempio n. 3
0
/*
 * Generate dependencies for all files.
 */
int main(int argc, char **argv)
{
	int len;
	const char *hpath;

	hpath = getenv("HPATH");
	if (!hpath) {
		fputs("mkdep: HPATH not set in environment.  "
		      "Don't bypass the top level Makefile.\n", stderr);
		return 1;
	}

	add_path(".");		/* for #include "..." */

	while (++argv, --argc > 0) {
		if (strncmp(*argv, "-I", 2) == 0) {
			if (*((*argv)+2)) {
				add_path((*argv)+2);
			}
			else {
				++argv;
				--argc;
				add_path(*argv);
			}
		}
		else if (strcmp(*argv, "--") == 0) {
			break;
		}
	}

	add_path(hpath);	/* must be last entry, for config files */

	while (--argc > 0) {
		const char * filename = *++argv;
		const char * command  = __depname;
		g_filename = 0;
		len = strlen(filename);
		memcpy(depname, filename, len+1);
		if (len > 2 && filename[len-2] == '.') {
			if (filename[len-1] == 'c' || filename[len-1] == 'S') {
			    depname[len-1] = 'o';
			    g_filename = filename;
			    command = "";
			}
		}
		do_depend(filename, command);
	}
	if (len_precious) {
		*(str_precious+len_precious) = '\0';
		printf(".PRECIOUS:%s\n", str_precious);
	}
	return 0;
}
Esempio n. 4
0
/*
 * Generate dependencies for all files.
 */
int main(int argc, char **argv)
{
    int len;
    add_path(".");		/* for #include "..." */
    while (++argv, --argc > 0) {
        if (strncmp(*argv, "-I", 2) == 0) {
            if (*((*argv)+2) ) {
                add_path((*argv)+2);
            }
            else {
                ++argv;
                --argc;
            }
        }
        else if (strcmp(*argv, "--") == 0) {
            break;
        }
    }

    while (--argc > 0) {
        const char * filename = *++argv;
#if TOC_MODE
        const char * command  = "";
#else
        const char * command  = __depname;
#endif
        g_filename = 0;
        len = strlen(filename);
        memcpy(depname, filename, len+1);
        if (len > 2 && filename[len-2] == '.') {
            if (filename[len-1] == 'c' ||
                    filename[len-1] == 'S' ||
                    filename[len-1] == 'C') {
                depname[len-1] = 'o';
                g_filename = filename;
                command = "";
            }
        }
        else if (len > 3 && filename[len-3] == '.') {
            if (filename[len-2] == 'c' && filename[len-1] == 'c') {
                depname[len-2] = 'o';
                depname[len-1] = '\0';
                g_filename = filename;
                command = "";
            }
        }
        else if (len > 4 && filename[len-4] == '.') {
            if ( filename[len-3] == 'c'  &&  // check for c++/cxx/cpp
                    (
                        (filename[len-2] == '+' && filename[len-1] == '+') ||
                        (filename[len-2] == 'x' && filename[len-1] == 'x') ||
                        (filename[len-2] == 'p' && filename[len-1] == 'p')
                    )
               ) {
                depname[len-3] = 'o';
                depname[len-2] = '\0';
                g_filename = filename;
                command = "";
            }
        }
        do_depend(filename, command);
    }
    if (len_precious) {
        *(str_precious+len_precious) = '\0';
        printf(".PRECIOUS:%s\n", str_precious);
    }
    return 0;
}
Esempio n. 5
0
int main(int argc, char **argv)
{
    llist_t *paths,*src,*todo;
    set_t *incl;
    map_t *deps;

    if (argc < 2) {
        fprintf(stderr,"FastDep v%s for LAMMPS\n"
                "Usage: %s [-I <path> ...] -- <src1> [<src2> ...]\n",
                version,argv[0]);
        fprintf(stderr,"Supported extensions: %s, %s, %s\n",
                extensions[0], extensions[1], extensions[2]);
        return 1;
    }

    /* hash tables for all known included files and dependencies
     * we guesstimate a little over 2x as many entries as sources. */
    incl = set_init(2*argc);
    deps = map_init(2*argc);

    /* list of include search paths. prefixed by "." and "..". */
    paths = llist_init();
    llist_append(paths,".");
    llist_append(paths,"..");

    while (++argv, --argc > 0) {
        if (strncmp(*argv, "-I", 2) == 0) {
            if ((*argv)[2] != '\0') {
                llist_append(paths,trim_path(*argv+2));
            } else {
                ++argv;
                --argc;
                if (argc > 0) {
                    if (strcmp(*argv,"--") == 0) {
                        break;
                    } else {
                        llist_append(paths,trim_path(*argv));
                    }
                }
            }
        } else if (strcmp(*argv,"--") == 0) {
            break;
        } /* ignore all unrecognized arguments before '--'. */
    }

    src = llist_init();
    while (++argv, --argc > 0) {
        llist_append(src,*argv);
    }

    /* process files to look for includes */
    todo = llist_init();
    find_includes(src->head,todo,paths,incl,deps);
    find_includes(todo->head,todo,paths,incl,deps);
    llist_free(todo);

    fprintf(stdout,"# FastDep v%s for LAMMPS\n",version);
    fputs("# Search path: ",stdout);
    llist_print(paths);
    fprintf(stdout,"# % 5d sources\n# % 5d includes\n# % 5d depfiles\n",
            llist_size(src),set_size(incl),map_size(deps));

    set_free(incl);
    do_depend(src->head,deps);

    llist_free(src);
    llist_free(paths);
    map_free(deps);
    return 0;
}
Esempio n. 6
0
/*
 * Generate dependencies for all files.
 */
int32_t main(int32_t argc, char **argv)
{
  int32_t len;
  int32_t i;
  char path[4096];

  add_path(".");		/* for #include "..." */

  while (++argv, --argc > 0) {
    if (strncmp(*argv, "-I", 2) == 0) {
      if (*((*argv)+2)) {
	add_path((*argv)+2);
      } else {
	++argv;
	--argc;
	add_path(*argv);
      }
    }
    else if (strcmp(*argv, "--") == 0) {
      break;
    }
  }

  while (--argc > 0) {
    const char * filename = *++argv;
    const char * command  = __depname;
    g_filename = 0;
    len = strlen(filename);
    memcpy(depname, filename, len+1);
    if((len>2)&&(filename[len-2] =='.')&&
       (filename[len-1]=='c'||filename[len-1]=='S')){
      /* .c or .S files */
      depname[len-1] = 'o';
      g_filename = filename;
      command = "";
    }else if((len>4)&&(filename[len-4]=='.')&&(filename[len-3]=='c')&&
	     (filename[len-2]=='p')&&(filename[len-1]=='p')){
      /* .cpp files */
      depname[len-3] = 'o';
      depname[len-2] = 0;
      g_filename = filename;
      command = "";
    }
    do_depend(filename, command);
  }
  
  for(i=0;i<nPendingDeps;i++) {
    const char * filename = pendingDeps[i];
    const char * command  = __depname;
    g_filename = 0;
    len = strlen(filename);
    memcpy(depname, filename, len+1);

/*    fprintf(stderr,"[%s]\n",filename); */
    
    do_depend(filename, command);
  }

  for(i=0;i<nFoundDeps;i++) {
    int32_t j;
    
    if( foundDeps[i] == 0 )
      continue;
    
    j=1;
    while( foundDeps[i][j] ) {
      expandDeps(foundDeps[i][j]);
      j++;
    }
  }

  getcwd(path,4096);

#if 0
  {
    int32_t j=0;
    while( allDeps[j] ) {
      if (allDeps[j][0] == '/')
	printf(" %s",allDeps[j]);
      else
	printf(" %s/%s",path,allDeps[j]);
      j++;
    }
    printf("\n");
  }
#endif

  for(i=0;i<nFoundDeps;i++) {
    int32_t j;
    
    if( foundDeps[i] == 0 )
      continue;
    
    if( foundDeps[i][0][strlen(foundDeps[i][0])-1] != 'o' )
      continue;
    
    printf("$(OBJ)/%s:",foundDeps[i][0]);
    j=1;
    while( foundDeps[i][j] ) {
      if (foundDeps[i][j][0] == '/')
	printf(" %s",foundDeps[i][j]);
      else
	printf(" %s/%s",path,foundDeps[i][j]);
      j++;
    }
    printf("\n");
  }

  return 0;
}
Esempio n. 7
0
/**
 * Check to see if we should try to start/stop service
 * @param P A service name as stated in the config file
 * @param action A string describing the action to execute
 * @return TRUE if the service was handled successfully otherwise FALSE
 */
void check_service(const char *P, const char *action) {

  Service_T s= NULL;

  ASSERT(P);
  ASSERT(action);

  if(NULL==(s= get_service(P))) {
    log("%s: Cannot %s program '%s' -- not found in %s\n",
          prog, action, P, Run.controlfile);
    return;
  }

  if(IS(action, "start")) {
    
    if(s->type==TYPE_PROCESS && is_process_running(s)) {
      DEBUG("%s: Process already running -- process %s\n", prog, P);
      monitor_set(s);
      return;
    }
    
    if(s->type==TYPE_PROCESS && !s->start) {
      DEBUG("%s: Start method not defined -- process %s\n", prog, P);
      monitor_set(s);
      return;
    }
    
    do_depend(s, "stop");
    do_start(s);
    do_depend(s, "start");
    
  } else if(IS(action, "stop")) {
    
    if(s->type==TYPE_PROCESS && !s->stop) {
      DEBUG("%s: Stop method not defined -- process %s\n", prog, P);
      monitor_unset(s);
      return;
    }
    
    do_depend(s, "stop");
    do_stop(s);
    
  } else if(IS(action, "restart")) {
    
    if(s->type==TYPE_PROCESS && (!s->start || !s->stop)) {
      DEBUG("%s: Start or stop method not defined -- process %s\n", prog, P);
      monitor_set(s);
      return;
    } else {
      log("Trying to restart '%s'\n", s->name);
    }
    
    do_depend(s, "stop");
    if(do_stop(s)) {
      /* Only start if stop succeeded */
      do_start(s);
      do_depend(s, "start");
    }
    
  } else if(IS(action, "monitor")) {
    
    /* We only enable monitoring of this service and all prerequisite
     * services. Chain of services which depends on this service keep
     * its state */
    do_monitor(s);
    
  } else if(IS(action, "unmonitor")) {
    
    /* We disable monitoring of this service and all services which
     * depends on it */
    do_depend(s, "unmonitor");
    do_unmonitor(s);
    
  }
    
}
Esempio n. 8
0
File: control.c Progetto: hafiz/yoke
/**
 * Check to see if we should try to start/stop service
 * @param S A service name as stated in the config file
 * @param A An action id describing the action to execute
 * @return FALSE for error, otherwise TRUE
 */
int control_service(const char *S, int A) {
  Service_T s = NULL;

  ASSERT(S);

  if (! (s = Util_getService(S))) {
    LogError("%s: service '%s' -- doesn't exist\n", prog, S);
    return FALSE;
  }

  switch(A) {

    case ACTION_START:
      if (s->type == TYPE_PROCESS) {
        if (Util_isProcessRunning(s)) {
          DEBUG("%s: Process already running -- process %s\n", prog, S);
          Util_monitorSet(s);
          return TRUE;
        }
        if (!s->start) {
          LogError("%s: Start method not defined -- process %s\n", prog, S);
          Util_monitorSet(s);
          return FALSE;
        }
      }
      do_depend(s, ACTION_STOP);
      do_start(s);
      do_depend(s, ACTION_START);
      break;

    case ACTION_STOP:
      if (s->type == TYPE_PROCESS && !s->stop) {
        LogError("%s: Stop method not defined -- process %s\n", prog, S);
        Util_monitorUnset(s);
        return FALSE;
      }
      /* soft unmonitor and stop: */
      do_depend(s, ACTION_STOP);
      do_stop(s);
      /* hard unmonitor - will reset all counters and flags: */
      do_depend(s, ACTION_UNMONITOR);
      do_unmonitor(s);
      break;

    case ACTION_RESTART:
      if (s->type == TYPE_PROCESS && (!s->start || !s->stop)) {
        LogError("%s: Start or stop method not defined -- process %s\n", prog, S);
        Util_monitorSet(s);
        return FALSE;
      }
      LogInfo("'%s' trying to restart\n", s->name);
      do_depend(s, ACTION_STOP);
      if (do_stop(s)) {
        /* Only start if stop succeeded */
        do_start(s);
        do_depend(s, ACTION_START);
      } else {
        /* enable monitoring of this service again to allow the restart retry
         * in the next cycle up to timeout limit */
        Util_monitorSet(s);
      }
      break;

    case ACTION_MONITOR:
      /* We only enable monitoring of this service and all prerequisite
       * services. Chain of services which depends on this service keep
       * its state */
      do_monitor(s);
      break;

    case ACTION_UNMONITOR:
      /* We disable monitoring of this service and all services which
       * depends on it */
      do_depend(s, ACTION_UNMONITOR);
      do_unmonitor(s);
      break;

    default:
      LogError("%s: service '%s' -- invalid action %s\n", prog, S, A);
      return FALSE;
  }
  return TRUE;
}
Esempio n. 9
0
/*
 * Generate dependencies for all files.
 */
int main(int argc, char **argv)
{
	int len;
	const char *hpath;

	/* Initialize include hash tabel */
        init_dep();

	hpath = getenv("HPATH");
	if (!hpath) {
		fputs("mkdep: HPATH not set in environment.  "
		      "Don't bypass the top level Makefile.\n", stderr);
		return 1;
	}

	add_path(".");		/* for #include "..." */

	while (++argv, --argc > 0) {
		if (strncmp(*argv, "-I", 2) == 0) {
			if (*((*argv)+2)) {
				add_path((*argv)+2);
			}
			else {
				++argv;
				--argc;
				add_path(*argv);
			}
		}
		else if (strcmp(*argv, "--") == 0) {
			break;
		}
	}

	add_path(hpath);	/* must be last entry, for config files */

	while (--argc > 0) {
		const char * filename = *++argv;
		int i;
		g_filename = 0;
		len = strlen(filename);
		memcpy(depname, filename, len+1);
		if (len > 2 && filename[len-2] == '.') {
			if (filename[len-1] == 'c' || filename[len-1] == 'S') {
			    depname[len-1] = 'o';
			    g_filename = filename;
			}
		}
		nb_include = 0;

                /*
		 * print the base dependancy between the .o and .c file.
		 */
		if (depname[len-1] == 'h') {
			continue;
		}
		printf("%s: %s", depname,filename);

		/*
		 * do basic dependancies on the C source file.
		 */
                handling_includes = 0;
		do_depend(filename);

		/*
		 * recurse dependancies on the included files.
		 * Warning, nb_include will grow over the loop.
		 */
                handling_includes = 1;
		for (i = 0;i < nb_include;i++) {
		    filename = include_list[i];
		    /*
		     * check the hash for existing dependencies.
		     * !!!
		     */
		    if (handling_includes) {
		        current_include = add_inc((char *)filename);
		        if (current_include->nb_includes >= 0) {
			    int i;

			    /*
			     * do not load and parse the file,
                             * dump the cache instead.
			     */
		            for (i = 0;i < current_include->nb_includes;i++)
                                add_local_include(current_include->includes[i]);

                            continue;
		        }
		    }
		    current_include = NULL;
		    do_depend(filename);
		}

                /*
		 * dump the dependancies found.
		 */
		for (i = 0;i < nb_include;i++)
			printf(" \\\n   %s", include_list[i]);
		printf("\n");
	}

	return 0;
}