mirror of
https://github.com/LibreELEC/LibreELEC.tv.git
synced 2025-07-29 13:46:49 +00:00
wait-time-sync: add optional -t/--timeout parameter
This commit is contained in:
parent
50926608a5
commit
c8c692f4ba
@ -2,14 +2,43 @@
|
||||
/* Copyright (C) 2020-present Team LibreELEC (https://libreelec.tv) */
|
||||
|
||||
#include <sys/timex.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
|
||||
int main()
|
||||
void usage(char *name)
|
||||
{
|
||||
int rc;
|
||||
if (!name)
|
||||
name = "wait-time-sync";
|
||||
|
||||
for (;;)
|
||||
printf("Usage: %s [-t seconds | --timeout seconds]\n", name);
|
||||
exit(2);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
unsigned timeout = UINT_MAX;
|
||||
int rc = 0;
|
||||
|
||||
if (argc == 3)
|
||||
{
|
||||
unsigned long val;
|
||||
char *p;
|
||||
|
||||
if (strcmp(argv[1], "-t") && strcmp(argv[1], "--timeout"))
|
||||
usage(argv[0]);
|
||||
val = strtoul(argv[2], &p, 0);
|
||||
if (*p || val == 0 || val >= UINT_MAX/3)
|
||||
usage(argv[0]);
|
||||
timeout = (unsigned)val * 3;
|
||||
}
|
||||
else if (argc != 1)
|
||||
usage(argv[0]);
|
||||
|
||||
for ( ; timeout; --timeout)
|
||||
{
|
||||
struct timex tx = {};
|
||||
|
||||
@ -19,5 +48,5 @@ int main()
|
||||
usleep(1000000U/3);
|
||||
}
|
||||
|
||||
return rc == -1 ? errno : 0;
|
||||
return rc == -1 ? errno : !timeout;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user