Coverage Report

Created: 2026-07-30 06:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/opensips/pt.h
Line
Count
Source
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
enum profiling_proc_level {
40
  LEVEL_OFF = 0,
41
  LEVEL_SIP,
42
  LEVEL_EXTRAPROCS,
43
  LEVEL_TIMER,
44
  LEVEL_FULL = LEVEL_TIMER,
45
};
46
47
#include "pt_scaling.h"
48
49
struct process_table {
50
  /* the UNIX pid of this process */
51
  int pid;
52
  /* the type/group of this process - optional, used by dynamic forking */
53
  enum process_type type;
54
  void *pg_filter;
55
  /* name/description of the process (null terminated) */
56
  char desc[MAX_PT_DESC];
57
  /* various flags describing properties of this process */
58
  unsigned int flags;
59
60
  /* pipe used by the process to receive designated jobs (used by IPC)
61
   * [1] for writting into by other process,
62
   * [0] to listen on by this process */
63
  int ipc_pipe[2];
64
  /* same as above, but the holder used when the corresponding process
65
   * does not exist */
66
  int ipc_pipe_holder[2];
67
68
  /* pipe used by the process to receive a synchronoys job
69
   * this pipe should only be used by a process to synchronously receive a
70
   * message after he knows that some other process will send it for sure,
71
   * and there's no other job that can overlap in the meantime */
72
  int ipc_sync_pipe[2];
73
  /* same as above, but holder for non-existing processes */
74
  int ipc_sync_pipe_holder[2];
75
76
  /* logging level of this process */
77
  int log_level;
78
  /* used when resetting the log level */
79
  int default_log_level;
80
  /* used for suppressing the E_CORE_LOG event for new logs while handling
81
   * the event itself */
82
  int suppress_log_event;
83
  /* process-level profiling verbosity for this process */
84
  enum profiling_proc_level profiling_proc_level;
85
86
  /* statistics of this process - they do not change during runtime,
87
   * even when the proc is terminated or respawn - we just hide/unhide */
88
  stat_var *load_rt;
89
  stat_var *load_1m;
90
  stat_var *load_10m;
91
  stat_var *pkg_total;
92
  stat_var *pkg_used;
93
  stat_var *pkg_rused;
94
  stat_var *pkg_mused;
95
  stat_var *pkg_free;
96
  stat_var *pkg_frags;
97
98
  /* the load statistic of this process */
99
  struct proc_load_info load;
100
101
  /* synchronization during fork */
102
  atomic_t startup_result;
103
};
104
105
106
extern struct process_table *pt;
107
extern unsigned int counted_max_processes;
108
extern int _termination_in_progress;
109
110
int   init_multi_proc_support();
111
void  set_proc_attrs(const char *fmt, ...);
112
int   count_init_child_processes(void);
113
int   count_child_processes(void);
114
115
0
#define OSS_PROC_NO_IPC        (1<<0)
116
0
#define OSS_PROC_NO_LOAD       (1<<1)
117
0
#define OSS_PROC_NEEDS_SCRIPT  (1<<2)
118
0
#define OSS_PROC_IS_EXTRA      (1<<3)
119
0
#define OSS_PROC_DOING_DUMP    (1<<4) /* this process is writing a corefile */
120
0
#define OSS_PROC_DYNAMIC       (1<<5) /* proc was created at runtime */
121
0
#define OSS_PROC_IS_RUNNING    (1<<6) /* proc is running */
122
0
#define OSS_PROC_TO_TERMINATE  (1<<7) /* proc is waited to terminate */
123
0
#define OSS_PROC_SELFEXIT      (1<<8) /* proc does controlled exit */
124
125
#define is_process_running(_idx) \
126
0
  ( (pt[_idx].flags&OSS_PROC_IS_RUNNING)?1:0 )
127
128
struct internal_fork_params {
129
  const char *proc_desc;
130
  unsigned int flags;
131
  enum process_type type;
132
};
133
134
struct internal_fork_handler {
135
        const char *desc;
136
        struct {
137
            int (*in_child)(const struct internal_fork_params *);
138
            int (*in_parent)(void);
139
        } post_fork;
140
        struct internal_fork_handler *_next;
141
};
142
143
pid_t internal_fork(const struct internal_fork_params *params);
144
void register_fork_handler(struct internal_fork_handler *h);
145
int run_post_fork_handlers(void);
146
147
/* return processes pid */
148
inline static int my_pid(void)
149
0
{
150
0
  return pt ? pt[process_no].pid : getpid();
151
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: action.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: receive.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: profiling.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
152
153
/* Get the process internal ID based on its PID 
154
 * @return: -1 or the index of the given process */
155
inline static int get_process_ID_by_PID(pid_t pid)
156
0
{
157
0
  int i;
158
159
0
  for( i=0 ; i<counted_max_processes ; i++ )
160
0
    if (pt[i].pid==pid)
161
0
      return i;
162
163
0
  return -1;
164
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: action.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: receive.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: profiling.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
165
166
void reset_process_slot(int p_id);
167
168
void dynamic_process_final_exit(void);
169
170
#endif