Comments on the pax patch?
Hi,
Attached is a patch to make pax-20090728 build under GNU/Hurd. Function
calls changed are readlink()->xreadlink() (new, same as for psmisc) and
realpath()->canonicalize_file_name().
Comments?
Thanks!
diff -ur pax-20090728/file_subs.c pax-20090728.modified/file_subs.c
--- pax-20090728/file_subs.c 2009-07-28 17:38:28.000000000 +0000
+++ pax-20090728.modified/file_subs.c 2011-10-12 19:03:24.000000000 +0000
@@ -342,6 +342,29 @@
* 0 if ok, -1 otherwise
*/
+char* xreadlink(const char *filename) {
+ int nchars, size = 128;
+ char *buffer;
+ if ((buffer=(char*)malloc(size)) == NULL) {
+ errno = ENOMEM;
+ return NULL;
+ }
+ while ((nchars = readlink(filename,buffer,size)) == size) {
+ size *= 2;
+ if ((buffer = (char*)realloc(buffer,size)) == NULL) {
+ errno = ENOMEM;
+ return NULL;
+ }
+ }
+ if (nchars < 0) {
+ free (buffer);
+ errno = EINVAL;
+ return NULL;
+ }
+ buffer[nchars]='\0';
+ return buffer;
+}
+
int
node_creat(ARCHD *arcn)
{
@@ -351,9 +374,8 @@
int pass = 0;
mode_t file_mode;
struct stat sb;
- char target[MAXPATHLEN];
+ char *target = NULL;
char *nm = arcn->name;
- int len;
/*
* create node based on type, if that fails try to unlink the node and
@@ -374,17 +396,16 @@
if (strcmp(NM_TAR, argv0) == 0 && Lflag) {
while (lstat(nm, &sb) == 0 &&
S_ISLNK(sb.st_mode)) {
- len = readlink(nm, target,
- sizeof target - 1);
- if (len == -1) {
+ target = xreadlink(nm);
+ if (target == NULL) {
syswarn(0, errno,
"cannot follow symlink %s in chain for %s",
nm, arcn->name);
res = -1;
goto badlink;
}
- target[len] = '\0';
nm = target;
+ free(target);
}
}
res = mkdir(nm, file_mode);
Only in pax-20090728.modified: file_subs.c~
diff -ur pax-20090728/tables.c pax-20090728.modified/tables.c
--- pax-20090728/tables.c 2009-07-28 17:38:28.000000000 +0000
+++ pax-20090728.modified/tables.c 2011-10-12 18:34:21.000000000 +0000
@@ -1126,17 +1126,18 @@
add_dir(char *name, struct stat *psb, int frc_mode)
{
DIRDATA *dblk;
- char realname[MAXPATHLEN], *rp;
+ char *rp;
if (dirp == NULL)
return;
if (havechd && *name != '/') {
- if ((rp = realpath(name, realname)) == NULL) {
+ if ((rp = canonicalize_file_name(name)) == NULL) {
paxwarn(1, "Cannot canonicalize %s", name);
return;
}
name = rp;
+ free(rp);
}
if (dircnt == dirsize) {
dblk = realloc(dirp, 2 * dirsize * sizeof(DIRDATA));
Reply to: