Skip to contentSkip to conversation

Porting git to HP NonStop

DISCUSSION Joachim Schmitz 5 participants 39 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw
Quoted 10 lines

From: [email protected] [mailto:[email protected]] On Behalf Of Joachim Schmitz
Sent: Friday, August 10, 2012 5:01 PM
To: [email protected]
Cc: [email protected]
Subject: RE: [PATCH v2] add tests for 'git rebase --keep-empty'

Hi folks

I'm a brand new subscriper of this mailing list, so please forgive if I

violate

Quoted 1 line

some protocol or talk about things that had been discussed to death

earlier.

Ahrgl, 1st mistake: wrong subject, sorry

Quoted 1 line

I'm currently in the process of porting git (1.7.11.4 for now) to the HP

NonStop

Quoted 6 lines

platform and found several issues:

- HP NonStop is lacking poll(), git is making quite some use of it. My Solution: I 'stole' the implementation from GNUlib, which implements poll() using select().
Git should either provide its own poll(), not use it at all or resort to

using

Quoted 3 lines

GNUlib, what do you think?.

- HP NonStop is lacking getrlimit(), fsync(), setitimer() and memory

mapped IO.

Quoted 4 lines

For now I've commented out the part that used getrlimit() and use a home brewed implementation for fsync(), setitimer() and mmap().

- git makes use of some C99 features or at least feature that are not

availabe in

Quoted 2 lines

C89, like 'inline'
C89 is the default compiler on HP NonStop, but we also habe a c99

compiler, so

Quoted 8 lines

telling configure to search for c99 should help here.

- libintl and libiconv sem to get linked in the wrong order, resulting in unresolved symbols.
I've just moved the "ifndef NO_GETTEXT" section of Makefile to above the "ifdef NEEDS_LIBICONF" section.

- HP NonStop doesn't have stat.st_blocks, this is used in

builtin/count-objects.c

Quoted 3 lines

around line 45, not sure yet how to fix that.

- HP NonStop doesn't have stat.st_?time.nsec, there are several places

what an

Quoted 5 lines

"#ifdef USE_NSEC" is missing, I can provide a diff if needed (offending
files: builtin/fetch-pack.c and read-cache.c).

- HP NonStop doesn't know SA_RESTART
I fixed that with a "#define SA_RESTART 0" in the 3 files affected

(builtin/log.c,

Quoted 3 lines

fast-import.c and progress.c)

- using C99 but not using #include <strings.h> results in compiler errors

due to

Quoted 1 line

a missing prototype for strcasecmp() I fixed it by adding that to

git-compat-

Quoted 3 lines

util.h

- HP NonStop doesn't have intptr_t and uintpr_t (in its stdint.h) I added

them to

Quoted 11 lines

git-compat-util.h

- HP NonStop doesn't need the " #define _XOPEN_SOURCE 600", just like __APPLE__, __FreeBSD__ etc, so I added a "&& !defined(__TANDEM) in git- compat-util.h

- there seems to be an issue with compat/fnmatch/fnmatch.c not including string.h, seems that HAVE_STRING_H is not #define'd anywhere.

- Once compiled and installed, a simple jojo@\hpitug:/home/jojo/GitHub $

git

Quoted 2 lines

clone git://github.com/git/git.git fails with:
/home/jojo/GitHub/git/.git/branches/: No such file or directory After

creating

Quoted 3 lines

those manually it fails because the directory isn't empty, catch-22
After some trial'n'error I found that the culprit seems to be the

subdirectories

Quoted 5 lines

branches, hook and info in /usr/local/share/git-core/templates/, if I remove/rename those, the above command works fine.
I have no idea why that is nor how to properly fix it, anyone out there?

Bye, Jojo

#1 lore raw
Quoted 7 lines · Joachim Schmitz
Quoted 5 lines

- HP NonStop is lacking poll(), git is making quite some use of it. My Solution: I 'stole' the implementation from GNUlib, which implements poll() using select().
Git should either provide its own poll(), not use it at all or resort to

using

Quoted 1 line

GNUlib, what do you think?.

poll() is usually better than select() because you don't need to worry about FD_SETSIZE. That said, the compat/ directory contains implementations of some functions. You could contribute a fake poll that uses select if it was under the GPLv2.

Quoted 4 lines
Quoted 1 line

- HP NonStop is lacking getrlimit(), fsync(), setitimer() and memory

mapped IO.

Quoted 2 lines

For now I've commented out the part that used getrlimit() and use a home brewed implementation for fsync(), setitimer() and mmap().

There is no need to define your own mmap(). Define NO_MMAP=1 in the Makefile. Git already has its own fake mmap and knows how to write it back to disk when making changes.

Quoted 6 lines
Quoted 1 line

- git makes use of some C99 features or at least feature that are not

availabe in

Quoted 2 lines

C89, like 'inline'
C89 is the default compiler on HP NonStop, but we also habe a c99

compiler, so

Quoted 1 line

telling configure to search for c99 should help here.

You could also disable inline by #define inline /**/, but this will probably result in a slower binary.

Quoted 3 lines
Quoted 1 line

- HP NonStop doesn't have stat.st_blocks, this is used in

builtin/count-objects.c

Quoted 1 line

around line 45, not sure yet how to fix that.

IIRC the block count is only used to give the user some notion of how much disk was wasted by the repository. You could hack a macro that redefines this as st_size.

Quoted 4 lines
Quoted 1 line

- HP NonStop doesn't have stat.st_?time.nsec, there are several places

what an

Quoted 2 lines

"#ifdef USE_NSEC" is missing, I can provide a diff if needed (offending
files: builtin/fetch-pack.c and read-cache.c).

I think this would be appreciated by anyone else that has a similar problem where the platform lacks nsec.

Quoted 12 lines
Quoted 1 line

- Once compiled and installed, a simple jojo@\hpitug:/home/jojo/GitHub $

git

Quoted 2 lines

clone git://github.com/git/git.git fails with:
/home/jojo/GitHub/git/.git/branches/: No such file or directory After

creating

Quoted 3 lines

those manually it fails because the directory isn't empty, catch-22
After some trial'n'error I found that the culprit seems to be the

subdirectories

Quoted 3 lines

branches, hook and info in /usr/local/share/git-core/templates/, if I remove/rename those, the above command works fine.
I have no idea why that is nor how to properly fix it, anyone out there?

This sounds like the templates directory was not created correctly during installation, or is being copied incorrectly during the git init process. I would start by comparing the structure and permissions of the templates directory on your HP NonStop system to one on a Linux system and see if there was a mistake made during the installation process. If the directory matches, I would then use git init --bare in a new directory to copy in the templates, and see if its the template copying code that is making an incorrect copy.

#2 lore raw
Quoted 15 lines

From: Shawn Pearce [mailto:[email protected]]
Sent: Friday, August 10, 2012 6:28 PM
To: Joachim Schmitz
Cc: [email protected]; [email protected]
Subject: Re: Porting git to HP NonStop

Quoted 7 lines · Joachim Schmitz
Quoted 7 lines

- HP NonStop is lacking poll(), git is making quite some use of it. My Solution: I 'stole' the implementation from GNUlib, which implements
poll() using select().
Git should either provide its own poll(), not use it at all or resort to

Quoted 4 lines
Quoted 2 lines

using

Quoted 1 line

GNUlib, what do you think?.

poll() is usually better than select() because you don't need to worry

about

Quoted 2 lines

FD_SETSIZE. That said, the compat/ directory contains implementations of some functions. You could contribute a fake poll that uses select if it

was under

Quoted 1 line

the GPLv2.

This is what I did. Just to see now that compat/win32/poll.c has exacly the same stuff...

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

- HP NonStop is lacking getrlimit(), fsync(), setitimer() and memory

mapped IO.

Quoted 2 lines

For now I've commented out the part that used getrlimit() and use a home brewed implementation for fsync(), setitimer() and mmap().

There is no need to define your own mmap(). Define NO_MMAP=1 in the Makefile. Git already has its own fake mmap and knows how to write it back

to

Quoted 1 line

disk when making changes.

Ah, excellent. Esp. as our home brewed implementation is pretty primitive.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

- git makes use of some C99 features or at least feature that are not

availabe in

Quoted 2 lines

C89, like 'inline'
C89 is the default compiler on HP NonStop, but we also habe a c99

compiler, so

Quoted 1 line

telling configure to search for c99 should help here.

You could also disable inline by #define inline /**/, but this will

probably result

Quoted 1 line

in a slower binary.

Even our C99 compiler doesn't inline, it merly recognizes the keyword and then warns about (unable to inline...)
But there are other C99 features used too.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

- HP NonStop doesn't have stat.st_blocks, this is used in

builtin/count-objects.c

Quoted 1 line

around line 45, not sure yet how to fix that.

IIRC the block count is only used to give the user some notion of how much

disk

Quoted 1 line

was wasted by the repository. You could hack a macro that redefines this

as

Quoted 1 line

st_size.

OK, thanks, will try that.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

- HP NonStop doesn't have stat.st_?time.nsec, there are several places

what an

Quoted 3 lines

"#ifdef USE_NSEC" is missing, I can provide a diff if needed (offending
files: builtin/fetch-pack.c and read-cache.c).

I think this would be appreciated by anyone else that has a similar

problem

Quoted 1 line

where the platform lacks nsec.

Will do.

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

- Once compiled and installed, a simple
jojo@\hpitug:/home/jojo/GitHub $

git

Quoted 2 lines

clone git://github.com/git/git.git fails with:
/home/jojo/GitHub/git/.git/branches/: No such file or directory After

Quoted 8 lines
Quoted 8 lines

creating

Quoted 3 lines

those manually it fails because the directory isn't empty, catch-22
After some trial'n'error I found that the culprit seems to be the

subdirectories

Quoted 3 lines

branches, hook and info in /usr/local/share/git-core/templates/, if I remove/rename those, the above command works fine.
I have no idea why that is nor how to properly fix it, anyone out

there?

Quoted 3 lines

This sounds like the templates directory was not created correctly during installation, or is being copied incorrectly during the git init process.

I would

Quoted 1 line

start by comparing the structure and permissions of the templates

directory on

Quoted 2 lines

your HP NonStop system to one on a Linux system and see if there was a mistake made during the installation process. If the directory matches, I

would

jojo@\hpitug:/usr/local/share/git-core/templates $ ls -laR total 41

drwxr-xr-x    1 SUPER.SUPER        SUPER       4096 Aug 10 12:10 .
drwxr-xr-x    1 SUPER.SUPER        SUPER       4096 Aug 10 08:19 ..
drwxr-xr-x    1 SUPER.SUPER        SUPER       4096 Aug 10 07:26 branches
drwxr-xr-x    1 SUPER.SUPER        SUPER       4096 Aug 10 07:26 hooks
drwxr-xr-x    1 SUPER.SUPER        SUPER       4096 Aug 10 07:26 info
-rw-r--r--    1 SUPER.SUPER        SUPER         73 Aug 10 07:26 description

./branches:
total 16

drwxr-xr-x    1 SUPER.SUPER        SUPER       4096 Aug 10 07:26 .
drwxr-xr-x    1 SUPER.SUPER        SUPER       4096 Aug 10 12:10 ..

./hooks:
total 43

drwxr-xr-x    1 SUPER.SUPER        SUPER       4096 Aug 10 07:26 .
drwxr-xr-x    1 SUPER.SUPER        SUPER       4096 Aug 10 12:10 ..
-rwxr-xr-x    1 SUPER.SUPER        SUPER        452 Aug 10 07:26

applypatch-msg.sample
-rwxr-xr-x 1 SUPER.SUPER SUPER 896 Aug 10 07:26
commit-msg.sample
-rwxr-xr-x 1 SUPER.SUPER SUPER 189 Aug 10 07:26
post-update.sample
-rwxr-xr-x 1 SUPER.SUPER SUPER 398 Aug 10 07:26
pre-applypatch.sample
-rwxr-xr-x 1 SUPER.SUPER SUPER 1704 Aug 10 07:26
pre-commit.sample
-rwxr-xr-x 1 SUPER.SUPER SUPER 4957 Aug 10 07:26
pre-rebase.sample
-rwxr-xr-x 1 SUPER.SUPER SUPER 1251 Aug 10 07:26
prepare-commit-msg.sample
-rwxr-xr-x 1 SUPER.SUPER SUPER 3611 Aug 10 07:26
update.sample

./info:
total 17

drwxr-xr-x    1 SUPER.SUPER        SUPER       4096 Aug 10 07:26 .
drwxr-xr-x    1 SUPER.SUPER        SUPER       4096 Aug 10 12:10 ..
-rw-r--r--    1 SUPER.SUPER        SUPER        240 Aug 10 07:26 exclude

jojo@\hpitug:/usr/local/share/git-core/templates $

SUPER.SUPER on NonStop is equivalent to root in UNIX. Everything is readable to everybody. Looks OK to me?

Quoted 1 line

then use git init --bare in a new directory to copy in the templates,

and see if

Quoted 1 line

its the template copying code that is making an incorrect copy.

"git init --bare" gives the same error. It isn't copying any of the subdirectories, only the file 'description'

Bye, Jojo

#3 lore raw
Quoted 6 lines · Joachim Schmitz
Quoted 1 line

then use git init --bare in a new directory to copy in the templates,

and see if

Quoted 1 line

its the template copying code that is making an incorrect copy.

"git init --bare" gives the same error. It isn't copying any of the subdirectories, only the file 'description'

Time to start debugging copy_templates_1 in builtin/init-db.c. :-(

#35 lore raw
In reply to Shawn Pearce
Quoted 29 lines

From: Joachim Schmitz [mailto:[email protected]]
Sent: Friday, August 10, 2012 10:09 PM
To: 'Shawn Pearce'
Cc: '[email protected]'; '[email protected]'
Subject: RE: Porting git to HP NonStop

Quoted 15 lines

From: Joachim Schmitz [mailto:[email protected]]
Sent: Friday, August 10, 2012 7:33 PM
To: 'Shawn Pearce'
Cc: '[email protected]'; '[email protected]'
Subject: RE: Porting git to HP NonStop

Quoted 9 lines

From: Shawn Pearce [mailto:[email protected]]
Sent: Friday, August 10, 2012 6:28 PM
To: Joachim Schmitz
Cc: [email protected]; [email protected]
Subject: Re: Porting git to HP NonStop

On Fri, Aug 10, 2012 at 8:04 AM, Joachim Schmitz
<[email protected]>
wrote:

<snip>

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

- HP NonStop doesn't have stat.st_?time.nsec, there are several places

what an

Quoted 3 lines

"#ifdef USE_NSEC" is missing, I can provide a diff if needed (offending
files: builtin/fetch-pack.c and read-cache.c).

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

I think this would be appreciated by anyone else that has a similar problem where the platform lacks nsec.

Will do.

OK, here we go:

/usr/local/bin/diff -EBbu ./builtin/fetch-pack.c.orig

./builtin/fetch-pack.c
<snip>

Sorry, this is not needed if I just set NO_NSEC, so just forget about it (and thanks to Junio for telling be)

git-compat-util.h 2012-08-10 09:59:56 -0500 line 78

Quoted 10 lines

/usr/local/bin/diff -EBbu ./git-compat-util.h.orig ./git-compat-util.h

git-compat-util.h 2012-08-10 09:59:56 -0500 renamed from git-compat-util.h.orig 2012-07-30 15:50:38 -0500 +1 -1
@@ -74,7 +74,8 @@
 # define _XOPEN_SOURCE 500
 # endif
 #elif !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__USLC__)
 && \
-      !defined(_M_UNIX) && !defined(__sgi) && !defined(__DragonFly__)
+      !defined(_M_UNIX) && !defined(__sgi) && !defined(__DragonFly__) &&

\

git-compat-util.h 2012-08-10 09:59:56 -0500

Quoted 13 lines
git-compat-util.h 2012-08-10 09:59:56 -0500 renamed from git-compat-util.h.orig 2012-07-30 15:50:38 -0500 +1 -0
+      !defined(__TANDEM)
 #define _XOPEN_SOURCE 600 /* glibc2 and AIX 5.3L need 500, OpenBSD

needs 600 for S_ISLNK() */ #define _XOPEN_SOURCE_EXTENDED 1 /* AIX 5.3L needs this */ #endif @@ -98,6 +99,11 @@ #include <stdlib.h> #include <stdarg.h> #include <string.h>

git-compat-util.h 2012-08-10 09:59:56 -0500 renamed from git-compat-util.h.orig 2012-07-30 15:50:38 -0500 +5 -0
+#ifdef __TANDEM
+# include <strings.h> /* for strcasecmp() */
+  typedef long int intptr_t;
+  typedef unsigned long int uintptr_t;
+#endif
 #include <errno.h>
 #include <limits.h>
 #include <sys/param.h>

This one still stands though, unless someone can come up with a better idea?

Bye, Jojo

#37 lore raw
In reply to Shawn Pearce
Quoted 15 lines

From: Joachim Schmitz [mailto:[email protected]]
Sent: Friday, August 10, 2012 7:33 PM
To: 'Shawn Pearce'
Cc: '[email protected]'; '[email protected]'
Subject: RE: Porting git to HP NonStop

Quoted 9 lines

From: Shawn Pearce [mailto:[email protected]]
Sent: Friday, August 10, 2012 6:28 PM
To: Joachim Schmitz
Cc: [email protected]; [email protected]
Subject: Re: Porting git to HP NonStop

On Fri, Aug 10, 2012 at 8:04 AM, Joachim Schmitz
<[email protected]>
wrote:

<snip>

Quoted 9 lines
Quoted 7 lines
Quoted 3 lines
Quoted 1 line

- HP NonStop doesn't have stat.st_blocks, this is used in

builtin/count-objects.c

Quoted 1 line

around line 45, not sure yet how to fix that.

IIRC the block count is only used to give the user some notion of how much disk was wasted by the repository. You could hack a macro that redefines this as st_size.

OK, thanks, will try that.

Setting "NO_ST_BLOCKS_IN_STRUCT_STAT = YesPlease" in Makefile helps, no need for further hacking ;-).

Quoted 11 lines
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

- HP NonStop doesn't have stat.st_?time.nsec, there are several places

what an

Quoted 3 lines

"#ifdef USE_NSEC" is missing, I can provide a diff if needed (offending
files: builtin/fetch-pack.c and read-cache.c).

I think this would be appreciated by anyone else that has a similar problem where the platform lacks nsec.

Will do.

OK, here we go:

/usr/local/bin/diff -EBbu ./builtin/fetch-pack.c.orig ./builtin/fetch-pack.c

builtin/fetch-pack.c 2012-08-10 01:50:28 -0500 renamed from builtin/fetch-pack.c.orig 2012-07-30 15:50:38 -0500 +2 -0
@@ -1096,7 +1096,9 @@
                int fd;
 
                mtime.sec = st.st_mtime;
+#ifdef USE_NSEC
                mtime.nsec = ST_MTIME_NSEC(st);
+#endif
                if (stat(shallow, &st)) {
                        if (mtime.sec)
                                die("shallow file was removed during

fetch");
/usr/local/bin/diff -EBbu ./read-cache.c.orig ./read-cache.c

read-cache.c 2012-08-09 10:57:57 -0500 renamed from read-cache.c.orig 2012-07-30 15:50:38 -0500 +6 -0
@@ -72,8 +72,10 @@
 {
        ce->ce_ctime.sec = (unsigned int)st->st_ctime;
        ce->ce_mtime.sec = (unsigned int)st->st_mtime;
+#ifdef USE_NSEC
        ce->ce_ctime.nsec = ST_CTIME_NSEC(*st);
        ce->ce_mtime.nsec = ST_MTIME_NSEC(*st);
+#endif
        ce->ce_dev = st->st_dev;
        ce->ce_ino = st->st_ino;
        ce->ce_uid = st->st_uid;
@@ -1465,7 +1467,9 @@
        }
        strbuf_release(&previous_name_buf);
        istate->timestamp.sec = st.st_mtime;
+#ifdef USE_NSEC
        istate->timestamp.nsec = ST_MTIME_NSEC(st);
+#endif
 
        while (src_offset <= mmap_size - 20 - 8) {
                /* After an array of active_nr index entries,
@@ -1821,7 +1825,9 @@
        if (ce_flush(&c, newfd) || fstat(newfd, &st))
                return -1;
        istate->timestamp.sec = (unsigned int)st.st_mtime;
+#ifdef USE_NSEC
        istate->timestamp.nsec = ST_MTIME_NSEC(st);
+#endif
        return 0;
 }
 

Hope this helps?

Could you also consider adding the following:

/usr/local/bin/diff -EBbu ./git-compat-util.h.orig ./git-compat-util.h

git-compat-util.h 2012-08-10 09:59:56 -0500 renamed from git-compat-util.h.orig 2012-07-30 15:50:38 -0500 +2 -1
@@ -74,7 +74,8 @@
 # define _XOPEN_SOURCE 500
 # endif
 #elif !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__USLC__) &&
\
-      !defined(_M_UNIX) && !defined(__sgi) && !defined(__DragonFly__)
+      !defined(_M_UNIX) && !defined(__sgi) && !defined(__DragonFly__) && \
+      !defined(__TANDEM)
 #define _XOPEN_SOURCE 600 /* glibc2 and AIX 5.3L need 500, OpenBSD needs

600 for S_ISLNK() */
#define _XOPEN_SOURCE_EXTENDED 1 /* AIX 5.3L needs this */ #endif
@@ -98,6 +99,11 @@
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
+#ifdef __TANDEM
+# include <strings.h> /* for strcasecmp() */
+ typedef long int intptr_t;
+ typedef unsigned long int uintptr_t;
+#endif
#include <errno.h>
#include <limits.h>
#include <sys/param.h>

Bye, Jojo

#38 lore raw
In reply to Shawn Pearce

Am 10.08.2012 18:27, schrieb Shawn Pearce:

Quoted 3 lines

There is no need to define your own mmap(). Define NO_MMAP=1 in the Makefile. Git already has its own fake mmap and knows how to write it back to disk when making changes.

Or better to say: the fake mmap has functionality that is sufficient for git. In particular, it does *not* write back changes to disk (it supports only MAP_PRIVATE), and the mapped area does not change if the file is changed by a third party.

-- Hannes

#36 lore raw
In reply to Joachim Schmitz
Quoted 11 lines · Joachim Schmitz

git-compat-util.h 2012-08-10 09:59:56 -0500 line 78

Quoted 10 lines

/usr/local/bin/diff -EBbu ./git-compat-util.h.orig ./git-compat-util.h

git-compat-util.h 2012-08-10 09:59:56 -0500 renamed from git-compat-util.h.orig 2012-07-30 15:50:38 -0500 +1 -1
@@ -74,7 +74,8 @@
 # define _XOPEN_SOURCE 500
 # endif
 #elif !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__USLC__)
 && \
-      !defined(_M_UNIX) && !defined(__sgi) && !defined(__DragonFly__)
+      !defined(_M_UNIX) && !defined(__sgi) && !defined(__DragonFly__) &&

\

Quoted 15 lines

git-compat-util.h 2012-08-10 09:59:56 -0500

Quoted 13 lines
git-compat-util.h 2012-08-10 09:59:56 -0500 renamed from git-compat-util.h.orig 2012-07-30 15:50:38 -0500 +1 -0
+      !defined(__TANDEM)
 #define _XOPEN_SOURCE 600 /* glibc2 and AIX 5.3L need 500, OpenBSD

needs 600 for S_ISLNK() */ #define _XOPEN_SOURCE_EXTENDED 1 /* AIX 5.3L needs this */ #endif @@ -98,6 +99,11 @@ #include <stdlib.h> #include <stdarg.h> #include <string.h>

git-compat-util.h 2012-08-10 09:59:56 -0500 renamed from git-compat-util.h.orig 2012-07-30 15:50:38 -0500 +5 -0
+#ifdef __TANDEM
+# include <strings.h> /* for strcasecmp() */
+  typedef long int intptr_t;
+  typedef unsigned long int uintptr_t;
+#endif
 #include <errno.h>
 #include <limits.h>
 #include <sys/param.h>

This one still stands though, unless someone can come up with a better idea?

This hunk looks unobtrusive and obviously will not impact other platforms, which is good.

#4 lore raw
In reply to Shawn Pearce
Quoted 7 lines

From: Shawn Pearce [mailto:[email protected]]
Sent: Friday, August 10, 2012 7:38 PM
To: Joachim Schmitz
Cc: [email protected]; [email protected]
Subject: Re: Porting git to HP NonStop

On Fri, Aug 10, 2012 at 10:32 AM, Joachim Schmitz

<[email protected]>

Quoted 10 lines
Quoted 7 lines · wrote:
Quoted 2 lines

then use git init --bare in a new directory to copy in the templates,

and see if

Quoted 1 line

its the template copying code that is making an incorrect copy.

"git init --bare" gives the same error. It isn't copying any of the subdirectories, only the file 'description'

Time to start debugging copy_templates_1 in builtin/init-db.c. :-(

Found the problem: our mkdir(dir,flags) fails with ENOENT when dir ends with a '/'.
Not sure whether this us a bug on out platform or just allowed by POSIX and as such a wrong assumption in git though?

[shortly after]
A bit of googleing revealed that there is a GNUlib solution for this, which claims that at least NetBSD 1.5.2 has the same problem.
(http://www.opensource.apple.com/source/gpatch/gpatch-2/patch/mkdir.c)

And apparently this has been discussed on the git mailing list too, 2 years ago:
http://lists-archives.com/git/728359-git-s-use-of-mkdir-2.html, there's a patch too.

For now I've fixed it like this:
/usr/local/bin/diff -EBbu ./builtin/init-db.c.orig ./builtin/init-db.c

builtin/init-db.c 2012-08-19 03:39:57 -0500 renamed from builtin/init-db.c.orig 2012-08-19 03:55:50 -0500 +9 -0
@@ -25,7 +25,16 @@
 
 static void safe_create_dir(const char *dir, int share)
 {
+#ifdef __TANDEM /* our mkdir() can't cope with a trailing '/' */
+       char mydir[PATH_MAX];
+
+       strcpy(mydir,dir);
+       if (dir[strlen(dir)-1] == '/')
+               mydir[strlen(dir)-1] = '\0';
+       if (mkdir(mydir, 0777) < 0) {
+#else
        if (mkdir(dir, 0777) < 0) {
+#endif
                if (errno != EEXIST) {
                        perror(dir);
                        exit(1);

Bye, Jojo

#5 lore raw
Quoted 10 lines · Joachim Schmitz

Found the problem: our mkdir(dir,flags) fails with ENOENT when dir ends with a '/'.
Not sure whether this us a bug on out platform or just allowed by POSIX and as such a wrong assumption in git though?

[shortly after]
A bit of googleing revealed that there is a GNUlib solution for this, which claims that at least NetBSD 1.5.2 has the same problem.
(http://www.opensource.apple.com/source/gpatch/gpatch-2/patch/mkdir.c)

Quoted 4 lines

And apparently this has been discussed on the git mailing list too, 2 years ago:
http://lists-archives.com/git/728359-git-s-use-of-mkdir-2.html, there's a patch too.

Given that newer BSDs have fixed libc to accept directory name with a trailing slash, and that we use mkdir(2) in many places, I think the right way to do so is still what I suggested in that old thread in the last paragraph of my message

http://thread.gmane.org/gmane.comp.version-control.git/155812/focus=155876

That is, have compat/tandem.c and define a replacement mkdir(2) in a way similar to how MinGW does so.

Quoted 8 lines

For now I've fixed it like this:
/usr/local/bin/diff -EBbu ./builtin/init-db.c.orig ./builtin/init-db.c

builtin/init-db.c 2012-08-19 03:39:57 -0500 renamed from builtin/init-db.c.orig 2012-08-19 03:55:50 -0500 +0 -0
@@ -25,7 +25,16 @@
 
 static void safe_create_dir(const char *dir, int share)
 {

builtin/init-db.c 2012-08-19 03:39:57 -0500 line 37

Quoted 10 lines
builtin/init-db.c 2012-08-19 03:39:57 -0500 renamed from builtin/init-db.c.orig 2012-08-19 03:55:50 -0500 +9 -0
+#ifdef __TANDEM /* our mkdir() can't cope with a trailing '/' */
+       char mydir[PATH_MAX];
+
+       strcpy(mydir,dir);
+       if (dir[strlen(dir)-1] == '/')
+               mydir[strlen(dir)-1] = '\0';
+       if (mkdir(mydir, 0777) < 0) {
+#else
        if (mkdir(dir, 0777) < 0) {
+#endif

Move that part inside #ifdef __TANDEM to define

	int tandem_mkdir(const char *dir, mode_t mode)
        {
		...
	}

in your new file compat/tandem.c, add

	#ifdef __TANDEM
        #define mkdir(a,b) tandem_mkdir((a), (b))
	#endif

to git-compat-util.h and then add compat/tandem.o to COMPAT_OBJS in the top-level Makefile.

That way we do not have to keep an ugly platform specific ifdef in the very generic codepath.

Quoted 7 lines
builtin/init-db.c 2012-08-19 03:39:57 -0500 renamed from builtin/init-db.c.orig 2012-08-19 03:55:50 -0500 +0 -0
                if (errno != EEXIST) {
                        perror(dir);
                        exit(1);

Bye, Jojo

#6 lore raw
Quoted 18 lines

From: Junio C Hamano [mailto:[email protected]]
Sent: Sunday, August 19, 2012 7:23 PM
To: Joachim Schmitz
Cc: 'Shawn Pearce'; [email protected]; [email protected]
Subject: Re: Porting git to HP NonStop

Quoted 10 lines · Joachim Schmitz

Found the problem: our mkdir(dir,flags) fails with ENOENT when dir ends with a '/'.
Not sure whether this us a bug on out platform or just allowed by POSIX and as such a wrong assumption in git though?

[shortly after]
A bit of googleing revealed that there is a GNUlib solution for this, which claims that at least NetBSD 1.5.2 has the same problem.
(http://www.opensource.apple.com/source/gpatch/gpatch-2/patch/mkdir.c)

Quoted 7 lines
Quoted 5 lines

And apparently this has been discussed on the git mailing list too, 2 years
ago:
http://lists-archives.com/git/728359-git-s-use-of-mkdir-2.html,
there's a patch too.

Given that newer BSDs have fixed libc to accept directory name with a

trailing

Quoted 1 line

slash, and that we use mkdir(2) in many places, I think the right way to

do so is

Quoted 1 line

still what I suggested in that old thread in the last paragraph of my

message

Quoted 6 lines

http://thread.gmane.org/gmane.comp.version-
control.git/155812/focus=155876

That is, have compat/tandem.c and define a replacement mkdir(2) in a way similar to how MinGW does so.

OK, I'll go for a compat/mkdir.c though.
We shouldn't call it tandem.c as Tandem, the Company, doesn't exist anymore and since more than a decade (bough by Compaq, then HP), only the __TANDEM survived in our compiler and headers/libraries. Could call it NonStop.c, but I don't really like that idea either, I'd rather keep it more generic, just in case someone else might need it too, or that issue someday gets fixed for NonStop.

Quoted 20 lines
Quoted 7 lines

For now I've fixed it like this:
/usr/local/bin/diff -EBbu ./builtin/init-db.c.orig ./builtin/init-db.c

builtin/init-db.c 2012-08-19 03:39:57 -0500 renamed from builtin/init-db.c.orig 2012-08-19 03:55:50 -0500 +0 -0
@@ -25,7 +25,16 @@
 
 static void safe_create_dir(const char *dir, int share)  {

builtin/init-db.c 2012-08-19 03:39:57 -0500 line 36

Quoted 10 lines
builtin/init-db.c 2012-08-19 03:39:57 -0500 renamed from builtin/init-db.c.orig 2012-08-19 03:55:50 -0500 +9 -0
+#ifdef __TANDEM /* our mkdir() can't cope with a trailing '/' */
+       char mydir[PATH_MAX];
+
+       strcpy(mydir,dir);
+       if (dir[strlen(dir)-1] == '/')
+               mydir[strlen(dir)-1] = '\0';
+       if (mkdir(mydir, 0777) < 0) {
+#else
        if (mkdir(dir, 0777) < 0) {
+#endif

Move that part inside #ifdef __TANDEM to define

Quoted 4 lines
	int tandem_mkdir(const char *dir, mode_t mode)
        {
		...
	}

I'll go for git_mkdir(), similar to other git wrappers, (like for mmap, pread, fopen, snprintf, vsnprintf, qsort). Could call it gitmkdir() too (like for basename, setenv, mkdtemp, mkstemps, unsetenv, strcasestr, strlcpy, strtoumax, strtoimax, strtok_r, hstrerror, memmem, strchrnul, memcpy), Opinions?
It seems the ones without the "_" are for missing APIs and the ones with "_" to wrap existing APIs (not sure about mmap and pread)?

Here it's current state:

$ cat compat/mkdir.c
#include "../git-compat-util.h"
#undef mkdir

/* for platforms that can't deal with a trailing '/' */ int git_mkdir(const char *dir, mode_t mode)

{
        int retval;
        char *tmp_dir = NULL;
        size_t len = strlen(dir);

        if (len && dir[len-1] == '/') {
                if ((tmp_dir = strdup(dir)) == NULL)
                        return -1;
                tmp_dir[len-1] = '\0';
        }
        else
                tmp_dir = (char *)dir;

        retval = mkdir(tmp_dir, mode);
        if (tmp_dir != dir)
                free(tmp_dir);

        return retval;
}

$

There is room for improvement though: it only removes one trailing slash. By far not as advanced and generic as GNUlib's mkdir wrapper, but should be good enough for git's usage.

Quoted 7 lines

in your new file compat/tandem.c, add

	#ifdef __TANDEM
        #define mkdir(a,b) tandem_mkdir((a), (b))
	#endif

to git-compat-util.h

Again, git_mkdir, see above

Quoted 2 lines

and then add compat/tandem.o to COMPAT_OBJS in the top-level Makefile.

For now I've added it to the (new) NOSTOP_KERNEL section.

We may want it to go along with some MKDIR_DISLIKES_TRAILING_SLASH or MKDIR_BOGUS_TRAILING_SLASH some such. Opinions, Ideas?

Quoted 1 line

That way we do not have to keep an ugly platform specific ifdef in the

very

Quoted 1 line

generic codepath.

Agreed, it was my quick and dirty fix for it.

Bye, Jojo

#7 lore raw
Quoted 1 line · Joachim Schmitz

OK, I'll go for a compat/mkdir.c though.

No. See below.

Quoted 6 lines

We shouldn't call it tandem.c as Tandem, the Company, doesn't exist anymore and since more than a decade (bough by Compaq, then HP), only the __TANDEM survived in our compiler and headers/libraries. Could call it NonStop.c, but I don't really like that idea either, I'd rather keep it more generic, just in case someone else might need it too, or that issue someday gets fixed for NonStop.

compat/hp_nonstop.c is also fine, but I think matching "#ifdef __TANDEM" is the most sensible.

And I wouldn't call it just "mkdir", as it is more likely than not that we will find other incompatibilities that needs to be absorbed in the compat/ layer, and we can add it to compat/tandem.c, but not to compat/mkdir.c, as that will be another nonstop specific tweak. A separate file, compat/tandem/mkdir.c, is fine, though.

Quoted 2 lines

I'll go for git_mkdir(), similar to other git wrappers, (like for mmap, pread, fopen, snprintf, vsnprintf, qsort).

Again, no. Your breakage is that having underlying system mkdir that does not understand trailing slash, which may not be specific to __TANDEM, but still is _not_ the only possible mode of breakage. Squatting on a generic "git_mkdir()" name makes it harder for other people to name their compat mkdir functions to tweak for the breakage on their platforms. The examples you listed are all "the platform does not offer it, so we implement the whole thing" kind, so it is in a different genre.

#8 lore raw
Quoted 12 lines

From: Junio C Hamano [mailto:[email protected]]
Sent: Monday, August 20, 2012 4:42 PM
To: Joachim Schmitz
Cc: 'Shawn Pearce'; [email protected]; [email protected]
Subject: Re: Porting git to HP NonStop

Quoted 1 line · Joachim Schmitz

OK, I'll go for a compat/mkdir.c though.

No. See below.

Quoted 8 lines
Quoted 6 lines

We shouldn't call it tandem.c as Tandem, the Company, doesn't exist anymore and since more than a decade (bough by Compaq, then HP), only the __TANDEM survived in our compiler and headers/libraries. Could call it NonStop.c, but I don't really like that idea either, I'd rather keep it more generic, just in case someone else might need it too, or that issue someday gets fixed for NonStop.

compat/hp_nonstop.c is also fine, but I think matching "#ifdef __TANDEM"

is

Quoted 3 lines

the most sensible.

And I wouldn't call it just "mkdir", as it is more likely than not that we

will find

Quoted 1 line

other incompatibilities that needs to be absorbed in the compat/ layer,

and we

Quoted 2 lines

can add it to compat/tandem.c, but not to compat/mkdir.c, as that will be another nonstop specific tweak.

I haven't found any other to be needed. Well, poll, maybe, but with only minor tweaks for the win32 one works for me (and those tweaks are compatible with win32

Quoted 6 lines

A separate file, compat/tandem/mkdir.c, is fine, though.

Quoted 2 lines

I'll go for git_mkdir(), similar to other git wrappers, (like for mmap, pread, fopen, snprintf, vsnprintf, qsort).

Again, no. Your breakage is that having underlying system mkdir that does

not

Quoted 1 line

understand trailing slash, which may not be specific to __TANDEM, but

still is

Quoted 1 line

_not_ the only possible mode of breakage.

Well, it is the only one GNUlib's mkdir caters for and I'd regard that an authoritative source...

Quoted 1 line

Squatting on a generic "git_mkdir()" name makes it harder for other people

to

Quoted 2 lines

name their compat mkdir functions to tweak for the breakage on their platforms. The examples you listed are all "the platform does not offer

it, so

Quoted 1 line

we implement the whole thing" kind, so it is in a different genre.

Nope, git_fopen() definitly is a wrapper for fopen(), as is git_vsnprintf() for vsnprintf().

Bye, Jojo

#9 lore raw
Quoted 5 lines · Joachim Schmitz

I haven't found any other to be needed. Well, poll, maybe, but with only minor tweaks for the win32 one works for me (and those tweaks are compatible with win32

Quoted 1 line

A separate file, compat/tandem/mkdir.c, is fine, though.

If you wouldn't have dozens of them, so compat/tandem/mkdir.c is not suitable; compat/tandem.c would be good, then.

Quoted 11 lines
Quoted 4 lines
Quoted 2 lines

I'll go for git_mkdir(), similar to other git wrappers, (like for mmap, pread, fopen, snprintf, vsnprintf, qsort).

Again, no. Your breakage is that having underlying system mkdir that does

not

Quoted 1 line

understand trailing slash, which may not be specific to __TANDEM, but

still is

Quoted 1 line

_not_ the only possible mode of breakage.

Well, it is the only one GNUlib's mkdir caters for and I'd regard that an authoritative source...

I suspect that you may be misunderstanding what compat/ is about, so let's try again.

Platform difference in mkdir may not be limited to "on this platform, the underlying one supplied by the system does not like path ending with a slash".

What I am saying is that it is unacceptable to call something that caters to that specific kind of difference from what the codebase expects with a generic name such as "git_mkdir()". Look at mingw's replacement. The platform difference over there is that the one from the system does not take mode parameter. Imagine that one was already called "git_mkdir()". Now we have two different kind of differences, and one has more officially-looking "git_mkdir()" name; yours cannot take it---what would you do in that case? Neither kind of difference is more officially sanctioned difference; don't call yours any more official/generic than necessary.

Your wrapper is not limited to tandem, but is applicable to ancient BSDs, so it is fine to call it as compat_mkdir_wo_trailing_slash(), so that it can be shared among platforms whose mkdir do not want to see trailing slashes. If you are going that route, the function should live in its own file (without any other wrapper), and not be named after specific platform (should be named after the specific difference from what we expect, instead). I am perfectly fine with that approach as well.

Quoted 9 lines
Quoted 1 line

Squatting on a generic "git_mkdir()" name makes it harder for other people

to

Quoted 2 lines

name their compat mkdir functions to tweak for the breakage on their platforms. The examples you listed are all "the platform does not offer

it, so

Quoted 1 line

we implement the whole thing" kind, so it is in a different genre.

Nope, git_fopen() definitly is a wrapper for fopen(), as is git_vsnprintf() for vsnprintf().

I was talking more about mmap() and pread().

For the two you mentioned, ideally they should have been named after the specific breakages they cover (fopen that does not error out on directories is primarily AIX thing IIRC, and snprintf returns bogus result are shared between HPUX and Windows), but over these years we haven't seen any other kind of differences from various platforms, so the need to rename them away is very low.

On the other hand, we already know there are at least two kinds of platform mkdir() that need different compat/ layer support, so calling one "git_mkdir()" to cover one particular kind of difference does not make any sense.

Besides, an earlier mistake is not a valid excuse to add new mistakes.

#10 lore raw
Quoted 8 lines

From: Junio C Hamano [mailto:[email protected]]
Sent: Monday, August 20, 2012 6:54 PM
To: Joachim Schmitz
Cc: 'Shawn Pearce'; [email protected]; [email protected]
Subject: Re: Porting git to HP NonStop

"Joachim Schmitz" <[email protected]> writes:

Quoted 7 lines
Quoted 5 lines

I haven't found any other to be needed. Well, poll, maybe, but with only minor tweaks for the win32 one works for me (and those tweaks are compatible with win32

Quoted 1 line

A separate file, compat/tandem/mkdir.c, is fine, though.

If you wouldn't have dozens of them, so compat/tandem/mkdir.c is not

suitable;

Quoted 11 lines

compat/tandem.c would be good, then.

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

I'll go for git_mkdir(), similar to other git wrappers, (like for mmap, pread, fopen, snprintf, vsnprintf, qsort).

Again, no. Your breakage is that having underlying system mkdir that does

not

Quoted 1 line

understand trailing slash, which may not be specific to __TANDEM, but

still is

Quoted 1 line

_not_ the only possible mode of breakage.

True.

Quoted 4 lines
Quoted 2 lines

Well, it is the only one GNUlib's mkdir caters for and I'd regard that an authoritative source...

I suspect that you may be misunderstanding what compat/ is about

I don't think so, it server the same purpose for git as gnulib does for others.

Quoted 3 lines

, so let's try again.
Platform difference in mkdir may not be limited to "on this platform, the underlying one supplied by the system does not like path ending with a

slash".

Quoted 2 lines

What I am saying is that it is unacceptable to call something that caters

to that

Quoted 4 lines

specific kind of difference from what the codebase expects with a generic name such as "git_mkdir()". Look at mingw's replacement. The platform difference over there is that the one from the system does not take mode parameter. Imagine that one was already called "git_mkdir()". Now we

have

Quoted 3 lines

two different kind of differences, and one has more officially-looking "git_mkdir()" name; yours cannot take it---what would you do in that case? Neither kind of difference is more officially sanctioned difference; don't

call

Quoted 1 line

yours any more official/generic than necessary.

Gnulib's rpl_mkdir caters for 3 possible problems, the WIN32 one which mkdir taking only one argument, the trailing slash one discussed here (victims being at least NetBSD 1.5.2 and current HP NonStop) and a trailing dot one (that allegedly Cygwin 1.5 suffered from).

As far as I can see git will not suffer from the latter, but even if, at that time a git_mkdir() could be expanded to cater for this to, just like gnulib's one does, there it is an additional section inside their rpl_mkdir().
And the WIN32 one is already being taken care of in compat/mingw.h. However, this could as easily get integrated into
a git_mkdir(), just like in gnulib.

Quoted 1 line

Your wrapper is not limited to tandem, but is applicable to ancient BSDs,

so it is

Quoted 1 line

fine to call it as compat_mkdir_wo_trailing_slash(), so that it can be

shared

Quoted 1 line

among platforms whose mkdir do not want to see trailing slashes. If you

are

Quoted 1 line

going that route, the function should live in its own file (without any

other

Quoted 1 line

wrapper), and not be named after specific platform (should be named after

the

Quoted 1 line

specific difference from what we expect, instead). I am perfectly fine

with that

Quoted 11 lines

approach as well.

Quoted 9 lines
Quoted 2 lines

Squatting on a generic "git_mkdir()" name makes it harder for other people

to

Quoted 3 lines

name their compat mkdir functions to tweak for the breakage on their platforms. The examples you listed are all "the platform does not offer

it, so

Quoted 1 line

we implement the whole thing" kind, so it is in a different genre.

Quoted 7 lines
Quoted 2 lines

Nope, git_fopen() definitly is a wrapper for fopen(), as is git_vsnprintf() for vsnprintf().

I was talking more about mmap() and pread().

For the two you mentioned, ideally they should have been named after the specific breakages they cover (fopen that does not error out on

directories is

Quoted 1 line

primarily AIX thing IIRC, and snprintf returns bogus result are shared

between

Quoted 2 lines

HPUX and Windows), but over these years we haven't seen any other kind of differences from various platforms, so the need to rename them away is

very

Quoted 3 lines

low.

On the other hand, we already know there are at least two kinds of

platform

Quoted 1 line

mkdir() that need different compat/ layer support, so calling one

"git_mkdir()"

Quoted 3 lines

to cover one particular kind of difference does not make any sense.

Besides, an earlier mistake is not a valid excuse to add new mistakes.

OK, so how about this:
/usr/local/bin/diff -EBbu ./compat/mkdir.c.orig ./compat/mkdir.c

compat/mkdir.c 2012-08-21 05:02:11 -0500 renamed from compat/mkdir.c.orig 2012-08-21 05:02:11 -0500 +24 -0
@@ -0,0 +1,24 @@
+#include "../git-compat-util.h"
+#undef mkdir
+
+/* for platforms that can't deal with a trailing '/' */
+int compat_mkdir_wo_trailing_slash(const char *dir, mode_t mode)
+{
+       int retval;
+       char *tmp_dir = NULL;
+       size_t len = strlen(dir);
+
+       if (len && dir[len-1] == '/') {
+               if ((tmp_dir = strdup(dir)) == NULL)
+                       return -1;
+               tmp_dir[len-1] = '\0';
+       }
+       else
+               tmp_dir = (char *)dir;
+
+       retval = mkdir(tmp_dir, mode);
+       if (tmp_dir != dir)
+               free(tmp_dir);
+
+       return retval;
+}

BTW: I've just today reported that mkdir bug to HP NonStop development. Let's see how fast they fix it and whether at all, but I'd be pretty surprised if that happened earlier than 6 months from now.

Bye, Jojo

#11 lore raw
Quoted 19 lines · Joachim Schmitz

OK, so how about this:
/usr/local/bin/diff -EBbu ./compat/mkdir.c.orig ./compat/mkdir.c

compat/mkdir.c 2012-08-21 05:02:11 -0500 renamed from compat/mkdir.c.orig 2012-08-21 05:02:11 -0500 +14 -0
@@ -0,0 +1,24 @@
+#include "../git-compat-util.h"
+#undef mkdir
+
+/* for platforms that can't deal with a trailing '/' */
+int compat_mkdir_wo_trailing_slash(const char *dir, mode_t mode)
+{
+       int retval;
+       char *tmp_dir = NULL;
+       size_t len = strlen(dir);
+
+       if (len && dir[len-1] == '/') {
+               if ((tmp_dir = strdup(dir)) == NULL)
+                       return -1;
+               tmp_dir[len-1] = '\0';

compat/mkdir.c 2012-08-21 05:02:11 -0500 line 24

Quoted 10 lines
compat/mkdir.c 2012-08-21 05:02:11 -0500 renamed from compat/mkdir.c.orig 2012-08-21 05:02:11 -0500 +10 -0
+       }
+       else
+               tmp_dir = (char *)dir;
+
+       retval = mkdir(tmp_dir, mode);
+       if (tmp_dir != dir)
+               free(tmp_dir);
+
+       return retval;
+}

Why not rearrange this so that you assign to dir the value of tmp_dir and then just pass dir to mkdir. Then you can avoid the recast of dir to (char*) in the else branch. Later, just call free(tmp_dir). Also, we have xstrndup. So I think the body of your function can become something like:

   if (len && dir[len-1] == '/')
       dir = tmp_dir = xstrndup(dir, len-1);

   retval = mkdir(dir, mode);
   free(tmp_dir);

-Brandon

#12 lore raw
Quoted 44 lines

From: Brandon Casey [mailto:[email protected]]
Sent: Wednesday, August 22, 2012 7:01 PM
To: Joachim Schmitz
Cc: Junio C Hamano; Shawn Pearce; [email protected]; [email protected]
Subject: Re: Porting git to HP NonStop

Quoted 18 lines · Joachim Schmitz

OK, so how about this:
/usr/local/bin/diff -EBbu ./compat/mkdir.c.orig ./compat/mkdir.c

compat/mkdir.c 2012-08-21 05:02:11 -0500 renamed from compat/mkdir.c.orig 2012-08-21 05:02:11 -0500 +13 -0
@@ -0,0 +1,24 @@
+#include "../git-compat-util.h"
+#undef mkdir
+
+/* for platforms that can't deal with a trailing '/' */ int
+compat_mkdir_wo_trailing_slash(const char *dir, mode_t mode) {
+       int retval;
+       char *tmp_dir = NULL;
+       size_t len = strlen(dir);
+
+       if (len && dir[len-1] == '/') {
+               if ((tmp_dir = strdup(dir)) == NULL)
+                       return -1;
+               tmp_dir[len-1] = '\0';

compat/mkdir.c 2012-08-21 05:02:11 -0500 line 23

Quoted 10 lines
compat/mkdir.c 2012-08-21 05:02:11 -0500 renamed from compat/mkdir.c.orig 2012-08-21 05:02:11 -0500 +10 -0
+       }
+       else
+               tmp_dir = (char *)dir;
+
+       retval = mkdir(tmp_dir, mode);
+       if (tmp_dir != dir)
+               free(tmp_dir);
+
+       return retval;
+}

Why not rearrange this so that you assign to dir the value of tmp_dir and then just pass dir to mkdir. Then you can avoid the recast of dir to (char*) in the else branch. Later, just call free(tmp_dir). Also, we have xstrndup. So I think the body of your function can become something like:

Quoted 2 lines
   if (len && dir[len-1] == '/')
       dir = tmp_dir = xstrndup(dir, len-1);

xstndup() can't fail?

Quoted 4 lines
   retval = mkdir(dir, mode);
   free(tmp_dir);

-Brandon

Bye, Jojo

#13 lore raw
Quoted 44 lines · Joachim Schmitz
Quoted 44 lines

From: Brandon Casey [mailto:[email protected]]
Sent: Wednesday, August 22, 2012 7:01 PM
To: Joachim Schmitz
Cc: Junio C Hamano; Shawn Pearce; [email protected]; [email protected]
Subject: Re: Porting git to HP NonStop

Quoted 18 lines · Joachim Schmitz

OK, so how about this:
/usr/local/bin/diff -EBbu ./compat/mkdir.c.orig ./compat/mkdir.c

compat/mkdir.c 2012-08-21 05:02:11 -0500 renamed from compat/mkdir.c.orig 2012-08-21 05:02:11 -0500 +13 -0
@@ -0,0 +1,24 @@
+#include "../git-compat-util.h"
+#undef mkdir
+
+/* for platforms that can't deal with a trailing '/' */ int
+compat_mkdir_wo_trailing_slash(const char *dir, mode_t mode) {
+       int retval;
+       char *tmp_dir = NULL;
+       size_t len = strlen(dir);
+
+       if (len && dir[len-1] == '/') {
+               if ((tmp_dir = strdup(dir)) == NULL)
+                       return -1;
+               tmp_dir[len-1] = '\0';

compat/mkdir.c 2012-08-21 05:02:11 -0500 line 23

Quoted 10 lines
compat/mkdir.c 2012-08-21 05:02:11 -0500 renamed from compat/mkdir.c.orig 2012-08-21 05:02:11 -0500 +10 -0
+       }
+       else
+               tmp_dir = (char *)dir;
+
+       retval = mkdir(tmp_dir, mode);
+       if (tmp_dir != dir)
+               free(tmp_dir);
+
+       return retval;
+}

Why not rearrange this so that you assign to dir the value of tmp_dir and then just pass dir to mkdir. Then you can avoid the recast of dir to (char*) in the else branch. Later, just call free(tmp_dir). Also, we have xstrndup. So I think the body of your function can become something like:

Quoted 4 lines
Quoted 2 lines
   if (len && dir[len-1] == '/')
       dir = tmp_dir = xstrndup(dir, len-1);

xstndup() can't fail?

Correct. It will either succeed or die. It will also try to free up some memory used by git if possible.

-Brandon

#14 lore raw
Quoted 55 lines

From: Brandon Casey [mailto:[email protected]]
Sent: Wednesday, August 22, 2012 7:23 PM
To: Joachim Schmitz
Cc: Junio C Hamano; Shawn Pearce; [email protected]; [email protected]
Subject: Re: Porting git to HP NonStop

Quoted 36 lines · Joachim Schmitz
Quoted 36 lines

From: Brandon Casey [mailto:[email protected]]
Sent: Wednesday, August 22, 2012 7:01 PM
To: Joachim Schmitz
Cc: Junio C Hamano; Shawn Pearce; [email protected]; [email protected]
Subject: Re: Porting git to HP NonStop

Quoted 25 lines · Joachim Schmitz

OK, so how about this:
/usr/local/bin/diff -EBbu ./compat/mkdir.c.orig ./compat/mkdir.c

compat/mkdir.c 2012-08-21 05:02:11 -0500 renamed from compat/mkdir.c.orig 2012-08-21 05:02:11 -0500 +20 -0
@@ -0,0 +1,24 @@
+#include "../git-compat-util.h"
+#undef mkdir
+
+/* for platforms that can't deal with a trailing '/' */ int
+compat_mkdir_wo_trailing_slash(const char *dir, mode_t mode) {
+       int retval;
+       char *tmp_dir = NULL;
+       size_t len = strlen(dir);
+
+       if (len && dir[len-1] == '/') {
+               if ((tmp_dir = strdup(dir)) == NULL)
+                       return -1;
+               tmp_dir[len-1] = '\0';
+       }
+       else
+               tmp_dir = (char *)dir;
+
+       retval = mkdir(tmp_dir, mode);
+       if (tmp_dir != dir)
+               free(tmp_dir);
Quoted 8 lines
Quoted 8 lines

compat/mkdir.c 2012-08-21 05:02:11 -0500 line 24

Quoted 3 lines
compat/mkdir.c 2012-08-21 05:02:11 -0500 renamed from compat/mkdir.c.orig 2012-08-21 05:02:11 -0500 +3 -0
+
+       return retval;
+}

Why not rearrange this so that you assign to dir the value of tmp_dir and then just pass dir to mkdir. Then you can avoid the recast of dir to (char*) in the else branch. Later, just call free(tmp_dir). Also, we have xstrndup. So I think the body of your function can become

something like:

Quoted 1 line
Quoted 1 line
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
   if (len && dir[len-1] == '/')
       dir = tmp_dir = xstrndup(dir, len-1);

xstndup() can't fail?

Correct. It will either succeed or die. It will also try to free up some memory used by git if possible.

OK. So let's use that then.

Bye, Jojo

#15 lore raw
In reply to Brandon Casey

Am 22.08.2012 19:00, schrieb Brandon Casey:

Quoted 5 lines

So I think the body of [compat_mkdir] can become
something like:

   if (len && dir[len-1] == '/')
       dir = tmp_dir = xstrndup(dir, len-1);

Don't use x* wrappers in the compat layer, at least not those that allocate memory: They behave unpredictably due to try_to_free_routine and may lead to recursive invocations.

Quoted 3 lines
   retval = mkdir(dir, mode);
   free(tmp_dir);

-- Hannes

#16 lore raw
Quoted 11 lines

-----Original Message-----
From: Johannes Sixt [mailto:[email protected]]
Sent: Wednesday, August 22, 2012 7:41 PM
To: Brandon Casey
Cc: Joachim Schmitz; Junio C Hamano; Shawn Pearce; [email protected]; [email protected]
Subject: Re: Porting git to HP NonStop

Am 22.08.2012 19:00, schrieb Brandon Casey:

Quoted 8 lines
Quoted 4 lines

So I think the body of [compat_mkdir] can become something like:

   if (len && dir[len-1] == '/')
       dir = tmp_dir = xstrndup(dir, len-1);

Don't use x* wrappers in the compat layer, at least not those that allocate
memory: They behave unpredictably due to try_to_free_routine and may lead to recursive invocations.

I was just following orders ;-)
What about the other proposal, xmemdupz? Same story I guess?

Bye, Jojo

#17 lore raw

Am 22.08.2012 20:02, schrieb Joachim Schmitz:

Quoted 7 lines
Quoted 4 lines

From: Johannes Sixt [mailto:[email protected]]
Don't use x* wrappers in the compat layer, at least not those that allocate
memory: They behave unpredictably due to try_to_free_routine and may lead to recursive invocations.

I was just following orders ;-)
What about the other proposal, xmemdupz? Same story I guess?

xmemdupz calls xmalloc, so, yes, same story.

-- Hannes

#18 lore raw
Quoted 14 lines

-----Original Message-----
From: Johannes Sixt [mailto:[email protected]]
Sent: Wednesday, August 22, 2012 8:09 PM
To: Joachim Schmitz
Cc: 'Brandon Casey'; 'Junio C Hamano'; 'Shawn Pearce'; [email protected]; [email protected]
Subject: Re: Porting git to HP NonStop

Am 22.08.2012 20:02, schrieb Joachim Schmitz:

Quoted 5 lines
Quoted 4 lines

From: Johannes Sixt [mailto:[email protected]] Don't use x* wrappers in the compat layer, at least not those that allocate
memory: They behave unpredictably due to try_to_free_routine and may lead to recursive invocations.

Quoted 4 lines
Quoted 2 lines

I was just following orders ;-)
What about the other proposal, xmemdupz? Same story I guess?

xmemdupz calls xmalloc, so, yes, same story.

So back to my original patch, using strdup, check the return value, etc.

Bye, Jojo

#19 lore raw
In reply to Johannes Sixt
Quoted 10 lines · Johannes Sixt

Am 22.08.2012 19:00, schrieb Brandon Casey:

Quoted 5 lines

So I think the body of [compat_mkdir] can become
something like:

   if (len && dir[len-1] == '/')
       dir = tmp_dir = xstrndup(dir, len-1);

Don't use x* wrappers in the compat layer, at least not those that allocate memory: They behave unpredictably due to try_to_free_routine and may lead to recursive invocations.

I thought that rule only applied to die handlers. i.e. don't use the x* wrappers to allocate memory in a die handler like compat/win32/syslog.c. At least that's what I wrote in 040a6551 when you pointed out this issue back then.

Admittedly, it could get pretty sticky trying to trace the die handlers to ensure they don't invoke your new compat/ function. So, yeah, adopting this rule of not using x* wrappers that allocate memory in compat/ generally seems like a good idea.

Should we also try to detect recursive invocation of die and friends? In theory recursion could be triggered by any die handler that makes use of a code path that calls an x* wrapper that allocates memory, couldn't it?

-Brandon

#20 lore raw
Quoted 22 lines · Brandon Casey
Quoted 10 lines · Johannes Sixt

Am 22.08.2012 19:00, schrieb Brandon Casey:

Quoted 5 lines

So I think the body of [compat_mkdir] can become
something like:

   if (len && dir[len-1] == '/')
       dir = tmp_dir = xstrndup(dir, len-1);

Don't use x* wrappers in the compat layer, at least not those that allocate memory: They behave unpredictably due to try_to_free_routine and may lead to recursive invocations.

I thought that rule only applied to die handlers. i.e. don't use the x* wrappers to allocate memory in a die handler like compat/win32/syslog.c. At least that's what I wrote in 040a6551 when you pointed out this issue back then.

Admittedly, it could get pretty sticky trying to trace the die handlers to ensure they don't invoke your new compat/ function. So, yeah, adopting this rule of not using x* wrappers that allocate memory in compat/ generally seems like a good idea.

Quoted 5 lines

Should we also try to detect recursive invocation of die and friends?

In theory recursion could be triggered by any die handler that makes use of a code path that calls an x* wrapper that allocates memory, couldn't it?

Correct, but at that point we will end up dying anyway, so...

#21 lore raw
In reply to Brandon Casey
Quoted 16 lines · Brandon Casey
Quoted 3 lines · Johannes Sixt

Don't use x* wrappers in the compat layer, at least not those that allocate memory: They behave unpredictably due to try_to_free_routine and may lead to recursive invocations.

I thought that rule only applied to die handlers. i.e. don't use the x* wrappers to allocate memory in a die handler like compat/win32/syslog.c. At least that's what I wrote in 040a6551 when you pointed out this issue back then.

Admittedly, it could get pretty sticky trying to trace the die handlers to ensure they don't invoke your new compat/ function. So, yeah, adopting this rule of not using x* wrappers that allocate memory in compat/ generally seems like a good idea.

Quoted 4 lines

Should we also try to detect recursive invocation of die and friends? In theory recursion could be triggered by any die handler that makes use of a code path that calls an x* wrapper that allocates memory, couldn't it?

Perhaps something like:

usage.c +14 -0
index a2a6678..2d0ff35 100644
@@ -80,8 +80,15 @@ void NORETURN usage(const char *err)
 
 void NORETURN die(const char *err, ...)
 {
+       static int dying;
        va_list params;
 
+       if (dying) {
+               fputs("fatal: recursion detected in die handler\n", stderr);
+               exit(128);
+       }
+       dying = 1;
+
        va_start(params, err);
        die_routine(err, params);
        va_end(params);
@@ -89,11 +96,18 @@ void NORETURN die(const char *err, ...)
 
 void NORETURN die_errno(const char *fmt, ...)
 {
+       static int dying;
        va_list params;
        char fmt_with_err[1024];
        char str_error[256], *err;
        int i, j;
 
+       if (dying) {
+               fputs("fatal: recursion detected in die handler\n", stderr);
+               exit(128);
+       }
+       dying = 1;
+
        err = strerror(errno);
        for (i = j = 0; err[i] && j < sizeof(str_error) - 1; ) {
                if ((str_error[j++] = err[i++]) != '%')

-Brandon

#22 lore raw
Quoted 31 lines · Brandon Casey

Perhaps something like:

usage.c +8 -0
index a2a6678..2d0ff35 100644
@@ -80,8 +80,15 @@ void NORETURN usage(const char *err)
 
 void NORETURN die(const char *err, ...)
 {
+       static int dying;
        va_list params;
 
+       if (dying) {
+               fputs("fatal: recursion detected in die handler\n", stderr);
+               exit(128);
+       }
+       dying = 1;
+
        va_start(params, err);
        die_routine(err, params);
        va_end(params);
@@ -89,11 +96,18 @@ void NORETURN die(const char *err, ...)
 
 void NORETURN die_errno(const char *fmt, ...)
 {
+       static int dying;
        va_list params;
        char fmt_with_err[1024];
        char str_error[256], *err;
        int i, j;

usage.c void NORETURN die(const char *err, ...) · line 113

Quoted 10 lines
usage.c +6 -0
 
+       if (dying) {
+               fputs("fatal: recursion detected in die handler\n", stderr);
+               exit(128);
+       }
+       dying = 1;
+
        err = strerror(errno);
        for (i = j = 0; err[i] && j < sizeof(str_error) - 1; ) {
                if ((str_error[j++] = err[i++]) != '%')

With two function-scope static, you can go like this:

die()
-> die_routine()
-> xsomething()

      -> die_errno()
        -> die_routine()
           -> xsomethingelse()
              -> die() or die_errno()

Not that we probably care too deeply about, as at least we won't infinitely recurse and die out of stack space.

#23 lore raw
Quoted 49 lines · Junio C Hamano
Quoted 31 lines · Brandon Casey

Perhaps something like:

usage.c +8 -0
index a2a6678..2d0ff35 100644
@@ -80,8 +80,15 @@ void NORETURN usage(const char *err)
 
 void NORETURN die(const char *err, ...)
 {
+       static int dying;
        va_list params;
 
+       if (dying) {
+               fputs("fatal: recursion detected in die handler\n", stderr);
+               exit(128);
+       }
+       dying = 1;
+
        va_start(params, err);
        die_routine(err, params);
        va_end(params);
@@ -89,11 +96,18 @@ void NORETURN die(const char *err, ...)
 
 void NORETURN die_errno(const char *fmt, ...)
 {
+       static int dying;
        va_list params;
        char fmt_with_err[1024];
        char str_error[256], *err;
        int i, j;

usage.c void NORETURN die(const char *err, ...) · line 113

Quoted 10 lines
usage.c +6 -0
 
+       if (dying) {
+               fputs("fatal: recursion detected in die handler\n", stderr);
+               exit(128);
+       }
+       dying = 1;
+
        err = strerror(errno);
        for (i = j = 0; err[i] && j < sizeof(str_error) - 1; ) {
                if ((str_error[j++] = err[i++]) != '%')

With two function-scope static, you can go like this:

die()
-> die_routine()
-> xsomething()

Quoted 7 lines
      -> die_errno()
        -> die_routine()
           -> xsomethingelse()
              -> die() or die_errno()

Not that we probably care too deeply about, as at least we won't infinitely recurse and die out of stack space.

Yeah, I noticed that, but didn't think it was important or likely. But there's no reason not to make "dying" a global.

-Brandon

#24 lore raw

Hi folks

There another API missing on HP NonStop and that is setitimer(), used in progress.c and build/log.c I do have a homebrewed implementation, on top of alarm(), it goes like this:

#include "../git-compat-util.h"
#undef getitimer
#undef setitimer

int
git_getitimer(int which, struct itimerval *value)

{
        int ret = 0;

        switch (which) {
                case ITIMER_REAL:
                        value->it_value.tv_usec = 0;
                        value->it_value.tv_sec = alarm(0);
                        ret = 0; /* if alarm() fails we get a SIGLIMIT */
                        break;
                case ITIMER_VIRTUAL: /* FALLTHRU */
                case ITIMER_PROF: errno = ENOTSUP; ret = -1; break;
                default: errno = EINVAL; ret = -1;
        }
        return ret;
}

int
git_setitimer(int which, const struct itimerval *value,
struct itimerval *ovalue)

{
        int ret = 0;

        if (!value
                || value->it_value.tv_usec < 0
                || value->it_value.tv_usec > 1000000
                || value->it_value.tv_sec < 0) {
                errno = EINVAL;
                return -1;
        }

        else if (ovalue)
                if (!git_getitimer(which, ovalue))
                        return -1; /* errno set in git_getitimer() */

        else
        switch (which) {
                case ITIMER_REAL:
                        alarm(value->it_value.tv_sec +
                                (value->it_value.tv_usec > 0) ? 1 : 0);
                        ret = 0; /* if alarm() fails we get a SIGLIMIT */
                        break;
                case ITIMER_VIRTUAL: /* FALLTHRU */
                case ITIMER_PROF: errno = ENOTSUP; ret = -1; break;
                default: errno = EINVAL; ret = -1;
        }

        return ret;
}

Worth being added to compat/, e.g. as setitimer.c, or, as itimer.c (as a by-product, it has getitimer() too)?

Bye, Jojo

#25 lore raw
Quoted 5 lines · Joachim Schmitz

Hi folks

There another API missing on HP NonStop and that is setitimer(), used in progress.c and build/log.c I do have a homebrewed implementation, on top of alarm(), it goes like this:

Quoted 7 lines

#include "../git-compat-util.h"
#undef getitimer
#undef setitimer

int
git_getitimer(int which, struct itimerval *value)

See Documentation/CodingGuidelines for style nits.

Quoted 50 lines
{
        int ret = 0;

        switch (which) {
                case ITIMER_REAL:
                        value->it_value.tv_usec = 0;
                        value->it_value.tv_sec = alarm(0);
                        ret = 0; /* if alarm() fails we get a SIGLIMIT */
                        break;
                case ITIMER_VIRTUAL: /* FALLTHRU */
                case ITIMER_PROF: errno = ENOTSUP; ret = -1; break;
                default: errno = EINVAL; ret = -1;
        }
        return ret;
}

int
git_setitimer(int which, const struct itimerval *value,
struct itimerval *ovalue)

{
        int ret = 0;

        if (!value
                || value->it_value.tv_usec < 0
                || value->it_value.tv_usec > 1000000
                || value->it_value.tv_sec < 0) {
                errno = EINVAL;
                return -1;
        }

        else if (ovalue)
                if (!git_getitimer(which, ovalue))
                        return -1; /* errno set in git_getitimer() */

        else
        switch (which) {
                case ITIMER_REAL:
                        alarm(value->it_value.tv_sec +
                                (value->it_value.tv_usec > 0) ? 1 : 0);
                        ret = 0; /* if alarm() fails we get a SIGLIMIT */
                        break;
                case ITIMER_VIRTUAL: /* FALLTHRU */
                case ITIMER_PROF: errno = ENOTSUP; ret = -1; break;
                default: errno = EINVAL; ret = -1;
        }

        return ret;
}
Quoted 2 lines

Worth being added to compat/, e.g. as setitimer.c, or, as itimer.c (as a by-product, it has getitimer() too)?

If it helps your port, compat/itimer.c sounds like a good place. Doesn't it need a new header file to introduce structures and constants, too?

#26 lore raw
Quoted 6 lines

From: Junio C Hamano [mailto:[email protected]]
Sent: Wednesday, August 22, 2012 10:50 PM
To: Joachim Schmitz
Cc: [email protected]; [email protected]
Subject: Re: Porting git to HP NonStop

Quoted 6 lines
Quoted 4 lines · Joachim Schmitz

Hi folks

There another API missing on HP NonStop and that is setitimer(), used in progress.c and build/log.c I do have a homebrewed implementation, on

top

Quoted 11 lines

of alarm(), it goes like this:

Quoted 8 lines

#include "../git-compat-util.h"
#undef getitimer
#undef setitimer

int
git_getitimer(int which, struct itimerval *value)

See Documentation/CodingGuidelines for style nits.

Will do and adjust code accordingly. Here I was more concerned about content though ;-)

...

Quoted 5 lines
Quoted 2 lines

Worth being added to compat/, e.g. as setitimer.c, or, as itimer.c (as a by-product, it has getitimer() too)?

If it helps your port, compat/itimer.c sounds like a good place. Doesn't it need a new header file to introduce structures and constants,

too?

You mean the ITIMER_* and struct itimerval, right?
On NonStop these are available in <sys/time.h>, so here's no need to add them.

Bye, Jojo

#27 lore raw
Quoted 7 lines · Joachim Schmitz
Quoted 2 lines

If it helps your port, compat/itimer.c sounds like a good place. Doesn't it need a new header file to introduce structures and constants,

too?

You mean the ITIMER_* and struct itimerval, right?
On NonStop these are available in <sys/time.h>, so here's no need to add them.

At least you would need a header to declare these two functions and make them visible so that the remainder of the codebase will not have to know about git_setitimer(), no? Or does your header files on NonStop declare setitimer() but does not implement it?

As your proposed name is not compat/tandem.c but more generic sounding compat/itimer.c, we would have to plan for systems other than NonStop, so we may later have to introduce makefile variables to ask that header file to declare the structure and define the constants that are missing from such a system. While you are porting to NonStop, you may not have to define/declare them, but knowing that these files are the place to later do so is part of the planning.

#28 lore raw
Quoted 14 lines

-----Original Message-----
From: Junio C Hamano [mailto:[email protected]]
Sent: Wednesday, August 22, 2012 11:12 PM
To: Joachim Schmitz
Cc: [email protected]; [email protected]
Subject: Re: Porting git to HP NonStop

Quoted 3 lines · Joachim Schmitz
Quoted 3 lines

If it helps your port, compat/itimer.c sounds like a good place. Doesn't it need a new header file to introduce structures and constants,

Quoted 8 lines
Quoted 5 lines

too?

You mean the ITIMER_* and struct itimerval, right?
On NonStop these are available in <sys/time.h>, so here's no need to add them.

At least you would need a header to declare these two functions and make them visible so that the remainder of the codebase will not have to know

about

Quoted 1 line

git_setitimer(), no? Or does your header files on NonStop declare

setitimer()

Quoted 1 line

but does not implement it?

No it doesn't, at least not if a form visible to a compiler...

Quoted 2 lines

As your proposed name is not compat/tandem.c but more generic sounding compat/itimer.c, we would have to plan for systems other than NonStop, so

we

Quoted 2 lines

may later have to introduce makefile variables to ask that header file to declare the structure and define the constants that are missing from such

a

Quoted 1 line

system. While you are porting to NonStop, you may not have to

define/declare

Quoted 1 line

them, but knowing that these files are the place to later do so is part of

the

Quoted 1 line

planning.

I thought of having the function decclaration in git-compat-util.h, just like for eg. setenv, gitmkdtemp, etc.

Bye, Jojo

#29 lore raw
Quoted 2 lines · Joachim Schmitz

I thought of having the function decclaration in git-compat-util.h, just like for eg. setenv, gitmkdtemp, etc.

Yeah, that's also fine, especially if you do not have to declare structures and constants.

Once you start having to declare other things in order to declare the function missing on the system, it won't be like setenv where a pair of #ifdef NO_SETENV/#endif just surrounds a single line. At that point, a separate header file to hold them together would become easier to read. It's a judgement call; we'll see how it turns out (we do not have to get everything right in our first attempt).

#30 lore raw
In reply to Brandon Casey
Quoted 24 lines · Brandon Casey
Quoted 5 lines · Joachim Schmitz

OK, so how about this:
/usr/local/bin/diff -EBbu ./compat/mkdir.c.orig ./compat/mkdir.c

compat/mkdir.c 2012-08-21 05:02:11 -0500 line 10

Quoted 10 lines
compat/mkdir.c 2012-08-21 05:02:11 -0500 renamed from compat/mkdir.c.orig 2012-08-21 05:02:11 -0500 +10 -0
@@ -0,0 +1,24 @@
+#include "../git-compat-util.h"
+#undef mkdir
+
+/* for platforms that can't deal with a trailing '/' */
+int compat_mkdir_wo_trailing_slash(const char *dir, mode_t mode)
+{
+       int retval;
+       char *tmp_dir = NULL;
+       size_t len = strlen(dir);
+ ...

Why not rearrange this so that you assign to dir the value of tmp_dir and then just pass dir to mkdir. Then you can avoid the recast of dir to (char*) in the else branch. Later, just call free(tmp_dir). Also, we have xstrndup. So I think the body of your function can become something like:

Quoted 5 lines
   if (len && dir[len-1] == '/')
       dir = tmp_dir = xstrndup(dir, len-1);

   retval = mkdir(dir, mode);
   free(tmp_dir);

Nice. And we have xmemdupz() would be even better as you followed-up.

Thanks.

#31 lore raw
Quoted 33 lines

-----Original Message-----
From: Junio C Hamano [mailto:[email protected]]
Sent: Wednesday, August 22, 2012 7:30 PM
To: Brandon Casey
Cc: Joachim Schmitz; Shawn Pearce; [email protected]; [email protected]
Subject: Re: Porting git to HP NonStop

Quoted 23 lines · Brandon Casey
Quoted 5 lines · Joachim Schmitz

OK, so how about this:
/usr/local/bin/diff -EBbu ./compat/mkdir.c.orig ./compat/mkdir.c

compat/mkdir.c 2012-08-21 05:02:11 -0500 line 9

Quoted 9 lines
compat/mkdir.c 2012-08-21 05:02:11 -0500 renamed from compat/mkdir.c.orig 2012-08-21 05:02:11 -0500 +9 -0
@@ -0,0 +1,24 @@
+#include "../git-compat-util.h"
+#undef mkdir
+
+/* for platforms that can't deal with a trailing '/' */ int
+compat_mkdir_wo_trailing_slash(const char *dir, mode_t mode) {
+       int retval;
+       char *tmp_dir = NULL;
+       size_t len = strlen(dir);
+ ...

Why not rearrange this so that you assign to dir the value of tmp_dir and then just pass dir to mkdir. Then you can avoid the recast of dir to (char*) in the else branch. Later, just call free(tmp_dir). Also, we have xstrndup. So I think the body of your function can become something like:

Quoted 7 lines
Quoted 5 lines
   if (len && dir[len-1] == '/')
       dir = tmp_dir = xstrndup(dir, len-1);

   retval = mkdir(dir, mode);
   free(tmp_dir);

Nice. And we have xmemdupz() would be even better as you followed-up.

How's that one used?

Bye, Jojo

#32 lore raw
Quoted 3 lines · Joachim Schmitz
Quoted 1 line

Nice. And we have xmemdupz() would be even better as you followed-up.

How's that one used?

I forgot that we frown upon use of any x<allocate>() wrapper in the compat/ layer as J6t mentioned.

So probably something along these lines...

	int retval;
	char *dir_to_free = NULL;
	size_t len = strlen(dir);

        if (len && dir[len - 1] == '/') {
		dir_to_free = malloc(len);
                if (!dir_to_free) {
			fprintf(stderr, "malloc failed!\n");
			exit(1);
		}
                memcpy(dir_to_free, dir, len - 1);
                dir_to_free[len - 1] = '\0';
                dir = dir_to_free;
	}                
	retval = mkdir(dir, mode);
	free(dir_to_free);
        return retval;

It might be possible to for the error path to get away with something like:

	if (!dir_to_free)
		return -1;

if we know the callers are prepared to see mkdir() failing with ENOMEM, but that is not very likely.

#33 lore raw
Quoted 7 lines

From: Junio C Hamano [mailto:[email protected]]
Sent: Wednesday, August 22, 2012 8:25 PM
To: Joachim Schmitz
Cc: 'Brandon Casey'; 'Shawn Pearce'; [email protected]; [email protected]
Subject: Re: Porting git to HP NonStop

Quoted 7 lines
Quoted 3 lines · Joachim Schmitz
Quoted 1 line

Nice. And we have xmemdupz() would be even better as you followed-up.

How's that one used?

I forgot that we frown upon use of any x<allocate>() wrapper in the

compat/

Quoted 13 lines

layer as J6t mentioned.

So probably something along these lines...

	int retval;
	char *dir_to_free = NULL;
	size_t len = strlen(dir);

        if (len && dir[len - 1] == '/') {
		dir_to_free = malloc(len);
                if (!dir_to_free) {
			fprintf(stderr, "malloc failed!\n");
			exit(1);
Quoted 8 lines
		}
                memcpy(dir_to_free, dir, len - 1);
                dir_to_free[len - 1] = '\0';
                dir = dir_to_free;
	}
	retval = mkdir(dir, mode);
	free(dir_to_free);
        return retval;

So why not just strdup? I stole the idea from gnulib...

int
rpl_mkdir (char const *dir, mode_t mode maybe_unused) {
int ret_val;
char *tmp_dir;
size_t len = strlen (dir);

  if (len && dir[len - 1] == '/')
    {
      tmp_dir = strdup (dir);
      if (!tmp_dir)
        {
          /* Rather than rely on strdup-posix, we set errno ourselves.  */
          errno = ENOMEM;
          return -1;
        }
      strip_trailing_slashes (tmp_dir);
    }
  else
    {
      tmp_dir = (char *) dir;
    }

They strip more than one trailing slash, but for git's purpose I believed this to be too much overhead. Also the errno stuff doesn't seem to be really needed IMHO. Same for the following code

#if FUNC_MKDIR_DOT_BUG
/* Additionally, cygwin 1.5 mistakenly creates a directory "d/./". */

  {
    char *last = last_component (tmp_dir);
    if (*last == '.' && (last[1] == '\0'
                         || (last[1] == '.' && last[2] == '\0')))
      {
        struct stat st;
        if (stat (tmp_dir, &st) == 0)
          errno = EEXIST;
        return -1;
      }

}
#endif /* FUNC_MKDIR_DOT_BUG */

Then it goes on like mine:

  ret_val = mkdir (tmp_dir, mode);

  if (tmp_dir != dir)
    free (tmp_dir);

return ret_val;
}

Compare:

$ cat compat/mkdir.c
#include "../git-compat-util.h"
#undef mkdir

/* for platforms that can't deal with a trailing '/' */ int compat_mkdir_wo_trailing_slash(const char *dir, mode_t mode)

{
        int retval;
        char *tmp_dir = NULL;
        size_t len = strlen(dir);

        if (len && dir[len-1] == '/') {
                if ((tmp_dir = strdup(dir)) == NULL)
                        return -1;
                tmp_dir[len-1] = '\0';
        }
        else
                tmp_dir = (char *)dir;

        retval = mkdir(tmp_dir, mode);
        if (tmp_dir != dir)
                free(tmp_dir);

        return retval;
}

Bye, Jojo

#34 lore raw
In reply to Brandon Casey
Quoted 8 lines · Brandon Casey

Also, we have xstrndup. So I think the body of your function can become something like:

   if (len && dir[len-1] == '/')
       dir = tmp_dir = xstrndup(dir, len-1);

   retval = mkdir(dir, mode);
   free(tmp_dir);

Actually, xmemdupz could be used in place of xstrndup since we've already called strlen.

-Brandon