diff options
Diffstat (limited to 'src/install.c')
-rw-r--r-- | src/install.c | 408 |
1 files changed, 204 insertions, 204 deletions
diff --git a/src/install.c b/src/install.c index 19efb1d1b..a4e0cab32 100644 --- a/src/install.c +++ b/src/install.c @@ -74,18 +74,18 @@ static bool use_default_selinux_context = true; static bool change_timestamps (struct stat const *from_sb, char const *to); static bool change_attributes (char const *name); static bool copy_file (const char *from, const char *to, - const struct cp_options *x); + const struct cp_options *x); static bool install_file_in_file_parents (char const *from, char *to, - struct cp_options *x); + struct cp_options *x); static bool install_file_in_dir (const char *from, const char *to_dir, - const struct cp_options *x); + const struct cp_options *x); static bool install_file_in_file (const char *from, const char *to, - const struct cp_options *x); + const struct cp_options *x); static void get_ids (void); static void strip (char const *name); static void announce_mkdir (char const *dir, void *options); static int make_ancestor (char const *dir, char const *component, - void *options); + void *options); void usage (int status); /* The user name that will own the files, or NULL to make the owner @@ -195,7 +195,7 @@ extra_mode (mode_t input) /* Return true if copy of file SRC_NAME to file DEST_NAME is necessary. */ static bool need_copy (const char *src_name, const char *dest_name, - const struct cp_options *x) + const struct cp_options *x) { struct stat src_sb, dest_sb; int src_fd, dest_fd; @@ -229,20 +229,20 @@ need_copy (const char *src_name, const char *dest_name, bool scontext_match; if (getfilecon (src_name, &file_scontext) == -1) - return true; + return true; if (getfilecon (dest_name, &to_scontext) == -1) - { - freecon (file_scontext); - return true; - } + { + freecon (file_scontext); + return true; + } scontext_match = STREQ (file_scontext, to_scontext); freecon (file_scontext); freecon (to_scontext); if (!scontext_match) - return true; + return true; } /* compare files content */ @@ -328,37 +328,37 @@ setdefaultfilecon (char const *file) if (first_call && IS_ABSOLUTE_FILE_NAME (file)) { /* Calling matchpathcon_init_prefix (NULL, "/first_component/") - is an optimization to minimize the expense of the following - matchpathcon call. Do it only once, just before the first - matchpathcon call. We *could* call matchpathcon_fini after - the final matchpathcon call, but that's not necessary, since - by then we're about to exit, and besides, the buffers it - would free are still reachable. */ + is an optimization to minimize the expense of the following + matchpathcon call. Do it only once, just before the first + matchpathcon call. We *could* call matchpathcon_fini after + the final matchpathcon call, but that's not necessary, since + by then we're about to exit, and besides, the buffers it + would free are still reachable. */ char const *p0; char const *p = file + 1; while (ISSLASH (*p)) - ++p; + ++p; /* Record final leading slash, for when FILE starts with two or more. */ p0 = p - 1; if (*p) - { - char *prefix; - do - { - ++p; - } - while (*p && !ISSLASH (*p)); - - prefix = malloc (p - p0 + 2); - if (prefix) - { - stpcpy (stpncpy (prefix, p0, p - p0), "/"); - matchpathcon_init_prefix (NULL, prefix); - free (prefix); - } - } + { + char *prefix; + do + { + ++p; + } + while (*p && !ISSLASH (*p)); + + prefix = malloc (p - p0 + 2); + if (prefix) + { + stpcpy (stpncpy (prefix, p0, p - p0), "/"); + matchpathcon_init_prefix (NULL, prefix); + free (prefix); + } + } } first_call = false; @@ -368,14 +368,14 @@ setdefaultfilecon (char const *file) STREQ (scontext, "<<none>>")) { if (scontext != NULL) - freecon (scontext); + freecon (scontext); return; } if (lsetfilecon (file, scontext) < 0 && errno != ENOTSUP) error (0, errno, - _("warning: %s: failed to change context to %s"), - quotearg_colon (file), scontext); + _("warning: %s: failed to change context to %s"), + quotearg_colon (file), scontext); freecon (scontext); return; @@ -414,11 +414,11 @@ static int process_dir (char *dir, struct savewd *wd, void *options) { return (make_dir_parents (dir, wd, - make_ancestor, options, - dir_mode, announce_mkdir, - dir_mode_bits, owner_id, group_id, false) - ? EXIT_SUCCESS - : EXIT_FAILURE); + make_ancestor, options, + dir_mode, announce_mkdir, + dir_mode_bits, owner_id, group_id, false) + ? EXIT_SUCCESS + : EXIT_FAILURE); } int @@ -462,131 +462,131 @@ main (int argc, char **argv) backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX"); while ((optc = getopt_long (argc, argv, "bcCsDdg:m:o:pt:TvS:Z:", long_options, - NULL)) != -1) + NULL)) != -1) { switch (optc) - { - case 'b': - make_backups = true; - if (optarg) - version_control_string = optarg; - break; - case 'c': - break; - case 'C': - copy_only_if_needed = true; - break; - case 's': - strip_files = true; + { + case 'b': + make_backups = true; + if (optarg) + version_control_string = optarg; + break; + case 'c': + break; + case 'C': + copy_only_if_needed = true; + break; + case 's': + strip_files = true; #ifdef SIGCHLD - /* System V fork+wait does not work if SIGCHLD is ignored. */ - signal (SIGCHLD, SIG_DFL); + /* System V fork+wait does not work if SIGCHLD is ignored. */ + signal (SIGCHLD, SIG_DFL); #endif - break; - case STRIP_PROGRAM_OPTION: - strip_program = xstrdup (optarg); - strip_program_specified = true; - break; - case 'd': - dir_arg = true; - break; - case 'D': - mkdir_and_install = true; - break; - case 'v': - x.verbose = true; - break; - case 'g': - group_name = optarg; - break; - case 'm': - specified_mode = optarg; - break; - case 'o': - owner_name = optarg; - break; - case 'p': - x.preserve_timestamps = true; - break; - case 'S': - make_backups = true; - backup_suffix_string = optarg; - break; - case 't': - if (target_directory) - error (EXIT_FAILURE, 0, - _("multiple target directories specified")); - else - { - struct stat st; - if (stat (optarg, &st) != 0) - error (EXIT_FAILURE, errno, _("accessing %s"), quote (optarg)); - if (! S_ISDIR (st.st_mode)) - error (EXIT_FAILURE, 0, _("target %s is not a directory"), - quote (optarg)); - } - target_directory = optarg; - break; - case 'T': - no_target_directory = true; - break; - - case PRESERVE_CONTEXT_OPTION_DEPRECATED: - error (0, 0, _("WARNING: --preserve_context is deprecated; " - "use --preserve-context instead")); - /* fall through */ - case PRESERVE_CONTEXT_OPTION: - if ( ! selinux_enabled) - { - error (0, 0, _("WARNING: ignoring --preserve-context; " - "this kernel is not SELinux-enabled")); - break; - } - x.preserve_security_context = true; - use_default_selinux_context = false; - break; - case 'Z': - if ( ! selinux_enabled) - { - error (0, 0, _("WARNING: ignoring --context (-Z); " - "this kernel is not SELinux-enabled")); - break; - } - scontext = optarg; - use_default_selinux_context = false; - break; - case_GETOPT_HELP_CHAR; - case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS); - default: - usage (EXIT_FAILURE); - } + break; + case STRIP_PROGRAM_OPTION: + strip_program = xstrdup (optarg); + strip_program_specified = true; + break; + case 'd': + dir_arg = true; + break; + case 'D': + mkdir_and_install = true; + break; + case 'v': + x.verbose = true; + break; + case 'g': + group_name = optarg; + break; + case 'm': + specified_mode = optarg; + break; + case 'o': + owner_name = optarg; + break; + case 'p': + x.preserve_timestamps = true; + break; + case 'S': + make_backups = true; + backup_suffix_string = optarg; + break; + case 't': + if (target_directory) + error (EXIT_FAILURE, 0, + _("multiple target directories specified")); + else + { + struct stat st; + if (stat (optarg, &st) != 0) + error (EXIT_FAILURE, errno, _("accessing %s"), quote (optarg)); + if (! S_ISDIR (st.st_mode)) + error (EXIT_FAILURE, 0, _("target %s is not a directory"), + quote (optarg)); + } + target_directory = optarg; + break; + case 'T': + no_target_directory = true; + break; + + case PRESERVE_CONTEXT_OPTION_DEPRECATED: + error (0, 0, _("WARNING: --preserve_context is deprecated; " + "use --preserve-context instead")); + /* fall through */ + case PRESERVE_CONTEXT_OPTION: + if ( ! selinux_enabled) + { + error (0, 0, _("WARNING: ignoring --preserve-context; " + "this kernel is not SELinux-enabled")); + break; + } + x.preserve_security_context = true; + use_default_selinux_context = false; + break; + case 'Z': + if ( ! selinux_enabled) + { + error (0, 0, _("WARNING: ignoring --context (-Z); " + "this kernel is not SELinux-enabled")); + break; + } + scontext = optarg; + use_default_selinux_context = false; + break; + case_GETOPT_HELP_CHAR; + case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS); + default: + usage (EXIT_FAILURE); + } } /* Check for invalid combinations of arguments. */ if (dir_arg & strip_files) error (EXIT_FAILURE, 0, - _("the strip option may not be used when installing a directory")); + _("the strip option may not be used when installing a directory")); if (dir_arg && target_directory) error (EXIT_FAILURE, 0, - _("target directory not allowed when installing a directory")); + _("target directory not allowed when installing a directory")); if (x.preserve_security_context && scontext != NULL) error (EXIT_FAILURE, 0, - _("cannot force target context to %s and preserve it"), - quote (scontext)); + _("cannot force target context to %s and preserve it"), + quote (scontext)); if (backup_suffix_string) simple_backup_suffix = xstrdup (backup_suffix_string); x.backup_type = (make_backups - ? xget_version (_("backup type"), - version_control_string) - : no_backups); + ? xget_version (_("backup type"), + version_control_string) + : no_backups); if (scontext && setfscreatecon (scontext) < 0) error (EXIT_FAILURE, errno, - _("failed to set default file creation context to %s"), - quote (scontext)); + _("failed to set default file creation context to %s"), + quote (scontext)); n_files = argc - optind; file = argv + optind; @@ -594,39 +594,39 @@ main (int argc, char **argv) if (n_files <= ! (dir_arg || target_directory)) { if (n_files <= 0) - error (0, 0, _("missing file operand")); + error (0, 0, _("missing file operand")); else - error (0, 0, _("missing destination file operand after %s"), - quote (file[0])); + error (0, 0, _("missing destination file operand after %s"), + quote (file[0])); usage (EXIT_FAILURE); } if (no_target_directory) { if (target_directory) - error (EXIT_FAILURE, 0, - _("cannot combine --target-directory (-t) " - "and --no-target-directory (-T)")); + error (EXIT_FAILURE, 0, + _("cannot combine --target-directory (-t) " + "and --no-target-directory (-T)")); if (2 < n_files) - { - error (0, 0, _("extra operand %s"), quote (file[2])); - usage (EXIT_FAILURE); - } + { + error (0, 0, _("extra operand %s"), quote (file[2])); + usage (EXIT_FAILURE); + } } else if (! (dir_arg || target_directory)) { if (2 <= n_files && target_directory_operand (file[n_files - 1])) - target_directory = file[--n_files]; + target_directory = file[--n_files]; else if (2 < n_files) - error (EXIT_FAILURE, 0, _("target %s is not a directory"), - quote (file[n_files - 1])); + error (EXIT_FAILURE, 0, _("target %s is not a directory"), + quote (file[n_files - 1])); } if (specified_mode) { struct mode_change *change = mode_compile (specified_mode); if (!change) - error (EXIT_FAILURE, 0, _("invalid mode %s"), quote (specified_mode)); + error (EXIT_FAILURE, 0, _("invalid mode %s"), quote (specified_mode)); mode = mode_adjust (0, false, 0, change, NULL); dir_mode = mode_adjust (0, true, 0, change, &dir_mode_bits); free (change); @@ -634,25 +634,25 @@ main (int argc, char **argv) if (strip_program_specified && !strip_files) error (0, 0, _("WARNING: ignoring --strip-program option as -s option was " - "not specified")); + "not specified")); if (copy_only_if_needed && x.preserve_timestamps) { error (0, 0, _("options --compare (-C) and --preserve-timestamps are " - "mutually exclusive")); + "mutually exclusive")); usage (EXIT_FAILURE); } if (copy_only_if_needed && strip_files) { error (0, 0, _("options --compare (-C) and --strip are mutually " - "exclusive")); + "exclusive")); usage (EXIT_FAILURE); } if (copy_only_if_needed && extra_mode (mode)) error (0, 0, _("the --compare (-C) option is ignored when you" - " specify a mode with non-permission bits")); + " specify a mode with non-permission bits")); get_ids (); @@ -661,24 +661,24 @@ main (int argc, char **argv) else { /* FIXME: it's a little gross that this initialization is - required by copy.c::copy. */ + required by copy.c::copy. */ hash_init (); if (!target_directory) { if (! (mkdir_and_install - ? install_file_in_file_parents (file[0], file[1], &x) - : install_file_in_file (file[0], file[1], &x))) - exit_status = EXIT_FAILURE; - } + ? install_file_in_file_parents (file[0], file[1], &x) + : install_file_in_file (file[0], file[1], &x))) + exit_status = EXIT_FAILURE; + } else - { - int i; - dest_info_init (&x); - for (i = 0; i < n_files; i++) - if (! install_file_in_dir (file[i], target_directory, &x)) - exit_status = EXIT_FAILURE; - } + { + int i; + dest_info_init (&x); + for (i = 0; i < n_files; i++) + if (! install_file_in_dir (file[i], target_directory, &x)) + exit_status = EXIT_FAILURE; + } } exit (exit_status); @@ -689,7 +689,7 @@ main (int argc, char **argv) static bool install_file_in_file_parents (char const *from, char *to, - struct cp_options *x) + struct cp_options *x) { bool save_working_directory = ! (IS_ABSOLUTE_FILE_NAME (from) && IS_ABSOLUTE_FILE_NAME (to)); @@ -712,12 +712,12 @@ install_file_in_file_parents (char const *from, char *to, int restore_errno = errno; savewd_finish (&wd); if (EXIT_SUCCESS < restore_result) - return false; + return false; if (restore_result < 0 && status == EXIT_SUCCESS) - { - error (0, restore_errno, _("cannot create directory %s"), to); - return false; - } + { + error (0, restore_errno, _("cannot create directory %s"), to); + return false; + } } return (status == EXIT_SUCCESS && install_file_in_file (from, to, x)); @@ -729,7 +729,7 @@ install_file_in_file_parents (char const *from, char *to, static bool install_file_in_file (const char *from, const char *to, - const struct cp_options *x) + const struct cp_options *x) { struct stat from_sb; if (x->preserve_timestamps && stat (from, &from_sb) != 0) @@ -753,7 +753,7 @@ install_file_in_file (const char *from, const char *to, static bool install_file_in_dir (const char *from, const char *to_dir, - const struct cp_options *x) + const struct cp_options *x) { const char *from_base = last_component (from); char *to = file_name_concat (to_dir, from_base, NULL); @@ -856,9 +856,9 @@ strip (char const *name) break; default: /* Parent. */ if (waitpid (pid, &status, 0) < 0) - error (EXIT_FAILURE, errno, _("waiting for strip")); + error (EXIT_FAILURE, errno, _("waiting for strip")); else if (! WIFEXITED (status) || WEXITSTATUS (status)) - error (EXIT_FAILURE, 0, _("strip process terminated abnormally")); + error (EXIT_FAILURE, 0, _("strip process terminated abnormally")); break; } } @@ -875,15 +875,15 @@ get_ids (void) { pw = getpwnam (owner_name); if (pw == NULL) - { - unsigned long int tmp; - if (xstrtoul (owner_name, NULL, 0, &tmp, NULL) != LONGINT_OK - || UID_T_MAX < tmp) - error (EXIT_FAILURE, 0, _("invalid user %s"), quote (owner_name)); - owner_id = tmp; - } + { + unsigned long int tmp; + if (xstrtoul (owner_name, NULL, 0, &tmp, NULL) != LONGINT_OK + || UID_T_MAX < tmp) + error (EXIT_FAILURE, 0, _("invalid user %s"), quote (owner_name)); + owner_id = tmp; + } else - owner_id = pw->pw_uid; + owner_id = pw->pw_uid; endpwent (); } else @@ -893,15 +893,15 @@ get_ids (void) { gr = getgrnam (group_name); if (gr == NULL) - { - unsigned long int tmp; - if (xstrtoul (group_name, NULL, 0, &tmp, NULL) != LONGINT_OK - || GID_T_MAX < tmp) - error (EXIT_FAILURE, 0, _("invalid group %s"), quote (group_name)); - group_id = tmp; - } + { + unsigned long int tmp; + if (xstrtoul (group_name, NULL, 0, &tmp, NULL) != LONGINT_OK + || GID_T_MAX < tmp) + error (EXIT_FAILURE, 0, _("invalid group %s"), quote (group_name)); + group_id = tmp; + } else - group_id = gr->gr_gid; + group_id = gr->gr_gid; endgrent (); } else @@ -934,7 +934,7 @@ usage (int status) { if (status != EXIT_SUCCESS) fprintf (stderr, _("Try `%s --help' for more information.\n"), - program_name); + program_name); else { printf (_("\ @@ -943,7 +943,7 @@ Usage: %s [OPTION]... [-T] SOURCE DEST\n\ or: %s [OPTION]... -t DIRECTORY SOURCE...\n\ or: %s [OPTION]... -d DIRECTORY...\n\ "), - program_name, program_name, program_name, program_name); + program_name, program_name, program_name, program_name); fputs (_("\ \n\ This install program copies files (often just compiled) into destination\n\ |