Skip to content

Commit

Permalink
Support for setitimer() on platforms lacking it
Browse files Browse the repository at this point in the history
Implementation includes getitimer(), but for now it is static.
Supports ITIMER_REAL only.

We may need a separate compatibility header file for ITIMER_* and
struct itimerval, but add only the prototype in git-compat-util.h
for now, as the initial motivatin of this change, HP NonStop, has
ITIMER_* and struct timeval in <sys/time>.

Signed-off-by: Joachim Schmitz <jojo@schmitz-digital.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jojo-Schmitz authored and gitster committed Aug 24, 2012
1 parent fab4b04 commit 55c96a1
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
50 changes: 50 additions & 0 deletions compat/itimer.c
@@ -0,0 +1,50 @@
#include "../git-compat-util.h"

static 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;
}
5 changes: 5 additions & 0 deletions git-compat-util.h
Expand Up @@ -162,6 +162,11 @@
#define probe_utf8_pathname_composition(a,b)
#endif

#ifdef NO_SETITIMER
#define setitimer(a,b,c) git_setitimer((a),(b),(c))
extern int git_setitimer(int, const struct itimerval *, struct itimerval *);
#endif

#ifndef NO_LIBGEN_H
#include <libgen.h>
#else
Expand Down

0 comments on commit 55c96a1

Please sign in to comment.