From: Bernhard Voelker Date: Tue, 2 Jul 2013 09:53:57 +0000 (+0200) Subject: mkdir,mkfifo,mknod: give scontext-related variable a better scope X-Git-Tag: v8.22~117 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=64a212cb75f78b60440efeed2de6461ed1f88ae8;p=thirdparty%2Fcoreutils.git mkdir,mkfifo,mknod: give scontext-related variable a better scope * src/mkdir.c (main): Move the variable ret and issuing the error message into the body of the scontext-related if-block. * src/mkfifo.c (main): Likewise. * src/mknod.c (main): Likewise. --- diff --git a/src/mkdir.c b/src/mkdir.c index 479faca85a..efd318497d 100644 --- a/src/mkdir.c +++ b/src/mkdir.c @@ -152,7 +152,6 @@ main (int argc, char **argv) int optc; security_context_t scontext = NULL; struct mkdir_options options; - int ret = 0; options.make_ancestor_function = NULL; options.mode = S_IRWXUGO; @@ -198,16 +197,18 @@ main (int argc, char **argv) if (scontext) { + int ret = 0; if (is_smack_enabled ()) ret = smack_set_label_for_self (scontext); else ret = setfscreatecon (scontext); + + if (ret < 0) + error (EXIT_FAILURE, errno, + _("failed to set default file creation context to %s"), + quote (scontext)); } - if (ret < 0) - error (EXIT_FAILURE, errno, - _("failed to set default file creation context to %s"), - quote (scontext)); if (options.make_ancestor_function || specified_mode) { diff --git a/src/mkfifo.c b/src/mkfifo.c index f9fcc0a609..4c6dac4687 100644 --- a/src/mkfifo.c +++ b/src/mkfifo.c @@ -77,7 +77,6 @@ main (int argc, char **argv) int exit_status = EXIT_SUCCESS; int optc; security_context_t scontext = NULL; - int ret = 0; initialize_main (&argc, &argv); set_program_name (argv[0]); @@ -112,16 +111,17 @@ main (int argc, char **argv) if (scontext) { + int ret = 0; if (is_smack_enabled ()) ret = smack_set_label_for_self (scontext); else ret = setfscreatecon (scontext); - } - if (ret < 0) - error (EXIT_FAILURE, errno, - _("failed to set default file creation context to %s"), - quote (scontext)); + if (ret < 0) + error (EXIT_FAILURE, errno, + _("failed to set default file creation context to %s"), + quote (scontext)); + } newmode = MODE_RW_UGO; if (specified_mode) diff --git a/src/mknod.c b/src/mknod.c index 4fd6ed0f4a..c79468c6dd 100644 --- a/src/mknod.c +++ b/src/mknod.c @@ -94,7 +94,6 @@ main (int argc, char **argv) int expected_operands; mode_t node_type; security_context_t scontext = NULL; - int ret = 0; initialize_main (&argc, &argv); set_program_name (argv[0]); @@ -168,16 +167,17 @@ main (int argc, char **argv) if (scontext) { + int ret = 0; if (is_smack_enabled ()) ret = smack_set_label_for_self (scontext); else ret = setfscreatecon (scontext); - } - if (ret < 0) - error (EXIT_FAILURE, errno, - _("failed to set default file creation context to %s"), - quote (scontext)); + if (ret < 0) + error (EXIT_FAILURE, errno, + _("failed to set default file creation context to %s"), + quote (scontext)); + } /* Only check the first character, to allow mnemonic usage like 'mknod /dev/rst0 character 18 0'. */