File Conn.c changed (mode: 100644) (index bf6b08b..3164c2c) |
... |
... |
static __thread char Conn_error[512]; |
66 |
66 |
static __thread char log_info[32]; |
static __thread char log_info[32]; |
67 |
67 |
|
|
68 |
68 |
static int Conn_log_fd = 2; |
static int Conn_log_fd = 2; |
69 |
|
static int debug_band = 11; |
|
|
69 |
|
static unsigned short debug_band = 11; |
70 |
70 |
static struct Conn_pool Conn_masters; /* Keeps track of listening sockets */ |
static struct Conn_pool Conn_masters; /* Keeps track of listening sockets */ |
71 |
71 |
static struct Conn_pool Conn_free; /* Keeps track of free Conns */ |
static struct Conn_pool Conn_free; /* Keeps track of free Conns */ |
72 |
72 |
|
|
|
... |
... |
static void Conn_wpool_worker_stats(const struct Conn_wpool_worker *w) |
151 |
151 |
struct Conn_wpool *Conn_wpool_create(const unsigned short workers) |
struct Conn_wpool *Conn_wpool_create(const unsigned short workers) |
152 |
152 |
{ |
{ |
153 |
153 |
struct Conn_wpool *ret; |
struct Conn_wpool *ret; |
154 |
|
int i; |
|
|
154 |
|
unsigned short i; |
155 |
155 |
struct Conn_wpool_worker *ww; |
struct Conn_wpool_worker *ww; |
156 |
156 |
|
|
157 |
157 |
ret = malloc(sizeof(struct Conn_wpool)); |
ret = malloc(sizeof(struct Conn_wpool)); |
|
... |
... |
static int Conn_recv_fd(int comm_fd) |
397 |
397 |
__cold void Log(const unsigned short level, char *format, ...) |
__cold void Log(const unsigned short level, char *format, ...) |
398 |
398 |
{ |
{ |
399 |
399 |
va_list ap; |
va_list ap; |
400 |
|
unsigned int len; |
|
|
400 |
|
size_t len; |
401 |
401 |
char line[512]; |
char line[512]; |
402 |
402 |
|
|
403 |
403 |
if (likely(level > Conn_debug_level)) |
if (likely(level > Conn_debug_level)) |
|
... |
... |
static void Conn_log_set_info(const char *info) |
428 |
428 |
snprintf(log_info, sizeof(log_info), "%s", info); |
snprintf(log_info, sizeof(log_info), "%s", info); |
429 |
429 |
} |
} |
430 |
430 |
|
|
431 |
|
char *Conn_dump(const void *buf_src0, const int len_src) |
|
|
431 |
|
char *Conn_dump(const void *buf_src0, const size_t len_src) |
432 |
432 |
{ |
{ |
433 |
|
int i, j; |
|
|
433 |
|
unsigned int i, j; |
434 |
434 |
char tmp[3]; |
char tmp[3]; |
435 |
435 |
char *buf_dst; |
char *buf_dst; |
436 |
436 |
unsigned char c; |
unsigned char c; |
437 |
437 |
const unsigned char *buf_src = buf_src0; |
const unsigned char *buf_src = buf_src0; |
438 |
438 |
|
|
439 |
|
if (len_src < 0) |
|
440 |
|
return strdup("[Error: len < 0]"); |
|
441 |
|
|
|
442 |
|
Log(30, "\tConn_dump(%p, len=%d)\n", |
|
|
439 |
|
Log(30, "\tConn_dump(%p, len=%zu)\n", |
443 |
440 |
buf_src, len_src); |
buf_src, len_src); |
444 |
441 |
|
|
445 |
442 |
buf_dst = malloc(len_src * 4 + 1); |
buf_dst = malloc(len_src * 4 + 1); |
|
... |
... |
char *Conn_dump(const void *buf_src0, const int len_src) |
456 |
453 |
buf_dst[j++] = tmp[1]; |
buf_dst[j++] = tmp[1]; |
457 |
454 |
buf_dst[j++] = ']'; |
buf_dst[j++] = ']'; |
458 |
455 |
} else { |
} else { |
459 |
|
buf_dst[j++] = c; |
|
|
456 |
|
buf_dst[j++] = (char) c; |
460 |
457 |
} |
} |
461 |
458 |
} |
} |
462 |
459 |
|
|
|
... |
... |
char *Conn_dump(const void *buf_src0, const int len_src) |
465 |
462 |
return buf_dst; |
return buf_dst; |
466 |
463 |
} |
} |
467 |
464 |
|
|
468 |
|
char *Conn_dumphex(const void *buf_src0, const int len_src) |
|
|
465 |
|
char *Conn_dumphex(const void *buf_src0, const size_t len_src) |
469 |
466 |
{ |
{ |
470 |
|
int i, j; |
|
|
467 |
|
unsigned int i, j; |
471 |
468 |
char tmp[3]; |
char tmp[3]; |
472 |
469 |
char *buf_dst; |
char *buf_dst; |
473 |
470 |
unsigned char c; |
unsigned char c; |
474 |
471 |
const unsigned char *buf_src = buf_src0; |
const unsigned char *buf_src = buf_src0; |
475 |
472 |
|
|
476 |
|
if (len_src < 0) |
|
477 |
|
return strdup("[Error: len < 0]"); |
|
478 |
|
|
|
479 |
|
Log(30, "\tConn_dumphex(%p, len=%d)\n", |
|
|
473 |
|
Log(30, "\tConn_dumphex(%p, len=%zu)\n", |
480 |
474 |
buf_src, len_src); |
buf_src, len_src); |
481 |
475 |
|
|
482 |
476 |
buf_dst = malloc(len_src * 2 + 1); |
buf_dst = malloc(len_src * 2 + 1); |
|
... |
... |
void Conn_debug(int fd, const unsigned short debug) |
505 |
499 |
/* |
/* |
506 |
500 |
* Do not use it yet, it sucks (the paras) |
* Do not use it yet, it sucks (the paras) |
507 |
501 |
*/ |
*/ |
508 |
|
static void Conn_poll_status(const short ev, char *ret) |
|
|
502 |
|
static void Conn_poll_status(const unsigned int ev, char *ret) |
509 |
503 |
{ |
{ |
510 |
504 |
int i = 0; |
int i = 0; |
511 |
505 |
|
|
|
... |
... |
__hot static void Conn_free_intern(struct Conn *C) |
737 |
731 |
/* Misc */ |
/* Misc */ |
738 |
732 |
C->error_state = 0; |
C->error_state = 0; |
739 |
733 |
|
|
740 |
|
C->tryat = Conn_now.tv_sec + C->delay; |
|
|
734 |
|
C->tryat = (unsigned int) Conn_now.tv_sec + C->delay; |
741 |
735 |
C->state = CONN_STATE_CONNECT_0; |
C->state = CONN_STATE_CONNECT_0; |
742 |
736 |
|
|
743 |
737 |
C->ibuf_head = 0; |
C->ibuf_head = 0; |
|
... |
... |
void Conn_set(struct Conn *C, const unsigned int var, const int val) |
867 |
861 |
C->auto_reconnect = (val == 0) ? 0 : 1; |
C->auto_reconnect = (val == 0) ? 0 : 1; |
868 |
862 |
break; |
break; |
869 |
863 |
case CONN_PARA_RECONNECT_DELAY: |
case CONN_PARA_RECONNECT_DELAY: |
870 |
|
C->delay = val; |
|
|
864 |
|
C->delay = (unsigned int) val; |
871 |
865 |
break; |
break; |
872 |
866 |
case CONN_PARA_IDLE_TIME: |
case CONN_PARA_IDLE_TIME: |
873 |
|
C->idle = val; |
|
|
867 |
|
C->idle = (unsigned int) val; |
874 |
868 |
break; |
break; |
875 |
869 |
case CONN_PARA_READ_TIMEOUT: |
case CONN_PARA_READ_TIMEOUT: |
876 |
|
C->read_timeout = val; |
|
|
870 |
|
C->read_timeout = (unsigned int) val; |
877 |
871 |
break; |
break; |
878 |
872 |
case CONN_PARA_CONN_TIMEOUT: |
case CONN_PARA_CONN_TIMEOUT: |
879 |
|
C->conn_timeout = val; |
|
|
873 |
|
C->conn_timeout = (unsigned int) val; |
880 |
874 |
break; |
break; |
881 |
875 |
case CONN_PARA_TRIGGER: |
case CONN_PARA_TRIGGER: |
882 |
|
C->trigger = val; |
|
|
876 |
|
C->trigger = (unsigned int) val; |
883 |
877 |
C->last_trigger = 0; |
C->last_trigger = 0; |
884 |
878 |
break; |
break; |
885 |
879 |
case CONN_PARA_IBUF: |
case CONN_PARA_IBUF: |
|
... |
... |
__hot static void Conn_default_cbs_recv(struct Conn *C) |
1021 |
1015 |
call_callback = 1; |
call_callback = 1; |
1022 |
1016 |
|
|
1023 |
1017 |
if (unlikely(Conn_debug_level >= 10)) { |
if (unlikely(Conn_debug_level >= 10)) { |
1024 |
|
dump = Conn_dump(C->ibuf + C->ibuf_tail, n); |
|
|
1018 |
|
dump = Conn_dump(C->ibuf + C->ibuf_tail, (unsigned int) n); |
1025 |
1019 |
Log(0, "\tReceived: %s\n", dump); |
Log(0, "\tReceived: %s\n", dump); |
1026 |
1020 |
free(dump); |
free(dump); |
1027 |
1021 |
} |
} |
1028 |
1022 |
|
|
1029 |
1023 |
C->trecv = Conn_now; |
C->trecv = Conn_now; |
1030 |
|
C->ibuf_tail += n; |
|
1031 |
|
C->bi += n; |
|
1032 |
|
xfer_in_this_call += n; |
|
|
1024 |
|
C->ibuf_tail += (unsigned int) n; |
|
1025 |
|
C->bi += (unsigned int) n; |
|
1026 |
|
xfer_in_this_call += (unsigned int) n; |
1033 |
1027 |
|
|
1034 |
1028 |
if (n < max) { |
if (n < max) { |
1035 |
1029 |
Log(3, "\tReaded less(%d < %d) than what we requested\n", |
Log(3, "\tReaded less(%d < %d) than what we requested\n", |
|
... |
... |
__hot static void Conn_default_cbs_send(struct Conn *C) |
1051 |
1045 |
{ |
{ |
1052 |
1046 |
ssize_t n; |
ssize_t n; |
1053 |
1047 |
unsigned int max; |
unsigned int max; |
1054 |
|
int count, xerrno, r; |
|
|
1048 |
|
int xerrno, r; |
|
1049 |
|
unsigned int count; |
1055 |
1050 |
char *buf; |
char *buf; |
1056 |
1051 |
char *dump; |
char *dump; |
1057 |
1052 |
|
|
|
... |
... |
__hot static void Conn_default_cbs_send(struct Conn *C) |
1141 |
1136 |
} |
} |
1142 |
1137 |
|
|
1143 |
1138 |
if (unlikely(Conn_debug_level >= 10)) { |
if (unlikely(Conn_debug_level >= 10)) { |
1144 |
|
dump = Conn_dump(buf, n); |
|
|
1139 |
|
dump = Conn_dump(buf, (unsigned int) n); |
1145 |
1140 |
Log(0, "\tSent: %s\n", dump); |
Log(0, "\tSent: %s\n", dump); |
1146 |
1141 |
free(dump); |
free(dump); |
1147 |
1142 |
} |
} |
1148 |
1143 |
|
|
1149 |
1144 |
C->tsend = Conn_now; |
C->tsend = Conn_now; |
1150 |
1145 |
if (n < count) { |
if (n < count) { |
1151 |
|
C->obuf_head += n; |
|
|
1146 |
|
C->obuf_head += (unsigned int) n; |
1152 |
1147 |
} else { |
} else { |
1153 |
1148 |
C->obuf_head = 0; |
C->obuf_head = 0; |
1154 |
1149 |
C->obuf_tail = 0; |
C->obuf_tail = 0; |
1155 |
1150 |
} |
} |
1156 |
|
C->bo += n; |
|
|
1151 |
|
C->bo += (unsigned int) n; |
1157 |
1152 |
|
|
1158 |
1153 |
if (C->band_width > 0) { |
if (C->band_width > 0) { |
1159 |
1154 |
/* What if band_tokens < n?! */ |
/* What if band_tokens < n?! */ |
1160 |
|
C->band_tokens -= n; |
|
|
1155 |
|
C->band_tokens -= (unsigned int) n; |
1161 |
1156 |
Log(debug_band, "\tBAND: Remove %d tokens -> %u...\n", |
Log(debug_band, "\tBAND: Remove %d tokens -> %u...\n", |
1162 |
1157 |
n, C->band_tokens); |
n, C->band_tokens); |
1163 |
1158 |
} |
} |
|
... |
... |
static int Conn_set_address(struct Conn *C, const int flags) |
1224 |
1219 |
struct sockaddr_in6 sa6; |
struct sockaddr_in6 sa6; |
1225 |
1220 |
socklen_t sa_len; |
socklen_t sa_len; |
1226 |
1221 |
char *paddr; |
char *paddr; |
1227 |
|
size_t addr_size; |
|
|
1222 |
|
socklen_t addr_size; |
1228 |
1223 |
int *pport; |
int *pport; |
1229 |
1224 |
|
|
1230 |
1225 |
/* Test if we need to regenerate. */ |
/* Test if we need to regenerate. */ |
|
... |
... |
static void Conn_speed(char *dst, const unsigned int dst_len, |
1378 |
1373 |
{ |
{ |
1379 |
1374 |
float sp; |
float sp; |
1380 |
1375 |
|
|
1381 |
|
sp = speed; |
|
|
1376 |
|
sp = (float) speed; |
1382 |
1377 |
|
|
1383 |
1378 |
if (speed < 1000) |
if (speed < 1000) |
1384 |
1379 |
snprintf(dst, dst_len, "%.2fBps", sp); |
snprintf(dst, dst_len, "%.2fBps", sp); |
|
... |
... |
static char *Conn_status_slot(struct Conn *C) |
1427 |
1422 |
|
|
1428 |
1423 |
strcat(flags, flags_postfix); |
strcat(flags, flags_postfix); |
1429 |
1424 |
|
|
1430 |
|
dT = Conn_now.tv_sec - C->start; |
|
|
1425 |
|
dT = (unsigned int) (Conn_now.tv_sec - C->start); |
1431 |
1426 |
if (dT == 0) |
if (dT == 0) |
1432 |
1427 |
dT = 1; |
dT = 1; |
1433 |
|
si = C->bi / dT; |
|
1434 |
|
so = C->bo / dT; |
|
|
1428 |
|
si = (unsigned int)(C->bi / dT); |
|
1429 |
|
so = (unsigned int)(C->bo / dT); |
1435 |
1430 |
|
|
1436 |
1431 |
Conn_speed(speedi, sizeof(speedi), si); |
Conn_speed(speedi, sizeof(speedi), si); |
1437 |
1432 |
Conn_speed(speedo, sizeof(speedo), so); |
Conn_speed(speedo, sizeof(speedo), so); |
|
... |
... |
static char *Conn_status_slot_html(struct Conn *C) |
1485 |
1480 |
char speedi[32], speedo[32]; |
char speedi[32], speedo[32]; |
1486 |
1481 |
unsigned int dT, si, so; |
unsigned int dT, si, so; |
1487 |
1482 |
|
|
1488 |
|
dT = Conn_now.tv_sec - C->start; |
|
|
1483 |
|
dT = (unsigned int) (Conn_now.tv_sec - C->start); |
1489 |
1484 |
if (dT == 0) |
if (dT == 0) |
1490 |
1485 |
dT = 1; |
dT = 1; |
1491 |
|
si = C->bi / dT; |
|
1492 |
|
so = C->bo / dT; |
|
|
1486 |
|
si = (unsigned int)(C->bi / dT); |
|
1487 |
|
so = (unsigned int)(C->bo / dT); |
1493 |
1488 |
|
|
1494 |
1489 |
Conn_speed(speedi, sizeof(speedi), si); |
Conn_speed(speedi, sizeof(speedi), si); |
1495 |
1490 |
Conn_speed(speedo, sizeof(speedo), so); |
Conn_speed(speedo, sizeof(speedo), so); |
|
... |
... |
static char *Conn_status_slot_html(struct Conn *C) |
1525 |
1520 |
/* flags: bit 1 = 1 - html */ |
/* flags: bit 1 = 1 - html */ |
1526 |
1521 |
char *Conn_status(const unsigned int flags) |
char *Conn_status(const unsigned int flags) |
1527 |
1522 |
{ |
{ |
1528 |
|
unsigned int len = 0, max, tmp_len; |
|
|
1523 |
|
int tmp_len; |
|
1524 |
|
unsigned long len = 0, max; |
1529 |
1525 |
char tmp[512]; |
char tmp[512]; |
1530 |
1526 |
char *buf, *per_slot, *ext = ""; |
char *buf, *per_slot, *ext = ""; |
1531 |
1527 |
char speedi[32], speedo[32]; |
char speedi[32], speedo[32]; |
|
... |
... |
char *Conn_status(const unsigned int flags) |
1548 |
1544 |
Conn_pending, Conn_no, Conn_max, Conn_total, |
Conn_pending, Conn_no, Conn_max, Conn_total, |
1549 |
1545 |
Conn_now.tv_sec - Conn_start, Conn_allocated, Conn_work_to_do, |
Conn_now.tv_sec - Conn_start, Conn_allocated, Conn_work_to_do, |
1550 |
1546 |
Conn_mem_structs, Conn_mem_buffers_in, Conn_mem_buffers_out); |
Conn_mem_structs, Conn_mem_buffers_in, Conn_mem_buffers_out); |
1551 |
|
if ((tmp_len > 0) && (len + tmp_len < max)) { |
|
|
1547 |
|
if (tmp_len < 0) |
|
1548 |
|
return strdup("snprintf error"); |
|
1549 |
|
if (len + (unsigned int) tmp_len < max) { |
1552 |
1550 |
strcat(buf, tmp); |
strcat(buf, tmp); |
1553 |
|
len += tmp_len; |
|
|
1551 |
|
len += (unsigned int) tmp_len; |
1554 |
1552 |
} |
} |
1555 |
1553 |
|
|
1556 |
1554 |
#if 0 |
#if 0 |
|
... |
... |
char *Conn_status(const unsigned int flags) |
1594 |
1592 |
if (C->type == CONN_TYPE_P2P) { |
if (C->type == CONN_TYPE_P2P) { |
1595 |
1593 |
bi += C->bi; |
bi += C->bi; |
1596 |
1594 |
bo += C->bo; |
bo += C->bo; |
1597 |
|
dT += Conn_now.tv_sec - C->start; |
|
|
1595 |
|
dT += (unsigned int) (Conn_now.tv_sec - C->start); |
1598 |
1596 |
} |
} |
1599 |
1597 |
|
|
1600 |
1598 |
if (flags & 1) |
if (flags & 1) |
|
... |
... |
char *Conn_status(const unsigned int flags) |
1604 |
1602 |
per_slot = Conn_status_slot(C); |
per_slot = Conn_status_slot(C); |
1605 |
1603 |
else |
else |
1606 |
1604 |
per_slot = Conn_status_slot_html(C); |
per_slot = Conn_status_slot_html(C); |
1607 |
|
len += snprintf(tmp, sizeof(tmp), "%s\n", per_slot); |
|
|
1605 |
|
tmp_len = snprintf(tmp, sizeof(tmp), "%s\n", per_slot); |
|
1606 |
|
if (tmp_len < 0) |
|
1607 |
|
return strdup("snprintf error"); |
|
1608 |
|
len += (unsigned int) tmp_len; |
1608 |
1609 |
if (len < max) |
if (len < max) |
1609 |
1610 |
strcat(buf, tmp); |
strcat(buf, tmp); |
1610 |
1611 |
|
|
|
... |
... |
char *Conn_status(const unsigned int flags) |
1621 |
1622 |
if (dT == 0) |
if (dT == 0) |
1622 |
1623 |
dT = 1; |
dT = 1; |
1623 |
1624 |
|
|
1624 |
|
Conn_speed(speedi, sizeof(speedi), bi / dT); |
|
1625 |
|
Conn_speed(speedo, sizeof(speedo), bo / dT); |
|
|
1625 |
|
Conn_speed(speedi, sizeof(speedi), (unsigned int)(bi / dT)); |
|
1626 |
|
Conn_speed(speedo, sizeof(speedo), (unsigned int)(bo / dT)); |
1626 |
1627 |
|
|
1627 |
1628 |
tmp_len = snprintf(tmp, sizeof(tmp), "Total speed I/O: %s/%s" |
tmp_len = snprintf(tmp, sizeof(tmp), "Total speed I/O: %s/%s" |
1628 |
1629 |
" Total bytes I/O: %llu/%llu\n", |
" Total bytes I/O: %llu/%llu\n", |
1629 |
1630 |
speedi, speedo, bi, bo); |
speedi, speedo, bi, bo); |
1630 |
|
if (len + tmp_len < max) { |
|
|
1631 |
|
if (tmp_len < 0) |
|
1632 |
|
return strdup("snprintf error"); |
|
1633 |
|
if (len + (unsigned int) tmp_len < max) { |
1631 |
1634 |
strcat(buf, tmp); |
strcat(buf, tmp); |
1632 |
|
len += tmp_len; |
|
|
1635 |
|
len += (unsigned int) tmp_len; |
1633 |
1636 |
} |
} |
1634 |
1637 |
|
|
1635 |
1638 |
return buf; |
return buf; |
|
... |
... |
unsigned long long Conn_get_id(const struct Conn *C) |
1784 |
1787 |
struct Conn *Conn_get(const unsigned long long id) |
struct Conn *Conn_get(const unsigned long long id) |
1785 |
1788 |
{ |
{ |
1786 |
1789 |
struct Conn *R = NULL; |
struct Conn *R = NULL; |
1787 |
|
int i; |
|
|
1790 |
|
unsigned int i; |
1788 |
1791 |
|
|
1789 |
|
for (i = Conn_no - 1; i >= 0; i--) { |
|
|
1792 |
|
for (i = 0; i < Conn_no; i++) { |
1790 |
1793 |
if (Conns[i].id == id) { |
if (Conns[i].id == id) { |
1791 |
1794 |
R = &Conns[i]; |
R = &Conns[i]; |
1792 |
1795 |
break; |
break; |
|
... |
... |
int Conn_set_cb(struct Conn *C, const unsigned int cb_type, |
1827 |
1830 |
char *Conn_ostrstr(struct Conn *C, const unsigned int off, const char *str, |
char *Conn_ostrstr(struct Conn *C, const unsigned int off, const char *str, |
1828 |
1831 |
const unsigned int flags) |
const unsigned int flags) |
1829 |
1832 |
{ |
{ |
1830 |
|
unsigned int len, str_len, i; |
|
|
1833 |
|
unsigned int len, i; |
|
1834 |
|
size_t str_len; |
1831 |
1835 |
char *buf, *ret = NULL; |
char *buf, *ret = NULL; |
1832 |
1836 |
int err; |
int err; |
1833 |
1837 |
|
|
|
... |
... |
static void Conn_rtrim(char *s, const char *chars) |
1912 |
1916 |
void Conn_for_every_line(struct Conn *C, void (*cb)(struct Conn *C, char *line)) |
void Conn_for_every_line(struct Conn *C, void (*cb)(struct Conn *C, char *line)) |
1913 |
1917 |
{ |
{ |
1914 |
1918 |
char *line; |
char *line; |
1915 |
|
unsigned int line_size; |
|
|
1919 |
|
size_t line_size; |
1916 |
1920 |
|
|
1917 |
1921 |
if (cb == NULL) |
if (cb == NULL) |
1918 |
1922 |
return; |
return; |
|
... |
... |
void Conn_for_every_line(struct Conn *C, void (*cb)(struct Conn *C, char *line)) |
1929 |
1933 |
|
|
1930 |
1934 |
cb(C, line); |
cb(C, line); |
1931 |
1935 |
|
|
1932 |
|
Conn_eat(C, line_size); |
|
|
1936 |
|
Conn_eat(C, (unsigned int) line_size); |
1933 |
1937 |
} |
} |
1934 |
1938 |
} |
} |
1935 |
1939 |
|
|
|
... |
... |
int Conn_printf(struct Conn *C, const char *format, ...) |
1941 |
1945 |
{ |
{ |
1942 |
1946 |
va_list ap; |
va_list ap; |
1943 |
1947 |
char *s; |
char *s; |
1944 |
|
int d, len, r, ret; |
|
|
1948 |
|
int d, r, ret; |
|
1949 |
|
ssize_t slen; |
|
1950 |
|
unsigned long len; |
1945 |
1951 |
char tmp[64]; |
char tmp[64]; |
1946 |
1952 |
|
|
1947 |
1953 |
ret = 0; |
ret = 0; |
|
... |
... |
int Conn_printf(struct Conn *C, const char *format, ...) |
1955 |
1961 |
break; |
break; |
1956 |
1962 |
} |
} |
1957 |
1963 |
|
|
1958 |
|
len = s - format; |
|
1959 |
|
r = Conn_enqueue_wait(C, format, len); |
|
|
1964 |
|
len = (long unsigned int) (s - format); |
|
1965 |
|
r = Conn_enqueue_wait(C, format, (unsigned int) len); |
1960 |
1966 |
/* TODO: Should we call error callback and close the connection? */ |
/* TODO: Should we call error callback and close the connection? */ |
1961 |
1967 |
if (unlikely(r == -1)) { |
if (unlikely(r == -1)) { |
1962 |
1968 |
ret = -1; |
ret = -1; |
|
... |
... |
int Conn_printf(struct Conn *C, const char *format, ...) |
1967 |
1973 |
s = tmp; |
s = tmp; |
1968 |
1974 |
switch (*format) { |
switch (*format) { |
1969 |
1975 |
case '%': tmp[0] = '%'; len = 1; break; |
case '%': tmp[0] = '%'; len = 1; break; |
1970 |
|
case 's': s = va_arg(ap, char *); len = strlen(s); break; |
|
|
1976 |
|
|
|
1977 |
|
case 's': |
|
1978 |
|
s = va_arg(ap, char *); |
|
1979 |
|
len = strlen(s); |
|
1980 |
|
break; |
1971 |
1981 |
|
|
1972 |
1982 |
case 'd': |
case 'd': |
1973 |
1983 |
d = va_arg(ap, int); |
d = va_arg(ap, int); |
1974 |
1984 |
/* TODO: replace this with another function. Doh! */ |
/* TODO: replace this with another function. Doh! */ |
1975 |
|
len = snprintf(tmp, sizeof(tmp), "%d", d); |
|
|
1985 |
|
slen = snprintf(tmp, sizeof(tmp), "%d", d); |
|
1986 |
|
if (slen < 0) |
|
1987 |
|
len = 0; |
|
1988 |
|
else |
|
1989 |
|
len = (unsigned long) slen; |
1976 |
1990 |
break; |
break; |
1977 |
1991 |
|
|
1978 |
1992 |
case 'c': |
case 'c': |
|
... |
... |
int Conn_printf(struct Conn *C, const char *format, ...) |
1988 |
2002 |
} |
} |
1989 |
2003 |
|
|
1990 |
2004 |
if (likely(s)) { |
if (likely(s)) { |
1991 |
|
r = Conn_enqueue_wait(C, s, len); |
|
|
2005 |
|
r = Conn_enqueue_wait(C, s, (unsigned int) len); |
1992 |
2006 |
if (unlikely(r == -1)) { |
if (unlikely(r == -1)) { |
1993 |
2007 |
ret = -1; |
ret = -1; |
1994 |
2008 |
break; |
break; |
|
... |
... |
static inline void Conn_poll_cb(struct Conn *C, const unsigned int revents) |
2357 |
2371 |
return; |
return; |
2358 |
2372 |
|
|
2359 |
2373 |
if (likely(revents & EPOLLOUT)) { |
if (likely(revents & EPOLLOUT)) { |
2360 |
|
Log(9, "\tWe can send data (state=%u)...\n", C->state); |
|
|
2374 |
|
Log(9, "\tWe can send data (state=%hhu)...\n", C->state); |
2361 |
2375 |
if (likely(C->state == CONN_STATE_OPEN)) { |
if (likely(C->state == CONN_STATE_OPEN)) { |
2362 |
2376 |
/* |
/* |
2363 |
2377 |
if (likely(C->cbs.send)) |
if (likely(C->cbs.send)) |
|
... |
... |
static inline int Conn_dispatch_events(struct Conn_wpool_worker *w, |
2387 |
2401 |
int epoll_fd, struct epoll_event *e, |
int epoll_fd, struct epoll_event *e, |
2388 |
2402 |
const unsigned short e_size, const int timeout) |
const unsigned short e_size, const int timeout) |
2389 |
2403 |
{ |
{ |
2390 |
|
int i, events, r; |
|
|
2404 |
|
int i, events; |
2391 |
2405 |
struct Conn *C; |
struct Conn *C; |
2392 |
2406 |
char sevents[16]; |
char sevents[16]; |
|
2407 |
|
ssize_t r; |
2393 |
2408 |
|
|
2394 |
2409 |
Log(10, "%s timeout2=%dms e_size=%hu...\n", __func__, |
Log(10, "%s timeout2=%dms e_size=%hu...\n", __func__, |
2395 |
2410 |
timeout, e_size); |
timeout, e_size); |
|
... |
... |
static inline int Conn_dispatch_events(struct Conn_wpool_worker *w, |
2454 |
2469 |
static int Conn_wpool_start_worker(struct Conn *C, struct Conn_wpool_worker *w, |
static int Conn_wpool_start_worker(struct Conn *C, struct Conn_wpool_worker *w, |
2455 |
2470 |
int listen_fd) |
int listen_fd) |
2456 |
2471 |
{ |
{ |
2457 |
|
int r, cpus, pipes[2]; |
|
|
2472 |
|
int r, pipes[2]; |
|
2473 |
|
long cpus; |
2458 |
2474 |
struct epoll_event ev; |
struct epoll_event ev; |
2459 |
2475 |
cpu_set_t cpuset; |
cpu_set_t cpuset; |
2460 |
2476 |
struct itimerspec new_value; |
struct itimerspec new_value; |
|
... |
... |
static int Conn_wpool_start_worker(struct Conn *C, struct Conn_wpool_worker *w, |
2497 |
2513 |
|
|
2498 |
2514 |
/* TODO: if we have gaps, the allocation is not correct! */ |
/* TODO: if we have gaps, the allocation is not correct! */ |
2499 |
2515 |
cpus = sysconf(_SC_NPROCESSORS_ONLN); |
cpus = sysconf(_SC_NPROCESSORS_ONLN); |
2500 |
|
Log(1, "%u cpus found.\n", cpus); |
|
|
2516 |
|
Log(1, "%ld cpus found.\n", cpus); |
2501 |
2517 |
CPU_ZERO(&cpuset); |
CPU_ZERO(&cpuset); |
2502 |
|
CPU_SET(w->id % cpus, &cpuset); |
|
|
2518 |
|
CPU_SET((size_t)(w->id % cpus), &cpuset); |
2503 |
2519 |
r = sched_setaffinity(0, sizeof(cpu_set_t), &cpuset); |
r = sched_setaffinity(0, sizeof(cpu_set_t), &cpuset); |
2504 |
2520 |
if (r != 0) { |
if (r != 0) { |
2505 |
2521 |
Log(0, "%s: Cannot set affinity: %s\n", |
Log(0, "%s: Cannot set affinity: %s\n", |
|
... |
... |
char *Conn_split_get(const struct Conn_split *s, const char *l) |
2823 |
2839 |
* Return a value as unsigned long |
* Return a value as unsigned long |
2824 |
2840 |
*/ |
*/ |
2825 |
2841 |
unsigned long Conn_split_get_ul(const struct Conn_split *s, const char *l, |
unsigned long Conn_split_get_ul(const struct Conn_split *s, const char *l, |
2826 |
|
unsigned int base) |
|
|
2842 |
|
const unsigned int base) |
2827 |
2843 |
{ |
{ |
2828 |
2844 |
char *r; |
char *r; |
2829 |
2845 |
unsigned long ret = 0; |
unsigned long ret = 0; |
2830 |
2846 |
|
|
2831 |
2847 |
r = Conn_split_get_e(s, l); |
r = Conn_split_get_e(s, l); |
2832 |
2848 |
if (r) |
if (r) |
2833 |
|
ret = strtoul(r, NULL, base); |
|
|
2849 |
|
ret = strtoul(r, NULL, (int) base); |
2834 |
2850 |
|
|
2835 |
2851 |
return ret; |
return ret; |
2836 |
2852 |
} |
} |
|
... |
... |
unsigned long long Conn_split_get_ull(const struct Conn_split *s, const char *l, |
2846 |
2862 |
|
|
2847 |
2863 |
r = Conn_split_get_e(s, l); |
r = Conn_split_get_e(s, l); |
2848 |
2864 |
if (r) |
if (r) |
2849 |
|
ret = strtoull(r, NULL, base); |
|
|
2865 |
|
ret = strtoull(r, NULL, (int) base); |
2850 |
2866 |
|
|
2851 |
2867 |
return ret; |
return ret; |
2852 |
2868 |
} |
} |
|
... |
... |
static int Conn_alphanum(const char *s) |
2888 |
2904 |
*/ |
*/ |
2889 |
2905 |
unsigned long long Conn_lifetime(struct Conn *C) |
unsigned long long Conn_lifetime(struct Conn *C) |
2890 |
2906 |
{ |
{ |
2891 |
|
return Conn_time_diff(&Conn_now, &C->time_open); |
|
|
2907 |
|
return (unsigned long long) Conn_time_diff(&Conn_now, &C->time_open); |
2892 |
2908 |
} |
} |
2893 |
2909 |
|
|
2894 |
2910 |
char *Conn_strerror(void) |
char *Conn_strerror(void) |
|
... |
... |
int Conn_init(const unsigned int max) |
2957 |
2973 |
Conn_total = 0; |
Conn_total = 0; |
2958 |
2974 |
Conn_max_reached = 0; |
Conn_max_reached = 0; |
2959 |
2975 |
gettimeofday(&Conn_now, NULL); |
gettimeofday(&Conn_now, NULL); |
2960 |
|
Conn_start = Conn_now.tv_sec; |
|
|
2976 |
|
Conn_start = (unsigned int) Conn_now.tv_sec; |
2961 |
2977 |
Conn_allocated = 0; |
Conn_allocated = 0; |
2962 |
2978 |
|
|
2963 |
2979 |
snprintf(Conn_error, sizeof(Conn_error), "%s", ""); |
snprintf(Conn_error, sizeof(Conn_error), "%s", ""); |
|
... |
... |
int Conn_shutdown(void) |
3025 |
3041 |
|
|
3026 |
3042 |
/* |
/* |
3027 |
3043 |
* Enqueues data but does not kick the sending |
* Enqueues data but does not kick the sending |
|
3044 |
|
* Returns -1 on error, 0 if ok. |
3028 |
3045 |
*/ |
*/ |
3029 |
|
__hot int Conn_enqueue_wait(struct Conn *C, const void *buf, const size_t count) |
|
|
3046 |
|
__hot int Conn_enqueue_wait(struct Conn *C, const void *buf, const unsigned int count) |
3030 |
3047 |
{ |
{ |
3031 |
|
unsigned int r; |
|
|
3048 |
|
int r; |
3032 |
3049 |
char *dump; |
char *dump; |
3033 |
3050 |
|
|
3034 |
3051 |
if (unlikely(Conn_debug_level >= 10)) { |
if (unlikely(Conn_debug_level >= 10)) { |
|
... |
... |
__hot int Conn_enqueue_wait(struct Conn *C, const void *buf, const size_t count) |
3047 |
3064 |
memcpy(C->obuf + C->obuf_tail, buf, count); |
memcpy(C->obuf + C->obuf_tail, buf, count); |
3048 |
3065 |
C->obuf_tail += count; |
C->obuf_tail += count; |
3049 |
3066 |
|
|
3050 |
|
return count; |
|
|
3067 |
|
return 0; |
3051 |
3068 |
} |
} |
3052 |
3069 |
|
|
3053 |
3070 |
/* |
/* |
3054 |
3071 |
* Enqueues data and kick the sending |
* Enqueues data and kick the sending |
3055 |
3072 |
*/ |
*/ |
3056 |
|
__hot int Conn_enqueue(struct Conn *C, const void *buf, const size_t count) |
|
|
3073 |
|
__hot int Conn_enqueue(struct Conn *C, const void *buf, const unsigned int count) |
3057 |
3074 |
{ |
{ |
3058 |
3075 |
int ret; |
int ret; |
3059 |
3076 |
|
|
|
... |
... |
__cold static struct Conn *Conn_clone(struct Conn *C) |
3147 |
3164 |
* Prepares a socket to be used in Conn_commit |
* Prepares a socket to be used in Conn_commit |
3148 |
3165 |
*/ |
*/ |
3149 |
3166 |
static int Conn_prepare_socket(struct Conn *C, struct sockaddr *bind_psa, |
static int Conn_prepare_socket(struct Conn *C, struct sockaddr *bind_psa, |
3150 |
|
int bind_sock_len) |
|
|
3167 |
|
socklen_t bind_sock_len) |
3151 |
3168 |
{ |
{ |
3152 |
3169 |
int fd, i, ret; |
int fd, i, ret; |
3153 |
3170 |
|
|
|
... |
... |
int Conn_commit(struct Conn *C) |
3208 |
3225 |
struct sockaddr *bind_psa = NULL; |
struct sockaddr *bind_psa = NULL; |
3209 |
3226 |
struct sockaddr_in bind_sa; |
struct sockaddr_in bind_sa; |
3210 |
3227 |
struct sockaddr_in6 bind_sa6; |
struct sockaddr_in6 bind_sa6; |
3211 |
|
int bind_sock_len = 0; |
|
|
3228 |
|
socklen_t bind_sock_len = 0; |
3212 |
3229 |
int do_connect = 0; |
int do_connect = 0; |
3213 |
|
int first_state = -1; |
|
|
3230 |
|
unsigned char first_state = 0xff; |
3214 |
3231 |
struct Conn_wpool_worker *w; |
struct Conn_wpool_worker *w; |
3215 |
3232 |
|
|
3216 |
3233 |
Log(10, "%s\n", __func__); |
Log(10, "%s\n", __func__); |
File duilder changed (mode: 100755) (index 60e7da0..a321672) |
... |
... |
function duilder_docs() |
26 |
26 |
mkdir -p "${EXPORT_PATH}" |
mkdir -p "${EXPORT_PATH}" |
27 |
27 |
fi |
fi |
28 |
28 |
|
|
|
29 |
|
if [ "${BUILD_SDEB}" = "1" ]; then |
|
30 |
|
if [ -d "debian" ]; then |
|
31 |
|
>debian/docs |
|
32 |
|
fi |
|
33 |
|
fi |
|
34 |
|
|
29 |
35 |
echo "[*] Copying docs to [${EXPORT_PATH}]..." |
echo "[*] Copying docs to [${EXPORT_PATH}]..." |
30 |
|
for f in README License LICENSE Changelog Changelog-last TODO FAQ INSTALL AUTHORS; do |
|
|
36 |
|
for f in README License LICENSE Changelog Changelog-last TODO FAQ INSTALL AUTHORS samples; do |
31 |
37 |
if [ -r "${f}" ]; then |
if [ -r "${f}" ]; then |
32 |
|
cp -vp "${f}" "${EXPORT_PATH}/" |
|
|
38 |
|
cp -avp "${f}" "${EXPORT_PATH}/" |
|
39 |
|
if [ "${BUILD_SDEB}" = "1" ]; then |
|
40 |
|
# No need to install the license file |
|
41 |
|
if [ "${f}" = "LICENSE" ]; then |
|
42 |
|
continue |
|
43 |
|
fi |
|
44 |
|
echo "${f}" >> debian/docs |
|
45 |
|
fi |
33 |
46 |
fi |
fi |
34 |
47 |
done |
done |
35 |
48 |
echo |
echo |
|
... |
... |
function duilder_git() |
60 |
73 |
exit 0 |
exit 0 |
61 |
74 |
fi |
fi |
62 |
75 |
|
|
|
76 |
|
echo "[*] Testing if a tag is present for HEAD..." |
|
77 |
|
D=`git describe | sed -e 's/^.*-g[0-9a-fA-F]*$//'` |
|
78 |
|
if [ "${D}" = "" ]; then |
|
79 |
|
echo "No annotated tag preset for HEAD! Please add one!" |
|
80 |
|
exit 1 |
|
81 |
|
fi |
|
82 |
|
|
63 |
83 |
if [ "${EXPORT_GIT}" = "1" ]; then |
if [ "${EXPORT_GIT}" = "1" ]; then |
64 |
84 |
echo "[*] Generating GIT tree for HTTP transport..." |
echo "[*] Generating GIT tree for HTTP transport..." |
65 |
85 |
if [ ! -d "${GIT_DEST}/${PRJ}.git" ]; then |
if [ ! -d "${GIT_DEST}/${PRJ}.git" ]; then |
|
... |
... |
function duilder_git() |
96 |
116 |
|
|
97 |
117 |
# get the list of tags |
# get the list of tags |
98 |
118 |
number_of_tags=0 |
number_of_tags=0 |
|
119 |
|
git show-ref --tags -d | grep refs/tags/v > duilder.tmp |
99 |
120 |
while read sha1 full_tag; do |
while read sha1 full_tag; do |
100 |
121 |
tag=`echo ${full_tag} | sed -e 's#refs/tags/##' | cut -d'^' -f1` |
tag=`echo ${full_tag} | sed -e 's#refs/tags/##' | cut -d'^' -f1` |
101 |
122 |
tags[${number_of_tags}]=${tag} |
tags[${number_of_tags}]=${tag} |
102 |
123 |
tags_commit[${number_of_tags}]=${sha1} |
tags_commit[${number_of_tags}]=${sha1} |
103 |
124 |
number_of_tags=$[${number_of_tags}+1] |
number_of_tags=$[${number_of_tags}+1] |
104 |
|
done < <(git show-ref --tags -d | grep refs/tags/v) |
|
|
125 |
|
done < duilder.tmp |
|
126 |
|
rm -f duilder.tmp |
105 |
127 |
|
|
106 |
128 |
# get the list of commits, test if is a tag and do the diff |
# get the list of commits, test if is a tag and do the diff |
107 |
129 |
prev="" |
prev="" |
|
... |
... |
function duilder_srpm() |
159 |
181 |
|
|
160 |
182 |
P="${PRJ}-${VER}" |
P="${PRJ}-${VER}" |
161 |
183 |
|
|
|
184 |
|
if [ "${BUILD_SRPM}" != "1" ]; then |
|
185 |
|
exit 0 |
|
186 |
|
fi |
|
187 |
|
|
162 |
188 |
if [ ! -d "${EXPORT_PATH}" ]; then |
if [ ! -d "${EXPORT_PATH}" ]; then |
163 |
189 |
echo "WARN: ${EXPORT_PATH} does not exists. Creating it..." |
echo "WARN: ${EXPORT_PATH} does not exists. Creating it..." |
164 |
190 |
mkdir -p "${EXPORT_PATH}" |
mkdir -p "${EXPORT_PATH}" |
165 |
191 |
fi |
fi |
166 |
192 |
|
|
167 |
|
if [ "${BUILD_SRPM}" != "1" ]; then |
|
168 |
|
exit 0 |
|
169 |
|
fi |
|
170 |
|
|
|
171 |
193 |
echo "[*] Building SRPM..." |
echo "[*] Building SRPM..." |
172 |
194 |
rpmbuild -ts "${P}.tar.gz" |
rpmbuild -ts "${P}.tar.gz" |
173 |
195 |
echo |
echo |
|
... |
... |
function duilder_srpm() |
185 |
207 |
if [ ! -z "${SRPM_DEST}" ]; then |
if [ ! -z "${SRPM_DEST}" ]; then |
186 |
208 |
echo "[*] Copying [${PKG}] to [${SRPM_DEST}]..." |
echo "[*] Copying [${PKG}] to [${SRPM_DEST}]..." |
187 |
209 |
cp -vp "${PKG}" "${SRPM_DEST}/" |
cp -vp "${PKG}" "${SRPM_DEST}/" |
188 |
|
echo |
|
189 |
210 |
fi |
fi |
190 |
211 |
|
|
191 |
212 |
echo "[*] Copying to export dir [${EXPORT_PATH}]..." |
echo "[*] Copying to export dir [${EXPORT_PATH}]..." |
|
... |
... |
function duilder_srpm() |
199 |
220 |
fi |
fi |
200 |
221 |
} |
} |
201 |
222 |
|
|
|
223 |
|
function duilder_sdeb() |
|
224 |
|
{ |
|
225 |
|
PRJ="${1}" |
|
226 |
|
VER="${2}" |
|
227 |
|
EXPORT_PATH="${3}" |
|
228 |
|
BUILD_SDEB="${4}" |
|
229 |
|
SDEB_DEST="${5}" |
|
230 |
|
SDEB_POST_RUN="${6}" |
|
231 |
|
|
|
232 |
|
P="${PRJ}-${VER}" |
|
233 |
|
|
|
234 |
|
if [ "${BUILD_SDEB}" != "1" ]; then |
|
235 |
|
exit 0 |
|
236 |
|
fi |
|
237 |
|
|
|
238 |
|
if [ ! -d "${EXPORT_PATH}" ]; then |
|
239 |
|
echo "WARN: ${EXPORT_PATH} does not exists. Creating it..." |
|
240 |
|
mkdir -p "${EXPORT_PATH}" |
|
241 |
|
fi |
|
242 |
|
|
|
243 |
|
echo "[*] Copying SDEB..." |
|
244 |
|
PKG="${PRJ}_${VER}.orig.tar.gz" |
|
245 |
|
|
|
246 |
|
if [ -n "${SDEB_DEST}" ]; then |
|
247 |
|
cp -vp "${P}.tar.gz" "${SDEB_DEST}/${PKG}" |
|
248 |
|
fi |
|
249 |
|
|
|
250 |
|
echo "[*] Copying to export dir [${DEB_EXPORT_PATH}]..." |
|
251 |
|
mkdir -p "${EXPORT_PATH}" |
|
252 |
|
cp -vp "${P}.tar.gz" "${EXPORT_PATH}/${PKG}" |
|
253 |
|
echo |
|
254 |
|
|
|
255 |
|
if [ -x "${SDEB_POST_RUN}" ]; then |
|
256 |
|
echo "[*] Running post SDEB build script [${SDEB_POST_RUN}]..." |
|
257 |
|
${SDEB_POST_RUN} "${SDEB}/${PKG}" |
|
258 |
|
fi |
|
259 |
|
} |
|
260 |
|
|
202 |
261 |
function duilder_tar() |
function duilder_tar() |
203 |
262 |
{ |
{ |
204 |
263 |
PRJ="${1}" |
PRJ="${1}" |
|
... |
... |
if [ -z "${REV}" ]; then |
275 |
334 |
fi |
fi |
276 |
335 |
|
|
277 |
336 |
# export variables - just in case a script cares |
# export variables - just in case a script cares |
278 |
|
export PRJ VER REV SHORT_DESCRIPTION EXPORT_PATH EXPORT_GIT GIT_PUSH GIT_DEST SRPM_DEST LICENSE |
|
|
337 |
|
export PRJ VER REV SHORT_DESCRIPTION EXPORT_PATH EXPORT_GIT GIT_PUSH GIT_DEST |
|
338 |
|
export SRPM_DEST SDEB_DEST LICENSE MAINTAINER_NAME MAINTAINER_EMAIL |
|
339 |
|
export HOME_PAGE BUILD_SRPM BUILD_SDEB |
279 |
340 |
|
|
280 |
341 |
|
|
281 |
342 |
# Multiplexer |
# Multiplexer |
|
... |
... |
if [ "${1}" = "srpm" ]; then |
303 |
364 |
exit $? |
exit $? |
304 |
365 |
fi |
fi |
305 |
366 |
|
|
|
367 |
|
if [ "${1}" = "sdeb" ]; then |
|
368 |
|
shift |
|
369 |
|
duilder_sdeb "$@" |
|
370 |
|
exit $? |
|
371 |
|
fi |
|
372 |
|
|
306 |
373 |
if [ "${1}" = "final" ]; then |
if [ "${1}" = "final" ]; then |
307 |
374 |
shift |
shift |
308 |
375 |
duilder_final "$@" |
duilder_final "$@" |
|
... |
... |
echo "[*] Duilder builder script" |
315 |
382 |
echo "[*] Copyright Catalin(ux) M. BOIE - catab at embedromix dot ro" |
echo "[*] Copyright Catalin(ux) M. BOIE - catab at embedromix dot ro" |
316 |
383 |
echo "[*] PRJ=${PRJ}, VER=${VER}, REV=${REV}" |
echo "[*] PRJ=${PRJ}, VER=${VER}, REV=${REV}" |
317 |
384 |
echo "[*] System: `uname -a`" |
echo "[*] System: `uname -a`" |
|
385 |
|
echo "[*] Parameters: ${@}" |
318 |
386 |
|
|
319 |
387 |
ETC="/etc" |
ETC="/etc" |
320 |
388 |
BIN="/bin" |
BIN="/bin" |
|
389 |
|
USR="/usr" |
321 |
390 |
USR_BIN="/usr/bin" |
USR_BIN="/usr/bin" |
322 |
391 |
USR_SBIN="/usr/sbin" |
USR_SBIN="/usr/sbin" |
323 |
392 |
USR_INCLUDE="/usr/include" |
USR_INCLUDE="/usr/include" |
|
... |
... |
else |
327 |
396 |
USR_LIB="/usr/lib64" |
USR_LIB="/usr/lib64" |
328 |
397 |
fi |
fi |
329 |
398 |
USR_SHARE="/usr/share" |
USR_SHARE="/usr/share" |
330 |
|
USR_SHARE_DOC="/usr/share/doc/${PRJ}-${VER}" |
|
|
399 |
|
USR_SHARE_DOC="/usr/share/doc/${PRJ}" |
331 |
400 |
SBIN="/usr/sbin" |
SBIN="/usr/sbin" |
332 |
401 |
VAR="/var" |
VAR="/var" |
333 |
402 |
VAR_LIB="/var/lib" |
VAR_LIB="/var/lib" |
334 |
403 |
MAN="/usr/share/man" |
MAN="/usr/share/man" |
|
404 |
|
PREFIX="/usr" |
335 |
405 |
|
|
336 |
406 |
while [ "${1}" != "" ]; do |
while [ "${1}" != "" ]; do |
337 |
407 |
xVAR="`echo ${1} | cut -d'=' -f1`" |
xVAR="`echo ${1} | cut -d'=' -f1`" |
338 |
|
xVAL="`echo ${1} | cut -d'=' -f2`" |
|
|
408 |
|
xVAL="`echo ${1} | cut -d'=' -f2 | sed -e "s|\\${prefix}|${PREFIX}|"`" |
|
409 |
|
shift |
339 |
410 |
case ${xVAR} in |
case ${xVAR} in |
340 |
411 |
--sysconfdir) |
--sysconfdir) |
341 |
412 |
ETC="${xVAL}" |
ETC="${xVAL}" |
|
... |
... |
while [ "${1}" != "" ]; do |
364 |
435 |
--mandir) |
--mandir) |
365 |
436 |
MAN="${xVAL}" |
MAN="${xVAL}" |
366 |
437 |
;; |
;; |
|
438 |
|
--prefix) |
|
439 |
|
PREFIX="${xVAL}" |
|
440 |
|
USR="${xVAL}" |
|
441 |
|
;; |
367 |
442 |
esac |
esac |
368 |
|
shift |
|
369 |
443 |
done |
done |
370 |
444 |
|
|
371 |
445 |
# Last fixes |
# Last fixes |
372 |
446 |
VAR_LOG="${VAR}/log" |
VAR_LOG="${VAR}/log" |
373 |
447 |
VAR_RUN="${VAR}/run" |
VAR_RUN="${VAR}/run" |
374 |
448 |
|
|
375 |
|
for i in ETC BIN USR_BIN USR_SBIN USR_INCLUDE USR_LIB USR_SHARE USR_SHARE_DOC SBIN VAR VAR_LIB MAN VAR_LOG VAR_RUN; do |
|
|
449 |
|
for i in ETC BIN USR USR_BIN USR_SBIN USR_INCLUDE USR_LIB USR_SHARE USR_SHARE_DOC SBIN VAR VAR_LIB MAN VAR_LOG VAR_RUN; do |
376 |
450 |
eval value=\$$i |
eval value=\$$i |
377 |
451 |
echo "[*] Var ${i}=${value}" |
echo "[*] Var ${i}=${value}" |
378 |
452 |
done |
done |
|
... |
... |
else |
466 |
540 |
echo "s#@NCURSES_FOUND@#1#g" >> tmp.sed |
echo "s#@NCURSES_FOUND@#1#g" >> tmp.sed |
467 |
541 |
fi |
fi |
468 |
542 |
|
|
|
543 |
|
if [ -n "${CC_SWITCHES}" ]; then |
|
544 |
|
_CC_SWITCHES="" |
|
545 |
|
echo "[*] Search for valid compiler flags..." |
|
546 |
|
add="" |
|
547 |
|
for s in ${CC_SWITCHES}; do |
|
548 |
|
echo -n " [*] Testing switch [${s}]..." |
|
549 |
|
set +e |
|
550 |
|
echo "int main(void) { return 0; }" | gcc ${s} -x c -pipe - -o /dev/null 2>/dev/null |
|
551 |
|
E=${?} |
|
552 |
|
set -e |
|
553 |
|
if [ "${E}" != "0" ]; then |
|
554 |
|
echo "not supported" |
|
555 |
|
else |
|
556 |
|
echo "supported" |
|
557 |
|
_CC_SWITCHES="${_CC_SWITCHES}${add}${s}" |
|
558 |
|
add=" " |
|
559 |
|
fi |
|
560 |
|
done |
|
561 |
|
fi |
|
562 |
|
|
469 |
563 |
# generic stuff |
# generic stuff |
470 |
564 |
echo "s#@PRJ@#${PRJ}#g" >> tmp.sed |
echo "s#@PRJ@#${PRJ}#g" >> tmp.sed |
471 |
565 |
echo "s#@VER@#${VER}#g" >> tmp.sed |
echo "s#@VER@#${VER}#g" >> tmp.sed |
472 |
566 |
echo "s#@REV@#${REV}#g" >> tmp.sed |
echo "s#@REV@#${REV}#g" >> tmp.sed |
473 |
567 |
echo "s#@ETC@#${ETC}#g" >> tmp.sed |
echo "s#@ETC@#${ETC}#g" >> tmp.sed |
474 |
568 |
echo "s#@BIN@#${BIN}#g" >> tmp.sed |
echo "s#@BIN@#${BIN}#g" >> tmp.sed |
|
569 |
|
echo "s#@USR@#${USR}#g" >> tmp.sed |
475 |
570 |
echo "s#@USR_BIN@#${USR_BIN}#g" >> tmp.sed |
echo "s#@USR_BIN@#${USR_BIN}#g" >> tmp.sed |
476 |
571 |
echo "s#@SBIN@#${SBIN}#g" >> tmp.sed |
echo "s#@SBIN@#${SBIN}#g" >> tmp.sed |
477 |
572 |
echo "s#@USR_SBIN@#${USR_SBIN}#g" >> tmp.sed |
echo "s#@USR_SBIN@#${USR_SBIN}#g" >> tmp.sed |
|
... |
... |
echo "s#@USR_SHARE_DOC@#${USR_SHARE_DOC}#g" >> tmp.sed |
487 |
582 |
echo "s#@MAN@#${MAN}#g" >> tmp.sed |
echo "s#@MAN@#${MAN}#g" >> tmp.sed |
488 |
583 |
# Export stuff |
# Export stuff |
489 |
584 |
echo "s#@EXPORT_PATH@#${EXPORT_PATH}#g" >> tmp.sed |
echo "s#@EXPORT_PATH@#${EXPORT_PATH}#g" >> tmp.sed |
|
585 |
|
# cc_switches |
|
586 |
|
echo "s#@CC_SWITCHES@#${_CC_SWITCHES}#g" >> tmp.sed |
|
587 |
|
echo "s#@MAINTAINER_NAME@#${MAINTAINER_NAME}#g" >> tmp.sed |
|
588 |
|
echo "s#@MAINTAINER_EMAIL@#${MAINTAINER_EMAIL}#g" >> tmp.sed |
|
589 |
|
echo "s#@SHORT_DESCRIPTION@#${SHORT_DESCRIPTION}#g" >> tmp.sed |
|
590 |
|
echo "s#@HOME_PAGE@#${HOME_PAGE}#g" >> tmp.sed |
490 |
591 |
|
|
491 |
592 |
|
|
492 |
593 |
|
|
|
... |
... |
if [ -r Makefile.in ]; then |
502 |
603 |
echo "export I_ETC := \$(DESTDIR)${ETC}" >> Makefile |
echo "export I_ETC := \$(DESTDIR)${ETC}" >> Makefile |
503 |
604 |
echo "export I_BIN := \$(DESTDIR)${BIN}" >> Makefile |
echo "export I_BIN := \$(DESTDIR)${BIN}" >> Makefile |
504 |
605 |
echo "export I_SBIN := \$(DESTDIR)${SBIN}" >> Makefile |
echo "export I_SBIN := \$(DESTDIR)${SBIN}" >> Makefile |
|
606 |
|
echo "export I_USR := \$(DESTDIR)${USR}" >> Makefile |
505 |
607 |
echo "export I_USR_BIN := \$(DESTDIR)${USR_BIN}" >> Makefile |
echo "export I_USR_BIN := \$(DESTDIR)${USR_BIN}" >> Makefile |
506 |
608 |
echo "export I_USR_SBIN := \$(DESTDIR)${USR_SBIN}" >> Makefile |
echo "export I_USR_SBIN := \$(DESTDIR)${USR_SBIN}" >> Makefile |
507 |
609 |
echo "export I_USR_INCLUDE := \$(DESTDIR)${USR_INCLUDE}" >> Makefile |
echo "export I_USR_INCLUDE := \$(DESTDIR)${USR_INCLUDE}" >> Makefile |
|
... |
... |
if [ -r Makefile.in ]; then |
544 |
646 |
echo " @./duilder git \"\$(PRJ)\" \"${GIT_DEST}\" \"${EXPORT_GIT}\" \"${GIT_CHANGELOG}\"" \"${GIT_PUSH}\" >> Makefile |
echo " @./duilder git \"\$(PRJ)\" \"${GIT_DEST}\" \"${EXPORT_GIT}\" \"${GIT_CHANGELOG}\"" \"${GIT_PUSH}\" >> Makefile |
545 |
647 |
echo " @./duilder tar \"\$(PRJ)\" \"\$(VER)\" \"${EXPORT_PATH}\" \"${EXCLUDE}\"" >> Makefile |
echo " @./duilder tar \"\$(PRJ)\" \"\$(VER)\" \"${EXPORT_PATH}\" \"${EXCLUDE}\"" >> Makefile |
546 |
648 |
echo " @./duilder srpm \"\$(PRJ)\" \"\$(VER)\" \"${EXPORT_PATH}\" \"${BUILD_SRPM}\" \"${SRPM_DEST}\" \"${SRPM_POST_RUN}\"" >> Makefile |
echo " @./duilder srpm \"\$(PRJ)\" \"\$(VER)\" \"${EXPORT_PATH}\" \"${BUILD_SRPM}\" \"${SRPM_DEST}\" \"${SRPM_POST_RUN}\"" >> Makefile |
|
649 |
|
echo " @./duilder sdeb \"\$(PRJ)\" \"\$(VER)\" \"${EXPORT_PATH}\" \"${BUILD_SDEB}\" \"${SDEB_DEST}\" \"${SDEB_POST_RUN}\"" >> Makefile |
547 |
650 |
echo " @./duilder docs \"\$(PRJ)\" \"\$(VER)\" \"${EXPORT_PATH}\"" >> Makefile |
echo " @./duilder docs \"\$(PRJ)\" \"\$(VER)\" \"${EXPORT_PATH}\"" >> Makefile |
548 |
651 |
echo " @./duilder final \"\$(PRJ)\" \"\$(VER)\" \"${RELEASE_SCRIPT}\"" >> Makefile |
echo " @./duilder final \"\$(PRJ)\" \"\$(VER)\" \"${RELEASE_SCRIPT}\"" >> Makefile |
549 |
652 |
echo " @rm -f \"\$(PRJ)-\$(VER).tar.gz\"" >> Makefile |
echo " @rm -f \"\$(PRJ)-\$(VER).tar.gz\"" >> Makefile |
|
... |
... |
if [ ! -z "${CONFIG_H}" ]; then |
560 |
663 |
sed -f tmp.sed ${CONFIG_H}.in > ${CONFIG_H} |
sed -f tmp.sed ${CONFIG_H}.in > ${CONFIG_H} |
561 |
664 |
fi |
fi |
562 |
665 |
|
|
|
666 |
|
if [ "${BUILD_SDEB}" = "1" ]; then |
|
667 |
|
AUTOGENERATE="${AUTOGENERATE} debian/control.in debian/changelog.in" |
|
668 |
|
AUTOGENERATE="${AUTOGENERATE} debian/copyright.in debian/rules.in" |
|
669 |
|
fi |
|
670 |
|
|
|
671 |
|
echo "[*] Autogenerate files from .in..." |
|
672 |
|
for f in ${AUTOGENERATE}; do |
|
673 |
|
if [ -r "${f}" ]; then |
|
674 |
|
dst="${f//.in/}" |
|
675 |
|
echo " [*] Autogenerate ${dst} from ${f}..." |
|
676 |
|
sed -f tmp.sed "${f}" > "${dst}" |
|
677 |
|
# We need to have the same rights (maybe is executable...) |
|
678 |
|
chmod --reference="${f}" "${dst}" |
|
679 |
|
fi |
|
680 |
|
done |
|
681 |
|
|
563 |
682 |
rm -f tmp.sed |
rm -f tmp.sed |
564 |
683 |
|
|
565 |
684 |
if [ "`basename ${0}`" = "duilderx" ]; then |
if [ "`basename ${0}`" = "duilderx" ]; then |