(Fix): replaced hardcoded C.__uint32_t / C.__int32_t casts with a C helper function (auth/utmpx_time.h) that lets the compiler handle type conversion.
This commit is contained in:
@@ -6,8 +6,10 @@ package auth
|
||||
/*
|
||||
#include <utmpx.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "utmpx_time.h"
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
@@ -49,8 +51,7 @@ func AddUtmpx(user string, tty uint8, pid uint32) *UtmpxSession {
|
||||
ut.ut_id[0] = C.char(ttyCh)
|
||||
|
||||
us := time.Now().UnixMicro()
|
||||
ut.ut_tv.tv_sec = C.__uint32_t(us / 1_000_000)
|
||||
ut.ut_tv.tv_usec = C.__int32_t(us % 1_000_000)
|
||||
C.latchd_set_utmpx_time(&ut, C.int64_t(us/1_000_000), C.int32_t(us%1_000_000))
|
||||
|
||||
C.setutxent()
|
||||
C.pututxline(&ut)
|
||||
|
||||
9
src/auth/utmpx_time.h
Normal file
9
src/auth/utmpx_time.h
Normal file
@@ -0,0 +1,9 @@
|
||||
// Helper: assign seconds + microseconds to utmpx's ut_tv field.
|
||||
// The C compiler handles the type conversion, so this works whether
|
||||
// ut_tv is struct timeval (long tv_sec/tv_usec) or the compat struct
|
||||
// (__uint32_t tv_sec / __int32_t tv_usec).
|
||||
|
||||
static inline void latchd_set_utmpx_time(struct utmpx *ut, int64_t sec, int32_t usec) {
|
||||
ut->ut_tv.tv_sec = sec;
|
||||
ut->ut_tv.tv_usec = usec;
|
||||
}
|
||||
Reference in New Issue
Block a user