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