Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit a9b7fed

Browse files
committed
Merge pull request #81 from laijs/sync-time
sync hardware time to system time when start pod
2 parents ad196e2 + c835eb9 commit a9b7fed

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

src/init.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,7 @@ static int hyper_start_pod(char *json, int length)
620620
if (pod->init_pid)
621621
fprintf(stdout, "pod init_pid exist %d\n", pod->init_pid);
622622

623+
hyper_sync_time_hctosys();
623624
if (hyper_parse_pod(pod, json, length) < 0) {
624625
fprintf(stderr, "parse pod json failed\n");
625626
return -1;

src/util.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,18 @@ int hyper_copy_dir(char *src, char *dest) {
9999
return -1;
100100
}
101101

102+
void hyper_sync_time_hctosys() {
103+
int pid;
104+
pid = fork();
105+
if (pid < 0) {
106+
perror("fail to fork to copy directory");
107+
} else if (pid == 0) {
108+
execlp("/busybox", "hwclock", "-s", NULL);
109+
perror("exec hwclock -s command failed");
110+
exit(-1);
111+
}
112+
}
113+
102114
int hyper_find_sd(char *addr, char **dev) {
103115
struct dirent **list;
104116
struct dirent *dir;

src/util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ int hyper_setup_env(struct env *envs, int num);
1919
int hyper_find_sd(char *addr, char **dev);
2020
int hyper_list_dir(char *path);
2121
int hyper_copy_dir(char *src, char *dst);
22+
void hyper_sync_time_hctosys();
2223
void online_cpu(void);
2324
void online_memory(void);
2425
int hyper_mkdir(char *path);

0 commit comments

Comments
 (0)