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