Browse code

Merge a888fca2a17d92a95d2343cdd1536fc4f83467fa into 26785f866eeadc6944af83ae1a57e8ff100f60f5

Matteo authored on 12/08/2022 12:33:53 • GitHub committed on 12/08/2022 12:33:53
Showing 1 changed files
... ...
@@ -23,6 +23,8 @@
23 23
 #include <ctype.h>
24 24
 #include <string.h>
25 25
 #include <stdlib.h>
26
+#include <stdint.h>
27
+#include <inttypes.h>
26 28
 #include <stdio.h>
27 29
 #include <time.h>
28 30
 #include <sys/time.h>
... ...
@@ -33,6 +35,12 @@
33 35
 
34 36
 #include "pv_time.h"
35 37
 
38
+#if defined(CLOCK_MONOTONIC_RAW)
39
+#define PV_MONOTONIC_CLOCK CLOCK_MONOTONIC_RAW
40
+#else
41
+#define PV_MONOTONIC_CLOCK CLOCK_MONOTONIC
42
+#endif
43
+
36 44
 int pv_parse_time_name(pv_spec_p sp, str *in)
37 45
 {
38 46
 	if(sp==NULL || in==NULL || in->len<=0)
... ...
@@ -306,6 +314,7 @@ int pv_get_timeval(struct sip_msg *msg, pv_param_t *param,
306 314
 		pv_value_t *res)
307 315
 {
308 316
 	struct timeval tv;
317
+	struct timespec ts;
309 318
 	str s;
310 319
 	struct tm lt;
311 320
 	char lbuf[64];
... ...
@@ -355,7 +364,18 @@ int pv_get_timeval(struct sip_msg *msg, pv_param_t *param,
355 364
 				return pv_get_null(msg, param, res);
356 365
 			s.s = _timeval_ts_buf;
357 366
 			return pv_get_strval(msg, param, res, &s);
358
-
367
+		case 6:
368
+			if (!clock_gettime(PV_MONOTONIC_CLOCK, &ts)) {
369
+				s.len = snprintf(_timeval_ts_buf, 64, "%" PRIu64,
370
+					(u_int64_t)ts.tv_sec * 1000000000 + (u_int64_t)ts.tv_nsec);
371
+				if(s.len<0)
372
+					return pv_get_null(msg, param, res);
373
+				s.s = _timeval_ts_buf;
374
+				return pv_get_strval(msg, param, res, &s);
375
+			} else {
376
+				LM_ERR("unable to get monotonic clock value\n");
377
+				return pv_get_null(msg, param, res);
378
+			}
359 379
 		default:
360 380
 			msg_set_time(msg);
361 381
 			return pv_get_uintval(msg, param, res, (unsigned int)msg->tval.tv_sec);
... ...
@@ -385,6 +405,8 @@ int pv_parse_timeval_name(pv_spec_p sp, str *in)
385 405
 				sp->pvp.pvn.u.isname.name.n = 4;
386 406
 			else if(strncmp(in->s, "Fn", 2)==0)
387 407
 				sp->pvp.pvn.u.isname.name.n = 5;
408
+			else if(strncmp(in->s, "Sm", 2)==0)
409
+				sp->pvp.pvn.u.isname.name.n = 6;
388 410
 			else goto error;
389 411
 		break;
390 412
 		default: