wdenk | 6aff311 | 2002-12-17 01:51:00 +0000 | [diff] [blame] | 1 | /* |
Grant Erickson | bc11756 | 2008-05-06 20:16:15 -0700 | [diff] [blame] | 2 | * (C) Copyright 2000-2008 |
wdenk | 6aff311 | 2002-12-17 01:51:00 +0000 | [diff] [blame] | 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
Wolfgang Denk | 3765b3e | 2013-10-07 13:07:26 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 6aff311 | 2002-12-17 01:51:00 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | /* |
wdenk | 3bac351 | 2003-03-12 10:41:04 +0000 | [diff] [blame] | 9 | * Command line user interface to firmware (=U-Boot) environment. |
wdenk | 6aff311 | 2002-12-17 01:51:00 +0000 | [diff] [blame] | 10 | * |
| 11 | * Implements: |
Marek Vasut | a8a752c | 2014-03-05 19:59:52 +0100 | [diff] [blame] | 12 | * fw_printenv [ -a key ] [[ -n name ] | [ name ... ]] |
Grant Erickson | bc11756 | 2008-05-06 20:16:15 -0700 | [diff] [blame] | 13 | * - prints the value of a single environment variable |
| 14 | * "name", the ``name=value'' pairs of one or more |
| 15 | * environment variables "name", or the whole |
| 16 | * environment if no names are specified. |
Marek Vasut | a8a752c | 2014-03-05 19:59:52 +0100 | [diff] [blame] | 17 | * fw_setenv [ -a key ] name [ value ... ] |
wdenk | 6aff311 | 2002-12-17 01:51:00 +0000 | [diff] [blame] | 18 | * - If a name without any values is given, the variable |
| 19 | * with this name is deleted from the environment; |
| 20 | * otherwise, all "value" arguments are concatenated, |
Grant Erickson | bc11756 | 2008-05-06 20:16:15 -0700 | [diff] [blame] | 21 | * separated by single blank characters, and the |
wdenk | 6aff311 | 2002-12-17 01:51:00 +0000 | [diff] [blame] | 22 | * resulting string is assigned to the environment |
| 23 | * variable "name" |
Marek Vasut | a8a752c | 2014-03-05 19:59:52 +0100 | [diff] [blame] | 24 | * |
| 25 | * If '-a key' is specified, the env block is encrypted with AES 128 CBC. |
| 26 | * The 'key' argument is in the format of 32 hexadecimal numbers (16 bytes |
| 27 | * of AES key), eg. '-a aabbccddeeff00112233445566778899'. |
wdenk | 6aff311 | 2002-12-17 01:51:00 +0000 | [diff] [blame] | 28 | */ |
| 29 | |
Joe Hershberger | e4a223f | 2012-10-03 09:38:49 +0000 | [diff] [blame] | 30 | #include <fcntl.h> |
| 31 | #include <getopt.h> |
wdenk | 6aff311 | 2002-12-17 01:51:00 +0000 | [diff] [blame] | 32 | #include <stdio.h> |
| 33 | #include <string.h> |
| 34 | #include <stdlib.h> |
Joe Hershberger | e4a223f | 2012-10-03 09:38:49 +0000 | [diff] [blame] | 35 | #include <sys/file.h> |
| 36 | #include <unistd.h> |
Stefano Babic | 9d80b49 | 2017-04-05 18:08:01 +0200 | [diff] [blame^] | 37 | #include "fw_env_private.h" |
wdenk | 6aff311 | 2002-12-17 01:51:00 +0000 | [diff] [blame] | 38 | #include "fw_env.h" |
| 39 | |
Andreas Fenkart | b92ae3a | 2015-12-09 13:13:27 +0100 | [diff] [blame] | 40 | #define CMD_PRINTENV "fw_printenv" |
wdenk | 6aff311 | 2002-12-17 01:51:00 +0000 | [diff] [blame] | 41 | #define CMD_SETENV "fw_setenv" |
Andreas Fenkart | b92ae3a | 2015-12-09 13:13:27 +0100 | [diff] [blame] | 42 | static int do_printenv; |
wdenk | 6aff311 | 2002-12-17 01:51:00 +0000 | [diff] [blame] | 43 | |
Stefano Babic | bd7b26f | 2010-05-24 12:08:16 +0200 | [diff] [blame] | 44 | static struct option long_options[] = { |
Andreas Fenkart | b92ae3a | 2015-12-09 13:13:27 +0100 | [diff] [blame] | 45 | {"aes", required_argument, NULL, 'a'}, |
| 46 | {"config", required_argument, NULL, 'c'}, |
Stefano Babic | bd7b26f | 2010-05-24 12:08:16 +0200 | [diff] [blame] | 47 | {"help", no_argument, NULL, 'h'}, |
Andreas Fenkart | b92ae3a | 2015-12-09 13:13:27 +0100 | [diff] [blame] | 48 | {"script", required_argument, NULL, 's'}, |
| 49 | {"noheader", required_argument, NULL, 'n'}, |
B, Ravi | d40dbfb | 2016-09-26 18:24:08 +0530 | [diff] [blame] | 50 | {"lock", required_argument, NULL, 'l'}, |
Stefano Babic | bd7b26f | 2010-05-24 12:08:16 +0200 | [diff] [blame] | 51 | {NULL, 0, NULL, 0} |
| 52 | }; |
| 53 | |
Andreas Fenkart | 81974f4 | 2016-04-05 23:13:42 +0200 | [diff] [blame] | 54 | static struct env_opts env_opts; |
| 55 | |
| 56 | /* setenv options */ |
| 57 | static int noheader; |
| 58 | |
| 59 | /* getenv options */ |
| 60 | static char *script_file; |
| 61 | |
Andreas Fenkart | b92ae3a | 2015-12-09 13:13:27 +0100 | [diff] [blame] | 62 | void usage_printenv(void) |
Stefano Babic | bd7b26f | 2010-05-24 12:08:16 +0200 | [diff] [blame] | 63 | { |
| 64 | |
Andreas Fenkart | b92ae3a | 2015-12-09 13:13:27 +0100 | [diff] [blame] | 65 | fprintf(stderr, |
| 66 | "Usage: fw_printenv [OPTIONS]... [VARIABLE]...\n" |
| 67 | "Print variables from U-Boot environment\n" |
| 68 | "\n" |
| 69 | " -h, --help print this help.\n" |
| 70 | #ifdef CONFIG_ENV_AES |
| 71 | " -a, --aes aes key to access environment\n" |
Michael Heimpold | 9884f44 | 2015-10-27 22:34:49 +0100 | [diff] [blame] | 72 | #endif |
Andreas Fenkart | b92ae3a | 2015-12-09 13:13:27 +0100 | [diff] [blame] | 73 | #ifdef CONFIG_FILE |
| 74 | " -c, --config configuration file, default:" CONFIG_FILE "\n" |
| 75 | #endif |
| 76 | " -n, --noheader do not repeat variable name in output\n" |
B, Ravi | d40dbfb | 2016-09-26 18:24:08 +0530 | [diff] [blame] | 77 | " -l, --lock lock node, default:/var/lock\n" |
Andreas Fenkart | b92ae3a | 2015-12-09 13:13:27 +0100 | [diff] [blame] | 78 | "\n"); |
| 79 | } |
| 80 | |
| 81 | void usage_setenv(void) |
| 82 | { |
| 83 | fprintf(stderr, |
| 84 | "Usage: fw_setenv [OPTIONS]... [VARIABLE]...\n" |
| 85 | "Modify variables in U-Boot environment\n" |
Stefano Babic | bd7b26f | 2010-05-24 12:08:16 +0200 | [diff] [blame] | 86 | "\n" |
Andreas Fenkart | b92ae3a | 2015-12-09 13:13:27 +0100 | [diff] [blame] | 87 | " -h, --help print this help.\n" |
| 88 | #ifdef CONFIG_ENV_AES |
| 89 | " -a, --aes aes key to access environment\n" |
| 90 | #endif |
| 91 | #ifdef CONFIG_FILE |
| 92 | " -c, --config configuration file, default:" CONFIG_FILE "\n" |
| 93 | #endif |
B, Ravi | d40dbfb | 2016-09-26 18:24:08 +0530 | [diff] [blame] | 94 | " -l, --lock lock node, default:/var/lock\n" |
Andreas Fenkart | b92ae3a | 2015-12-09 13:13:27 +0100 | [diff] [blame] | 95 | " -s, --script batch mode to minimize writes\n" |
Stefano Babic | bd7b26f | 2010-05-24 12:08:16 +0200 | [diff] [blame] | 96 | "\n" |
Andreas Fenkart | b92ae3a | 2015-12-09 13:13:27 +0100 | [diff] [blame] | 97 | "Examples:\n" |
| 98 | " fw_setenv foo bar set variable foo equal bar\n" |
| 99 | " fw_setenv foo clear variable foo\n" |
| 100 | " fw_setenv --script file run batch script\n" |
| 101 | "\n" |
| 102 | "Script Syntax:\n" |
| 103 | " key [space] value\n" |
Vagrant Cascadian | 0e28065 | 2016-03-15 12:11:12 -0700 | [diff] [blame] | 104 | " lines starting with '#' are treated as comment\n" |
Andreas Fenkart | b92ae3a | 2015-12-09 13:13:27 +0100 | [diff] [blame] | 105 | "\n" |
| 106 | " A variable without value will be deleted. Any number of spaces are\n" |
| 107 | " allowed between key and value. Space inside of the value is treated\n" |
| 108 | " as part of the value itself.\n" |
| 109 | "\n" |
| 110 | "Script Example:\n" |
| 111 | " netdev eth0\n" |
| 112 | " kernel_addr 400000\n" |
| 113 | " foo empty empty empty empty empty empty\n" |
| 114 | " bar\n" |
| 115 | "\n"); |
Stefano Babic | bd7b26f | 2010-05-24 12:08:16 +0200 | [diff] [blame] | 116 | } |
| 117 | |
Andreas Fenkart | af93e3d | 2015-12-09 13:13:26 +0100 | [diff] [blame] | 118 | static void parse_common_args(int argc, char *argv[]) |
wdenk | 6aff311 | 2002-12-17 01:51:00 +0000 | [diff] [blame] | 119 | { |
Stefano Babic | bd7b26f | 2010-05-24 12:08:16 +0200 | [diff] [blame] | 120 | int c; |
wdenk | 6aff311 | 2002-12-17 01:51:00 +0000 | [diff] [blame] | 121 | |
Andreas Fenkart | 371ee13 | 2015-12-09 13:13:24 +0100 | [diff] [blame] | 122 | #ifdef CONFIG_FILE |
Andreas Fenkart | 81974f4 | 2016-04-05 23:13:42 +0200 | [diff] [blame] | 123 | env_opts.config_file = CONFIG_FILE; |
Andreas Fenkart | 371ee13 | 2015-12-09 13:13:24 +0100 | [diff] [blame] | 124 | #endif |
| 125 | |
B, Ravi | d40dbfb | 2016-09-26 18:24:08 +0530 | [diff] [blame] | 126 | while ((c = getopt_long(argc, argv, ":a:c:l:h", long_options, NULL)) != |
Andreas Fenkart | af93e3d | 2015-12-09 13:13:26 +0100 | [diff] [blame] | 127 | EOF) { |
Stefano Babic | bd7b26f | 2010-05-24 12:08:16 +0200 | [diff] [blame] | 128 | switch (c) { |
Marek Vasut | a8a752c | 2014-03-05 19:59:52 +0100 | [diff] [blame] | 129 | case 'a': |
Andreas Fenkart | 81974f4 | 2016-04-05 23:13:42 +0200 | [diff] [blame] | 130 | if (parse_aes_key(optarg, env_opts.aes_key)) { |
Andreas Fenkart | 371ee13 | 2015-12-09 13:13:24 +0100 | [diff] [blame] | 131 | fprintf(stderr, "AES key parse error\n"); |
Andreas Fenkart | af93e3d | 2015-12-09 13:13:26 +0100 | [diff] [blame] | 132 | exit(EXIT_FAILURE); |
Andreas Fenkart | 371ee13 | 2015-12-09 13:13:24 +0100 | [diff] [blame] | 133 | } |
Andreas Fenkart | 81974f4 | 2016-04-05 23:13:42 +0200 | [diff] [blame] | 134 | env_opts.aes_flag = 1; |
Marek Vasut | a8a752c | 2014-03-05 19:59:52 +0100 | [diff] [blame] | 135 | break; |
Andreas Fenkart | 371ee13 | 2015-12-09 13:13:24 +0100 | [diff] [blame] | 136 | #ifdef CONFIG_FILE |
Michael Heimpold | 9884f44 | 2015-10-27 22:34:49 +0100 | [diff] [blame] | 137 | case 'c': |
Andreas Fenkart | 81974f4 | 2016-04-05 23:13:42 +0200 | [diff] [blame] | 138 | env_opts.config_file = optarg; |
Michael Heimpold | 9884f44 | 2015-10-27 22:34:49 +0100 | [diff] [blame] | 139 | break; |
Andreas Fenkart | 371ee13 | 2015-12-09 13:13:24 +0100 | [diff] [blame] | 140 | #endif |
B, Ravi | d40dbfb | 2016-09-26 18:24:08 +0530 | [diff] [blame] | 141 | case 'l': |
| 142 | env_opts.lockname = optarg; |
| 143 | break; |
Andreas Fenkart | 07ce944 | 2015-12-09 13:13:23 +0100 | [diff] [blame] | 144 | case 'h': |
Andreas Fenkart | b92ae3a | 2015-12-09 13:13:27 +0100 | [diff] [blame] | 145 | do_printenv ? usage_printenv() : usage_setenv(); |
Andreas Fenkart | 07ce944 | 2015-12-09 13:13:23 +0100 | [diff] [blame] | 146 | exit(EXIT_SUCCESS); |
| 147 | break; |
Andreas Fenkart | af93e3d | 2015-12-09 13:13:26 +0100 | [diff] [blame] | 148 | default: |
| 149 | /* ignore unknown options */ |
| 150 | break; |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | /* Reset getopt for the next pass. */ |
| 155 | opterr = 1; |
| 156 | optind = 1; |
| 157 | } |
| 158 | |
| 159 | int parse_printenv_args(int argc, char *argv[]) |
| 160 | { |
| 161 | int c; |
| 162 | |
| 163 | parse_common_args(argc, argv); |
| 164 | |
B, Ravi | d40dbfb | 2016-09-26 18:24:08 +0530 | [diff] [blame] | 165 | while ((c = getopt_long(argc, argv, "a:c:ns:l:h", long_options, NULL)) |
| 166 | != EOF) { |
Andreas Fenkart | af93e3d | 2015-12-09 13:13:26 +0100 | [diff] [blame] | 167 | switch (c) { |
| 168 | case 'n': |
Andreas Fenkart | 81974f4 | 2016-04-05 23:13:42 +0200 | [diff] [blame] | 169 | noheader = 1; |
Andreas Fenkart | af93e3d | 2015-12-09 13:13:26 +0100 | [diff] [blame] | 170 | break; |
| 171 | case 'a': |
| 172 | case 'c': |
| 173 | case 'h': |
B, Ravi | d40dbfb | 2016-09-26 18:24:08 +0530 | [diff] [blame] | 174 | case 'l': |
Andreas Fenkart | af93e3d | 2015-12-09 13:13:26 +0100 | [diff] [blame] | 175 | /* ignore common options */ |
| 176 | break; |
Andreas Fenkart | 07ce944 | 2015-12-09 13:13:23 +0100 | [diff] [blame] | 177 | default: /* '?' */ |
Andreas Fenkart | b92ae3a | 2015-12-09 13:13:27 +0100 | [diff] [blame] | 178 | usage_printenv(); |
Andreas Fenkart | 07ce944 | 2015-12-09 13:13:23 +0100 | [diff] [blame] | 179 | exit(EXIT_FAILURE); |
| 180 | break; |
| 181 | } |
| 182 | } |
| 183 | return 0; |
| 184 | } |
| 185 | |
| 186 | int parse_setenv_args(int argc, char *argv[]) |
| 187 | { |
| 188 | int c; |
| 189 | |
Andreas Fenkart | af93e3d | 2015-12-09 13:13:26 +0100 | [diff] [blame] | 190 | parse_common_args(argc, argv); |
Andreas Fenkart | 371ee13 | 2015-12-09 13:13:24 +0100 | [diff] [blame] | 191 | |
B, Ravi | d40dbfb | 2016-09-26 18:24:08 +0530 | [diff] [blame] | 192 | while ((c = getopt_long(argc, argv, "a:c:ns:l:h", long_options, NULL)) |
| 193 | != EOF) { |
Andreas Fenkart | 07ce944 | 2015-12-09 13:13:23 +0100 | [diff] [blame] | 194 | switch (c) { |
Stefano Babic | bd7b26f | 2010-05-24 12:08:16 +0200 | [diff] [blame] | 195 | case 's': |
Andreas Fenkart | 81974f4 | 2016-04-05 23:13:42 +0200 | [diff] [blame] | 196 | script_file = optarg; |
Stefano Babic | bd7b26f | 2010-05-24 12:08:16 +0200 | [diff] [blame] | 197 | break; |
Andreas Fenkart | af93e3d | 2015-12-09 13:13:26 +0100 | [diff] [blame] | 198 | case 'a': |
| 199 | case 'c': |
Stefano Babic | bd7b26f | 2010-05-24 12:08:16 +0200 | [diff] [blame] | 200 | case 'h': |
B, Ravi | d40dbfb | 2016-09-26 18:24:08 +0530 | [diff] [blame] | 201 | case 'l': |
Andreas Fenkart | af93e3d | 2015-12-09 13:13:26 +0100 | [diff] [blame] | 202 | /* ignore common options */ |
Andreas Fenkart | 07ce944 | 2015-12-09 13:13:23 +0100 | [diff] [blame] | 203 | break; |
Daniel Hobi | 29ccd7c | 2010-09-16 14:36:09 +0200 | [diff] [blame] | 204 | default: /* '?' */ |
Andreas Fenkart | b92ae3a | 2015-12-09 13:13:27 +0100 | [diff] [blame] | 205 | usage_setenv(); |
Andreas Fenkart | 07ce944 | 2015-12-09 13:13:23 +0100 | [diff] [blame] | 206 | exit(EXIT_FAILURE); |
| 207 | break; |
Stefano Babic | bd7b26f | 2010-05-24 12:08:16 +0200 | [diff] [blame] | 208 | } |
| 209 | } |
Andreas Fenkart | 07ce944 | 2015-12-09 13:13:23 +0100 | [diff] [blame] | 210 | return 0; |
| 211 | } |
| 212 | |
| 213 | int main(int argc, char *argv[]) |
| 214 | { |
B, Ravi | d40dbfb | 2016-09-26 18:24:08 +0530 | [diff] [blame] | 215 | char *lockname = "/var/lock/" CMD_PRINTENV ".lock"; |
Andreas Fenkart | 07ce944 | 2015-12-09 13:13:23 +0100 | [diff] [blame] | 216 | int lockfd = -1; |
| 217 | int retval = EXIT_SUCCESS; |
Andreas Fenkart | b92ae3a | 2015-12-09 13:13:27 +0100 | [diff] [blame] | 218 | char *_cmdname; |
Andreas Fenkart | 07ce944 | 2015-12-09 13:13:23 +0100 | [diff] [blame] | 219 | |
Andreas Fenkart | b92ae3a | 2015-12-09 13:13:27 +0100 | [diff] [blame] | 220 | _cmdname = *argv; |
| 221 | if (strrchr(_cmdname, '/') != NULL) |
| 222 | _cmdname = strrchr(_cmdname, '/') + 1; |
Andreas Fenkart | 07ce944 | 2015-12-09 13:13:23 +0100 | [diff] [blame] | 223 | |
Andreas Fenkart | b92ae3a | 2015-12-09 13:13:27 +0100 | [diff] [blame] | 224 | if (strcmp(_cmdname, CMD_PRINTENV) == 0) { |
| 225 | do_printenv = 1; |
| 226 | } else if (strcmp(_cmdname, CMD_SETENV) == 0) { |
| 227 | do_printenv = 0; |
Andreas Fenkart | 07ce944 | 2015-12-09 13:13:23 +0100 | [diff] [blame] | 228 | } else { |
| 229 | fprintf(stderr, |
| 230 | "Identity crisis - may be called as `%s' or as `%s' but not as `%s'\n", |
Andreas Fenkart | b92ae3a | 2015-12-09 13:13:27 +0100 | [diff] [blame] | 231 | CMD_PRINTENV, CMD_SETENV, _cmdname); |
Andreas Fenkart | 07ce944 | 2015-12-09 13:13:23 +0100 | [diff] [blame] | 232 | exit(EXIT_FAILURE); |
| 233 | } |
| 234 | |
Andreas Fenkart | b92ae3a | 2015-12-09 13:13:27 +0100 | [diff] [blame] | 235 | if (do_printenv) { |
| 236 | if (parse_printenv_args(argc, argv)) |
| 237 | exit(EXIT_FAILURE); |
| 238 | } else { |
| 239 | if (parse_setenv_args(argc, argv)) |
| 240 | exit(EXIT_FAILURE); |
| 241 | } |
| 242 | |
Andreas Fenkart | 1ce6869 | 2015-12-09 13:13:25 +0100 | [diff] [blame] | 243 | /* shift parsed flags, jump to non-option arguments */ |
| 244 | argc -= optind; |
| 245 | argv += optind; |
| 246 | |
B, Ravi | d40dbfb | 2016-09-26 18:24:08 +0530 | [diff] [blame] | 247 | if (env_opts.lockname) { |
| 248 | lockname = malloc(sizeof(env_opts.lockname) + |
| 249 | sizeof(CMD_PRINTENV) + 10); |
| 250 | if (!lockname) { |
| 251 | fprintf(stderr, "Unable allocate memory"); |
| 252 | exit(EXIT_FAILURE); |
| 253 | } |
| 254 | |
| 255 | sprintf(lockname, "%s/%s.lock", |
| 256 | env_opts.lockname, CMD_PRINTENV); |
| 257 | } |
| 258 | |
Andreas Fenkart | 07ce944 | 2015-12-09 13:13:23 +0100 | [diff] [blame] | 259 | lockfd = open(lockname, O_WRONLY | O_CREAT | O_TRUNC, 0666); |
| 260 | if (-1 == lockfd) { |
| 261 | fprintf(stderr, "Error opening lock file %s\n", lockname); |
| 262 | return EXIT_FAILURE; |
| 263 | } |
| 264 | |
| 265 | if (-1 == flock(lockfd, LOCK_EX)) { |
| 266 | fprintf(stderr, "Error locking file %s\n", lockname); |
| 267 | close(lockfd); |
| 268 | return EXIT_FAILURE; |
| 269 | } |
Stefano Babic | bd7b26f | 2010-05-24 12:08:16 +0200 | [diff] [blame] | 270 | |
Andreas Fenkart | b92ae3a | 2015-12-09 13:13:27 +0100 | [diff] [blame] | 271 | if (do_printenv) { |
Andreas Fenkart | 81974f4 | 2016-04-05 23:13:42 +0200 | [diff] [blame] | 272 | if (fw_printenv(argc, argv, noheader, &env_opts) != 0) |
Joe Hershberger | e4a223f | 2012-10-03 09:38:49 +0000 | [diff] [blame] | 273 | retval = EXIT_FAILURE; |
Andreas Fenkart | b92ae3a | 2015-12-09 13:13:27 +0100 | [diff] [blame] | 274 | } else { |
Andreas Fenkart | 81974f4 | 2016-04-05 23:13:42 +0200 | [diff] [blame] | 275 | if (!script_file) { |
| 276 | if (fw_setenv(argc, argv, &env_opts) != 0) |
Joe Hershberger | e4a223f | 2012-10-03 09:38:49 +0000 | [diff] [blame] | 277 | retval = EXIT_FAILURE; |
Stefano Babic | bd7b26f | 2010-05-24 12:08:16 +0200 | [diff] [blame] | 278 | } else { |
Andreas Fenkart | 81974f4 | 2016-04-05 23:13:42 +0200 | [diff] [blame] | 279 | if (fw_parse_script(script_file, &env_opts) != 0) |
Joe Hershberger | e4a223f | 2012-10-03 09:38:49 +0000 | [diff] [blame] | 280 | retval = EXIT_FAILURE; |
Stefano Babic | bd7b26f | 2010-05-24 12:08:16 +0200 | [diff] [blame] | 281 | } |
wdenk | 6aff311 | 2002-12-17 01:51:00 +0000 | [diff] [blame] | 282 | } |
| 283 | |
B, Ravi | d40dbfb | 2016-09-26 18:24:08 +0530 | [diff] [blame] | 284 | if (env_opts.lockname) |
| 285 | free(lockname); |
| 286 | |
Joe Hershberger | e4a223f | 2012-10-03 09:38:49 +0000 | [diff] [blame] | 287 | flock(lockfd, LOCK_UN); |
| 288 | close(lockfd); |
| 289 | return retval; |
wdenk | 6aff311 | 2002-12-17 01:51:00 +0000 | [diff] [blame] | 290 | } |