Skip to content

Commit a4ea3b1

Browse files
Александр Поповcursoragent
andcommitted
fix: extend pid field to 32-bit (getpid returns 32-bit on modern systems)
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent cafc338 commit a4ea3b1

8 files changed

Lines changed: 14 additions & 13 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
objs
22
dep
3+
proxy-secret
4+
proxy-multi.conf

common/pid.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ npid_t PID;
3838

3939
void init_common_PID (void) {
4040
if (!PID.pid) {
41-
int p = getpid ();
42-
assert (!(p & 0xffff0000));
43-
PID.pid = p;
41+
PID.pid = (unsigned) getpid ();
4442
}
4543
if (!PID.utime) {
4644
PID.utime = time (0);
@@ -80,8 +78,8 @@ int process_id_is_newer (struct process_id *a, struct process_id *b) {
8078
assert (!memcmp (a, b, 6));
8179
if (a->utime < b->utime) { return 0; }
8280
if (a->utime > b->utime) { return 1; }
83-
int x = (a->pid - b->pid) & 0x7fff;
84-
if (x && x <= 0x3fff) { return 1; }
81+
unsigned x = (a->pid - b->pid) & 0x7fffffff;
82+
if (x && x <= 0x3fffffff) { return 1; }
8583
return 0;
8684
}
8785

common/pid.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@
2929
struct process_id {
3030
unsigned ip;
3131
short port;
32-
unsigned short pid;
32+
unsigned pid; /* was unsigned short; getpid() returns 32-bit on modern systems */
3333
int utime;
3434
};
3535

3636
struct process_id_ext {
3737
unsigned ip;
3838
short port;
39-
unsigned short pid;
39+
unsigned pid;
4040
int utime;
4141
int actor_id;
4242
};

common/tl-parse.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ static inline int __tl_store_init (struct tl_out_state *tlio_out, void *out, voi
770770

771771
int tls_init_raw_msg (struct tl_out_state *tlio_out, struct process_id *pid, long long qid) {
772772
if (pid) {
773-
memcpy (&tlio_out->out_pid_buf, pid, 12);
773+
memcpy (&tlio_out->out_pid_buf, pid, sizeof (struct process_id));
774774
TL_OUT_PID = &tlio_out->out_pid_buf;
775775
} else {
776776
TL_OUT_PID = 0;

net/net-rpc-targets.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424

2525
#include <assert.h>
26+
#include <stddef.h>
2627
#include <stdlib.h>
2728
#include <string.h>
2829
#include <unistd.h>
@@ -40,7 +41,7 @@
4041
#include "common/mp-queue.h"
4142
#include "common/server-functions.h"
4243

43-
#define rpc_target_cmp(a,b) (RPC_TARGET_INFO(a)->PID.port ? memcmp (&RPC_TARGET_INFO(a)->PID, &RPC_TARGET_INFO(b)->PID, 6) : memcmp (&RPC_TARGET_INFO(a)->PID, &RPC_TARGET_INFO(b)->PID, 8))
44+
#define rpc_target_cmp(a,b) (RPC_TARGET_INFO(a)->PID.port ? memcmp (&RPC_TARGET_INFO(a)->PID, &RPC_TARGET_INFO(b)->PID, 6) : memcmp (&RPC_TARGET_INFO(a)->PID, &RPC_TARGET_INFO(b)->PID, offsetof (struct process_id, utime)))
4445

4546
//DEFINE_TREE(rpc_target, rpc_target_job_t, rpc_target_cmp, MALLOC)
4647

net/net-tcp-rpc-client.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ static int tcp_rpcc_process_handshake_packet (connection_job_t C, struct raw_mes
299299
}
300300
assert (rwm_fetch_data (msg, &P, packet_len) == packet_len);
301301
if (!matches_pid (&P.sender_pid, &D->remote_pid) && !(TCP_RPCC_FUNC(C)->mode_flags & TCP_RPC_IGNORE_PID)) {
302-
vkprintf (1, "PID mismatch during client RPC handshake: local %08x:%d:%d:%d, remote %08x:%d:%d:%d\n",
302+
vkprintf (1, "PID mismatch during client RPC handshake: local %08x:%d:%u:%d, remote %08x:%d:%u:%d\n",
303303
D->remote_pid.ip, D->remote_pid.port, D->remote_pid.pid, D->remote_pid.utime, P.sender_pid.ip, P.sender_pid.port, P.sender_pid.pid, P.sender_pid.utime);
304304
tcp_rpcc_send_handshake_error_packet (C, -6);
305305
return -6;

net/net-tcp-rpc-server.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ static int tcp_rpcs_process_handshake_packet (connection_job_t C, struct raw_mes
287287
assert (rwm_fetch_data (msg, &P, packet_len) == packet_len);
288288
memcpy (&D->remote_pid, &P.sender_pid, sizeof (struct process_id));
289289
if (!matches_pid (&PID, &P.peer_pid) && !(TCP_RPCS_FUNC(C)->mode_flags & TCP_RPC_IGNORE_PID)) {
290-
vkprintf (1, "PID mismatch during handshake: local %08x:%d:%d:%d, remote %08x:%d:%d:%d\n",
290+
vkprintf (1, "PID mismatch during handshake: local %08x:%d:%u:%d, remote %08x:%d:%u:%d\n",
291291
PID.ip, PID.port, PID.pid, PID.utime, P.peer_pid.ip, P.peer_pid.port, P.peer_pid.pid, P.peer_pid.utime);
292292
tcp_rpcs_send_handshake_error_packet (C, -4);
293293
return -4;

vv/vv-io.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
#include <stdio.h>
2424
#include <arpa/inet.h>
2525

26-
#define PID_PRINT_STR "[" IP_PRINT_STR ":%d:%d:%d]"
26+
#define PID_PRINT_STR "[" IP_PRINT_STR ":%d:%u:%d]"
2727
#define IP_PRINT_STR "%d.%d.%d.%d"
2828

29-
#define PID_TO_PRINT(a) IP_TO_PRINT((a)->ip), (int)(a)->port, (int)(a)->pid, (a)->utime
29+
#define PID_TO_PRINT(a) IP_TO_PRINT((a)->ip), (int)(a)->port, (unsigned)(a)->pid, (a)->utime
3030
#define IP_TO_PRINT(a) ((a) >> 24) & 0xff, ((a) >> 16) & 0xff, ((a) >> 8) & 0xff, (a) & 0xff
3131

3232
#define IPV6_PRINT_STR "%s"

0 commit comments

Comments
 (0)