Skip to content

Commit

Permalink
Avoid copying timeval onto stack
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip Prindeville authored and olofhagsand committed Aug 15, 2023
1 parent 4a605ff commit dc0f740
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion apps/backend/backend_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ backend_monitoring_state_get(clicon_handle h,
if (ce->ce_source_host)
cprintf(cb, "<source-host>%s</source-host>", ce->ce_source_host);
if (ce->ce_time.tv_sec != 0){
if (time2str(ce->ce_time, timestr, sizeof(timestr)) < 0){
if (time2str(&ce->ce_time, timestr, sizeof(timestr)) < 0){
clicon_err(OE_UNIX, errno, "time2str");
goto done;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/src/clixon_netconf_monitoring.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ per_datastore(clicon_handle h,
{
int retval = -1;
uint32_t sid;
struct timeval tv = {0,};
struct timeval tv;
char timestr[28];

cprintf(cb, "<datastore><name>%s</name>", db);
Expand All @@ -83,7 +83,7 @@ per_datastore(clicon_handle h,
cprintf(cb, "<global-lock>");
cprintf(cb, "<locked-by-session>%u</locked-by-session>", sid);
xmldb_lock_timestamp(h, db, &tv);
if (time2str(tv, timestr, sizeof(timestr)) < 0){
if (time2str(&tv, timestr, sizeof(timestr)) < 0){
clicon_err(OE_UNIX, errno, "time2str");
goto done;
}
Expand Down Expand Up @@ -321,7 +321,7 @@ netconf_monitoring_statistics_init(clicon_handle h)
cvec *cvv = NULL;

gettimeofday(&tv, NULL);
if (time2str(tv, timestr, sizeof(timestr)) < 0)
if (time2str(&tv, timestr, sizeof(timestr)) < 0)
goto done;
clicon_data_set(h, "netconf-start-time", timestr); /* RFC 6022 */
if ((cvv = cvec_new(0)) == NULL){
Expand Down
2 changes: 1 addition & 1 deletion lib/src/clixon_proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ clixon_process_status(clicon_handle h,
cprintf(cbret, "<status xmlns=\"%s\">%s</status>", CLIXON_LIB_NS,
clicon_int2str(proc_state_map, pe->pe_state));
if (timerisset(&pe->pe_starttime)){
if (time2str(pe->pe_starttime, timestr, sizeof(timestr)) < 0){
if (time2str(&pe->pe_starttime, timestr, sizeof(timestr)) < 0){
clicon_err(OE_UNIX, errno, "time2str");
goto done;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/clixon_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ stream_notify(clicon_handle h,
goto done;
}
gettimeofday(&tv, NULL);
if (time2str(tv, timestr, sizeof(timestr)) < 0){
if (time2str(&tv, timestr, sizeof(timestr)) < 0){
clicon_err(OE_UNIX, errno, "time2str");
goto done;
}
Expand Down Expand Up @@ -645,7 +645,7 @@ stream_notify_xml(clicon_handle h,
goto done;
}
gettimeofday(&tv, NULL);
if (time2str(tv, timestr, sizeof(timestr)) < 0){
if (time2str(&tv, timestr, sizeof(timestr)) < 0){
clicon_err(OE_UNIX, errno, "time2str");
goto done;
}
Expand Down
10 changes: 4 additions & 6 deletions util/clixon_util_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,21 +241,19 @@ main(int argc, char **argv)
break;
case 's': /* start-time */
if (*optarg == '+' || *optarg == '-'){
struct timeval t;
t = now;
struct timeval t = now;
t.tv_sec += atoi(optarg);
if (time2str(t, start, sizeof(start)) < 0)
if (time2str(&t, start, sizeof(start)) < 0)
goto done;
}
else
strcpy(start, optarg);
break;
case 'e': /* stop-time */
if (*optarg == '+' || *optarg == '-'){
struct timeval t;
t = now;
struct timeval t = now;
t.tv_sec += atoi(optarg);
if (time2str(t, stop, sizeof(stop)) < 0)
if (time2str(&t, stop, sizeof(stop)) < 0)
goto done;
}
else
Expand Down

0 comments on commit dc0f740

Please sign in to comment.