opkg: allow to configure the path to the signature verification script
[project/opkg-lede.git] / libopkg / opkg_conf.c
1 /* opkg_conf.c - the opkg package management system
2
3 Copyright (C) 2009 Ubiq Technologies <graham.gower@gmail.com>
4
5 Carl D. Worth
6 Copyright (C) 2001 University of Southern California
7
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
12
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
17 */
18
19 #include <stdio.h>
20 #include <sys/types.h>
21 #include <sys/stat.h>
22 #include <fcntl.h>
23 #include <glob.h>
24 #include <unistd.h>
25
26 #include "opkg_conf.h"
27 #include "pkg_vec.h"
28 #include "pkg.h"
29 #include "xregex.h"
30 #include "sprintf_alloc.h"
31 #include "opkg_message.h"
32 #include "file_util.h"
33 #include "opkg_defines.h"
34 #include "libbb/libbb.h"
35
36 static int lock_fd;
37 static char *lock_file = NULL;
38
39 static opkg_conf_t _conf;
40 opkg_conf_t *conf = &_conf;
41
42 /*
43 * Config file options
44 */
45 opkg_option_t options[] = {
46 {"cache", OPKG_OPT_TYPE_STRING, &_conf.cache},
47 {"force_defaults", OPKG_OPT_TYPE_BOOL, &_conf.force_defaults},
48 {"force_maintainer", OPKG_OPT_TYPE_BOOL, &_conf.force_maintainer},
49 {"force_depends", OPKG_OPT_TYPE_BOOL, &_conf.force_depends},
50 {"force_overwrite", OPKG_OPT_TYPE_BOOL, &_conf.force_overwrite},
51 {"force_downgrade", OPKG_OPT_TYPE_BOOL, &_conf.force_downgrade},
52 {"force_reinstall", OPKG_OPT_TYPE_BOOL, &_conf.force_reinstall},
53 {"force_space", OPKG_OPT_TYPE_BOOL, &_conf.force_space},
54 {"force_postinstall", OPKG_OPT_TYPE_BOOL, &_conf.force_postinstall},
55 {"force_checksum", OPKG_OPT_TYPE_BOOL, &_conf.force_checksum},
56 {"check_signature", OPKG_OPT_TYPE_BOOL, &_conf.check_signature},
57 {"no_check_certificate", OPKG_OPT_TYPE_BOOL, &_conf.no_check_certificate},
58 {"ftp_proxy", OPKG_OPT_TYPE_STRING, &_conf.ftp_proxy},
59 {"http_proxy", OPKG_OPT_TYPE_STRING, &_conf.http_proxy},
60 {"http_timeout", OPKG_OPT_TYPE_STRING, &_conf.http_timeout},
61 {"no_proxy", OPKG_OPT_TYPE_STRING, &_conf.no_proxy},
62 {"test", OPKG_OPT_TYPE_BOOL, &_conf.noaction},
63 {"noaction", OPKG_OPT_TYPE_BOOL, &_conf.noaction},
64 {"download_only", OPKG_OPT_TYPE_BOOL, &_conf.download_only},
65 {"nodeps", OPKG_OPT_TYPE_BOOL, &_conf.nodeps},
66 {"nocase", OPKG_OPT_TYPE_BOOL, &_conf.nocase},
67 {"offline_root", OPKG_OPT_TYPE_STRING, &_conf.offline_root},
68 {"overlay_root", OPKG_OPT_TYPE_STRING, &_conf.overlay_root},
69 {"proxy_passwd", OPKG_OPT_TYPE_STRING, &_conf.proxy_passwd},
70 {"proxy_user", OPKG_OPT_TYPE_STRING, &_conf.proxy_user},
71 {"query-all", OPKG_OPT_TYPE_BOOL, &_conf.query_all},
72 {"size", OPKG_OPT_TYPE_BOOL, &_conf.size},
73 {"tmp_dir", OPKG_OPT_TYPE_STRING, &_conf.tmp_dir},
74 {"verbosity", OPKG_OPT_TYPE_INT, &_conf.verbosity},
75 {"verify_program", OPKG_OPT_TYPE_STRING, &_conf.verify_program},
76 {NULL, 0, NULL}
77 };
78
79 static int resolve_pkg_dest_list(void)
80 {
81 nv_pair_list_elt_t *iter;
82 nv_pair_t *nv_pair;
83 pkg_dest_t *dest;
84 char *root_dir;
85
86 for (iter = nv_pair_list_first(&conf->tmp_dest_list); iter;
87 iter = nv_pair_list_next(&conf->tmp_dest_list, iter)) {
88 nv_pair = (nv_pair_t *) iter->data;
89
90 if (conf->offline_root) {
91 sprintf_alloc(&root_dir, "%s%s", conf->offline_root,
92 nv_pair->value);
93 } else {
94 root_dir = xstrdup(nv_pair->value);
95 }
96
97 dest =
98 pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name,
99 root_dir, conf->lists_dir);
100 free(root_dir);
101
102 if (conf->default_dest == NULL)
103 conf->default_dest = dest;
104
105 if (conf->dest_str && !strcmp(dest->name, conf->dest_str)) {
106 conf->default_dest = dest;
107 conf->restrict_to_default_dest = 1;
108 }
109 }
110
111 if (conf->dest_str && !conf->restrict_to_default_dest) {
112 opkg_msg(ERROR, "Unknown dest name: `%s'.\n", conf->dest_str);
113 return -1;
114 }
115
116 return 0;
117 }
118
119 static int opkg_conf_set_option(const char *name, const char *value)
120 {
121 int i = 0;
122
123 while (options[i].name) {
124 if (strcmp(options[i].name, name) == 0) {
125 switch (options[i].type) {
126 case OPKG_OPT_TYPE_BOOL:
127 if (*(int *)options[i].value) {
128 opkg_msg(ERROR,
129 "Duplicate boolean option %s, "
130 "leaving this option on.\n",
131 name);
132 return 0;
133 }
134 *((int *const)options[i].value) = 1;
135 return 0;
136 case OPKG_OPT_TYPE_INT:
137 if (value) {
138 if (*(int *)options[i].value) {
139 opkg_msg(ERROR,
140 "Duplicate option %s, "
141 "using first seen value \"%d\".\n",
142 name,
143 *((int *)options[i].
144 value));
145 return 0;
146 }
147 *((int *const)options[i].value) =
148 atoi(value);
149 return 0;
150 } else {
151 opkg_msg(ERROR,
152 "Option %s needs an argument\n",
153 name);
154 return -1;
155 }
156 case OPKG_OPT_TYPE_STRING:
157 if (value) {
158 if (*(char **)options[i].value) {
159 opkg_msg(ERROR,
160 "Duplicate option %s, "
161 "using first seen value \"%s\".\n",
162 name,
163 *((char **)options[i].
164 value));
165 return 0;
166 }
167 *((char **const)options[i].value) =
168 xstrdup(value);
169 return 0;
170 } else {
171 opkg_msg(ERROR,
172 "Option %s needs an argument\n",
173 name);
174 return -1;
175 }
176 }
177 }
178 i++;
179 }
180
181 opkg_msg(ERROR, "Unrecognized option: %s=%s\n", name, value);
182 return -1;
183 }
184
185 static int
186 opkg_conf_parse_file(const char *filename,
187 pkg_src_list_t * pkg_src_list,
188 pkg_src_list_t * dist_src_list)
189 {
190 int line_num = 0;
191 int err = 0;
192 FILE *file;
193 regex_t valid_line_re, comment_re;
194 #define regmatch_size 14
195 regmatch_t regmatch[regmatch_size];
196
197 file = fopen(filename, "r");
198 if (file == NULL) {
199 opkg_perror(ERROR, "Failed to open %s", filename);
200 err = -1;
201 goto err0;
202 }
203
204 opkg_msg(INFO, "Loading conf file %s.\n", filename);
205
206 err = xregcomp(&comment_re,
207 "^[[:space:]]*(#.*|[[:space:]]*)$", REG_EXTENDED);
208 if (err)
209 goto err1;
210
211 err = xregcomp(&valid_line_re,
212 "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))"
213 "[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))"
214 "[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))"
215 "([[:space:]]+([^[:space:]]+))?([[:space:]]+(.*))?[[:space:]]*$",
216 REG_EXTENDED);
217 if (err)
218 goto err2;
219
220 while (1) {
221 char *line;
222 char *type, *name, *value, *extra;
223
224 line_num++;
225
226 line = file_read_line_alloc(file);
227 if (line == NULL)
228 break;
229
230 if (regexec(&comment_re, line, 0, 0, 0) == 0)
231 goto NEXT_LINE;
232
233 if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) ==
234 REG_NOMATCH) {
235 opkg_msg(ERROR, "%s:%d: Ignoring invalid line: `%s'\n",
236 filename, line_num, line);
237 goto NEXT_LINE;
238 }
239
240 /* This has to be so ugly to deal with optional quotation marks */
241 if (regmatch[2].rm_so > 0) {
242 type = xstrndup(line + regmatch[2].rm_so,
243 regmatch[2].rm_eo - regmatch[2].rm_so);
244 } else {
245 type = xstrndup(line + regmatch[3].rm_so,
246 regmatch[3].rm_eo - regmatch[3].rm_so);
247 }
248
249 if (regmatch[5].rm_so > 0) {
250 name = xstrndup(line + regmatch[5].rm_so,
251 regmatch[5].rm_eo - regmatch[5].rm_so);
252 } else {
253 name = xstrndup(line + regmatch[6].rm_so,
254 regmatch[6].rm_eo - regmatch[6].rm_so);
255 }
256
257 if (regmatch[8].rm_so > 0) {
258 value = xstrndup(line + regmatch[8].rm_so,
259 regmatch[8].rm_eo - regmatch[8].rm_so);
260 } else {
261 value = xstrndup(line + regmatch[9].rm_so,
262 regmatch[9].rm_eo - regmatch[9].rm_so);
263 }
264
265 extra = NULL;
266 if (regmatch[11].rm_so > 0) {
267 if (regmatch[13].rm_so > 0
268 && regmatch[13].rm_so != regmatch[13].rm_eo)
269 extra =
270 xstrndup(line + regmatch[11].rm_so,
271 regmatch[13].rm_eo -
272 regmatch[11].rm_so);
273 else
274 extra = xstrndup(line + regmatch[11].rm_so,
275 regmatch[11].rm_eo -
276 regmatch[11].rm_so);
277 }
278
279 if (regmatch[13].rm_so != regmatch[13].rm_eo
280 && strncmp(type, "dist", 4) != 0) {
281 opkg_msg(ERROR,
282 "%s:%d: Ignoring config line with trailing garbage: `%s'\n",
283 filename, line_num, line);
284 } else {
285
286 /* We use the conf->tmp_dest_list below instead of
287 conf->pkg_dest_list because we might encounter an
288 offline_root option later and that would invalidate the
289 directories we would have computed in
290 pkg_dest_list_init. (We do a similar thing with
291 tmp_src_nv_pair_list for sake of symmetry.) */
292 if (strcmp(type, "option") == 0) {
293 opkg_conf_set_option(name, value);
294 } else if (strcmp(type, "dist") == 0) {
295 if (!nv_pair_list_find
296 ((nv_pair_list_t *) dist_src_list, name)) {
297 pkg_src_list_append(dist_src_list, name,
298 value, extra, 0);
299 } else {
300 opkg_msg(ERROR,
301 "Duplicate dist declaration (%s %s). "
302 "Skipping.\n", name, value);
303 }
304 } else if (strcmp(type, "dist/gz") == 0) {
305 if (!nv_pair_list_find
306 ((nv_pair_list_t *) dist_src_list, name)) {
307 pkg_src_list_append(dist_src_list, name,
308 value, extra, 1);
309 } else {
310 opkg_msg(ERROR,
311 "Duplicate dist declaration (%s %s). "
312 "Skipping.\n", name, value);
313 }
314 } else if (strcmp(type, "src") == 0) {
315 if (!nv_pair_list_find
316 ((nv_pair_list_t *) pkg_src_list, name)) {
317 pkg_src_list_append(pkg_src_list, name,
318 value, extra, 0);
319 } else {
320 opkg_msg(ERROR,
321 "Duplicate src declaration (%s %s). "
322 "Skipping.\n", name, value);
323 }
324 } else if (strcmp(type, "src/gz") == 0) {
325 if (!nv_pair_list_find
326 ((nv_pair_list_t *) pkg_src_list, name)) {
327 pkg_src_list_append(pkg_src_list, name,
328 value, extra, 1);
329 } else {
330 opkg_msg(ERROR,
331 "Duplicate src declaration (%s %s). "
332 "Skipping.\n", name, value);
333 }
334 } else if (strcmp(type, "dest") == 0) {
335 nv_pair_list_append(&conf->tmp_dest_list, name,
336 value);
337 } else if (strcmp(type, "lists_dir") == 0) {
338 conf->lists_dir = xstrdup(value);
339 } else if (strcmp(type, "arch") == 0) {
340 opkg_msg(INFO,
341 "Supported arch %s priority (%s)\n",
342 name, value);
343 if (!value) {
344 opkg_msg(NOTICE,
345 "No priority given for architecture %s,"
346 "defaulting to 10\n", name);
347 value = xstrdup("10");
348 }
349 nv_pair_list_append(&conf->arch_list, name,
350 value);
351 } else {
352 opkg_msg(ERROR,
353 "%s:%d: Ignoring invalid line: `%s'\n",
354 filename, line_num, line);
355 }
356
357 }
358
359 free(type);
360 free(name);
361 free(value);
362 if (extra)
363 free(extra);
364
365 NEXT_LINE:
366 free(line);
367 }
368
369 regfree(&valid_line_re);
370 err2:
371 regfree(&comment_re);
372 err1:
373 if (fclose(file) == EOF) {
374 opkg_perror(ERROR, "Couldn't close %s", filename);
375 err = -1;
376 }
377 err0:
378 return err;
379 }
380
381 int opkg_conf_write_status_files(void)
382 {
383 pkg_dest_list_elt_t *iter;
384 pkg_dest_t *dest;
385 pkg_vec_t *all;
386 pkg_t *pkg;
387 int i, ret = 0;
388
389 if (conf->noaction)
390 return 0;
391
392 list_for_each_entry(iter, &conf->pkg_dest_list.head, node) {
393 dest = (pkg_dest_t *) iter->data;
394
395 dest->status_fp = fopen(dest->status_file_name, "w");
396 if (dest->status_fp == NULL && errno != EROFS) {
397 opkg_perror(ERROR, "Can't open status file %s",
398 dest->status_file_name);
399 ret = -1;
400 }
401 }
402
403 all = pkg_vec_alloc();
404 pkg_hash_fetch_available(all);
405
406 for (i = 0; i < all->len; i++) {
407 pkg = all->pkgs[i];
408 /* We don't need most uninstalled packages in the status file */
409 if (pkg->state_status == SS_NOT_INSTALLED
410 && (pkg->state_want == SW_UNKNOWN
411 || (pkg->state_want == SW_DEINSTALL
412 && pkg->state_flag != SF_HOLD)
413 || pkg->state_want == SW_PURGE)) {
414 continue;
415 }
416 if (pkg->dest == NULL) {
417 opkg_msg(ERROR,
418 "Internal error: package %s has a NULL dest\n",
419 pkg->name);
420 continue;
421 }
422 if (pkg->dest->status_fp)
423 pkg_print_status(pkg, pkg->dest->status_fp);
424 }
425
426 pkg_vec_free(all);
427
428 list_for_each_entry(iter, &conf->pkg_dest_list.head, node) {
429 dest = (pkg_dest_t *) iter->data;
430 if (dest->status_fp && fclose(dest->status_fp) == EOF) {
431 opkg_perror(ERROR, "Couldn't close %s",
432 dest->status_file_name);
433 ret = -1;
434 }
435 }
436
437 return ret;
438 }
439
440 char *root_filename_alloc(char *filename)
441 {
442 char *root_filename;
443 sprintf_alloc(&root_filename, "%s%s",
444 (conf->offline_root ? conf->offline_root : ""), filename);
445 return root_filename;
446 }
447
448 static int glob_errfunc(const char *epath, int eerrno)
449 {
450 if (eerrno == ENOENT)
451 /* If leading dir does not exist, we get GLOB_NOMATCH. */
452 return 0;
453
454 opkg_msg(ERROR, "glob failed for %s: %s\n", epath, strerror(eerrno));
455 return 0;
456 }
457
458 int opkg_conf_init(void)
459 {
460 pkg_src_list_init(&conf->pkg_src_list);
461 pkg_src_list_init(&conf->dist_src_list);
462 pkg_dest_list_init(&conf->pkg_dest_list);
463 pkg_dest_list_init(&conf->tmp_dest_list);
464 nv_pair_list_init(&conf->arch_list);
465
466 return 0;
467 }
468
469 int opkg_conf_load(void)
470 {
471 int i, glob_ret;
472 char *tmp, *tmp_dir_base, **tmp_val;
473 glob_t globbuf;
474 char *etc_opkg_conf_pattern;
475
476 conf->restrict_to_default_dest = 0;
477 conf->default_dest = NULL;
478
479 if (!conf->offline_root)
480 conf->offline_root = xstrdup(getenv("OFFLINE_ROOT"));
481
482 if (conf->conf_file) {
483 struct stat st;
484 if (stat(conf->conf_file, &st) == -1) {
485 opkg_perror(ERROR, "Couldn't stat %s", conf->conf_file);
486 goto err0;
487 }
488 if (opkg_conf_parse_file(conf->conf_file,
489 &conf->pkg_src_list,
490 &conf->dist_src_list))
491 goto err1;
492 }
493
494 if (conf->offline_root)
495 sprintf_alloc(&etc_opkg_conf_pattern, "%s/etc/opkg/*.conf",
496 conf->offline_root);
497 else {
498 const char *conf_file_dir = getenv("OPKG_CONF_DIR");
499 if (conf_file_dir == NULL)
500 conf_file_dir = OPKG_CONF_DEFAULT_CONF_FILE_DIR;
501 sprintf_alloc(&etc_opkg_conf_pattern, "%s/*.conf",
502 conf_file_dir);
503 }
504
505 memset(&globbuf, 0, sizeof(globbuf));
506 glob_ret = glob(etc_opkg_conf_pattern, 0, glob_errfunc, &globbuf);
507 if (glob_ret && glob_ret != GLOB_NOMATCH) {
508 free(etc_opkg_conf_pattern);
509 globfree(&globbuf);
510 goto err1;
511 }
512
513 free(etc_opkg_conf_pattern);
514
515 for (i = 0; i < globbuf.gl_pathc; i++) {
516 if (globbuf.gl_pathv[i])
517 if (conf->conf_file &&
518 !strcmp(conf->conf_file, globbuf.gl_pathv[i]))
519 continue;
520 if (opkg_conf_parse_file(globbuf.gl_pathv[i],
521 &conf->pkg_src_list,
522 &conf->dist_src_list) < 0) {
523 globfree(&globbuf);
524 goto err1;
525 }
526 }
527
528 globfree(&globbuf);
529
530 if (conf->offline_root)
531 sprintf_alloc(&lock_file, "%s/%s", conf->offline_root,
532 OPKGLOCKFILE);
533 else
534 sprintf_alloc(&lock_file, "%s", OPKGLOCKFILE);
535
536 lock_fd = creat(lock_file, S_IRUSR | S_IWUSR | S_IRGRP);
537 if (lock_fd == -1) {
538 opkg_perror(ERROR, "Could not create lock file %s", lock_file);
539 goto err2;
540 }
541
542 if (lockf(lock_fd, F_TLOCK, (off_t) 0) == -1) {
543 opkg_perror(ERROR, "Could not lock %s", lock_file);
544 if (close(lock_fd) == -1)
545 opkg_perror(ERROR, "Couldn't close descriptor %d (%s)",
546 lock_fd, lock_file);
547 lock_fd = -1;
548 goto err2;
549 }
550
551 if (conf->tmp_dir)
552 tmp_dir_base = conf->tmp_dir;
553 else
554 tmp_dir_base = getenv("TMPDIR");
555
556 sprintf_alloc(&tmp, "%s/%s",
557 tmp_dir_base ? tmp_dir_base :
558 OPKG_CONF_DEFAULT_TMP_DIR_BASE, OPKG_CONF_TMP_DIR_SUFFIX);
559 if (conf->tmp_dir)
560 free(conf->tmp_dir);
561 conf->tmp_dir = mkdtemp(tmp);
562 if (conf->tmp_dir == NULL) {
563 opkg_perror(ERROR, "Creating temp dir %s failed", tmp);
564 goto err3;
565 }
566
567 pkg_hash_init();
568 hash_table_init("file-hash", &conf->file_hash,
569 OPKG_CONF_DEFAULT_HASH_LEN);
570 hash_table_init("obs-file-hash", &conf->obs_file_hash,
571 OPKG_CONF_DEFAULT_HASH_LEN / 16);
572
573 if (conf->lists_dir == NULL)
574 conf->lists_dir = xstrdup(OPKG_CONF_LISTS_DIR);
575
576 if (conf->verify_program == NULL)
577 conf->verify_program = xstrdup(OPKG_CONF_DEFAULT_VERIFY_PROGRAM);
578
579 if (conf->offline_root) {
580 sprintf_alloc(&tmp, "%s/%s", conf->offline_root,
581 conf->lists_dir);
582 free(conf->lists_dir);
583 conf->lists_dir = tmp;
584 }
585
586 /* if no architectures were defined, then default all, noarch, and host architecture */
587 if (nv_pair_list_empty(&conf->arch_list)) {
588 nv_pair_list_append(&conf->arch_list, "all", "1");
589 nv_pair_list_append(&conf->arch_list, "noarch", "1");
590 nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
591 }
592
593 /* Even if there is no conf file, we'll need at least one dest. */
594 if (nv_pair_list_empty(&conf->tmp_dest_list)) {
595 nv_pair_list_append(&conf->tmp_dest_list,
596 OPKG_CONF_DEFAULT_DEST_NAME,
597 OPKG_CONF_DEFAULT_DEST_ROOT_DIR);
598 }
599
600 if (resolve_pkg_dest_list())
601 goto err4;
602
603 nv_pair_list_deinit(&conf->tmp_dest_list);
604
605 return 0;
606
607 err4:
608 free(conf->lists_dir);
609
610 pkg_hash_deinit();
611 hash_table_deinit(&conf->file_hash);
612 hash_table_deinit(&conf->obs_file_hash);
613
614 if (rmdir(conf->tmp_dir) == -1)
615 opkg_perror(ERROR, "Couldn't remove dir %s", conf->tmp_dir);
616 err3:
617 if (lockf(lock_fd, F_ULOCK, (off_t) 0) == -1)
618 opkg_perror(ERROR, "Couldn't unlock %s", lock_file);
619
620 if (close(lock_fd) == -1)
621 opkg_perror(ERROR, "Couldn't close descriptor %d (%s)",
622 lock_fd, lock_file);
623 if (unlink(lock_file) == -1)
624 opkg_perror(ERROR, "Couldn't unlink %s", lock_file);
625 err2:
626 if (lock_file) {
627 free(lock_file);
628 lock_file = NULL;
629 }
630 err1:
631 pkg_src_list_deinit(&conf->pkg_src_list);
632 pkg_src_list_deinit(&conf->dist_src_list);
633 pkg_dest_list_deinit(&conf->pkg_dest_list);
634 nv_pair_list_deinit(&conf->arch_list);
635
636 for (i = 0; options[i].name; i++) {
637 if (options[i].type == OPKG_OPT_TYPE_STRING) {
638 tmp_val = (char **)options[i].value;
639 if (*tmp_val) {
640 free(*tmp_val);
641 *tmp_val = NULL;
642 }
643 }
644 }
645 err0:
646 nv_pair_list_deinit(&conf->tmp_dest_list);
647 if (conf->dest_str)
648 free(conf->dest_str);
649 if (conf->conf_file)
650 free(conf->conf_file);
651
652 return -1;
653 }
654
655 void opkg_conf_deinit(void)
656 {
657 int i;
658 char **tmp;
659
660 if (conf->tmp_dir)
661 rm_r(conf->tmp_dir);
662
663 if (conf->lists_dir)
664 free(conf->lists_dir);
665
666 if (conf->dest_str)
667 free(conf->dest_str);
668
669 if (conf->conf_file)
670 free(conf->conf_file);
671
672 pkg_src_list_deinit(&conf->pkg_src_list);
673 pkg_src_list_deinit(&conf->dist_src_list);
674 pkg_dest_list_deinit(&conf->pkg_dest_list);
675 nv_pair_list_deinit(&conf->arch_list);
676
677 for (i = 0; options[i].name; i++) {
678 if (options[i].type == OPKG_OPT_TYPE_STRING) {
679 tmp = (char **)options[i].value;
680 if (*tmp) {
681 free(*tmp);
682 *tmp = NULL;
683 }
684 }
685 }
686
687 if (conf->verbosity >= DEBUG) {
688 hash_print_stats(&conf->pkg_hash);
689 hash_print_stats(&conf->file_hash);
690 hash_print_stats(&conf->obs_file_hash);
691 }
692
693 pkg_hash_deinit();
694 hash_table_deinit(&conf->file_hash);
695 hash_table_deinit(&conf->obs_file_hash);
696
697 if (lock_fd != -1) {
698 if (lockf(lock_fd, F_ULOCK, (off_t) 0) == -1)
699 opkg_perror(ERROR, "Couldn't unlock %s", lock_file);
700
701 if (close(lock_fd) == -1)
702 opkg_perror(ERROR, "Couldn't close descriptor %d (%s)",
703 lock_fd, lock_file);
704
705 }
706
707 if (lock_file) {
708 if (unlink(lock_file) == -1)
709 opkg_perror(ERROR, "Couldn't unlink %s", lock_file);
710
711 free(lock_file);
712 }
713 }