Go to:
Gentoo Home
Documentation
Forums
Lists
Bugs
Planet
Store
Wiki
Get Gentoo!
Gentoo's Bugzilla – Attachment 366866 Details for
Bug 465000
xattr pax-marking in src_compile() fails
Home
|
New
–
[Ex]
|
Browse
|
Search
|
Privacy Policy
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
c version of the wrapper
install.py.c (text/x-csrc), 8.52 KB, created by
Anthony Basile
on 2014-01-03 17:31:47 UTC
(
hide
)
Description:
c version of the wrapper
Filename:
MIME Type:
Creator:
Anthony Basile
Created:
2014-01-03 17:31:47 UTC
Size:
8.52 KB
patch
obsolete
>#define _GNU_SOURCE >#include <stdio.h> >#include <stdlib.h> >#include <string.h> >#include <fnmatch.h> > >#include <getopt.h> > >#include <unistd.h> >#include <sys/types.h> >#include <sys/wait.h> >#include <sys/stat.h> >#include <sys/xattr.h> > >void >copyxattr(const char *source, const char *target) >{ > int i, j; > char *exclude, *portage_xattr_exclude; // The string of excluded xattr names > int len; // The length of the string of excluded xattr names > ssize_t lsize, xsize; // The size in bytes of the list of xattrs and the values > char *lxattr, *value; // String of xattr names and the values > > lsize = listxattr(source, 0, 0); > lxattr = (char *)malloc(lsize); > listxattr(source, lxattr, lsize); > > portage_xattr_exclude = getenv("PORTAGE_XATTR_EXCLUDE"); > if (portage_xattr_exclude == NULL) > exclude = strdup("security.* system.nfs4_acl"); > else > exclude = strdup(portage_xattr_exclude); > > len = strlen(exclude); > > // Convert exclude[] to an array of concatenated null terminated strings > // lxattr[] is already such an array > for (i=0; i<len; i++) > if (isspace(exclude[i])) > exclude[i] = 0; > > i = 0 ; > while(1) { > while (lxattr[i++] == 0); > if (i>=lsize) > break; > > j = 0 ; > while(1) { > while (exclude[j++] == 0); > if (j>=len) > break; > if (!fnmatch(&exclude[j-1], &lxattr[i-1], 0)) > goto skip; > while (exclude[j++] != 0); > if (j>=len) > break; > } > > //printf("|%s|\n", &lxattr[i-1]); > xsize = getxattr(source, &lxattr[i-1], 0, 0); > if (xsize != -1) { > value = (char *)malloc(xsize); > memset(value, 0, xsize); > getxattr(source, &lxattr[i-1], value, xsize); > setxattr(target, &lxattr[i-1], value, xsize, 0); > } > > skip: > while (lxattr[i++] != 0); > if (i>=lsize) > break; > } > > free(lxattr); > free(exclude); > > return; >} > > >char * >which(void) >{ > /* FIXME: I don't know what path portage should search so I'll hard code it for now > > char *path, *env_path = getenv("PATH"); // The string of the $PATH to search > > // We strdup the path string because we're going to play > // with it below using the pointer 'dir', and then free it > if (env_path == NULL) > path = strdup("/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin"); > else > path = strdup(env_path); > */ > > // FIXME: This should be searching $PATH or somethin --- zmedico help! > char *path = strdup("/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin"); > > char *dir = path; // A diectorin in the $PATH string > char *p = NULL, *file; // File name = path + "/install" > > struct stat s; > > do { > p = strchr (dir, ':'); > if (p != NULL) > *p = 0; > asprintf(&file,"%s/%s", dir, "install"); > if (stat(file, &s) == 0) > if (s.st_mode & S_IFDIR != 0) > return strdup(file); > dir = p + 1; > } > while (p != NULL); > > free(path); >} > > > >int >main(int argc, char* argv[], char* envp[]) >{ > int i ; > int status ; // exit status of child install process > char *cmd_line = ""; // parsed command line reconstructed > > int opts_directory = 0; // if -d is given, then all arguments are directories > int opts_target_directory = 0; // if the -t option was given, then we're installing to a target directory > int target_is_directory = 0; // if the target is actually a directory > > int first, last; // argv indices of the first file/directory and last > char *target; // the target file or directory > char *path; // path to the target file > > struct stat s; // to test if a file is a regular file or a directory > > > while (1) > { > static struct option long_options[] = > { > { "backup", required_argument, 0, 0 }, > { "compare", no_argument, 0, 'C'}, > { "directory", no_argument, 0, 'd'}, > { "group", required_argument, 0, 'g'}, > { "mode", required_argument, 0, 'm'}, > { "owner", required_argument, 0, 'o'}, > { "preserve-timestamps", no_argument, 0, 'p'}, > { "strip-program", required_argument, 0, 0 }, > { "suffix", required_argument, 0, 'S'}, > { "target-directory", required_argument, 0, 't'}, > { "no-target-directory", no_argument, 0, 'T'}, > { "verbose", no_argument, 0, 'v'}, > { "preserve-context", no_argument, 0, 0 }, > { "context", required_argument, 0, 'Z'}, > { "help", no_argument, 0, 0 }, > { "version", no_argument, 0, 0 }, > { 0, 0, 0, 0 } > }; > > int option_index = 0; > > int c = getopt_long(argc, argv, "bcCdDg:m:o:psS:t:TvZ:", long_options, &option_index); > > if (c == -1) > break; > > switch (c) > { > case 0: > asprintf(&cmd_line, "%s --%s", cmd_line, long_options[option_index].name) ; > if (optarg) > asprintf(&cmd_line, "%s=%s", cmd_line, optarg); > break; > > case 'b': > asprintf (&cmd_line, "%s -b", cmd_line); > break; > > case 'c': > break; > > case 'C': > asprintf (&cmd_line, "%s -C", cmd_line); > break; > > case 'd': > opts_directory = 1 ; > asprintf (&cmd_line, "%s -d", cmd_line); > break; > > case 'D': > asprintf (&cmd_line, "%s -D", cmd_line); > break; > > case 'g': > asprintf (&cmd_line, "%s -g %s", cmd_line, optarg); > break; > > case 'm': > asprintf (&cmd_line, "%s -m %s", cmd_line, optarg); > break; > > case 'o': > asprintf (&cmd_line, "%s -o %s", cmd_line, optarg); > break; > > case 'p': > asprintf (&cmd_line, "%s -p", cmd_line); > break; > > case 's': > asprintf (&cmd_line, "%s -s", cmd_line); > break; > > case 't': > opts_target_directory = 1 ; > asprintf (&target, "%s", optarg); > asprintf (&cmd_line, "%s -t %s", cmd_line, optarg); > break; > > case 'T': > asprintf (&cmd_line, "%s -T", cmd_line); > break; > > case 'v': > asprintf (&cmd_line, "%s -v", cmd_line); > break; > > case 'Z': > asprintf (&cmd_line, "%s -Z %s", cmd_line, optarg); > break; > > case '?': > break; > > default: > abort (); > } > } > > first = optind; > while (optind < argc) > asprintf (&cmd_line, "%s %s", cmd_line, argv[optind++]); > last = optind-1; > > if (fork()) { > wait(&status); > > // If all the targets are directories, do nothing > if (opts_directory) > return EXIT_SUCCESS; > > if (!opts_target_directory) { > target = argv[last]; > if (stat(target, &s) != 0) > return EXIT_FAILURE; > target_is_directory = s.st_mode & S_IFDIR; > } else { > //target was set above for -t option > target_is_directory = 1; > } > > if (target_is_directory) { > // If -t was passed, then the last argv *is* a file, > // so we include it for copyxattr(). > if (opts_target_directory) > last++; > > for (i=first; i<last; i++) { > // Reproduce install behavior and skip > // directories that are not a target > stat(argv[i], &s); > if (s.st_mode & S_IFDIR) > continue; > > asprintf (&path, "%s/%s", target, argv[i]); > copyxattr (argv[i], path); > } > } else > copyxattr (argv[first], target); > > } else { > char *install = which(); // search path for install > execve (install, argv, envp); > free(install); > } > > return EXIT_SUCCESS; >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 465000
:
351430
|
351470
|
351474
|
351600
|
366866
|
367452
|
367656
|
368280