Project

General

Profile

Enhancement #750 » 0015-sanitize-add-bip_clock_gettime-util-function.patch

Loïc Gomez, 2022-01-10 19:28

View differences:

src/connection.c
873 873
list_t *wait_event(list_t *cn_list, time_t *msec, int *nc)
874 874
{
875 875
	fd_set fds_read, fds_write, fds_except;
876
	int maxfd = -1, err, errtime;
876
	int maxfd = -1, err;
877 877
	list_t *cn_newdata;
878 878
	list_iterator_t it;
879 879
	struct timeval tv;
......
944 944
	mylog(LOG_DEBUGTOOMUCH, "msec: %d, sec: %d, usec: %d", *msec, tv.tv_sec,
945 945
			tv.tv_usec);
946 946

  
947
	errtime = clock_gettime(CLOCK_MONOTONIC, &btv);
948
	if (errtime != 0) {
949
		fatal("clock_gettime: %s", strerror(errno));
950
	}
951

  
947
	bip_clock_gettime(CLOCK_MONOTONIC, &btv);
952 948
	err = select(maxfd + 1, &fds_read, &fds_write, &fds_except, &tv);
953 949

  
954 950
	if (err == 0) {
......
961 957
				tv.tv_sec, tv.tv_usec);
962 958
	}
963 959

  
964
	errtime = clock_gettime(CLOCK_MONOTONIC, &etv);
965
	if (errtime != 0) {
966
		fatal("clock_gettime: %s", strerror(errno));
967
	}
968

  
960
	bip_clock_gettime(CLOCK_MONOTONIC, &etv);
969 961
	if (etv.tv_sec < btv.tv_sec)
970 962
		mylog(LOG_ERROR, "Time rewinded ! not touching interval");
971 963
	else {
src/util.c
157 157
	return res;
158 158
}
159 159

  
160
void bip_clock_gettime(clockid_t clockid, struct timespec *tp)
161
{
162
	int err = clock_gettime(clockid, tp);
163

  
164
	if (err != 0)
165
		fatal("clock_gettime: %s", strerror(errno));
166

  
167
	if (tp->tv_sec < 0 || tp->tv_nsec < 0)
168
		fatal("clock_gettime returned negative time");
169
}
170

  
160 171
/*
161 172
 * <nick> ::= <letter> { <letter> | <number> | <special> }
162 173
 * <special> ::= '-' | '[' | ']' | '\' | '`' | '^' | '{' | '}'
src/util.h
177 177
char *bip_strdup(const char *str);
178 178
char *bip_strcat_fit(size_t *remaining, char *str, const char *str2);
179 179
char *bip_strcatf_fit(size_t *remaining, char *str, const char *str2, ...);
180
void bip_clock_gettime(clockid_t clockid, struct timespec *tp);
180 181
#define array_each(a, idx, ptr) for ((idx) = 0; \
181 182
		(idx) < (a)->elemc && (((ptr) = array_get((a), (idx))) || 1); \
182 183
		(idx)++)
183
- 
(14-14/24)