void pkg_install_config(void) { int do_cache_index; char *value; parse_pkg_install_conf(); if ((value = getenv("PKG_DBDIR")) != NULL) pkgdb_set_dir(value, 2); else if (config_pkg_dbdir != NULL) pkgdb_set_dir(config_pkg_dbdir, 1); config_pkg_dbdir = xstrdup(pkgdb_get_dir()); if ((value = getenv("PKG_REFCOUNT_DBDIR")) != NULL) config_pkg_refcount_dbdir = value; else if (config_pkg_refcount_dbdir == NULL) config_pkg_refcount_dbdir = xasprintf("%s.refcount", pkgdb_get_dir()); if (pkg_vulnerabilities_dir == NULL) pkg_vulnerabilities_dir = pkgdb_get_dir(); pkg_vulnerabilities_file = xasprintf("%s/pkg-vulnerabilities", pkg_vulnerabilities_dir); if (pkg_vulnerabilities_url == NULL) { pkg_vulnerabilities_url = xasprintf("%s/pkg-vulnerabilities.gz", tnf_vulnerability_base); } if (verified_installation == NULL) verified_installation = "never"; if (check_vulnerabilities == NULL) check_vulnerabilities = "never"; if (do_license_check == NULL) do_license_check = "no"; if ((value = getenv("PKG_PATH")) != NULL) config_pkg_path = value; if (strcasecmp(cache_index, "yes") == 0) do_cache_index = 1; else { if (strcasecmp(cache_index, "no")) warnx("Invalid value for configuration option " "CACHE_INDEX"); do_cache_index = 0; } if (config_cache_connections && *config_cache_connections) { long v = strtol(config_cache_connections, &value, 10); if (*value == '\0') { if (v >= INT_MAX || v < 0) v = -1; cache_connections = v; } } config_cache_connections = xasprintf("%d", cache_connections); if (config_cache_connections_host) { long v = strtol(config_cache_connections_host, &value, 10); if (*value == '\0') { if (v >= INT_MAX || v < 0) v = -1; cache_connections_host = v; } } config_cache_connections_host = xasprintf("%d", cache_connections_host); #ifndef BOOTSTRAP fetchConnectionCacheInit(cache_connections, cache_connections_host); #endif snprintf(fetch_flags, sizeof(fetch_flags), "%s%s%s%s", (do_cache_index) ? "c" : "", (verbose_netio && *verbose_netio) ? "v" : "", (active_ftp && *active_ftp) ? "a" : "", (ignore_proxy && *ignore_proxy) ? "d" : ""); }
/* * Entry point */ int main(int argc, char *argv[]) { struct stat sb; struct sigaction sa; const char *p, *s; char *end, *q; int c, e, r; #ifndef __minix while ((c = getopt(argc, argv, "14AaB:dFilMmN:no:qRrS:sT:Uvw:")) != -1) #else while ((c = getopt(argc, argv, "146AaB:dFilMmN:no:qRrS:sT:Uvw:")) != -1) #endif switch (c) { case '1': once_flag = 1; break; case '4': family = PF_INET; break; #ifndef __minix case '6': family = PF_INET6; break; #endif case 'A': A_flag = 1; break; case 'a': a_flag = 1; break; case 'B': B_size = (off_t)strtol(optarg, &end, 10); if (*optarg == '\0' || *end != '\0') errx(1, "invalid buffer size (%s)", optarg); break; case 'd': d_flag = 1; break; case 'F': F_flag = 1; break; case 'i': i_flag = 1; break; case 'l': l_flag = 1; break; case 'o': o_flag = 1; o_filename = optarg; break; case 'M': case 'm': if (r_flag) errx(1, "the -m and -r flags " "are mutually exclusive"); m_flag = 1; break; case 'N': N_filename = optarg; break; case 'n': n_flag = 1; break; case 'q': v_level = 0; break; case 'R': R_flag = 1; break; case 'r': if (m_flag) errx(1, "the -m and -r flags " "are mutually exclusive"); r_flag = 1; break; case 'S': S_size = (off_t)strtol(optarg, &end, 10); if (*optarg == '\0' || *end != '\0') errx(1, "invalid size (%s)", optarg); break; case 's': s_flag = 1; break; case 'T': T_secs = strtol(optarg, &end, 10); if (*optarg == '\0' || *end != '\0') errx(1, "invalid timeout (%s)", optarg); break; case 'U': U_flag = 1; break; case 'v': v_level++; break; case 'w': a_flag = 1; w_secs = strtol(optarg, &end, 10); if (*optarg == '\0' || *end != '\0') errx(1, "invalid delay (%s)", optarg); break; default: usage(); exit(EX_USAGE); } argc -= optind; argv += optind; if (!argc) { usage(); exit(EX_USAGE); } fetchConnectionCacheInit(10, 1); /* allocate buffer */ if (B_size < MINBUFSIZE) B_size = MINBUFSIZE; if ((buf = malloc(B_size)) == NULL) errx(1, "%s", strerror(ENOMEM)); /* timeouts */ if ((s = getenv("FTP_TIMEOUT")) != NULL) { ftp_timeout = strtol(s, &end, 10); if (*s == '\0' || *end != '\0' || ftp_timeout < 0) { warnx("FTP_TIMEOUT (%s) is not a positive integer", s); ftp_timeout = 0; } } if ((s = getenv("HTTP_TIMEOUT")) != NULL) { http_timeout = strtol(s, &end, 10); if (*s == '\0' || *end != '\0' || http_timeout < 0) { warnx("HTTP_TIMEOUT (%s) is not a positive integer", s); http_timeout = 0; } } /* signal handling */ sa.sa_flags = 0; sa.sa_handler = sig_handler; sigemptyset(&sa.sa_mask); sigaction(SIGALRM, &sa, NULL); sa.sa_flags = SA_RESETHAND; sigaction(SIGINT, &sa, NULL); /* output file */ if (o_flag) { if (strcmp(o_filename, "-") == 0) { o_stdout = 1; if (i_flag) { warnx("-i and -o - are incompatible, dropping -i"); i_flag = 0; } } else if (stat(o_filename, &sb) == -1) { if (errno == ENOENT) { if (argc > 1) errx(EX_USAGE, "%s is not a directory", o_filename); } else { err(EX_IOERR, "%s", o_filename); } } else { if (sb.st_mode & S_IFDIR) o_directory = 1; } } /* check if output is to a tty (for progress report) */ v_tty = isatty(STDERR_FILENO); if (v_tty) pgrp = getpgrp(); r = 0; /* authentication */ if (v_tty) fetchAuthMethod = query_auth; if (N_filename != NULL) setenv("NETRC", N_filename, 1); while (argc) { if ((p = strrchr(*argv, '/')) == NULL) p = *argv; else p++; if (!*p) p = "fetch.out"; fetchLastErrCode = 0; if (o_flag) { if (o_stdout) { e = fetch(*argv, "-"); } else if (o_directory) { #ifndef __minix asprintf(&q, "%s/%s", o_filename, p); #else { int len; if ((q = malloc(sizeof(char)*MINBUFSIZE)) != NULL) { len = snprintf(q, MINBUFSIZE, "%s/%s", o_filename, p); if (len >= MINBUFSIZE) { free(q); q = NULL; } } else { err(1, "Unable to allocate memory"); } } #endif e = fetch(*argv, q); free(q); } else { e = fetch(*argv, o_filename); } } else { e = fetch(*argv, p); } if (sigint) kill(getpid(), SIGINT); if (e == 0 && once_flag) exit(0); if (e) { r = 1; if ((fetchLastErrCode && fetchLastErrCode != FETCH_UNAVAIL && fetchLastErrCode != FETCH_MOVED && fetchLastErrCode != FETCH_URL && fetchLastErrCode != FETCH_RESOLV && fetchLastErrCode != FETCH_UNKNOWN)) { if (w_secs && v_level) fprintf(stderr, "Waiting %ld seconds " "before retrying\n", w_secs); if (w_secs) sleep(w_secs); if (a_flag) continue; } } argc--, argv++; } exit(r); }