diff options
| author | Jeroen Hofstee <jhofstee@victronenergy.com> | 2025-04-30 13:41:32 +0200 |
|---|---|---|
| committer | Armin Kuster <akuster808@gmail.com> | 2025-05-17 12:11:18 -0600 |
| commit | ef74a629a802fc9ffd476e9d68bbad78d2d3e620 (patch) | |
| tree | b8163e995aa02d5180b073fb74c05ae882f2000d | |
| parent | 54c92c9e89c4436092a4eba74c32807ce299fb09 (diff) | |
| download | meta-openembedded-ef74a629a802fc9ffd476e9d68bbad78d2d3e620.tar.gz | |
can-utils: fix printing / reading timestamps
Backport a patch to correctly handle 64bit timestamps.
Signed-off-by: Jeroen Hofstee <jhofstee@victronenergy.com>
Signed-off-by: Armin Kuster <akuster808@gmail.com>
| -rw-r--r-- | meta-oe/recipes-extended/socketcan/can-utils/0001-timestamp-formatting-always-use-64-bit-for-timestamp.patch | 422 | ||||
| -rw-r--r-- | meta-oe/recipes-extended/socketcan/can-utils_2023.03.bb | 4 |
2 files changed, 425 insertions, 1 deletions
diff --git a/meta-oe/recipes-extended/socketcan/can-utils/0001-timestamp-formatting-always-use-64-bit-for-timestamp.patch b/meta-oe/recipes-extended/socketcan/can-utils/0001-timestamp-formatting-always-use-64-bit-for-timestamp.patch new file mode 100644 index 0000000000..47f3792c39 --- /dev/null +++ b/meta-oe/recipes-extended/socketcan/can-utils/0001-timestamp-formatting-always-use-64-bit-for-timestamp.patch | |||
| @@ -0,0 +1,422 @@ | |||
| 1 | From 05eb82fc959328f851d4b939d394529ac377de19 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: TyK <tisyang@gmail.com> | ||
| 3 | Date: Mon, 27 Nov 2023 10:59:21 +0800 | ||
| 4 | Subject: [PATCH] timestamp formatting: always use 64-bit for timestamp | ||
| 5 | formatting. | ||
| 6 | |||
| 7 | Using C99 `unsigned long long` to format `struct timeval`'s `tv_sec` | ||
| 8 | and `tv_usec`, fix incorrect print on some 32bit platform which | ||
| 9 | are using time64. | ||
| 10 | |||
| 11 | Upstream-Status: Backport [https://github.com/linux-can/can-utils/commit/ceda93bd5c56927c72d48dcaa30e17d6ecea86b8] | ||
| 12 | --- | ||
| 13 | asc2log.c | 38 +++++++++++++++++++++++--------------- | ||
| 14 | candump.c | 6 +++--- | ||
| 15 | canlogserver.c | 4 ++-- | ||
| 16 | canplayer.c | 11 +++++++---- | ||
| 17 | isotpdump.c | 8 ++++---- | ||
| 18 | isotpperf.c | 4 ++-- | ||
| 19 | isotpsniffer.c | 6 +++--- | ||
| 20 | j1939cat.c | 4 ++-- | ||
| 21 | j1939spy.c | 6 +++--- | ||
| 22 | log2asc.c | 11 +++++++---- | ||
| 23 | slcanpty.c | 4 ++-- | ||
| 24 | 11 files changed, 58 insertions(+), 44 deletions(-) | ||
| 25 | |||
| 26 | diff --git a/asc2log.c b/asc2log.c | ||
| 27 | index ea6b486..4eb3609 100644 | ||
| 28 | --- a/asc2log.c | ||
| 29 | +++ b/asc2log.c | ||
| 30 | @@ -73,7 +73,7 @@ void print_usage(char *prg) | ||
| 31 | |||
| 32 | void prframe(FILE *file, struct timeval *tv, int dev, struct canfd_frame *cf, unsigned int max_dlen, char *extra_info) { | ||
| 33 | |||
| 34 | - fprintf(file, "(%lu.%06lu) ", tv->tv_sec, tv->tv_usec); | ||
| 35 | + fprintf(file, "(%llu.%06llu) ", (unsigned long long)tv->tv_sec, (unsigned long long)tv->tv_usec); | ||
| 36 | |||
| 37 | if (dev > 0) | ||
| 38 | fprintf(file, "can%d ", dev-1); | ||
| 39 | @@ -141,11 +141,14 @@ void eval_can(char* buf, struct timeval *date_tvp, char timestamps, char base, i | ||
| 40 | char dir[3]; /* 'Rx' or 'Tx' plus terminating zero */ | ||
| 41 | char *extra_info; | ||
| 42 | int i, items; | ||
| 43 | + unsigned long long sec, usec; | ||
| 44 | |||
| 45 | /* check for ErrorFrames */ | ||
| 46 | - if (sscanf(buf, "%lu.%lu %d %s", | ||
| 47 | - &read_tv.tv_sec, &read_tv.tv_usec, | ||
| 48 | + if (sscanf(buf, "%llu.%llu %d %s", | ||
| 49 | + &sec, &usec, | ||
| 50 | &interface, tmp1) == 4) { | ||
| 51 | + read_tv.tv_sec = sec; | ||
| 52 | + read_tv.tv_usec = usec; | ||
| 53 | |||
| 54 | if (!strncmp(tmp1, "ErrorFrame", strlen("ErrorFrame"))) { | ||
| 55 | |||
| 56 | @@ -165,18 +168,20 @@ void eval_can(char* buf, struct timeval *date_tvp, char timestamps, char base, i | ||
| 57 | |||
| 58 | /* check for CAN frames with (hexa)decimal values */ | ||
| 59 | if (base == 'h') | ||
| 60 | - items = sscanf(buf, "%lu.%lu %d %s %2s %c %x %x %x %x %x %x %x %x %x", | ||
| 61 | - &read_tv.tv_sec, &read_tv.tv_usec, &interface, | ||
| 62 | + items = sscanf(buf, "%llu.%llu %d %s %2s %c %x %x %x %x %x %x %x %x %x", | ||
| 63 | + &sec, &usec, &interface, | ||
| 64 | tmp1, dir, &rtr, &dlc, | ||
| 65 | &data[0], &data[1], &data[2], &data[3], | ||
| 66 | &data[4], &data[5], &data[6], &data[7]); | ||
| 67 | else | ||
| 68 | - items = sscanf(buf, "%lu.%lu %d %s %2s %c %x %d %d %d %d %d %d %d %d", | ||
| 69 | - &read_tv.tv_sec, &read_tv.tv_usec, &interface, | ||
| 70 | + items = sscanf(buf, "%llu.%llu %d %s %2s %c %x %d %d %d %d %d %d %d %d", | ||
| 71 | + &sec, &usec, &interface, | ||
| 72 | tmp1, dir, &rtr, &dlc, | ||
| 73 | &data[0], &data[1], &data[2], &data[3], | ||
| 74 | &data[4], &data[5], &data[6], &data[7]); | ||
| 75 | |||
| 76 | + read_tv.tv_sec = sec; | ||
| 77 | + read_tv.tv_usec = usec; | ||
| 78 | if (items < 7 ) /* make sure we've read the dlc */ | ||
| 79 | return; | ||
| 80 | |||
| 81 | @@ -246,6 +251,7 @@ void eval_canfd(char* buf, struct timeval *date_tvp, char timestamps, int dplace | ||
| 82 | char *extra_info; | ||
| 83 | char *ptr; | ||
| 84 | int i; | ||
| 85 | + unsigned long long sec, usec; | ||
| 86 | |||
| 87 | /* The CANFD format is mainly in hex representation but <DataLength> | ||
| 88 | and probably some content we skip anyway. Don't trust the docs! */ | ||
| 89 | @@ -255,19 +261,21 @@ void eval_canfd(char* buf, struct timeval *date_tvp, char timestamps, int dplace | ||
| 90 | 100000 214 223040 80000000 46500250 460a0250 20011736 20010205 */ | ||
| 91 | |||
| 92 | /* check for valid line without symbolic name */ | ||
| 93 | - if (sscanf(buf, "%lu.%lu %*s %d %2s %s %hhx %hhx %x %d ", | ||
| 94 | - &read_tv.tv_sec, &read_tv.tv_usec, &interface, | ||
| 95 | + if (sscanf(buf, "%llu.%llu %*s %d %2s %s %hhx %hhx %x %d ", | ||
| 96 | + &sec, &usec, &interface, | ||
| 97 | dir, tmp1, &brs, &esi, &dlc, &dlen) != 9) { | ||
| 98 | |||
| 99 | /* check for valid line with a symbolic name */ | ||
| 100 | - if (sscanf(buf, "%lu.%lu %*s %d %2s %s %*s %hhx %hhx %x %d ", | ||
| 101 | - &read_tv.tv_sec, &read_tv.tv_usec, &interface, | ||
| 102 | + if (sscanf(buf, "%llu.%llu %*s %d %2s %s %*s %hhx %hhx %x %d ", | ||
| 103 | + &sec, &usec, &interface, | ||
| 104 | dir, tmp1, &brs, &esi, &dlc, &dlen) != 9) { | ||
| 105 | |||
| 106 | /* no valid CANFD format pattern */ | ||
| 107 | return; | ||
| 108 | } | ||
| 109 | } | ||
| 110 | + read_tv.tv_sec = sec; | ||
| 111 | + read_tv.tv_usec = usec; | ||
| 112 | |||
| 113 | /* check for allowed (unsigned) value ranges */ | ||
| 114 | if ((dlen > CANFD_MAX_DLEN) || (dlc > CANFD_MAX_DLC) || | ||
| 115 | @@ -427,12 +435,12 @@ int main(int argc, char **argv) | ||
| 116 | FILE *infile = stdin; | ||
| 117 | FILE *outfile = stdout; | ||
| 118 | static int verbose; | ||
| 119 | - static struct timeval tmp_tv; /* tmp frame timestamp from ASC file */ | ||
| 120 | static struct timeval date_tv; /* date of the ASC file */ | ||
| 121 | static int dplace; /* decimal place 4, 5 or 6 or uninitialized */ | ||
| 122 | static char base; /* 'd'ec or 'h'ex */ | ||
| 123 | static char timestamps; /* 'a'bsolute or 'r'elative */ | ||
| 124 | int opt; | ||
| 125 | + unsigned long long sec, usec; | ||
| 126 | |||
| 127 | while ((opt = getopt(argc, argv, "I:O:v?")) != -1) { | ||
| 128 | switch (opt) { | ||
| 129 | @@ -505,12 +513,12 @@ int main(int argc, char **argv) | ||
| 130 | gettimeofday(&date_tv, NULL); | ||
| 131 | } | ||
| 132 | if (verbose) | ||
| 133 | - printf("date %lu => %s", date_tv.tv_sec, ctime(&date_tv.tv_sec)); | ||
| 134 | + printf("date %llu => %s", (unsigned long long)date_tv.tv_sec, ctime(&date_tv.tv_sec)); | ||
| 135 | continue; | ||
| 136 | } | ||
| 137 | |||
| 138 | /* check for decimal places length in valid CAN frames */ | ||
| 139 | - if (sscanf(buf, "%lu.%s %s ", &tmp_tv.tv_sec, tmp2, | ||
| 140 | + if (sscanf(buf, "%llu.%s %s ", &sec, tmp2, | ||
| 141 | tmp1) != 3) | ||
| 142 | continue; /* dplace remains zero until first found CAN frame */ | ||
| 143 | |||
| 144 | @@ -529,7 +537,7 @@ int main(int argc, char **argv) | ||
| 145 | /* so try to get CAN frames and ErrorFrames and convert them */ | ||
| 146 | |||
| 147 | /* check classic CAN format or the CANFD tag which can take both types */ | ||
| 148 | - if (sscanf(buf, "%lu.%lu %s ", &tmp_tv.tv_sec, &tmp_tv.tv_usec, tmp1) == 3){ | ||
| 149 | + if (sscanf(buf, "%llu.%llu %s ", &sec, &usec, tmp1) == 3){ | ||
| 150 | if (!strncmp(tmp1, "CANFD", 5)) | ||
| 151 | eval_canfd(buf, &date_tv, timestamps, dplace, outfile); | ||
| 152 | else | ||
| 153 | diff --git a/candump.c b/candump.c | ||
| 154 | index 82f75b1..4ae8864 100644 | ||
| 155 | --- a/candump.c | ||
| 156 | +++ b/candump.c | ||
| 157 | @@ -224,7 +224,7 @@ static inline void sprint_timestamp(const char timestamp, const struct timeval * | ||
| 158 | { | ||
| 159 | switch (timestamp) { | ||
| 160 | case 'a': /* absolute with timestamp */ | ||
| 161 | - sprintf(ts_buffer, "(%010lu.%06lu) ", tv->tv_sec, tv->tv_usec); | ||
| 162 | + sprintf(ts_buffer, "(%010llu.%06llu) ", (unsigned long long)tv->tv_sec, (unsigned long long)tv->tv_usec); | ||
| 163 | break; | ||
| 164 | |||
| 165 | case 'A': /* absolute with date */ | ||
| 166 | @@ -234,7 +234,7 @@ static inline void sprint_timestamp(const char timestamp, const struct timeval * | ||
| 167 | |||
| 168 | tm = *localtime(&tv->tv_sec); | ||
| 169 | strftime(timestring, 24, "%Y-%m-%d %H:%M:%S", &tm); | ||
| 170 | - sprintf(ts_buffer, "(%s.%06lu) ", timestring, tv->tv_usec); | ||
| 171 | + sprintf(ts_buffer, "(%s.%06llu) ", timestring, (unsigned long long)tv->tv_usec); | ||
| 172 | } | ||
| 173 | break; | ||
| 174 | |||
| 175 | @@ -251,7 +251,7 @@ static inline void sprint_timestamp(const char timestamp, const struct timeval * | ||
| 176 | diff.tv_sec--, diff.tv_usec += 1000000; | ||
| 177 | if (diff.tv_sec < 0) | ||
| 178 | diff.tv_sec = diff.tv_usec = 0; | ||
| 179 | - sprintf(ts_buffer, "(%03lu.%06lu) ", diff.tv_sec, diff.tv_usec); | ||
| 180 | + sprintf(ts_buffer, "(%03llu.%06llu) ", (unsigned long long)diff.tv_sec, (unsigned long long)diff.tv_usec); | ||
| 181 | |||
| 182 | if (timestamp == 'd') | ||
| 183 | *last_tv = *tv; /* update for delta calculation */ | ||
| 184 | diff --git a/canlogserver.c b/canlogserver.c | ||
| 185 | index 51d548f..349d64e 100644 | ||
| 186 | --- a/canlogserver.c | ||
| 187 | +++ b/canlogserver.c | ||
| 188 | @@ -408,8 +408,8 @@ int main(int argc, char **argv) | ||
| 189 | |||
| 190 | idx = idx2dindex(addr.can_ifindex, s[i]); | ||
| 191 | |||
| 192 | - sprintf(temp, "(%lu.%06lu) %*s ", | ||
| 193 | - tv.tv_sec, tv.tv_usec, max_devname_len, devname[idx]); | ||
| 194 | + sprintf(temp, "(%llu.%06llu) %*s ", | ||
| 195 | + (unsigned long long)tv.tv_sec, (unsigned long long)tv.tv_usec, max_devname_len, devname[idx]); | ||
| 196 | sprint_canframe(temp+strlen(temp), &frame, 0, maxdlen); | ||
| 197 | strcat(temp, "\n"); | ||
| 198 | |||
| 199 | diff --git a/canplayer.c b/canplayer.c | ||
| 200 | index 51adc77..96346ce 100644 | ||
| 201 | --- a/canplayer.c | ||
| 202 | +++ b/canplayer.c | ||
| 203 | @@ -259,6 +259,7 @@ int main(int argc, char **argv) | ||
| 204 | int txidx; /* sendto() interface index */ | ||
| 205 | int eof, txmtu, i, j; | ||
| 206 | char *fret; | ||
| 207 | + unsigned long long sec, usec; | ||
| 208 | |||
| 209 | while ((opt = getopt(argc, argv, "I:l:tin:g:s:xv?")) != -1) { | ||
| 210 | switch (opt) { | ||
| 211 | @@ -419,11 +420,12 @@ int main(int argc, char **argv) | ||
| 212 | |||
| 213 | eof = 0; | ||
| 214 | |||
| 215 | - if (sscanf(buf, "(%lu.%lu) %s %s", &log_tv.tv_sec, &log_tv.tv_usec, | ||
| 216 | - device, ascframe) != 4) { | ||
| 217 | + if (sscanf(buf, "(%llu.%llu) %s %s", &sec, &usec, device, ascframe) != 4) { | ||
| 218 | fprintf(stderr, "incorrect line format in logfile\n"); | ||
| 219 | return 1; | ||
| 220 | } | ||
| 221 | + log_tv.tv_sec = sec; | ||
| 222 | + log_tv.tv_usec = usec; | ||
| 223 | |||
| 224 | if (use_timestamps) { /* throttle sending due to logfile timestamps */ | ||
| 225 | |||
| 226 | @@ -505,11 +507,12 @@ int main(int argc, char **argv) | ||
| 227 | break; | ||
| 228 | } | ||
| 229 | |||
| 230 | - if (sscanf(buf, "(%lu.%lu) %s %s", &log_tv.tv_sec, &log_tv.tv_usec, | ||
| 231 | - device, ascframe) != 4) { | ||
| 232 | + if (sscanf(buf, "(%llu.%llu) %s %s", &sec, &usec, device, ascframe) != 4) { | ||
| 233 | fprintf(stderr, "incorrect line format in logfile\n"); | ||
| 234 | return 1; | ||
| 235 | } | ||
| 236 | + log_tv.tv_sec = sec; | ||
| 237 | + log_tv.tv_usec = usec; | ||
| 238 | |||
| 239 | /* | ||
| 240 | * ensure the fractions of seconds are 6 decimal places long to catch | ||
| 241 | diff --git a/isotpdump.c b/isotpdump.c | ||
| 242 | index d22725e..e9e96ce 100644 | ||
| 243 | --- a/isotpdump.c | ||
| 244 | +++ b/isotpdump.c | ||
| 245 | @@ -361,7 +361,7 @@ int main(int argc, char **argv) | ||
| 246 | |||
| 247 | switch (timestamp) { | ||
| 248 | case 'a': /* absolute with timestamp */ | ||
| 249 | - printf("(%lu.%06lu) ", tv.tv_sec, tv.tv_usec); | ||
| 250 | + printf("(%llu.%06llu) ", (unsigned long long)tv.tv_sec, (unsigned long long)tv.tv_usec); | ||
| 251 | break; | ||
| 252 | |||
| 253 | case 'A': /* absolute with date */ | ||
| 254 | @@ -372,7 +372,7 @@ int main(int argc, char **argv) | ||
| 255 | tm = *localtime(&tv.tv_sec); | ||
| 256 | strftime(timestring, 24, "%Y-%m-%d %H:%M:%S", | ||
| 257 | &tm); | ||
| 258 | - printf("(%s.%06lu) ", timestring, tv.tv_usec); | ||
| 259 | + printf("(%s.%06llu) ", timestring, (unsigned long long)tv.tv_usec); | ||
| 260 | } break; | ||
| 261 | |||
| 262 | case 'd': /* delta */ | ||
| 263 | @@ -388,8 +388,8 @@ int main(int argc, char **argv) | ||
| 264 | diff.tv_sec--, diff.tv_usec += 1000000; | ||
| 265 | if (diff.tv_sec < 0) | ||
| 266 | diff.tv_sec = diff.tv_usec = 0; | ||
| 267 | - printf("(%lu.%06lu) ", diff.tv_sec, | ||
| 268 | - diff.tv_usec); | ||
| 269 | + printf("(%llu.%06llu) ", (unsigned long long)diff.tv_sec, | ||
| 270 | + (unsigned long long)diff.tv_usec); | ||
| 271 | |||
| 272 | if (timestamp == 'd') | ||
| 273 | last_tv = | ||
| 274 | diff --git a/isotpperf.c b/isotpperf.c | ||
| 275 | index 154d5cd..ad0dc2a 100644 | ||
| 276 | --- a/isotpperf.c | ||
| 277 | +++ b/isotpperf.c | ||
| 278 | @@ -403,9 +403,9 @@ int main(int argc, char **argv) | ||
| 279 | |||
| 280 | /* check devisor to be not zero */ | ||
| 281 | if (diff_tv.tv_sec * 1000 + diff_tv.tv_usec / 1000){ | ||
| 282 | - printf("%lu.%06lus ", diff_tv.tv_sec, diff_tv.tv_usec); | ||
| 283 | + printf("%llu.%06llus ", (unsigned long long)diff_tv.tv_sec, (unsigned long long)diff_tv.tv_usec); | ||
| 284 | printf("=> %lu byte/s", (fflen * 1000) / | ||
| 285 | - (diff_tv.tv_sec * 1000 + diff_tv.tv_usec / 1000)); | ||
| 286 | + (unsigned long)(diff_tv.tv_sec * 1000 + diff_tv.tv_usec / 1000)); | ||
| 287 | } else | ||
| 288 | printf("(no time available) "); | ||
| 289 | |||
| 290 | diff --git a/isotpsniffer.c b/isotpsniffer.c | ||
| 291 | index 2b6de40..f976149 100644 | ||
| 292 | --- a/isotpsniffer.c | ||
| 293 | +++ b/isotpsniffer.c | ||
| 294 | @@ -101,7 +101,7 @@ void printbuf(unsigned char *buffer, int nbytes, int color, int timestamp, | ||
| 295 | switch (timestamp) { | ||
| 296 | |||
| 297 | case 'a': /* absolute with timestamp */ | ||
| 298 | - printf("(%lu.%06lu) ", tv->tv_sec, tv->tv_usec); | ||
| 299 | + printf("(%llu.%06llu) ", (unsigned long long)tv->tv_sec, (unsigned long long)tv->tv_usec); | ||
| 300 | break; | ||
| 301 | |||
| 302 | case 'A': /* absolute with date */ | ||
| 303 | @@ -111,7 +111,7 @@ void printbuf(unsigned char *buffer, int nbytes, int color, int timestamp, | ||
| 304 | |||
| 305 | tm = *localtime(&tv->tv_sec); | ||
| 306 | strftime(timestring, 24, "%Y-%m-%d %H:%M:%S", &tm); | ||
| 307 | - printf("(%s.%06lu) ", timestring, tv->tv_usec); | ||
| 308 | + printf("(%s.%06llu) ", timestring, (unsigned long long)tv->tv_usec); | ||
| 309 | } | ||
| 310 | break; | ||
| 311 | |||
| 312 | @@ -128,7 +128,7 @@ void printbuf(unsigned char *buffer, int nbytes, int color, int timestamp, | ||
| 313 | diff.tv_sec--, diff.tv_usec += 1000000; | ||
| 314 | if (diff.tv_sec < 0) | ||
| 315 | diff.tv_sec = diff.tv_usec = 0; | ||
| 316 | - printf("(%lu.%06lu) ", diff.tv_sec, diff.tv_usec); | ||
| 317 | + printf("(%llu.%06llu) ", (unsigned long long)diff.tv_sec, (unsigned long long)diff.tv_usec); | ||
| 318 | |||
| 319 | if (timestamp == 'd') | ||
| 320 | *last_tv = *tv; /* update for delta calculation */ | ||
| 321 | diff --git a/j1939cat.c b/j1939cat.c | ||
| 322 | index 4234aad..238c4ff 100644 | ||
| 323 | --- a/j1939cat.c | ||
| 324 | +++ b/j1939cat.c | ||
| 325 | @@ -148,8 +148,8 @@ static void j1939cat_print_timestamp(struct j1939cat_priv *priv, const char *nam | ||
| 326 | if (!(cur->tv_sec | cur->tv_nsec)) | ||
| 327 | return; | ||
| 328 | |||
| 329 | - fprintf(stderr, " %s: %lu s %lu us (seq=%03u, send=%07u)", | ||
| 330 | - name, cur->tv_sec, cur->tv_nsec / 1000, | ||
| 331 | + fprintf(stderr, " %s: %llu s %llu us (seq=%03u, send=%07u)", | ||
| 332 | + name, (unsigned long long)cur->tv_sec, (unsigned long long)cur->tv_nsec / 1000, | ||
| 333 | stats->tskey, stats->send); | ||
| 334 | |||
| 335 | fprintf(stderr, "\n"); | ||
| 336 | diff --git a/j1939spy.c b/j1939spy.c | ||
| 337 | index e49ed14..56950ea 100644 | ||
| 338 | --- a/j1939spy.c | ||
| 339 | +++ b/j1939spy.c | ||
| 340 | @@ -268,14 +268,14 @@ int main(int argc, char **argv) | ||
| 341 | goto abs_time; | ||
| 342 | } else if ('a' == s.time) { | ||
| 343 | abs_time: | ||
| 344 | - printf("(%lu.%04lu)", tdut.tv_sec, tdut.tv_usec / 100); | ||
| 345 | + printf("(%llu.%04llu)", (unsigned long long)tdut.tv_sec, (unsigned long long)tdut.tv_usec / 100); | ||
| 346 | } else if ('A' == s.time) { | ||
| 347 | struct tm tm; | ||
| 348 | tm = *localtime(&tdut.tv_sec); | ||
| 349 | - printf("(%04u%02u%02uT%02u%02u%02u.%04lu)", | ||
| 350 | + printf("(%04u%02u%02uT%02u%02u%02u.%04llu)", | ||
| 351 | tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, | ||
| 352 | tm.tm_hour, tm.tm_min, tm.tm_sec, | ||
| 353 | - tdut.tv_usec/100); | ||
| 354 | + (unsigned long long)tdut.tv_usec/100); | ||
| 355 | } | ||
| 356 | } | ||
| 357 | printf(" %s ", libj1939_addr2str(&src)); | ||
| 358 | diff --git a/log2asc.c b/log2asc.c | ||
| 359 | index a1cf364..85634f8 100644 | ||
| 360 | --- a/log2asc.c | ||
| 361 | +++ b/log2asc.c | ||
| 362 | @@ -190,6 +190,7 @@ int main(int argc, char **argv) | ||
| 363 | FILE *infile = stdin; | ||
| 364 | FILE *outfile = stdout; | ||
| 365 | static int maxdev, devno, i, crlf, fdfmt, nortrdlc, d4, opt, mtu; | ||
| 366 | + unsigned long long sec, usec; | ||
| 367 | |||
| 368 | while ((opt = getopt(argc, argv, "I:O:4nfr?")) != -1) { | ||
| 369 | switch (opt) { | ||
| 370 | @@ -259,18 +260,20 @@ int main(int argc, char **argv) | ||
| 371 | if (buf[0] != '(') | ||
| 372 | continue; | ||
| 373 | |||
| 374 | - if (sscanf(buf, "(%lu.%lu) %s %s %s", &tv.tv_sec, &tv.tv_usec, | ||
| 375 | + if (sscanf(buf, "(%llu.%llu) %s %s %s", &sec, &usec, | ||
| 376 | device, ascframe, extra_info) != 5) { | ||
| 377 | |||
| 378 | /* do not evaluate the extra info */ | ||
| 379 | extra_info[0] = 0; | ||
| 380 | |||
| 381 | - if (sscanf(buf, "(%lu.%lu) %s %s", &tv.tv_sec, &tv.tv_usec, | ||
| 382 | + if (sscanf(buf, "(%llu.%llu) %s %s", &sec, &usec, | ||
| 383 | device, ascframe) != 4) { | ||
| 384 | fprintf(stderr, "incorrect line format in logfile\n"); | ||
| 385 | return 1; | ||
| 386 | } | ||
| 387 | } | ||
| 388 | + tv.tv_sec = sec; | ||
| 389 | + tv.tv_usec = usec; | ||
| 390 | |||
| 391 | if (!start_tv.tv_sec) { /* print banner */ | ||
| 392 | start_tv = tv; | ||
| 393 | @@ -305,9 +308,9 @@ int main(int argc, char **argv) | ||
| 394 | tv.tv_sec = tv.tv_usec = 0; | ||
| 395 | |||
| 396 | if (d4) | ||
| 397 | - fprintf(outfile, "%4lu.%04lu ", tv.tv_sec, tv.tv_usec/100); | ||
| 398 | + fprintf(outfile, "%4llu.%04llu ", (unsigned long long)tv.tv_sec, (unsigned long long)tv.tv_usec/100); | ||
| 399 | else | ||
| 400 | - fprintf(outfile, "%4lu.%06lu ", tv.tv_sec, tv.tv_usec); | ||
| 401 | + fprintf(outfile, "%4llu.%06llu ", (unsigned long long)tv.tv_sec, (unsigned long long)tv.tv_usec); | ||
| 402 | |||
| 403 | if ((mtu == CAN_MTU) && (fdfmt == 0)) | ||
| 404 | can_asc(&cf, devno, nortrdlc, extra_info, outfile); | ||
| 405 | diff --git a/slcanpty.c b/slcanpty.c | ||
| 406 | index fa97cd6..fc86d4f 100644 | ||
| 407 | --- a/slcanpty.c | ||
| 408 | +++ b/slcanpty.c | ||
| 409 | @@ -363,8 +363,8 @@ int can2pty(int pty, int socket, int *tstamp) | ||
| 410 | if (ioctl(socket, SIOCGSTAMP, &tv) < 0) | ||
| 411 | perror("SIOCGSTAMP"); | ||
| 412 | |||
| 413 | - sprintf(&buf[ptr + 2*frame.can_dlc], "%04lX", | ||
| 414 | - (tv.tv_sec%60)*1000 + tv.tv_usec/1000); | ||
| 415 | + sprintf(&buf[ptr + 2*frame.can_dlc], "%04llX", | ||
| 416 | + (unsigned long long)(tv.tv_sec%60)*1000 + tv.tv_usec/1000); | ||
| 417 | } | ||
| 418 | |||
| 419 | strcat(buf, "\r"); /* add terminating character */ | ||
| 420 | -- | ||
| 421 | 2.43.0 | ||
| 422 | |||
diff --git a/meta-oe/recipes-extended/socketcan/can-utils_2023.03.bb b/meta-oe/recipes-extended/socketcan/can-utils_2023.03.bb index ca6cb7db58..5a7beb978a 100644 --- a/meta-oe/recipes-extended/socketcan/can-utils_2023.03.bb +++ b/meta-oe/recipes-extended/socketcan/can-utils_2023.03.bb | |||
| @@ -4,7 +4,9 @@ LIC_FILES_CHKSUM = "file://include/linux/can.h;endline=44;md5=a9e1169c6c9a114a61 | |||
| 4 | 4 | ||
| 5 | DEPENDS = "libsocketcan" | 5 | DEPENDS = "libsocketcan" |
| 6 | 6 | ||
| 7 | SRC_URI = "git://github.com/linux-can/${BPN}.git;protocol=https;branch=master" | 7 | SRC_URI = "git://github.com/linux-can/${BPN}.git;protocol=https;branch=master \ |
| 8 | file://0001-timestamp-formatting-always-use-64-bit-for-timestamp.patch \ | ||
| 9 | " | ||
| 8 | 10 | ||
| 9 | SRCREV = "cfe41963f3425e9adb01a70cfaddedf5e5982720" | 11 | SRCREV = "cfe41963f3425e9adb01a70cfaddedf5e5982720" |
| 10 | 12 | ||
