Skip to content

Commit

Permalink
Add offsets to timestamps.
Browse files Browse the repository at this point in the history
Change-Id: I337e27915174e471d802cd187940b1cc63300118
  • Loading branch information
grke committed May 29, 2017
1 parent 9131186 commit 540c5e5
Show file tree
Hide file tree
Showing 27 changed files with 252 additions and 192 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ burp_SOURCES = \
src/slist.c src/slist.h \
src/ssl.c src/ssl.h \
src/strlist.c src/strlist.h \
src/times.c src/times.h \
src/yajl_gen_w.c src/yajl_gen_w.h \
src/client/acl.c src/client/acl.h \
src/client/auth.c src/client/auth.h \
Expand Down
2 changes: 1 addition & 1 deletion manpages/burp.8
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ Path to the directory in which to store backups.
When turned on (which is the default) and the client is on version 1.3.6 or greater, the structure of the storage directory will mimic that of the original filesystem on the client.
.TP
\fBtimestamp_format=[strftime format]\fR
This allows you to tweak the format of the timestamps of individual backups. See 'man strftime' to see available substitutions. If this option is unset, burp uses "%Y-%m-%d %H:%M:%S".
This allows you to tweak the format of the timestamps of individual backups. See 'man strftime' to see available substitutions. If this option is unset, burp uses "%Y-%m-%d %H:%M:%S %z".
.TP
\fBpassword_check=[0|1]\fR
Allows you to turn client password checking on or off. The default is on. SSL certificates will still be checked if you turn passwords off. This option can be overridden by the client configuration files in clientconfdir on the server.
Expand Down
1 change: 1 addition & 0 deletions src/client/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "../cmd.h"
#include "../handy.h"
#include "../log.h"
#include "../times.h"
#include "list.h"

/* Note: The chars in this function are not the same as in the CMD_ set.
Expand Down
1 change: 1 addition & 0 deletions src/client/monitor/json_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "../../handy.h"
#include "../../iobuf.h"
#include "../../log.h"
#include "../../times.h"
#include "json_input.h"
#include "lline.h"
#include "sel.h"
Expand Down
8 changes: 4 additions & 4 deletions src/client/monitor/status_client_ncurses.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "../../handy.h"
#include "../../iobuf.h"
#include "../../log.h"
#include "../../times.h"
#include "json_input.h"
#include "lline.h"
#include "sel.h"
Expand Down Expand Up @@ -71,7 +72,7 @@ static void print_line(const char *string, int row, int col)

static char *get_bu_str(struct bu *bu)
{
static char ret[32];
static char ret[38];
if(!bu) snprintf(ret, sizeof(ret), "never");
else if(!bu->bno) snprintf(ret, sizeof(ret), "%s", bu->timestamp);
else snprintf(ret, sizeof(ret), "%07" PRIu64 " %s",
Expand Down Expand Up @@ -372,8 +373,7 @@ static void screen_header(int col)
#ifdef UTEST
date="1977-10-02 00:10:20";
#else
time_t t=time(NULL);
date=getlocaldatestr(t);
date=gettimenow();
#endif
l=strlen(date);
#ifdef HAVE_NCURSES
Expand Down Expand Up @@ -532,7 +532,7 @@ static void update_screen_clients(struct sel *sel, int *x, int col,
#endif
struct cstat *c;
int star_printed=0;
int max_cname=28*((float)col/100);
int max_cname=23*((float)col/100);
#ifdef HAVE_NCURSES
if(actg==ACTION_STATUS_SNAPSHOT)
#endif
Expand Down
1 change: 1 addition & 0 deletions src/cntr.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "handy.h"
#include "iobuf.h"
#include "log.h"
#include "times.h"

#include "client/monitor/sel.h"
#include "client/monitor/json_input.h"
Expand Down
2 changes: 1 addition & 1 deletion src/conffile.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "pathcmp.h"
#include "prepend.h"
#include "strlist.h"
#include "server/timestamp.h"
#include "times.h"
#include "client/glob_windows.h"
#include "conffile.h"

Expand Down
78 changes: 0 additions & 78 deletions src/handy.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,60 +426,6 @@ int chuser_and_or_chgrp(const char *user, const char *group)
return 0;
}

static const char *format_datestr(const struct tm *ctm)
{
static char buf[32]="";
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", ctm);
return buf;
}

const char *getdatestr(const time_t t)
{
const struct tm *ctm=NULL;

if(!t
|| !(ctm=gmtime(&t)))
return "never";
return format_datestr(ctm);
}

const char *getlocaldatestr(const time_t t)
{
const struct tm *ctm=NULL;
ctm=localtime(&t);
return format_datestr(ctm);
}

const char *time_taken(time_t d)
{
static char str[32]="";
int seconds=0;
int minutes=0;
int hours=0;
int days=0;
char ss[4]="";
char ms[4]="";
char hs[4]="";
char ds[4]="";
seconds=d % 60;
minutes=(d/60) % 60;
hours=(d/60/60) % 24;
days=(d/60/60/24);
if(days)
{
snprintf(ds, sizeof(ds), "%02d:", days);
snprintf(hs, sizeof(hs), "%02d:", hours);
}
else if(hours)
{
snprintf(hs, sizeof(hs), "%02d:", hours);
}
snprintf(ms, sizeof(ms), "%02d:", minutes);
snprintf(ss, sizeof(ss), "%02d", seconds);
snprintf(str, sizeof(str), "%s%s%s%s", ds, hs, ms, ss);
return str;
}

// Not in dpth.c so that Windows client can see it.
int dpth_protocol1_is_compressed(int compressed, const char *datapath)
{
Expand Down Expand Up @@ -614,30 +560,6 @@ void convert_backslashes(char **path)
}
#endif

char *encode_time(time_t utime, char *buf)
{
const struct tm *tm;
int n=0;
time_t time=utime;

#ifdef HAVE_WIN32
/* Avoid a seg fault in Microsoft's CRT localtime_r(),
* which incorrectly references a NULL returned from gmtime() if
* time is negative before or after the timezone adjustment. */
struct tm *gtm;

if(!(gtm=gmtime(&time))) return buf;

if(gtm->tm_year==1970 && gtm->tm_mon==1 && gtm->tm_mday<3) return buf;
#endif

if((tm=localtime(&time)))
n=sprintf(buf, "%04d-%02d-%02d %02d:%02d:%02d",
tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec);
return buf+n;
}

char *strlwr(char *s)
{
char *tmp=s;
Expand Down
5 changes: 0 additions & 5 deletions src/handy.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ extern int set_keepalive(int fd, int value);
extern int init_client_socket(const char *host, const char *port);
extern void reuseaddr(int fd);
extern int chuser_and_or_chgrp(const char *user, const char *group);
extern const char *getdatestr(time_t t);
extern const char *getlocaldatestr(time_t t);
extern const char *time_taken(time_t d);
extern int dpth_protocol1_is_compressed(int compressed, const char *datapath);
#ifndef HAVE_WIN32
extern void setup_signal(int sig, void handler(int sig));
Expand Down Expand Up @@ -65,6 +62,4 @@ extern int breakpoint(int breaking, const char *func);
extern void convert_backslashes(char **path);
#endif

extern char *encode_time(time_t utime, char *buf);

#endif
22 changes: 4 additions & 18 deletions src/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "iobuf.h"
#include "log.h"
#include "strlist.h"
#include "times.h"

const char *prog="unknown";
const char *prog_long="unknown";
Expand All @@ -28,22 +29,6 @@ void log_init(char *progname)
else prog=progname;
}

#ifndef UTEST
static char *gettm(void)
{
time_t t=0;
const struct tm *ctm=NULL;
static char tmbuf[32]="";

time(&t);
ctm=localtime(&t);
// Windows does not like the %T strftime format option - you get
// complaints under gdb.
strftime(tmbuf, sizeof(tmbuf), "%Y-%m-%d %H:%M:%S", ctm);
return tmbuf;
}
#endif

void logp(const char *fmt, ...)
{
#ifndef UTEST
Expand All @@ -54,7 +39,8 @@ void logp(const char *fmt, ...)
vsnprintf(buf, sizeof(buf), fmt, ap);
pid=(int)getpid();
if(logfzp)
fzp_printf(logfzp, "%s: %s[%d] %s", gettm(), prog, pid, buf);
fzp_printf(logfzp, "%s: %s[%d] %s",
gettimenow(), prog, pid, buf);
else
{
if(do_syslog)
Expand All @@ -79,7 +65,7 @@ void logp(const char *fmt, ...)
}
else
fprintf(stdout, "%s: %s[%d] %s",
gettm(), prog, pid, buf);
gettimenow(), prog, pid, buf);
}
}
va_end(ap);
Expand Down
6 changes: 4 additions & 2 deletions src/server/backup.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ static int do_backup_server(struct async *as, struct sdirs *sdirs,
|| open_log(asfd, sdirs, cconfs))
goto error;

set_cntr_bno(cntr, sdirs);

if(append_to_resume_file(sdirs->working))
goto error;
}
Expand All @@ -185,6 +187,8 @@ static int do_backup_server(struct async *as, struct sdirs *sdirs,
|| open_log(asfd, sdirs, cconfs))
goto error;

set_cntr_bno(cntr, sdirs);

if(write_incexc(sdirs->rworking, incexc))
{
logp("unable to write incexc\n");
Expand All @@ -198,8 +202,6 @@ static int do_backup_server(struct async *as, struct sdirs *sdirs,
}
}

set_cntr_bno(cntr, sdirs);

if(resume)
{
struct stat statp;
Expand Down
10 changes: 5 additions & 5 deletions src/server/bu_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static int maybe_add_ent(const char *dir, const char *d_name,
int include_working)
{
int ret=-1;
char buf[32]="";
char buf[38]="";
struct stat statp;
char *fullpath=NULL;
char *timestamp=NULL;
Expand Down Expand Up @@ -154,9 +154,9 @@ static int do_bu_get_list(struct sdirs *sdirs,
int i=0;
int n=0;
int ret=-1;
char realwork[32]="";
char realfinishing[32]="";
char realcurrent[32]="";
char realwork[38]="";
char realfinishing[38]="";
char realcurrent[38]="";
struct dirent **dp=NULL;
const char *dir=NULL;
uint16_t flags=0;
Expand Down Expand Up @@ -234,7 +234,7 @@ int bu_get_list_with_working(struct sdirs *sdirs, struct bu **bu_list,

int bu_get_current(struct sdirs *sdirs, struct bu **bu_list)
{
char real[32]="";
char real[38]="";
// FIX THIS: should not need to specify "current".
if(get_link(sdirs->client, "current", real, sizeof(real)))
return -1;
Expand Down
3 changes: 2 additions & 1 deletion src/server/child.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ int write_status(enum cntr_status cntr_status,
static struct iobuf *wbuf=NULL;

if(!wasfd) return 0;
if(!cntr || !cntr->bno) return 0;
if(!cntr || !cntr->bno)
return 0;

// Only update every 2 seconds.
now=time(NULL);
Expand Down
1 change: 1 addition & 0 deletions src/server/child.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef _CHILD_H
#define _CHILD_H

#include "cstat.h"
#include "monitor/cstat.h"

struct async;
Expand Down
36 changes: 1 addition & 35 deletions src/server/monitor/json_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "../../prepend.h"
#include "../../strlist.h"
#include "../../yajl_gen_w.h"
#include "../timestamp.h"
#include "browse.h"
#include "json_output.h"

Expand Down Expand Up @@ -91,41 +92,6 @@ static int json_end(struct asfd *asfd)
return ret;
}

// Portable timegm, copied from 'man timegm'.
static time_t my_timegm(struct tm *tm)
{
time_t ret;
char *tz;

if((tz=getenv("TZ")))
{
if(!(tz=strdup_w(tz, __func__)))
return -1;
}
setenv("TZ", "UTC0", 1);
tzset();
ret=mktime(tm);
if(tz)
{
setenv("TZ", tz, 1);
free_w(&tz);
}
else
unsetenv("TZ");
tzset();
return ret;
}

static long timestamp_to_long(const char *buf)
{
struct tm tm;
const char *b=NULL;
if(!(b=strchr(buf, ' '))) return 0;
memset(&tm, 0, sizeof(struct tm));
if(!strptime(b, " %Y-%m-%d %H:%M:%S", &tm)) return 0;
return (long)my_timegm(&tm);
}

static int flag_matches(struct bu *bu, uint16_t flag)
{
return (bu && (bu->flags & flag));
Expand Down
1 change: 0 additions & 1 deletion src/server/monitor/status_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,6 @@ static int parse_client_data(struct asfd *srfd,
printf("backup: %s\n", backup?:"");
printf("logfile: %s\n", logfile?:"");
*/

if(json_send(srfd, clist, cstat, bu, logfile, browse,
get_int(confs[OPT_MONITOR_BROWSE_CACHE]), *peer_version))
goto error;
Expand Down
5 changes: 5 additions & 0 deletions src/server/protocol2/backup_phase2.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "../../protocol2/blist.h"
#include "../../protocol2/rabin/rabin.h"
#include "../../slist.h"
#include "../child.h"
#include "../manios.h"
#include "../resume.h"
#include "champ_chooser/champ_client.h"
Expand Down Expand Up @@ -927,6 +928,10 @@ int do_backup_phase2_server_protocol2(struct async *as, struct asfd *chfd,
memset(&wbuf, 0, sizeof(struct iobuf));
while(!(end_flags&END_BACKUP))
{
if(write_status(CNTR_STATUS_BACKUP,
csb && csb->path.buf?csb->path.buf:"", cntr))
goto end;

if(maybe_add_from_scan(manios, slist, chfd, &csb, cntr))
goto end;

Expand Down
Loading

0 comments on commit 540c5e5

Please sign in to comment.