Bug#304668: libc6.1: calls to clock_settime() fail with "invalid argument" error always
Package: libc6.1
Version: 2.3.2.ds1-20
Severity: normal
Tags: patch
Any calls to to clock_settime() fail with EINVAL. Here is a test program
to reproduce it (mostly stolen from LTP);
=========
#include <errno.h>
#include <syscall.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
/* weak symbols. In newer glibc, these symbols should be present. Then
* it will supersede the definition from this code using _syscall
*/
#pragma weak clock_settime
#pragma weak clock_gettime
static void setup();
static void cleanup();
static struct timespec saved; /* Used to reset the time */
int
main(int ac, char **av)
{
int lc; /* loop counter */
char *msg; /* message returned from parse_opts */
struct timespec spec; /* Used to specify time for test */
/* perform global setup for test */
setup();
spec.tv_sec = saved.tv_sec+5000;
spec.tv_nsec = saved.tv_nsec;
if (clock_settime(CLOCK_REALTIME, &spec) < 0) {
perror("clock_settime");
exit(1);
}
printf("clock_settime(2) Passed\n");
/* Clean up and exit */
cleanup();
return 0;
}
/* setup() - performs all ONE TIME setup for this test */
void
setup()
{
/* Check whether we are root */
if (geteuid() != 0) {
fprintf(stderr, "Test must be run as root\n");
exit(1);
}
/* Save the current time specifications */
if (clock_gettime(CLOCK_REALTIME, &saved) < 0) {
if (errno == ENOSYS) {
/* System call not implemened */
perror("clock_gettime");
exit(1);
}
fprintf(stderr, "ERROR: Could not save the current time\n");
exit(1);
}
} /* End setup() */
/*
* cleanup() - Performs one time cleanup for this test at
* completion or premature exit
*/
void
cleanup()
{
/* Set the saved time */
if (clock_settime(CLOCK_REALTIME, &saved) < 0) {
perror("FATAL COULD NOT RESET THE CLOCK");
exit(1);
}
} /* End cleanup() */
=========
Link this with librt and run the executable as root (only root can call
clock_settime() with CLOCK_REALTIME).
This problem is caused by a typo in glibc 2.3.2. This typo was fixed in
glibc 2.3.4. Here is a patch to fix it:
=========
#! /bin/sh -e
# All lines beginning with `# DP:' are a description of the patch.
# DP: Description: Fix clock_settime typo
# DP: Author: Khalid Aziz <khalid.aziz@hp.com>
# DP: Upstream status: Fixed in glibc 2.3.4
# DP: Status Details: There is a typo in clock_settime which causes
# DP: any and every call to clock_settime to terminate with EINVAL.
# DP: Date: Apr 13, 2005
if [ $# -ne 2 ]; then
echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
exit 1
fi
case "$1" in
-patch) patch -d "$2" -f --no-backup-if-mismatch -p1 < $0;;
-unpatch) patch -d "$2" -f --no-backup-if-mismatch -R -p1 < $0;;
*)
echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
exit 1
esac
exit 0
# append the patch here and adjust the -p? flag in the patch calls.
--- glibc-2.3.2/sysdeps/unix/clock_settime.c 2005-04-13 10:51:46.299187007 -0600
+++ glibc-2.3.2-settime_fix/sysdeps/unix/clock_settime.c 2005-04-13 10:51:32.786491860 -0600
@@ -64,8 +64,8 @@ clock_settime (clockid_t clock_id, const
retval = settimeofday (&tv, NULL); \
} while (0)
-#ifdef SYSDEP_GETTIME
- SYSDEP_GETTIME;
+#ifdef SYSDEP_SETTIME
+ SYSDEP_SETTIME;
#endif
#ifndef HANDLED_REALTIME
=========
Please include this patch in glibc 2.3.2 in the next version. It is not
possible to use clock_settime() without this patch.
-- System Information:
Debian Release: 3.1
APT prefers testing
APT policy: (500, 'testing'), (1, 'experimental')
Architecture: ia64
Kernel: Linux 2.6.8-1-mckinley
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)
Versions of packages libc6.1 depends on:
ii libdb1-compat 2.1.3-7 The Berkeley database routines [gl
-- no debconf information
Reply to: