Skip to contentSkip to conversation

linux-user: remove host stime() syscall

PATCH Applied Laurent Vivier 3 participants 4 messages Nov 12, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user: remove host stime() syscall

stime() has been withdrawn from glibc
(12cbde1dae6f "Use clock_settime to implement stime; withdraw stime.")

Implement the target stime() syscall using host clock_settime(CLOCK_REALTIME, ...) as it is done internally in glibc.

Tested qemu-ppc/x86_64 with:

	#include <time.h>
	#include <stdio.h>

	int main(void)
	{
		time_t t;
		int ret;

		/* date -u -d"2019-11-12T15:11:00" "+%s" */
		t = 1573571460;
		ret = stime(&t);
		printf("ret %d\n", ret);
		return 0;
	}

        # date; ./stime; date
        Tue Nov 12 14:18:32 UTC 2019
        ret 0
        Tue Nov 12 15:11:00 UTC 2019
---
 linux-user/syscall.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
linux-user/syscall.c +5 -3
index ab9d933e53af..c4dcdc94b10c 100644
@@ -7763,10 +7763,12 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
 #ifdef TARGET_NR_stime /* not on alpha */
     case TARGET_NR_stime:
         {
-            time_t host_time;
-            if (get_user_sal(host_time, arg1))
+            struct timespec ts;
+            ts.tv_nsec = 0;
+            if (get_user_sal(ts.tv_sec, arg1)) {
                 return -TARGET_EFAULT;
-            return get_errno(stime(&host_time));
+            }
+            return get_errno(clock_settime(CLOCK_REALTIME, &ts));
         }
 #endif
 #ifdef TARGET_NR_alarm /* not on alpha */
Signature · 1 line
2.21.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 29 lines · Laurent Vivier

stime() has been withdrawn from glibc
(12cbde1dae6f "Use clock_settime to implement stime; withdraw stime.")

Implement the target stime() syscall using host clock_settime(CLOCK_REALTIME, ...) as it is done internally in glibc.

Tested qemu-ppc/x86_64 with:

        #include <time.h>
        #include <stdio.h>

        int main(void)
        {
                time_t t;
                int ret;

                /* date -u -d"2019-11-12T15:11:00" "+%s" */
                t = 1573571460;
                ret = stime(&t);
                printf("ret %d\n", ret);
                return 0;
        }

        # date; ./stime; date
        Tue Nov 12 14:18:32 UTC 2019
        ret 0
        Tue Nov 12 15:11:00 UTC 2019
Quoted 4 lines

---

thanks
-- PMM

#2 lore raw
In reply to Laurent Vivier
Quoted 28 lines · Laurent Vivier

stime() has been withdrawn from glibc
(12cbde1dae6f "Use clock_settime to implement stime; withdraw stime.")

Implement the target stime() syscall using host clock_settime(CLOCK_REALTIME, ...) as it is done internally in glibc.

Tested qemu-ppc/x86_64 with:

	#include <time.h>
	#include <stdio.h>

	int main(void)
	{
		time_t t;
		int ret;

		/* date -u -d"2019-11-12T15:11:00" "+%s" */
		t = 1573571460;
		ret = stime(&t);
		printf("ret %d\n", ret);
		return 0;
	}

        # date; ./stime; date
        Tue Nov 12 14:18:32 UTC 2019
        ret 0
        Tue Nov 12 15:11:00 UTC 2019
Quoted 3 lines

Fixes the build issue for me. Thanks Laurent!

- Cole

author Applied
#3 lore raw
In reply to Laurent Vivier

Le 12/11/2019 à 15:25, Laurent Vivier a écrit :

Quoted 46 lines

stime() has been withdrawn from glibc
(12cbde1dae6f "Use clock_settime to implement stime; withdraw stime.")

Implement the target stime() syscall using host clock_settime(CLOCK_REALTIME, ...) as it is done internally in glibc.

Tested qemu-ppc/x86_64 with:

	#include <time.h>
	#include <stdio.h>

	int main(void)
	{
		time_t t;
		int ret;

		/* date -u -d"2019-11-12T15:11:00" "+%s" */
		t = 1573571460;
		ret = stime(&t);
		printf("ret %d\n", ret);
		return 0;
	}

        # date; ./stime; date
        Tue Nov 12 14:18:32 UTC 2019
        ret 0
        Tue Nov 12 15:11:00 UTC 2019
---
 linux-user/syscall.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
linux-user/syscall.c +0 -2
index ab9d933e53af..c4dcdc94b10c 100644
@@ -7763,10 +7763,12 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
 #ifdef TARGET_NR_stime /* not on alpha */
     case TARGET_NR_stime:
         {
-            time_t host_time;
-            if (get_user_sal(host_time, arg1))

linux-user/syscall.c static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, · line 7774

Quoted 10 lines
linux-user/syscall.c +5 -1
+            struct timespec ts;
+            ts.tv_nsec = 0;
+            if (get_user_sal(ts.tv_sec, arg1)) {
                 return -TARGET_EFAULT;
-            return get_errno(stime(&host_time));
+            }
+            return get_errno(clock_settime(CLOCK_REALTIME, &ts));
         }
 #endif
 #ifdef TARGET_NR_alarm /* not on alpha */

Applied to my linux-user branch.

Thanks,
Laurent