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