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