Coverage Report

Created: 2025-07-11 06:28

/src/opensips/pt.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Process Table
3
 *
4
 * Copyright (C) 2001-2003 FhG Fokus
5
 * Copyright (C) 2008-2019 OpenSIPS Project
6
 *
7
 * This file is part of opensips, a free SIP server.
8
 *
9
 * opensips is free software; you can redistribute it and/or modify
10
 * it under the terms of the GNU General Public License as published by
11
 * the Free Software Foundation; either version 2 of the License, or
12
 * (at your option) any later version
13
 *
14
 * opensips is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22
 */
23
24
25
#ifndef _PT_H
26
#define _PT_H
27
28
#include <sys/types.h>
29
#include <unistd.h>
30
31
#include "atomic.h"
32
#include "pt_load.h"
33
34
0
#define MAX_PT_DESC 128
35
36
enum process_type { TYPE_NONE=0, TYPE_UDP, TYPE_TCP,
37
  TYPE_TIMER, TYPE_MODULE};
38
39
#include "pt_scaling.h"
40
41
struct process_table {
42
  /* the UNIX pid of this process */
43
  int pid;
44
  /* the type/group of this process - optional, used by dynamic forking */
45
  enum process_type type;
46
  void *pg_filter;
47
  /* name/description of the process (null terminated) */
48
  char desc[MAX_PT_DESC];
49
  /* various flags describing properties of this process */
50
  unsigned int flags;
51
52
  /* pipe used by the process to receive designated jobs (used by IPC)
53
   * [1] for writting into by other process,
54
   * [0] to listen on by this process */
55
  int ipc_pipe[2];
56
  /* same as above, but the holder used when the corresponding process
57
   * does not exist */
58
  int ipc_pipe_holder[2];
59
60
  /* pipe used by the process to receive a synchronoys job
61
   * this pipe should only be used by a process to synchronously receive a
62
   * message after he knows that some other process will send it for sure,
63
   * and there's no other job that can overlap in the meantime */
64
  int ipc_sync_pipe[2];
65
  /* same as above, but holder for non-existing processes */
66
  int ipc_sync_pipe_holder[2];
67
68
  /* holder for the unixsocks used by TCP layer for inter-proc communication;
69
   * used when the corresponding process does not exist */
70
  int tcp_socks_holder[2];
71
  /* unix socket on which TCP MAIN listens */
72
  int unix_sock;
73
74
  /* logging level of this process */
75
  int log_level;
76
  /* used when resetting the log level */
77
  int default_log_level;
78
  /* used for suppressing the E_CORE_LOG event for new logs while handling
79
   * the event itself */
80
  int suppress_log_event;
81
82
  /* statistics of this process - they do not change during runtime,
83
   * even when the proc is terminated or respawn - we just hide/unhide */
84
  stat_var *load_rt;
85
  stat_var *load_1m;
86
  stat_var *load_10m;
87
  stat_var *pkg_total;
88
  stat_var *pkg_used;
89
  stat_var *pkg_rused;
90
  stat_var *pkg_mused;
91
  stat_var *pkg_free;
92
  stat_var *pkg_frags;
93
94
  /* the load statistic of this process */
95
  struct proc_load_info load;
96
97
  /* synchronization during fork */
98
  atomic_t startup_result;
99
};
100
101
102
extern struct process_table *pt;
103
extern unsigned int counted_max_processes;
104
extern int _termination_in_progress;
105
106
int   init_multi_proc_support();
107
void  set_proc_attrs(const char *fmt, ...);
108
int   count_init_child_processes(void);
109
int   count_child_processes(void);
110
111
0
#define OSS_PROC_NO_IPC        (1<<0)
112
0
#define OSS_PROC_NO_LOAD       (1<<1)
113
0
#define OSS_PROC_NEEDS_SCRIPT  (1<<2)
114
0
#define OSS_PROC_IS_EXTRA      (1<<3)
115
0
#define OSS_PROC_DOING_DUMP    (1<<4) /* this process is writing a corefile */
116
0
#define OSS_PROC_DYNAMIC       (1<<5) /* proc was created at runtime */
117
0
#define OSS_PROC_IS_RUNNING    (1<<6) /* proc is running */
118
0
#define OSS_PROC_TO_TERMINATE  (1<<7) /* proc is waited to terminate */
119
0
#define OSS_PROC_SELFEXIT      (1<<8) /* proc does controlled exit */
120
121
#define is_process_running(_idx) \
122
0
  ( (pt[_idx].flags&OSS_PROC_IS_RUNNING)?1:0 )
123
124
struct internal_fork_params {
125
  const char *proc_desc;
126
  unsigned int flags;
127
  enum process_type type;
128
};
129
130
struct internal_fork_handler {
131
        const char *desc;
132
        struct {
133
            int (*in_child)(const struct internal_fork_params *);
134
            int (*in_parent)(void);
135
        } post_fork;
136
        struct internal_fork_handler *_next;
137
};
138
139
pid_t internal_fork(const struct internal_fork_params *params);
140
void register_fork_handler(struct internal_fork_handler *h);
141
int run_post_fork_handlers(void);
142
143
/* return processes pid */
144
inline static int my_pid(void)
145
0
{
146
0
  return pt ? pt[process_no].pid : getpid();
147
0
}
Unexecuted instantiation: dprint.c:my_pid
Unexecuted instantiation: pt.c:my_pid
Unexecuted instantiation: statistics.c:my_pid
Unexecuted instantiation: ipc.c:my_pid
Unexecuted instantiation: core_stats.c:my_pid
Unexecuted instantiation: pt_load.c:my_pid
Unexecuted instantiation: sr_module.c:my_pid
Unexecuted instantiation: db_insertq.c:my_pid
Unexecuted instantiation: proto_tcp.c:my_pid
Unexecuted instantiation: proto_udp.c:my_pid
Unexecuted instantiation: net_tcp_proc.c:my_pid
Unexecuted instantiation: net_tcp.c:my_pid
Unexecuted instantiation: tcp_common.c:my_pid
Unexecuted instantiation: net_udp.c:my_pid
Unexecuted instantiation: net_tcp_report.c:my_pid
Unexecuted instantiation: event_interface.c:my_pid
Unexecuted instantiation: async.c:my_pid
Unexecuted instantiation: daemonize.c:my_pid
Unexecuted instantiation: timer.c:my_pid
Unexecuted instantiation: reactor.c:my_pid
Unexecuted instantiation: io_wait.c:my_pid
Unexecuted instantiation: sr_module_deps.c:my_pid
Unexecuted instantiation: cfg_reload.c:my_pid
Unexecuted instantiation: socket_info.c:my_pid
Unexecuted instantiation: pt_scaling.c:my_pid
Unexecuted instantiation: signals.c:my_pid
Unexecuted instantiation: msg_translator.c:my_pid
Unexecuted instantiation: cfg.tab.c:my_pid
Unexecuted instantiation: shutdown.c:my_pid
148
149
/* Get the process internal ID based on its PID 
150
 * @return: -1 or the index of the given process */
151
inline static int get_process_ID_by_PID(pid_t pid)
152
0
{
153
0
  int i;
154
155
0
  for( i=0 ; i<counted_max_processes ; i++ )
156
0
    if (pt[i].pid==pid)
157
0
      return i;
158
159
0
  return -1;
160
0
}
Unexecuted instantiation: dprint.c:get_process_ID_by_PID
Unexecuted instantiation: pt.c:get_process_ID_by_PID
Unexecuted instantiation: statistics.c:get_process_ID_by_PID
Unexecuted instantiation: ipc.c:get_process_ID_by_PID
Unexecuted instantiation: core_stats.c:get_process_ID_by_PID
Unexecuted instantiation: pt_load.c:get_process_ID_by_PID
Unexecuted instantiation: sr_module.c:get_process_ID_by_PID
Unexecuted instantiation: db_insertq.c:get_process_ID_by_PID
Unexecuted instantiation: proto_tcp.c:get_process_ID_by_PID
Unexecuted instantiation: proto_udp.c:get_process_ID_by_PID
Unexecuted instantiation: net_tcp_proc.c:get_process_ID_by_PID
Unexecuted instantiation: net_tcp.c:get_process_ID_by_PID
Unexecuted instantiation: tcp_common.c:get_process_ID_by_PID
Unexecuted instantiation: net_udp.c:get_process_ID_by_PID
Unexecuted instantiation: net_tcp_report.c:get_process_ID_by_PID
Unexecuted instantiation: event_interface.c:get_process_ID_by_PID
Unexecuted instantiation: async.c:get_process_ID_by_PID
Unexecuted instantiation: daemonize.c:get_process_ID_by_PID
Unexecuted instantiation: timer.c:get_process_ID_by_PID
Unexecuted instantiation: reactor.c:get_process_ID_by_PID
Unexecuted instantiation: io_wait.c:get_process_ID_by_PID
Unexecuted instantiation: sr_module_deps.c:get_process_ID_by_PID
Unexecuted instantiation: cfg_reload.c:get_process_ID_by_PID
Unexecuted instantiation: socket_info.c:get_process_ID_by_PID
Unexecuted instantiation: pt_scaling.c:get_process_ID_by_PID
Unexecuted instantiation: signals.c:get_process_ID_by_PID
Unexecuted instantiation: msg_translator.c:get_process_ID_by_PID
Unexecuted instantiation: cfg.tab.c:get_process_ID_by_PID
Unexecuted instantiation: shutdown.c:get_process_ID_by_PID
161
162
void reset_process_slot(int p_id);
163
164
void dynamic_process_final_exit(void);
165
166
#endif