mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-03-31 03:21:32 +00:00
env: tool: add command line option to input lockfile path
The default lockname is set to /var/lock. This limits the usage of this application where OS uses different lockfile location parameter. For example, In case of android, the default lock path location is /data. Hence by providing the command line option to input lockfile path will be useful to reuse the tool across multiple operating system. usage: ./fw_printenv -l <lockfile path> Signed-off-by: Ravi Babu <ravibabu@ti.com>
This commit is contained in:
parent
279dcd8975
commit
d40dbfb740
2 changed files with 30 additions and 6 deletions
1
tools/env/fw_env.h
vendored
1
tools/env/fw_env.h
vendored
|
@ -63,6 +63,7 @@ struct env_opts {
|
||||||
#endif
|
#endif
|
||||||
int aes_flag; /* Is AES encryption used? */
|
int aes_flag; /* Is AES encryption used? */
|
||||||
uint8_t aes_key[AES_KEY_LENGTH];
|
uint8_t aes_key[AES_KEY_LENGTH];
|
||||||
|
char *lockname;
|
||||||
};
|
};
|
||||||
|
|
||||||
int parse_aes_key(char *key, uint8_t *bin_key);
|
int parse_aes_key(char *key, uint8_t *bin_key);
|
||||||
|
|
35
tools/env/fw_env_main.c
vendored
35
tools/env/fw_env_main.c
vendored
|
@ -46,6 +46,7 @@ static struct option long_options[] = {
|
||||||
{"help", no_argument, NULL, 'h'},
|
{"help", no_argument, NULL, 'h'},
|
||||||
{"script", required_argument, NULL, 's'},
|
{"script", required_argument, NULL, 's'},
|
||||||
{"noheader", required_argument, NULL, 'n'},
|
{"noheader", required_argument, NULL, 'n'},
|
||||||
|
{"lock", required_argument, NULL, 'l'},
|
||||||
{NULL, 0, NULL, 0}
|
{NULL, 0, NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -72,6 +73,7 @@ void usage_printenv(void)
|
||||||
" -c, --config configuration file, default:" CONFIG_FILE "\n"
|
" -c, --config configuration file, default:" CONFIG_FILE "\n"
|
||||||
#endif
|
#endif
|
||||||
" -n, --noheader do not repeat variable name in output\n"
|
" -n, --noheader do not repeat variable name in output\n"
|
||||||
|
" -l, --lock lock node, default:/var/lock\n"
|
||||||
"\n");
|
"\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,6 +90,7 @@ void usage_setenv(void)
|
||||||
#ifdef CONFIG_FILE
|
#ifdef CONFIG_FILE
|
||||||
" -c, --config configuration file, default:" CONFIG_FILE "\n"
|
" -c, --config configuration file, default:" CONFIG_FILE "\n"
|
||||||
#endif
|
#endif
|
||||||
|
" -l, --lock lock node, default:/var/lock\n"
|
||||||
" -s, --script batch mode to minimize writes\n"
|
" -s, --script batch mode to minimize writes\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Examples:\n"
|
"Examples:\n"
|
||||||
|
@ -119,7 +122,7 @@ static void parse_common_args(int argc, char *argv[])
|
||||||
env_opts.config_file = CONFIG_FILE;
|
env_opts.config_file = CONFIG_FILE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while ((c = getopt_long(argc, argv, ":a:c:h", long_options, NULL)) !=
|
while ((c = getopt_long(argc, argv, ":a:c:l:h", long_options, NULL)) !=
|
||||||
EOF) {
|
EOF) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'a':
|
case 'a':
|
||||||
|
@ -134,6 +137,9 @@ static void parse_common_args(int argc, char *argv[])
|
||||||
env_opts.config_file = optarg;
|
env_opts.config_file = optarg;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
case 'l':
|
||||||
|
env_opts.lockname = optarg;
|
||||||
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
do_printenv ? usage_printenv() : usage_setenv();
|
do_printenv ? usage_printenv() : usage_setenv();
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
|
@ -155,8 +161,8 @@ int parse_printenv_args(int argc, char *argv[])
|
||||||
|
|
||||||
parse_common_args(argc, argv);
|
parse_common_args(argc, argv);
|
||||||
|
|
||||||
while ((c = getopt_long(argc, argv, "a:c:ns:h", long_options, NULL)) !=
|
while ((c = getopt_long(argc, argv, "a:c:ns:l:h", long_options, NULL))
|
||||||
EOF) {
|
!= EOF) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'n':
|
case 'n':
|
||||||
noheader = 1;
|
noheader = 1;
|
||||||
|
@ -164,6 +170,7 @@ int parse_printenv_args(int argc, char *argv[])
|
||||||
case 'a':
|
case 'a':
|
||||||
case 'c':
|
case 'c':
|
||||||
case 'h':
|
case 'h':
|
||||||
|
case 'l':
|
||||||
/* ignore common options */
|
/* ignore common options */
|
||||||
break;
|
break;
|
||||||
default: /* '?' */
|
default: /* '?' */
|
||||||
|
@ -181,8 +188,8 @@ int parse_setenv_args(int argc, char *argv[])
|
||||||
|
|
||||||
parse_common_args(argc, argv);
|
parse_common_args(argc, argv);
|
||||||
|
|
||||||
while ((c = getopt_long(argc, argv, "a:c:ns:h", long_options, NULL)) !=
|
while ((c = getopt_long(argc, argv, "a:c:ns:l:h", long_options, NULL))
|
||||||
EOF) {
|
!= EOF) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 's':
|
case 's':
|
||||||
script_file = optarg;
|
script_file = optarg;
|
||||||
|
@ -190,6 +197,7 @@ int parse_setenv_args(int argc, char *argv[])
|
||||||
case 'a':
|
case 'a':
|
||||||
case 'c':
|
case 'c':
|
||||||
case 'h':
|
case 'h':
|
||||||
|
case 'l':
|
||||||
/* ignore common options */
|
/* ignore common options */
|
||||||
break;
|
break;
|
||||||
default: /* '?' */
|
default: /* '?' */
|
||||||
|
@ -203,7 +211,7 @@ int parse_setenv_args(int argc, char *argv[])
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
const char *lockname = "/var/lock/" CMD_PRINTENV ".lock";
|
char *lockname = "/var/lock/" CMD_PRINTENV ".lock";
|
||||||
int lockfd = -1;
|
int lockfd = -1;
|
||||||
int retval = EXIT_SUCCESS;
|
int retval = EXIT_SUCCESS;
|
||||||
char *_cmdname;
|
char *_cmdname;
|
||||||
|
@ -235,6 +243,18 @@ int main(int argc, char *argv[])
|
||||||
argc -= optind;
|
argc -= optind;
|
||||||
argv += optind;
|
argv += optind;
|
||||||
|
|
||||||
|
if (env_opts.lockname) {
|
||||||
|
lockname = malloc(sizeof(env_opts.lockname) +
|
||||||
|
sizeof(CMD_PRINTENV) + 10);
|
||||||
|
if (!lockname) {
|
||||||
|
fprintf(stderr, "Unable allocate memory");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
sprintf(lockname, "%s/%s.lock",
|
||||||
|
env_opts.lockname, CMD_PRINTENV);
|
||||||
|
}
|
||||||
|
|
||||||
lockfd = open(lockname, O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
lockfd = open(lockname, O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
||||||
if (-1 == lockfd) {
|
if (-1 == lockfd) {
|
||||||
fprintf(stderr, "Error opening lock file %s\n", lockname);
|
fprintf(stderr, "Error opening lock file %s\n", lockname);
|
||||||
|
@ -260,6 +280,9 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (env_opts.lockname)
|
||||||
|
free(lockname);
|
||||||
|
|
||||||
flock(lockfd, LOCK_UN);
|
flock(lockfd, LOCK_UN);
|
||||||
close(lockfd);
|
close(lockfd);
|
||||||
return retval;
|
return retval;
|
||||||
|
|
Loading…
Add table
Reference in a new issue