Skip to content

Commit 3ab2602

Browse files
committed
better PID-list management/messaging
1 parent 00aae9a commit 3ab2602

File tree

4 files changed

+28
-22
lines changed

4 files changed

+28
-22
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# CHANGELOG
22

33
* **2025.06.05 Current - ts-warp-1.5.8, gui-warp-1.0.27 (gui-warp-v1.0.34-mac), ns-warp-1.0.7**
4+
* `ts-warp.c, pidlist.c`: better `PID`-list management
5+
* `inifile.c`: suppress negative name lookup messages
46
* `gui-warp.py`: INI-tab Text-field resizing corrected
57

68
* **2025.06.04 ts-warp-1.5.8, gui-warp-1.0.27 (gui-warp-v1.0.34-mac), ns-warp-1.0.7**

inifile.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,11 @@ struct ini_section *getsection(struct ini_section *ini, char *name) {
429429

430430
struct ini_section *s;
431431

432+
if (!name || !name[0]) {
433+
printl(LOG_VERB, "getsection(): Empty section name queried!");
434+
return NULL;
435+
}
436+
432437
s = ini;
433438
while (s) {
434439
if (!strcmp(s->section_name, name)) {
@@ -595,16 +600,14 @@ struct ini_section *ini_look_server(struct ini_section *ini, struct uvaddr addr_
595600
while (t) {
596601
if ((t->target_type == INI_TARGET_HOST || t->target_type == INI_TARGET_DOMAIN)) {
597602
/* Perform namelookup only if section has target_host or target_domain */
598-
if (!addr_u.name[0] && getnameinfo((struct sockaddr *)&addr_u.ip_addr, sizeof(addr_u.ip_addr), host,
599-
sizeof host, 0, 0, NI_NAMEREQD))
600-
printl(LOG_VERB, "Unspecified / irresolvable hostname: [%s]",
601-
inet2str(&addr_u.ip_addr, buf1));
602-
else
603-
if (!domain && (domain = strchr(host, '.'))) {
603+
if (!addr_u.name[0] &&
604+
getnameinfo((struct sockaddr *)&addr_u.ip_addr, sizeof(addr_u.ip_addr),
605+
host, sizeof host, 0, 0, NI_NAMEREQD) == 0 &&
606+
!domain && (domain = strchr(host, '.'))) {
604607
domainlen = strnlen(++domain, HOST_NAME_MAX - 1);
605608
printl(LOG_VERB, "IP: [%s] resolves to: [%s] domain: [%s]",
606-
inet2str(&addr_u.ip_addr, buf1), host, domain?:"");
607-
}
609+
inet2str(&addr_u.ip_addr, buf1), host, domain ? : "");
610+
}
608611
}
609612

610613
switch(t->target_type) {

pidlist.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ struct pid_list *pidlist_add(struct pid_list *root, char *section_name, pid_t pi
6262
c->next = n;
6363
}
6464

65-
printl(LOG_INFO, "Clients list. Added PID: [%d], Section: [%s]", n->pid, n->section_name);
65+
printl(LOG_INFO, "Clients list. Added PID: [%d]", n->pid);
6666
return root;
6767
}
6868

ts-warp.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -590,14 +590,6 @@ All parameters are optional:
590590
fcntl(csock, F_SETFL, ~O_NONBLOCK); /* Don't block client connections */
591591
printl(LOG_INFO, "Client: [%d], IP: [%s] accepted", cn++, inet2str(&caddr, buf));
592592

593-
/* -- Get the client original destination from NAT ---------------------------------------------------------- */
594-
595-
/* Initialize daddr */
596-
daddr_len = sizeof(daddr.ip_addr);
597-
memset(&daddr.ip_addr, 0, daddr_len);
598-
memset(&daddr.name, 0, sizeof(daddr.name) - 1);
599-
daddr.ip_addr.ss_family = caddr.ss_family;
600-
601593
/* -- Process the PIDs list: remove exitted clients and execute workload balance functions ------------------ */
602594
c = pids;
603595

@@ -609,7 +601,7 @@ All parameters are optional:
609601

610602
while (c) {
611603
push_ini = NULL;
612-
if (!c->section_name || strlen(c->section_name) == 0) {
604+
if (c->traffic.daddr.ss_family && (!c->section_name || strlen(c->section_name) == 0)) {
613605
tmp_daddr.ip_addr = c->traffic.daddr;
614606
if ((push_ini = ini_look_server(ini_root, tmp_daddr))) {
615607
free(c->section_name);
@@ -619,7 +611,8 @@ All parameters are optional:
619611

620612
if (c == pids && c->status >= 0) { /* Remove pidlist root entry */
621613
pids = c->next;
622-
if (!push_ini) push_ini = getsection(ini_root, c->section_name);
614+
if (!push_ini && c->section_name && c->section_name[0])
615+
push_ini = getsection(ini_root, c->section_name);
623616
if (c->status && push_ini && push_ini->section_balance != SECTION_BALANCE_NONE)
624617
pushback_ini(&ini_root, push_ini);
625618
free(c->section_name);
@@ -628,13 +621,15 @@ All parameters are optional:
628621
} else if (c && c->next && c->next->status >= 0) { /* Remove a pidlist entry */
629622
d = c->next;
630623
c->next = d->next;
631-
if (!push_ini) push_ini = getsection(ini_root, c->section_name);
624+
if (!push_ini && c->section_name && c->section_name[0])
625+
push_ini = getsection(ini_root, c->section_name);
632626
if (d->status && push_ini && push_ini->section_balance != SECTION_BALANCE_NONE)
633627
pushback_ini(&ini_root, push_ini);
634628
free(d->section_name);
635629
free(d);
636630
} else {
637-
if (!push_ini) push_ini = getsection(ini_root, c->section_name);
631+
if (!push_ini && c->section_name && c->section_name[0])
632+
push_ini = getsection(ini_root, c->section_name);
638633
if (push_ini && push_ini->section_balance == SECTION_BALANCE_ROUNDROBIN)
639634
pushback_ini(&ini_root, push_ini);
640635
}
@@ -653,12 +648,18 @@ All parameters are optional:
653648
close(csock);
654649

655650
/* Save the client into the list */
656-
pids = pidlist_add(pids, s_ini ? s_ini->section_name : "", cpid, caddr, daddr.ip_addr);
651+
pids = pidlist_add(pids, "", cpid, caddr, tmp_daddr.ip_addr);
657652
}
658653

659654
if (cpid == 0) {
660655
/* -- Client processing (child) ------------------------------------------------------------------------- */
661656

657+
/* Initialize daddr */
658+
daddr_len = sizeof(daddr.ip_addr);
659+
memset(&daddr.ip_addr, 0, daddr_len);
660+
memset(&daddr.name, 0, sizeof(daddr.name) - 1);
661+
daddr.ip_addr.ss_family = caddr.ss_family;
662+
662663
ssock.t = CHS_SOCKET; /* Type socket */
663664
#if (WITH_LIBSSH2)
664665
ssock.c = NULL;

0 commit comments

Comments
 (0)