Ejemplo n.º 1
0
Archivo: main.c Proyecto: CBke/cmus
static char *file_url_absolute(const char *str)
{
	char *absolute;

	if (strncmp(str, "http://", 7) == 0)
		return xstrdup(str);

	absolute = path_absolute(str);
	if (absolute == NULL)
		die_errno("get_current_dir_name");
	return absolute;
}
Ejemplo n.º 2
0
Archivo: path.c Proyecto: rofl0r/ncdu
char *path_real(const char *orig) {
  int links = 0;
  char *tmp, *ret;

  if(orig == NULL)
    return NULL;

  if((tmp = path_absolute(orig)) == NULL)
    return NULL;
  ret = path_real_rec(tmp, &links);
  free(tmp);
  return ret;
}
Ejemplo n.º 3
0
/* just gets the file SRC and store in local file DEST
 * doesn't parse any LIST output
 * returns 0 on success, else -1
 */
static int do_the_get(const char *src, const char *dest,
                      putmode_t how, unsigned opt)
{
    char *fulldest;
    char *tmp;
    transfer_mode_t type;

    type = ascii_transfer(src) ? tmAscii : gvDefaultType;
    if(test(opt, GET_ASCII))
        type = tmAscii;
    else if(test(opt, GET_BINARY))
        type = tmBinary;

    tmp = getcwd(NULL, 0);
    if (tmp == (char *)NULL)
        return -1;

    fulldest = path_absolute(dest, tmp, 0);

#if 0 && (defined(HAVE_SETPROCTITLE) || defined(linux))
    if(gvUseEnvString && ftp_connected())
        setproctitle("%s, get %s", ftp->url->hostname, src);
#endif

    int r = ftp_getfile(src, dest, how, type,
                        test(opt, GET_VERBOSE)
                        && !gvSighupReceived
                        && !test(opt, GET_NOHUP) ? transfer : 0);

    if(r == 0 && (test(opt, GET_NOHUP) || gvSighupReceived)) {
        fprintf(stderr, "%s [%sb of ",
                src, human_size(ftp->ti.size));
        fprintf(stderr, "%sb]\n", human_size(ftp->ti.total_size));
    }
    if(test(opt, GET_NOHUP)) {
        if(r == 0)
            transfer_mail_msg(_("received %s\n"), src);
        else
            transfer_mail_msg(_("failed to receive %s: %s\n"),
                              src, ftp_getreply(false));
    }
    free(fulldest);
#if 0 && (defined(HAVE_SETPROCTITLE) || defined(linux))
    if(gvUseEnvString && ftp_connected())
        setproctitle("%s", ftp->url->hostname);
#endif

    free(tmp);

    return r;
}
Ejemplo n.º 4
0
int
main_run(void* main_arg) {
	int result = RENDERCOMPILE_RESULT_OK;
	rendercompile_input_t input = rendercompile_parse_command_line(environment_command_line());

	FOUNDATION_UNUSED(main_arg);

	if (input.display_help) {
		rendercompile_print_usage();
		goto exit;
	}

	resource_source_set_path(STRING_ARGS(input.source_path));
	resource_compile_register(render_compile);

	size_t ifile, fsize;
	for (ifile = 0, fsize = array_size(input.input_files); ifile < fsize; ++ifile) {
		uuid_t uuid = string_to_uuid(STRING_ARGS(input.input_files[ifile]));
		if (uuid_is_null(uuid)) {
			char buffer[BUILD_MAX_PATHLEN];
			string_t pathstr = string_copy(buffer, sizeof(buffer), STRING_ARGS(input.input_files[ifile]));
			pathstr = path_clean(STRING_ARGS(pathstr), sizeof(buffer));
			pathstr = path_absolute(STRING_ARGS(pathstr), sizeof(buffer));
			uuid = resource_import_map_lookup(STRING_ARGS(pathstr));
		}
		if (uuid_is_null(uuid)) {
			log_warnf(HASH_RESOURCE, WARNING_INVALID_VALUE, STRING_CONST("Failed to lookup: %.*s"), STRING_FORMAT(input.input_files[ifile]));
			result = RENDERCOMPILE_RESULT_INVALID_INPUT;
			break;
		}

		if (resource_compile(uuid, RESOURCE_PLATFORM_ALL)) {
			string_const_t uuidstr = string_from_uuid_static(uuid);
			log_infof(HASH_RESOURCE, STRING_CONST("Successfully compiled: %.*s (%.*s)"),
			          STRING_FORMAT(uuidstr), STRING_FORMAT(input.input_files[ifile]));
		}
		else {
			string_const_t uuidstr = string_from_uuid_static(uuid);
			log_warnf(HASH_RESOURCE, WARNING_UNSUPPORTED, STRING_CONST("Failed to compile: %.*s (%.*s)"),
			          STRING_FORMAT(uuidstr), STRING_FORMAT(input.input_files[ifile]));
		}
	}

exit:

	array_deallocate(input.input_files);

	return result;
}
Ejemplo n.º 5
0
Archivo: cmus.c Proyecto: Aseeker/cmus
enum file_type cmus_detect_ft(const char *name, char **ret)
{
	char *absolute;
	struct stat st;

	if (is_http_url(name) || is_cue_url(name)) {
		*ret = xstrdup(name);
		return FILE_TYPE_URL;
	}

	if (is_cdda_url(name)) {
		*ret = complete_cdda_url(cdda_device, name);
		return FILE_TYPE_CDDA;
	}

	*ret = NULL;
	absolute = path_absolute(name);
	if (absolute == NULL)
		return FILE_TYPE_INVALID;

	/* stat follows symlinks, lstat does not */
	if (stat(absolute, &st) == -1) {
		free(absolute);
		return FILE_TYPE_INVALID;
	}

	if (S_ISDIR(st.st_mode)) {
		*ret = absolute;
		return FILE_TYPE_DIR;
	}
	if (!S_ISREG(st.st_mode)) {
		free(absolute);
		errno = EINVAL;
		return FILE_TYPE_INVALID;
	}

	*ret = absolute;
	if (cmus_is_playlist(absolute))
		return FILE_TYPE_PL;

	/* NOTE: it could be FILE_TYPE_PL too! */
	return FILE_TYPE_FILE;
}
Ejemplo n.º 6
0
Archivo: path.c Proyecto: rofl0r/ncdu
int path_chdir(const char *path) {
  char **arr, *cur;
  int i, r = -1;

  if((cur = path_absolute(path)) == NULL)
    return -1;

  i = path_split(cur, &arr);
  if(chdir("/") < 0)
    goto path_chdir_done;
  while(--i >= 0)
    if(chdir(arr[i]) < 0)
      goto path_chdir_done;
  r = 0;

path_chdir_done:
  free(cur);
  free(arr);
  return r;
}
Ejemplo n.º 7
0
int ftp_maybe_isdir(rfile *fp)
{
    if(risdir(fp))
        return 1;

    if(rislink(fp)) {
        /* found a link; if the link is in the cache,
         * check if it's a directory, else we don't
         * read the directory just to check if it's a
         * directory
         */
        char *adir = base_dir_xptr(fp->path);
        char *ap = path_absolute(fp->link, adir, ftp->homedir);
        rfile *lnfp = ftp_cache_get_file(ap);
        free(adir);
        free(ap);
        if(lnfp)
            return risdir(lnfp) ? 1 : 0;
        else
            /* return maybe ;-) */
            return 2;
    }
    return 0;
}
Ejemplo n.º 8
0
void debug_file_path (const char *path)
{
	path_absolute(path, file_path, 0);
	close(file_fd);
	debug_file_reopen();
}
Ejemplo n.º 9
0
static int
render_import_program(stream_t* stream, const uuid_t uuid) {
	char buffer[1024];
	char pathbuf[BUILD_MAX_PATHLEN];
	resource_source_t source;
	resource_platform_t platformdecl = {-1, -1, -1, -1, -1, -1};
	uint64_t platform;
	tick_t timestamp;
	int ret = 0;

	resource_source_initialize(&source);
	resource_source_read(&source, uuid);

	platform = resource_platform(platformdecl);
	timestamp = time_system();

	while (!stream_eos(stream)) {
		string_const_t type, ref;
		string_const_t fullpath;
		string_const_t uuidstr;
		uuid_t shaderuuid;
		hash_t typehash;
		string_t line = stream_read_line_buffer(stream, buffer, sizeof(buffer), '\n');
		string_split(STRING_ARGS(line), STRING_CONST(" \t"),
		             &type, &ref, false);

		type = string_strip(STRING_ARGS(type), STRING_CONST(STRING_WHITESPACE));
		ref = string_strip(STRING_ARGS(ref), STRING_CONST(STRING_WHITESPACE));
		if (!type.length || !ref.length)
			continue;

		typehash = hash(STRING_ARGS(type));
		if ((typehash != HASH_VERTEXSHADER) && (typehash != HASH_PIXELSHADER)) {
			log_warnf(HASH_RESOURCE, WARNING_SUSPICIOUS, STRING_CONST("Ignore invalid line: %.*s"),
			          STRING_FORMAT(line));
			continue;
		}

		shaderuuid = string_to_uuid(STRING_ARGS(ref));
		if (uuid_is_null(shaderuuid)) {
			if (path_is_absolute(STRING_ARGS(ref))) {
				fullpath = ref;
			}
			else {
				string_t full;
				string_const_t path = stream_path(stream);
				path = path_directory_name(STRING_ARGS(path));
				full = path_concat(pathbuf, sizeof(pathbuf),
				                   STRING_ARGS(path), STRING_ARGS(ref));
				full = path_absolute(STRING_ARGS(full), sizeof(pathbuf));
				fullpath = string_const(STRING_ARGS(full));
			}

			resource_signature_t sig = resource_import_lookup(STRING_ARGS(fullpath));
			if (uuid_is_null(sig.uuid)) {
				if (!resource_import(STRING_ARGS(fullpath), uuid_null())) {
					log_warnf(HASH_RESOURCE, WARNING_SUSPICIOUS, STRING_CONST("Unable to import linked shader: %.*s"),
					          STRING_FORMAT(fullpath));
					ret = -1;
					goto finalize;
				}
				sig = resource_import_lookup(STRING_ARGS(fullpath));
				if (uuid_is_null(sig.uuid)) {
					log_warnf(HASH_RESOURCE, WARNING_SUSPICIOUS,
					          STRING_CONST("Import linked shader gave no UUID: %.*s"),
					          STRING_FORMAT(fullpath));
					ret = -1;
					goto finalize;
				}
			}
			shaderuuid = sig.uuid;
		}

		if (!uuid_is_null(shaderuuid)) {
			uuidstr = string_from_uuid_static(shaderuuid);
			resource_source_set(&source, timestamp, typehash,
			                    platform, STRING_ARGS(uuidstr));
		}
	}

	resource_source_set(&source, timestamp, HASH_RESOURCE_TYPE,
	                    0, STRING_CONST("program"));

	if (!resource_source_write(&source, uuid, false)) {
		string_const_t uuidstr = string_from_uuid_static(uuid);
		log_warnf(HASH_RESOURCE, WARNING_SUSPICIOUS, STRING_CONST("Failed writing imported program: %.*s"),
		          STRING_FORMAT(uuidstr));
		ret = -1;
		goto finalize;
	}
	else {
		string_const_t uuidstr = string_from_uuid_static(uuid);
		log_infof(HASH_RESOURCE, STRING_CONST("Wrote imported program: %.*s"),
		          STRING_FORMAT(uuidstr));
	}

finalize:
	resource_source_finalize(&source);

	return ret;
}
Ejemplo n.º 10
0
static int
render_import_shader(stream_t* stream, const uuid_t uuid) {
	char buffer[1024];
	char pathbuf[BUILD_MAX_PATHLEN];
	resource_source_t source;
	resource_platform_t platformdecl = {-1, -1, -1, -1, -1, -1};
	uint64_t platform;
	tick_t timestamp;
	int ret = 0;

	resource_source_initialize(&source);
	resource_source_read(&source, uuid);

	platform = resource_platform(platformdecl);
	timestamp = time_system();

	while (!stream_eos(stream)) {
		uuid_t shaderuuid;
		string_const_t target, ref, fullpath;
		string_t line = stream_read_line_buffer(stream, buffer, sizeof(buffer), '\n');
		string_split(STRING_ARGS(line), STRING_CONST(" \t"),
		             &target, &ref, false);

		ref = string_strip(STRING_ARGS(ref), STRING_CONST(STRING_WHITESPACE));
		shaderuuid = string_to_uuid(STRING_ARGS(ref));
		if (uuid_is_null(shaderuuid)) {
			if (path_is_absolute(STRING_ARGS(ref))) {
				fullpath = ref;
			}
			else {
				string_t full;
				string_const_t path = stream_path(stream);
				path = path_directory_name(STRING_ARGS(path));
				full = path_concat(pathbuf, sizeof(pathbuf),
				                   STRING_ARGS(path), STRING_ARGS(ref));
				full = path_absolute(STRING_ARGS(full), sizeof(pathbuf));
				fullpath = string_const(STRING_ARGS(full));
			}

			resource_signature_t sig = resource_import_lookup(STRING_ARGS(fullpath));
			if (uuid_is_null(sig.uuid)) {
				if (!resource_import(STRING_ARGS(fullpath), uuid_null())) {
					log_warnf(HASH_RESOURCE, WARNING_SUSPICIOUS,
					          STRING_CONST("Unable to import linked shader: %.*s"),
					          STRING_FORMAT(fullpath));
					ret = -1;
					goto finalize;
				}
				sig = resource_import_lookup(STRING_ARGS(fullpath));
				if (uuid_is_null(sig.uuid)) {
					log_warnf(HASH_RESOURCE, WARNING_SUSPICIOUS,
					          STRING_CONST("Import linked shader gave no UUID: %.*s"),
					          STRING_FORMAT(fullpath));
					ret = -1;
					goto finalize;
				}
			}
			shaderuuid = sig.uuid;
		}

		if (!uuid_is_null(shaderuuid)) {
			resource_platform_t targetplatformdecl =
			    render_import_parse_target(STRING_ARGS(target), platformdecl);
			uint64_t targetplatform = resource_platform(targetplatformdecl);

			if (resource_autoimport_need_update(shaderuuid, targetplatform))
				resource_autoimport(shaderuuid);

			const string_const_t uuidstr = string_from_uuid_static(shaderuuid);
			resource_source_set(&source, timestamp, HASH_SHADER,
			                    targetplatform, STRING_ARGS(uuidstr));
			resource_source_set_dependencies(uuid, targetplatform, &shaderuuid, 1);
		}
	}

	resource_source_set(&source, timestamp, HASH_RESOURCE_TYPE,
	                    0, STRING_CONST("shader"));

	if (!resource_source_write(&source, uuid, false)) {
		string_const_t uuidstr = string_from_uuid_static(uuid);
		log_warnf(HASH_RESOURCE, WARNING_SUSPICIOUS, STRING_CONST("Failed writing imported shader: %.*s"),
		          STRING_FORMAT(uuidstr));
		ret = -1;
		goto finalize;
	}
	else {
		string_const_t uuidstr = string_from_uuid_static(uuid);
		log_infof(HASH_RESOURCE, STRING_CONST("Wrote imported shader: %.*s"),
		          STRING_FORMAT(uuidstr));
	}

finalize:
	resource_source_finalize(&source);

	return 0;
}
Ejemplo n.º 11
0
END_TEST

START_TEST(test_path_absolute)
{
	ck_assert(path_data[_i].absolute == path_absolute(path_data[_i].path));
}
Ejemplo n.º 12
0
const char* vs_list_refpaths(const char* name)
{
	char* path = (char*)path_absolute(name);
	path_translateInPlace(path, "windows");
	return path;
}
Ejemplo n.º 13
0
char *ftp_path_absolute(const char *path)
{
    return path_absolute(path, ftp->curdir, ftp->homedir);
}
Ejemplo n.º 14
0
/* creates path (and all elements in path)
 * PATH should be an absolute path
 * returns -1 on error, 0 if no directories created, else 1
 */
int ftp_mkpath(const char *path)
{
    bool one_created = false;
    char *p, *orgp, *e = 0;

    if(!path)
        return 0;

    /* check if we already has created this path */
    if(ftp_path_part_of(path, ftp->last_mkpath))
        return 0;

    /* check if this path is a part of current directory */
    if(ftp_path_part_of(path, ftp->curdir))
        return 0;

    orgp = p = xstrdup(path);
    path_collapse(p);
    unquote(p);

    if(*p == '/') {
        e = xmalloc(1);
        *e = 0;
    }

    while(true) {
        char *tmp, *foo;
        tmp = strqsep(&p, '/');
        if(!tmp)
            break;

        if (e)
        {
            if (asprintf(&foo, "%s/%s", e, tmp) == -1)
            {
              fprintf(stderr, _("Failed to allocate memory.\n"));
              free(e);
              free(orgp);
              return -1;
            }
        }
        else
            foo = xstrdup(tmp);

        free(e);
        e = foo;


        /* check if we already has created this path */
        if(ftp_path_part_of(e, ftp->last_mkpath))
            continue;

        /* check if this path is a part of current directory */
        if(ftp_path_part_of(e, ftp->curdir))
            continue;

        if(strcmp(e, ".") != 0) {
            ftp_mkdir_verb(e, vbNone);
            one_created = (ftp->code == ctComplete);
        }
    }

    free(ftp->last_mkpath);
    ftp->last_mkpath = path_absolute(path, ftp->curdir, ftp->homedir);

    free(e);
    free(orgp);
    return one_created;
}
Ejemplo n.º 15
0
static void getfiles(list *gl, unsigned int opt, const char *output)
{
    listitem *li;
    rfile *fp, *lnfp;
    const char *opath, *ofile;
    char *link = 0;

    list_sort(gl, get_sort_func, false);

    li = gl->first;
    while(li && !get_quit) {
        fp = (rfile *)li->data;

        if(!ftp_connected())
            return;

        if(gvSighupReceived) {
            if(!test(opt, GET_RESUME))
                opt |= GET_UNIQUE;
            opt |= GET_FORCE;
        }

        opath = fp->path;
        ofile = base_name_ptr(opath);

        if(strcmp(ofile, ".")==0 || strcmp(ofile, "..")==0) {
            transfer_nextfile(gl, &li, true);
            continue;
        }

        if(test(opt, GET_INTERACTIVE) && !get_batch && !gvSighupReceived) {
						char* sp = shortpath(opath, 42, ftp->homedir);
            int a = ask(ASKYES|ASKNO|ASKCANCEL|ASKALL, ASKYES,
                        _("Get '%s'?"), sp);
						free(sp);
            if(a == ASKNO) {
                transfer_nextfile(gl, &li, true);
                continue;
            }
            if(a == ASKCANCEL) {
                get_quit = true;
                break;
            }
            if(a == ASKALL)
                get_batch = true;
            /* else a==ASKYES */
        }


        if(rislink(fp)) {
            link_to_link__duh:
            if(test(opt, GET_NO_DEREFERENCE)) {
                /* link the file, don't copy */
                const int r = getfile(fp, opt, output, ofile);
                transfer_nextfile(gl, &li, r == 0);
                continue;
            }

            {
                char *xcurdir = base_dir_xptr(opath);
                link = path_absolute(fp->link, xcurdir, ftp->homedir);
                stripslash(link);
                free(xcurdir);
                ftp_trace("found link: '%s' -> '%s'\n", opath, link);
            }

            lnfp = ftp_get_file(link);
            if(lnfp == 0) {
                /* couldn't dereference the link, try to RETR it */
                ftp_trace("unable to dereference link\n");
                const int r = getfile(fp, opt, output, ofile);
                transfer_nextfile(gl, &li, r == 0);
                continue;
            }

            if(strncmp(opath, lnfp->path, strlen(lnfp->path)) == 0) {
                ftp_trace("opath == '%s', lnfp->path == '%s'\n", opath,
                          lnfp->path);
								char* sp = shortpath(lnfp->path, 42, ftp->homedir);
                fprintf(stderr, _("%s: circular link -- skipping\n"), sp);
								free(sp);
                transfer_nextfile(gl, &li, true);
                continue;
            }

            fp = lnfp;

            if(rislink(fp))
                /* found a link pointing to another link
                 */
                /* forgive me father, for I have goto'ed */
                goto link_to_link__duh;
        }

        if(risdir(fp)) {
            if(test(opt, GET_RECURSIVE)) {
                char *recurs_output;
                char *recurs_mask;
                list *rgl;


                if((get_dir_glob_mask && fnmatch(get_dir_glob_mask,
                                                 base_name_ptr(fp->path),
                                                 FNM_EXTMATCH) == FNM_NOMATCH)
#ifdef HAVE_REGEX
                   || (get_dir_rx_mask_set && regexec(&get_dir_rx_mask,
                                                      base_name_ptr(fp->path),
                                                      0, 0, 0) == REG_NOMATCH)
#endif
                    )
                    {
                    } else {
                        char *q_recurs_mask;

                        bool success = true;
                        if(!test(opt, GET_PARENTS))
                            success = asprintf(&recurs_output, "%s/%s",
                                     output ? output : ".", ofile) != -1;
                        else
                            success = asprintf(&recurs_output, "%s",
                                     output ? output : ".") != -1;
                        if (!success)
                        {
                          fprintf(stderr, _("Failed to allocate memory.\n"));
                          transfer_nextfile(gl, &li, true);
			                    continue;
                        }
                        if (asprintf(&recurs_mask, "%s/*", opath) == -1)
                        {
                          free(recurs_output);
                          fprintf(stderr, _("Failed to allocate memory.\n"));
                          transfer_nextfile(gl, &li, true);
                          continue;
                        }
                        rgl = rglob_create();
                        q_recurs_mask = backslash_quote(recurs_mask);
                        rglob_glob(rgl, q_recurs_mask, true, true, get_exclude_func);
                        free(q_recurs_mask);
                        if(list_numitem(rgl) > 0)
                            getfiles(rgl, opt, recurs_output);
                        if(test(opt, GET_PRESERVE))
                            get_preserve_attribs(fp, recurs_output);
                        rglob_destroy(rgl);
                        free(recurs_output);
                    }
            } else if(test(opt, GET_VERBOSE)) {
							char* sp = shortpath(opath, 42, ftp->homedir);
							fprintf(stderr, _("%s: omitting directory\n"), sp);
							free(sp);
            }
            transfer_nextfile(gl, &li, true);
            continue;
        }
        if(!risreg(fp)) {
            if(test(opt, GET_VERBOSE)) {
							char* sp = shortpath(opath, 42, ftp->homedir);
                fprintf(stderr, _("%s: not a regular file\n"), sp);
								free(sp);
						}
            transfer_nextfile(gl, &li, true);
            continue;
        }
        const int r = getfile(fp, opt, output, ofile);

        transfer_nextfile(gl, &li, r == 0);

        if(gvInterrupted) {
            gvInterrupted = false;
            if(li && !get_quit && ftp_connected() && !gvSighupReceived)
            {
                int a = ask(ASKYES|ASKNO, ASKYES,
                            _("Continue transfer?"));
                if(a == ASKNO) {
                    get_quit = true;
                    break;
                }
                /* else a == ASKYES */
                fprintf(stderr, _("Excellent!!!\n"));
            }
        }
    }
}
Ejemplo n.º 16
0
int check_add_deps(struct listitem *svc, int type)
{
   char buf[PATH_MAX + 1];
   char oldpath[PATH_MAX + 1];
   struct dirent *tdirent;
   struct dep *deps = NULL;
   struct listitem *new_svc;
   DIR *d_tmp;

   /* remember where we started */
   if(!getcwd(oldpath, PATH_MAX + 1)) {
      print_errno(MSG_GETCWD);
      return 0;
   }

   /* Create path */
   strncpy(buf, svc->abs_path, PATH_MAX+1);
   if(type == DEP_NEEDS) {
      if(!path_append(buf, C_NEEDS)) return 0;
   } else {
      if(!path_append(buf, C_WANTS)) return 0;
   }

   d_tmp = opendir(buf);
   if(d_tmp == NULL) {
      if(errno != ENOENT) {
         print_errno(buf);
         return 0;
      }
      return 1;                 /* it's fine when there's no dependencies */
   }

   if(chdir(buf) == -1) {       /* change to needs or wants */
      print_errno(buf);
      return 0;
   }

   while((tdirent = readdir(d_tmp)) != NULL) {
      if(*(tdirent->d_name) == '.') continue;              /* ignore .* */

      /*
       * skip non-working directories / broken links path_absolute reports
       * errors on failure 
       */
      if(!path_absolute(tdirent->d_name, buf, PATH_MAX + 1)) continue;

      /* 1. create the service we depend on 2. initialize its dependencies */
      if(!(new_svc = gen_svc_tree(buf))) return 0;

      /*
       * We need ALL dependencies, as we are called only once per service; no
       * need to test that first! And the other service CANNOT know anything
       * about us yet, so we always add us to its list. 
       */

      /*
       * Dependencies: - a.needs b; add b to the list of dependencies. -
       * a.needs b; add a to the list of needed by b. 1. check whether the
       * dependency already exists 2. otherwise add it 3. do it once for needs, 
       * once for needed_by 
       */

      /* create a dependency entry containing us */
      deps = dep_create(svc);
      if(!deps) return 0;

      if(type == DEP_NEEDS) {
         /* add us to the other service */
         dep_entry_add(&(new_svc->needed_by), deps);

         /* add other service to us */
         deps = dep_create(new_svc);
         if(!deps) return 0;
         dep_entry_add(&(svc->needs), deps);
      } else {
         /* add us to the other service */
         dep_entry_add(&(new_svc->wanted_by), deps);

         /* add other service to us */
         deps = dep_create(new_svc);
         if(!deps) return 0;
         dep_entry_add(&(svc->wants), deps);
      }
   }
   if(chdir(oldpath) == -1) {
      print_errno(buf);
      return 0;
   }
   closedir(d_tmp);

   return 1;
}