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