mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-02-07 22:03:50 +00:00
Refactor and check for more errors
This commit is contained in:
parent
2c634751cc
commit
068586f28f
@ -420,7 +420,7 @@ build/print_git_revision: build/print_git_revision.c
|
|||||||
|
|
||||||
src/include/switch_version.h: src/include/switch_version.h.in Makefile build/print_git_revision $(libfreeswitch_la_SOURCES) $(library_include_HEADERS)
|
src/include/switch_version.h: src/include/switch_version.h.in Makefile build/print_git_revision $(libfreeswitch_la_SOURCES) $(library_include_HEADERS)
|
||||||
@cat $< > $@; \
|
@cat $< > $@; \
|
||||||
if [ -d .git ]; then \
|
if [ -d .git ] && [ -n "$$(which git)" ]; then \
|
||||||
xver="$$(./build/print_git_revision)"; \
|
xver="$$(./build/print_git_revision)"; \
|
||||||
sed -e "/#define *SWITCH_VERSION_REVISION/{s/\"\([^\"]*\)\"/\"\1$$xver\"/}" \
|
sed -e "/#define *SWITCH_VERSION_REVISION/{s/\"\([^\"]*\)\"/\"\1$$xver\"/}" \
|
||||||
$< > $@; \
|
$< > $@; \
|
||||||
|
@ -9,51 +9,50 @@
|
|||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
int sys(char *buf, int buflen, char *cmd) {
|
static int sys(char *buf, int buflen, char *cmd) {
|
||||||
int i, p[2];
|
int i, p[2];
|
||||||
pipe(p);
|
if (pipe(p)) return 255;
|
||||||
if (!(i=fork())) {
|
if (!(i=fork())) {
|
||||||
close(p[0]);
|
close(p[0]);
|
||||||
dup2(p[1],1);
|
dup2(p[1],1);
|
||||||
close(p[1]);
|
close(p[1]);
|
||||||
execlp("sh","sh","-c",cmd,NULL);
|
execlp("sh","sh","-c",cmd,NULL);
|
||||||
} else {
|
} else {
|
||||||
int s, x, c=0;
|
int s, x=0;
|
||||||
close(p[1]);
|
close(p[1]);
|
||||||
waitpid(i,&s,0);
|
waitpid(i,&s,0);
|
||||||
if (!(WIFEXITED(s))) return 255;
|
if (!(WIFEXITED(s))) return 255;
|
||||||
if (WEXITSTATUS(s)) return WEXITSTATUS(s);
|
if (WEXITSTATUS(s)) return WEXITSTATUS(s);
|
||||||
while ((x=read(p[0],buf,buflen-1))>0) c+=x;
|
if (buf) {
|
||||||
if (x<0) return 1;
|
while (buflen>1 && (x=read(p[0],buf,buflen-1))>0) buf+=x,buflen-=x;
|
||||||
buf[c] = 0;
|
close(p[0]);
|
||||||
|
if (x<0) return 255;
|
||||||
|
*buf=0;
|
||||||
|
} else close(p[0]);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sys1(char *buf, int buflen, char *cmd) {
|
static int sys1(char *buf, int buflen, char *cmd) {
|
||||||
int r = sys(buf,buflen,cmd);
|
int r; char *c;
|
||||||
char *c;
|
if ((r=sys(buf,buflen,cmd))) return r;
|
||||||
if (r!=0) return r;
|
|
||||||
if ((c=strstr(buf,"\n"))) *c=0;
|
if ((c=strstr(buf,"\n"))) *c=0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
char buf[256], xdate[256], xfdate[256], xcommit[256], xver[256];
|
char xver[256], xdate[256], xfdate[256], xcommit[256];
|
||||||
time_t xdate_t;
|
time_t xdate_t; struct tm *xdate_tm;
|
||||||
struct tm *xdate_tm;
|
if ((sys1(xdate,sizeof(xdate),"git log -n1 --format='%ct' HEAD"))) return 1;
|
||||||
|
xdate_t=(time_t)atoi(xdate);
|
||||||
sys1(xdate,sizeof(xdate),"git log -n1 --format='%ct' HEAD");
|
if (!(xdate_tm=gmtime(&xdate_t))) return 1;
|
||||||
xdate_t = (time_t) atoi(xdate);
|
|
||||||
if (!(xdate_tm = gmtime(&xdate_t))) return 1;
|
|
||||||
strftime(xfdate,sizeof(xfdate),"%Y%m%dT%H%M%SZ",xdate_tm);
|
strftime(xfdate,sizeof(xfdate),"%Y%m%dT%H%M%SZ",xdate_tm);
|
||||||
sys1(xcommit,sizeof(xcommit),"git rev-list -n1 --abbrev=10 --abbrev-commit HEAD");
|
if ((sys1(xcommit,sizeof(xcommit),"git rev-list -n1 --abbrev=10 --abbrev-commit HEAD")))
|
||||||
|
return 1;
|
||||||
snprintf(xver,sizeof(xver),"+git~%s~%s",xfdate,xcommit);
|
snprintf(xver,sizeof(xver),"+git~%s~%s",xfdate,xcommit);
|
||||||
if ((sys(buf,sizeof(buf),"git diff-index --quiet HEAD"))) {
|
if ((sys(NULL,0,"git diff-index --quiet HEAD"))) {
|
||||||
time_t now_t = time(NULL);
|
char buf[256], now[256]; time_t now_t=time(NULL); struct tm *now_tm;
|
||||||
struct tm *now_tm = gmtime(&now_t);
|
if (!(now_tm=gmtime(&now_t))) return 1;
|
||||||
char now[256];
|
|
||||||
if (!now_tm) return 1;
|
|
||||||
strftime(now,sizeof(now),"%Y%m%dT%H%M%SZ",now_tm);
|
strftime(now,sizeof(now),"%Y%m%dT%H%M%SZ",now_tm);
|
||||||
snprintf(buf,sizeof(buf),"%s+unclean~%s",xver,now);
|
snprintf(buf,sizeof(buf),"%s+unclean~%s",xver,now);
|
||||||
strncpy(xver,buf,sizeof(xver));
|
strncpy(xver,buf,sizeof(xver));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user