KVServer::KVServer()
{
	// Initialize our hash table
	MallocFactory* mf = standard_malloc_factory_init();
	hash_table_init(&db, mf, hash, cmp);

	// Create the server's socket
	sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
	if (sock == -1) {
		fprintf(stderr, "(KeyValueServer) Failed to open server socket!\n");
		exit(1);
	}

	bzero((char*)&server_addr, sizeof(server_addr));
	server_addr.sin_family = AF_INET;
	server_addr.sin_port = htons(KEYVAL_PORT);
	server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
	if (bind(sock, (sockaddr*)&server_addr, sizeof(server_addr)) == -1) {
		fprintf(stderr, "(KeyValueServer) Failed to bind server socket!\n");
		exit(1);
	}
}
Exemple #2
0
hash_table_t * load_alts(const char * path, size_t hs, char a[][BUFSIZ]) {
  char           buffer[BUFSIZ];
  FILE *         alts_file;
  hash_table_t * hash_table;
  uint32_t       i, j, k;

  hash_table = hash_table_init(hs);
  alts_file  = fopen(path, "r");

  for (i = 0; i < NUMA; i++) {
    fgets(buffer, BUFSIZ, alts_file);
    char * key = malloc(BUFSIZ);
    char * val = malloc(BUFSIZ);
    memset(key, '\0', BUFSIZ);
    memset(val, '\0', BUFSIZ);
    for (j = 0; j < BUFSIZ; j++) {
      if (buffer[j] == ',') {
        key[j] = '\0';
        break;
      }
      key[j] = buffer[j];
    }
    for (k = j + 1; k < BUFSIZ; k++) {
      if (buffer[k] == '\n') {
        val[k-j-1] = '\0';
        break;
      }
      val[k-j-1] = buffer[k];
      if (buffer[k] == '\0') break;
    }
    snprintf(a[i], BUFSIZ, "%s", key);
    key_val_t * kv = make_kv(key, strlen(key)+1, val, strlen(val)+1);
    hash_table_insert(hash_table, kv);
    free(kv);
  }

  fclose(alts_file);
  return hash_table;
}
Exemple #3
0
int pkg_hash_init(const char *name, hash_table_t *hash, int len)
{
  return hash_table_init(name, hash, len);
}
Exemple #4
0
int main(int argc, char **argv)
{
	int n, a, b, choice, ris, i, j;
	int *path;
	char tmp1[MAX_STR], tmp2[MAX_STR];
	Hash_table ht;
	Graph g;
	FILE *fp;

	if(argc < 2){
		fprintf(stderr, "Parameters error!\nUsage: %s <input file>\n", argv[0]);
		return -1;
	}

	if((fp=fopen(argv[1], "r")) == NULL){
		fprintf(stderr, "Can't open file %s\n", argv[1]);
		return -2;
	}

	fscanf(fp, "%d", &n);
	ht = hash_table_init(n);
	g  = graph_init(n);

	while(fscanf(fp, "%s %s", tmp1, tmp2) == 2)
	{
		if((a = hash_table_get(ht, tmp1)) == -1)
			a = hash_table_insert(ht, tmp1);
		if((b = hash_table_get(ht, tmp2)) == -1)
			b = hash_table_insert(ht, tmp2);
		graph_insert(g, create_edge(a,b));
	}
	fclose(fp);

	printf( "===== G R A P H =====\n"
		"1 - Shortest simple path between two nodes\n"
		"2 - Longest simple path between two nodes\n"
		"3 - Number of all simple paths between two nodes\n"
		"4 - Show strong connected nodes\n"
		"5 - Show edges to strong connect the graph\n"
		"6 - Exit\n");

	do{
		printf("\nChoice: ");
		scanf("%d", &choice);
		switch(choice)
		{
			case 1:
				printf("Start node: ");
				scanf("%s", tmp1);
				printf("End node:   ");
				scanf("%s", tmp2);
				if(hash_table_get(ht, tmp1) != -1 && hash_table_get(ht, tmp2) != -1)
				{
					ris = graph_get_shortest_path(g, hash_table_get(ht, tmp1), hash_table_get(ht, tmp2), &path);
					if(ris > 0)
					{
						printf("\nDistance = %d\n\nPath:\n", ris);
						for(i=0; i<=ris; i++)
							printf("%s\n", hash_table_get_name(ht, path[i]));
						free(path);
					}
					else
						printf("There is no path between these two nodes\n");
				}
				else
					printf("Error, inexistent nodes\n");
			break;

			case 2:
				printf("Start node: ");
				scanf("%s", tmp1);
				printf("End node:   ");
				scanf("%s", tmp2);
				if(hash_table_get(ht, tmp1) != -1 && hash_table_get(ht, tmp2) != -1)
				{
					ris = graph_get_longest_path(g, hash_table_get(ht, tmp1), hash_table_get(ht, tmp2), &path);
					if(ris > 0)
					{
						printf("\nDistance = %d\n\nPath:\n", ris);
						for(i=0; i<=ris; i++)
							printf("%s\n", hash_table_get_name(ht, path[i]));
						free(path);
					}
					else
						printf("There is no path between these two nodes\n");
				} 
				else
					printf("Error, inexistent nodes\n");
			break;
			
			case 3:
				printf("Start node: ");
				scanf("%s", tmp1);
				printf("End node:   ");
				scanf("%s", tmp2);
				if(hash_table_get(ht, tmp1) != -1 && hash_table_get(ht, tmp2) != -1)
					printf("Number of simple paths: %d\n",
							graph_number_of_simple_path(g, hash_table_get(ht, tmp1), hash_table_get(ht, tmp2)));	
				else
					printf("Error, inexistent nodes\n");
			break;
			case 4:
				path = graph_get_scc(g);
				//for every scc group
				for(i=0; i<n; i++)
				{
					a = 0;	//counter
					for(j=0; j<n; j++)
						if(path[j] == i)
						{
							printf("%s\n", hash_table_get_name(ht, j));
							a++;
						}
					if(a != 0)
						printf("============\n");
					else
						break;
				}
			break;
		}
	}while(choice != 6);

	hash_table_destroy(ht);
	graph_destroy(g);

	return 0;
}
Exemple #5
0
int main(int argc, char **argv)
{
    int c;                      /* command line arg */
    int server_s;                   /* boa socket */

    /* set umask to u+rw, u-x, go-rwx */
    c = umask(~0600);
    if (c == -1) {
        perror("umask");
        exit(1);
    }

    devnullfd = open("/dev/null", 0);

    /* make STDIN and STDOUT point to /dev/null */
    if (devnullfd == -1) {
        DIE("can't open /dev/null");
    }
#if 0
    if (dup2(devnullfd, STDIN_FILENO) == -1) {
        DIE("can't dup2 /dev/null to STDIN_FILENO");
    }

    if (dup2(devnullfd, STDOUT_FILENO) == -1) {
        DIE("can't dup2 /dev/null to STDOUT_FILENO");
    }
#endif

    /* but first, update timestamp, because log_error_time uses it */
    (void) time(&current_time);

    while ((c = getopt(argc, argv, "c:r:d")) != -1) {
        switch (c) {
        case 'c':
            if (server_root)
                free(server_root);
            server_root = strdup(optarg);
            if (!server_root) {
                perror("strdup (for server_root)");
                exit(1);
            }
            break;
        case 'r':
            if (chdir(optarg) == -1) {
                log_error_time();
                perror("chdir (to chroot)");
                exit(1);
            }
            if (chroot(optarg) == -1) {
                log_error_time();
                perror("chroot");
                exit(1);
            }
            if (chdir("/") == -1) {
                log_error_time();
                perror("chdir (after chroot)");
                exit(1);
            }
            break;
        case 'd':
            do_fork = 1;
            break;
        default:
            fprintf(stderr, "Usage: %s [-c serverroot] [-r chroot] [-d] [-b] [-q bitrate]\n", argv[0]);
            exit(1);
        }
    }

#ifdef DAVINCI_IPCAM
	if(ApproDrvInit(BOA_MSG_TYPE) < 0){
		exit(1);
	}
	//printf("func_get_mem Begin\n");
    if (func_get_mem(NULL)) {
        ApproDrvExit();
        exit(1);
    }
	//printf("SysDrvInit Begin\n");

	if(SysDrvInit(SYS_BOA_MSG) < 0){
        ApproDrvExit();
        exit(1);
	}
	//printf("InitFileMsgDrv Begin\n");

    if (InitFileMsgDrv(FILE_MSG_KEY, FILE_BOA_MSG) < 0) {
	ApproDrvExit();
	SysDrvExit();
	exit(1);
    }
	//printf("hash_table_init Begin\n");

    if (hash_table_init() < 0) {
        exit(1);
    }
	//printf("arg_hash_table_init Begin\n");

    if(arg_hash_table_init() < 0) {
        exit(1);
    }
	//printf("uri_hash_table_init Begin\n");

    if(uri_hash_table_init() < 0) {
        exit(1);
    }
	
#endif

#ifdef PSIA_MEDIA
	//printf("psia_uri_hash_table_init Begin\n");

    if(psia_uri_hash_table_init() < 0) {
        exit(1);
    }
#endif
	//printf("fixup_server_root Begin\n");

    fixup_server_root();
	printf("read_config_files Begin\n");
    read_config_files();
#ifdef DAVINCI_IPCAM
    {
    //printf("ControlSystemData Begin\n");
        unsigned short value;
		#if 1
        if (ControlSystemData(SFIELD_GET_HTTPPORT, (void *)&value, sizeof(value)) >= 0)
            server_port = value;
		#endif
		
		dbg("server_port=%d\n", server_port);
    }
#endif
    open_logs();
    server_s = create_server_socket();
    init_signals();
    drop_privs();
    create_common_env();
    build_needs_escape();
	

    if (max_connections < 1) {
        struct rlimit rl;

        /* has not been set explicitly */
        c = getrlimit(RLIMIT_NOFILE, &rl);
        if (c < 0) {
            perror("getrlimit");
            exit(1);
        }
        max_connections = rl.rlim_cur;
    }
	

    /* background ourself */
    if (do_fork) {
        switch(fork()) {
        case -1:
            /* error */
            perror("fork");
            exit(1);
            break;
        case 0:
            /* child, success */
            break;
        default:
            /* parent, success */
            exit(0);
            break;
        }
    }
	

	/* Ask system server to start upnp */
	//system("/opt/dvr/boot_proc 2\n");//add by sxh upnp

    /* main loop */
    timestamp();

    status.requests = 0;
    status.errors = 0;

    start_time = current_time;
    select_loop(server_s);
    return 0;
}
Exemple #6
0
/***********************************************************************
 * Creates and links a new module to a process
 */
struct module* module_new(struct process* pcs, const WCHAR* name,
                          enum module_type type, BOOL virtual,
                          DWORD64 mod_addr, DWORD64 size,
                          unsigned long stamp, unsigned long checksum)
{
    struct module*      module;
    unsigned            i;

    assert(type == DMT_ELF || type == DMT_PE || type == DMT_MACHO);
    if (!(module = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*module))))
	return NULL;

    module->next = pcs->lmodules;
    pcs->lmodules = module;

    TRACE("=> %s %s-%s %s\n",
          get_module_type(type, virtual),
	  wine_dbgstr_longlong(mod_addr), wine_dbgstr_longlong(mod_addr + size),
          debugstr_w(name));

    pool_init(&module->pool, 65536);

    module->process = pcs;
    module->module.SizeOfStruct = sizeof(module->module);
    module->module.BaseOfImage = mod_addr;
    module->module.ImageSize = size;
    module_set_module(module, name);
    module->module.ImageName[0] = '\0';
    lstrcpynW(module->module.LoadedImageName, name, sizeof(module->module.LoadedImageName) / sizeof(WCHAR));
    module->module.SymType = SymNone;
    module->module.NumSyms = 0;
    module->module.TimeDateStamp = stamp;
    module->module.CheckSum = checksum;

    memset(module->module.LoadedPdbName, 0, sizeof(module->module.LoadedPdbName));
    module->module.CVSig = 0;
    memset(module->module.CVData, 0, sizeof(module->module.CVData));
    module->module.PdbSig = 0;
    memset(&module->module.PdbSig70, 0, sizeof(module->module.PdbSig70));
    module->module.PdbAge = 0;
    module->module.PdbUnmatched = FALSE;
    module->module.DbgUnmatched = FALSE;
    module->module.LineNumbers = FALSE;
    module->module.GlobalSymbols = FALSE;
    module->module.TypeInfo = FALSE;
    module->module.SourceIndexed = FALSE;
    module->module.Publics = FALSE;

    module->reloc_delta       = 0;
    module->type              = type;
    module->is_virtual        = virtual;
    for (i = 0; i < DFI_LAST; i++) module->format_info[i] = NULL;
    module->sortlist_valid    = FALSE;
    module->sorttab_size      = 0;
    module->addr_sorttab      = NULL;
    module->num_sorttab       = 0;
    module->num_symbols       = 0;

    vector_init(&module->vsymt, sizeof(struct symt*), 128);
    /* FIXME: this seems a bit too high (on a per module basis)
     * need some statistics about this
     */
    hash_table_init(&module->pool, &module->ht_symbols, 4096);
    hash_table_init(&module->pool, &module->ht_types,   4096);
    vector_init(&module->vtypes, sizeof(struct symt*),  32);

    module->sources_used      = 0;
    module->sources_alloc     = 0;
    module->sources           = 0;
    wine_rb_init(&module->sources_offsets_tree, &source_rb_functions);

    return module;
}
Exemple #7
0
/* Open a network interface to look at packets on the network */
int pksh_pkopen (int argc, char * argv [])
{
  /* GNU long options */
  static struct option const long_options [] =
    {
      { "help",           no_argument,       NULL, 'h' },
      { "snapshot",       required_argument, NULL, 's' },
      { "promiscuous",    no_argument,       NULL, 'p' },
      { "timeout",        required_argument, NULL, 't' },

      { "hardware-size",  required_argument, NULL,  128 },
      { "ip-size" ,       required_argument, NULL,  129 },
      { "hostname-size",  required_argument, NULL,  130 },

      { "hw",             required_argument, NULL,  128 },
      { "ip",             required_argument, NULL,  129 },
      { "ht",             required_argument, NULL,  130 },

      { NULL,             0,                 NULL,  0 }
    };

  int option;

  /* Local variables */
  int rc = 0;
  char * name = NULL;
  int as_parameter = 0;

  int snapshot = DEFAULT_SNAPSHOT;
  int promiscuous = 1;
  int timeout = DEFAULT_TIMEOUT;
  int hwsize = DEFAULT_HW_SIZE;
  int ipsize = DEFAULT_IP_SIZE;
  int hostsize = DEFAULT_HOST_SIZE;

  char ebuf [PCAP_ERRBUF_SIZE] = { '\0' };
  char * ptrptr;

  /* pcap descriptor */
  pcap_t * pcap = NULL;
  interface_t * interface;

  /* BPF filter */
  char * filter = NULL;

  /* Parse command line options */
#define OPTSTRING "hs:pt:"

  optind = 0;
  optarg = NULL;
  while ((option = getopt_long (argc, argv, OPTSTRING, long_options, NULL)) != -1)
    {
      switch (option)
	{
	default:  usage (argv [0]); return -1;

	case 'h': usage (argv [0]); return 0;

	case 's': snapshot = atoi (optarg); break;
	case 'p': promiscuous = 0;          break;
	case 't': timeout = atoi (optarg);  break;

	case 128: hwsize = atoi (optarg);   break;
	case 129: ipsize = atoi (optarg);   break;
	case 130: hostsize = atoi (optarg); break;
	}
    }

  /* Check if the user has specified one (or more) parameters */
  if (optind >= argc)
    {
      /* None chosen via command line parameters, then find a suitable interface using pcap_lookupdev() */
      if (! (name = pcap_lookupdev (ebuf)))
	{
	  printf ("Unable to locate the default interface (%s).\n", ebuf);
	  if (getuid () && geteuid ())
	    printf ("Maybe you do not have permissions to look at packets on the network\n"),
	      printf ("since opening a network interface in promiscuous mode is a privileged operation\n");
	  else
	    printf ("Please obtain the list of all suitable interfaces via the 'lsdev' command,\n"),
	      printf ("then issue again this command passing the interface name as parameter\n");
	  return -1;
	}
      printf ("interface %s has been chosen by default for packet sniffing\n", name);
      as_parameter = 0;
    }
  else
    {
      int roomsize = 0;

      as_parameter = 1;

      /* More than one interface may be specified in a comma separated list */
      name = strtok_r (argv [optind ++], ",", & ptrptr);

      /* Build a filter from all remaining command line arguments */
      roomsize = 0;
      filter = NULL;
      while (optind < argc)
	{
	  roomsize += (strlen (argv [optind]) + 1 + 1);
	  filter = realloc (filter, roomsize);
	  strcat (filter, argv [optind ++]);
	  if (optind != argc - 1)
	    strcat (filter, " ");
	}
    }

  /* Start processing first interface */
  while (name)
    {
      /*
       * Lookup for the given name in the table of enabled interfaces
       * (to avoid multiple open on the same network interface)
       */
      if ((interface = intfbyname (interfaces, name)))
	printf ("%s: interface %s already enabled for packet capturing. Skipping it!\n", argv [0], name);
      else
	{
	  /* Time to initialize pcap library for the specified interface */
	  if (! (pcap = pcap_open_live (name, snapshot, promiscuous, timeout, ebuf)))
	    {
	      rc = -1;
	      printf ("%s: cannot open interface %s (%s)\n", argv [0], name, ebuf);
	    }
	  else
	    {
	      /* Get a new descriptor and save current parameters to the table of interfaces managed by this program */
	      if (! (interfaces = intfadd (interfaces, name, snapshot, promiscuous, timeout, filter, pcap, & interface)))
		{
		  rc = -1;
		  printf ("Sorry! There is no space left. Too many open network interfaces\n");

		  /* Release the pcap descriptor */
		  pcap_close (pcap);
		}
	      else
		{
		  /* Initialize the hash tables for host management */
		  interface -> hwnames . size = hwsize;
		  hash_table_init (& interface -> hwnames);

		  interface -> ipnames . size = ipsize;
		  hash_table_init (& interface -> ipnames);

		  interface -> hostnames . size = hostsize;
		  hash_table_init (& interface -> hostnames);

		  /* Keep track of the last active interface */
		  setactiveintf (interface);

		  /* Update user prompt to include the active interface */
		  pkshprompt (name);
		}
	    }
	}

      /* Process next interface (if any) */
      name = as_parameter ? strtok_r (NULL, ",", & ptrptr) : NULL;
    }

  if (filter)
    free (filter);

  return rc;
}
Exemple #8
0
struct hash_table* hash_table_create(hash_fn_t hash_fn, eql_fn_t eql_fn)
{
    struct hash_table* ht = calloc(1, sizeof(*ht));
    hash_table_init(ht, hash_fn, eql_fn, HASH_TABLE_DEFAULT_INITIAL_CAPACITY);
    return ht;
}
int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
{
     int err;
     char *tmp_dir_base;
     nv_pair_list_t tmp_dest_nv_pair_list;
     char * lists_dir =NULL;
     glob_t globbuf;
     char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
     char *pending_dir  =NULL;

     memset(conf, 0, sizeof(ipkg_conf_t));

     pkg_src_list_init(&conf->pkg_src_list);

     nv_pair_list_init(&tmp_dest_nv_pair_list);
     pkg_dest_list_init(&conf->pkg_dest_list);

     nv_pair_list_init(&conf->arch_list);

     conf->restrict_to_default_dest = 0;
     conf->default_dest = NULL;


     if (args->tmp_dir)
	  tmp_dir_base = args->tmp_dir;
     else 
	  tmp_dir_base = getenv("TMPDIR");
     sprintf_alloc(&conf->tmp_dir, "%s/%s",
		   tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE,
		   IPKG_CONF_TMP_DIR_SUFFIX);
     conf->tmp_dir = mkdtemp(conf->tmp_dir);
     if (conf->tmp_dir == NULL) {
	  fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
		  __FUNCTION__, conf->tmp_dir, strerror(errno));
	  return errno;
     }

     conf->force_depends = 0;
     conf->force_defaults = 0;
     conf->force_overwrite = 0;
     conf->force_downgrade = 0;
     conf->force_reinstall = 0;
     conf->force_space = 0;
     conf->force_removal_of_essential_packages = 0;
     conf->force_removal_of_dependent_packages = 0;
     conf->nodeps = 0;
     conf->verbose_wget = 0;
     conf->ipkg_libdir = NULL;
     conf->offline_root = NULL;
     conf->offline_root_pre_script_cmd = NULL;
     conf->offline_root_post_script_cmd = NULL;
     conf->multiple_providers = 0;
     conf->verbosity = 1;
     conf->noaction = 0;

     conf->http_proxy = NULL;
     conf->ftp_proxy = NULL;
     conf->no_proxy = NULL;
     conf->proxy_user = NULL;
     conf->proxy_passwd = NULL;

     pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN);
     hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
     hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
     lists_dir=(char *)malloc(1);
     lists_dir[0]='\0';
     if (args->conf_file) {
	  struct stat stat_buf;
	  err = stat(args->conf_file, &stat_buf);
	  if (err == 0)
	       if (ipkg_conf_parse_file(conf, args->conf_file,
				    &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
                   /* Memory leakage from ipkg_conf_parse-file */
                   return -1;
               }
                   
     }

     /* if (!lists_dir ){*/
     if (strlen(lists_dir)<=1 ){
	     if (args->ipkg_libdir) {
		     lists_dir = realloc(lists_dir,strlen(args->ipkg_libdir)+strlen("/lists")+2);
		     sprintf (lists_dir,"%s/lists",args->ipkg_libdir);
	     }else if (conf->ipkg_libdir) {
		     lists_dir = realloc(lists_dir,strlen(conf->ipkg_libdir)+strlen("/lists")+2);
		     sprintf (lists_dir,"%s/lists",conf->ipkg_libdir);
	     }else{
		     lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2);
		     sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR);
	     }
     }

     if (args->offline_root) {
            char *tmp = malloc(strlen(lists_dir) + strlen(args->offline_root) + 1);
            sprintf_alloc(&tmp, "%s/%s",args->offline_root,lists_dir);
            free(lists_dir);
            lists_dir = tmp;
     }

     pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
     snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");

     conf->lists_dir = strdup(lists_dir);
     conf->pending_dir = strdup(pending_dir);

     if (args->offline_root) 
	  sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root);
     memset(&globbuf, 0, sizeof(globbuf));
     err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf);
     if (!err) {
	  int i;
	  for (i = 0; i < globbuf.gl_pathc; i++) {
	       if (globbuf.gl_pathv[i]) 
		    if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i], 
				         &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
                        /* Memory leakage from ipkg_conf_parse-file */
                        return -1;
	            }
	  }
     }
     globfree(&globbuf);

     /* if no architectures were defined, then default all, noarch, and host architecture */
     if (nv_pair_list_empty(&conf->arch_list)) {
	  nv_pair_list_append(&conf->arch_list, "all", "1");
	  nv_pair_list_append(&conf->arch_list, "noarch", "1");
	  nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
     }

     /* Even if there is no conf file, we'll need at least one dest. */
     if (tmp_dest_nv_pair_list.head == NULL) {
	  nv_pair_list_append(&tmp_dest_nv_pair_list,
			      IPKG_CONF_DEFAULT_DEST_NAME,
			      IPKG_CONF_DEFAULT_DEST_ROOT_DIR);
     }

     /* After parsing the file, set options from command-line, (so that
	command-line arguments take precedence) */
     /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c
	really needs to be cleaned up. There is so much duplication
	right now it is ridiculous. Maybe ipkg_conf_t should just save
	a pointer to args_t (which could then not be freed), rather
	than duplicating every field here? */
     if (args->force_depends) {
	  conf->force_depends = 1;
     }
     if (args->force_defaults) {
	  conf->force_defaults = 1;
     }
     if (args->force_overwrite) {
	  conf->force_overwrite = 1;
     }
     if (args->force_downgrade) {
	  conf->force_downgrade = 1;
     }
     if (args->force_reinstall) {
	  conf->force_reinstall = 1;
     }
     if (args->force_removal_of_dependent_packages) {
	  conf->force_removal_of_dependent_packages = 1;
     }
     if (args->force_removal_of_essential_packages) {
	  conf->force_removal_of_essential_packages = 1;
     }
     if (args->nodeps) {
	  conf->nodeps = 1;
     }
     if (args->noaction) {
	  conf->noaction = 1;
     }
     if (args->query_all) {
	  conf->query_all = 1;
     }
     if (args->verbose_wget) {
	  conf->verbose_wget = 1;
     }
     if (args->multiple_providers) {
	  conf->multiple_providers = 1;
     }
     if (args->verbosity != conf->verbosity) {
	  conf->verbosity = args->verbosity;
     } 

     ipkg_conf_override_string(&conf->ipkg_libdir, 
			       args->ipkg_libdir);
     ipkg_conf_override_string(&conf->offline_root, 
			       args->offline_root);
     ipkg_conf_override_string(&conf->offline_root_pre_script_cmd, 
			       args->offline_root_pre_script_cmd);
     ipkg_conf_override_string(&conf->offline_root_post_script_cmd, 
			       args->offline_root_post_script_cmd);

/* Pigi: added a flag to disable the checking of structures if the command does not need to 
         read anything from there.
*/
     if ( !(args->nocheckfordirorfile)){
        /* need to run load the source list before dest list -Jamey */
        if ( !(args->noreadfeedsfile))
           set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
   
        /* Now that we have resolved conf->offline_root, we can commit to
	   the directory names for the dests and load in all the package
	   lists. */
        set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
   
        if (args->dest) {
	     err = ipkg_conf_set_default_dest(conf, args->dest);
	     if (err) {
	          return err;
	     }
        }
     }
     nv_pair_list_deinit(&tmp_dest_nv_pair_list);
     free(lists_dir);
     free(pending_dir);

     return 0;
}
Exemple #10
0
/***********************************************************************
 * Creates and links a new module to a process 
 */
struct module* module_new(struct process* pcs, const char* name, 
                          enum module_type type, BOOL virtual,
                          unsigned long mod_addr, unsigned long size,
                          unsigned long stamp, unsigned long checksum) 
{
    struct module*      module;

    assert(type == DMT_ELF || type == DMT_PE);
    if (!(module = HeapAlloc(GetProcessHeap(), 0, sizeof(*module))))
	return NULL;

    memset(module, 0, sizeof(*module));

    module->next = pcs->lmodules;
    pcs->lmodules = module;

    TRACE("=> %s %08lx-%08lx %s\n", 
          get_module_type(type, virtual), mod_addr, mod_addr + size, name);

    pool_init(&module->pool, 65536);
    
    module->module.SizeOfStruct = sizeof(module->module);
    module->module.BaseOfImage = mod_addr;
    module->module.ImageSize = size;
    module_fill_module(name, module->module.ModuleName,
                       sizeof(module->module.ModuleName));
    module->module.ImageName[0] = '\0';
    lstrcpynA(module->module.LoadedImageName, name, sizeof(module->module.LoadedImageName));
    module->module.SymType = SymNone;
    module->module.NumSyms = 0;
    module->module.TimeDateStamp = stamp;
    module->module.CheckSum = checksum;

    memset(module->module.LoadedPdbName, 0, sizeof(module->module.CVData));
    module->module.CVSig = 0;
    memset(module->module.CVData, 0, sizeof(module->module.CVData));
    module->module.PdbSig = 0;
    memset(&module->module.PdbSig70, 0, sizeof(module->module.PdbSig70));
    module->module.PdbAge = 0;
    module->module.PdbUnmatched = FALSE;
    module->module.DbgUnmatched = FALSE;
    module->module.LineNumbers = FALSE;
    module->module.GlobalSymbols = FALSE;
    module->module.TypeInfo = FALSE;
    module->module.SourceIndexed = 0;
    module->module.Publics = 0;

    module->type              = type;
    module->is_virtual        = virtual ? TRUE : FALSE;
    module->sortlist_valid    = FALSE;
    module->addr_sorttab      = NULL;
    /* FIXME: this seems a bit too high (on a per module basis)
     * need some statistics about this
     */
    hash_table_init(&module->pool, &module->ht_symbols, 4096);
    hash_table_init(&module->pool, &module->ht_types,   4096);
    vector_init(&module->vtypes, sizeof(struct symt*),  32);

    module->sources_used      = 0;
    module->sources_alloc     = 0;
    module->sources           = 0;

    return module;
}
Exemple #11
0
int slang_init_sym_table() {
    symTable = hash_table_init(sizeof(const char*), sym_hash, sym_key_compare, sym_val_free);
    return symTable != 0;
}
int
main(int argc, char **argv)
{
	char *envstr, **cmd_argv, **targv;
	int i, ret, cmd_argc;
	struct passwd *pw;
	struct stat st;
	char fpath[MAXPATHLEN];

	tzset();

	TAILQ_INIT(&cvs_variables);
	SLIST_INIT(&repo_locks);
	SLIST_INIT(&temp_files);

	hash_table_init(&created_directories, 100);
	hash_table_init(&created_cvs_directories, 100);

	/* check environment so command-line options override it */
	if ((envstr = getenv("CVS_RSH")) != NULL)
		cvs_rsh = envstr;

	if (((envstr = getenv("CVSEDITOR")) != NULL) ||
	    ((envstr = getenv("VISUAL")) != NULL) ||
	    ((envstr = getenv("EDITOR")) != NULL))
		cvs_editor = envstr;

	if ((envstr = getenv("CVSREAD")) != NULL)
		cvs_readonly = 1;

	if ((envstr = getenv("CVSREADONLYFS")) != NULL) {
		cvs_readonlyfs = 1;
		cvs_nolog = 1;
	}

	if ((cvs_homedir = getenv("HOME")) == NULL) {
		if ((pw = getpwuid(getuid())) != NULL)
			cvs_homedir = pw->pw_dir;
	}

	if ((envstr = getenv("TMPDIR")) != NULL)
		cvs_tmpdir = envstr;

	ret = cvs_getopt(argc, argv);

	argc -= ret;
	argv += ret;
	if (argc == 0)
		usage();

	cmdp = cvs_findcmd(argv[0]);
	if (cmdp == NULL) {
		fprintf(stderr, "Unknown command: `%s'\n\n", argv[0]);
		fprintf(stderr, "CVS commands are:\n");
		for (i = 0; cvs_cdt[i] != NULL; i++)
			fprintf(stderr, "\t%-16s%s\n",
			    cvs_cdt[i]->cmd_name, cvs_cdt[i]->cmd_descr);
		exit(1);
	}

	/*
	 * check the tmp dir, either specified through
	 * the environment variable TMPDIR, or via
	 * the global option -T <dir>
	 */
	if (stat(cvs_tmpdir, &st) == -1)
		fatal("stat failed on `%s': %s", cvs_tmpdir, strerror(errno));
	else if (!S_ISDIR(st.st_mode))
		fatal("`%s' is not valid temporary directory", cvs_tmpdir);

	if (cvs_readrc == 1 && cvs_homedir != NULL) {
		cvs_read_rcfile();

		if (cvs_defargs != NULL) {
			if ((targv = cvs_makeargv(cvs_defargs, &i)) == NULL)
				fatal("failed to load default arguments to %s",
				    __progname);

			cvs_getopt(i, targv);
			cvs_freeargv(targv, i);
			xfree(targv);
		}
	}

	/* setup signal handlers */
	signal(SIGTERM, sighandler);
	signal(SIGINT, sighandler);
	signal(SIGHUP, sighandler);
	signal(SIGABRT, sighandler);
	signal(SIGALRM, sighandler);
	signal(SIGPIPE, sighandler);

	cvs_cmdop = cmdp->cmd_op;

	cmd_argc = cvs_build_cmd(&cmd_argv, argv, argc);

	cvs_file_init();

	if (cvs_cmdop == CVS_OP_SERVER) {
		cmdp->cmd(cmd_argc, cmd_argv);
		cvs_cleanup();
		return (0);
	}

	cvs_umask = umask(0);
	umask(cvs_umask);

	if ((current_cvsroot = cvsroot_get(".")) == NULL) {
		cvs_log(LP_ERR,
		    "No CVSROOT specified! Please use the '-d' option");
		fatal("or set the CVSROOT environment variable.");
	}

	if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
		cmdp->cmd(cmd_argc, cmd_argv);
		cvs_cleanup();
		return (0);
	}

	(void)xsnprintf(fpath, sizeof(fpath), "%s/%s",
	    current_cvsroot->cr_dir, CVS_PATH_ROOT);

	if (stat(fpath, &st) == -1 && cvs_cmdop != CVS_OP_INIT) {
		if (errno == ENOENT)
			fatal("repository '%s' does not exist",
			    current_cvsroot->cr_dir);
		else
			fatal("%s: %s", current_cvsroot->cr_dir,
			    strerror(errno));
	} else {
		if (!S_ISDIR(st.st_mode))
			fatal("'%s' is not a directory",
			    current_cvsroot->cr_dir);
	}

	if (cvs_cmdop != CVS_OP_INIT) {
		cvs_parse_configfile();
		cvs_parse_modules();
	}

	cmdp->cmd(cmd_argc, cmd_argv);
	cvs_cleanup();

	return (0);
}