2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #include <sys/socket.h>
33 #include <sys/types.h>
36 #include <urcu/list.h> /* URCU list library (-lurcu) */
37 #include <ust/ustctl.h> /* UST control lib (-lust) */
38 #include <lttng/liblttngctl.h>
40 #include "liblttsessiondcomm.h"
41 #include "ltt-sessiond.h"
45 const char default_home_dir
[] = DEFAULT_HOME_DIR
;
46 const char default_tracing_group
[] = DEFAULT_TRACING_GROUP
;
47 const char default_ust_sock_dir
[] = DEFAULT_UST_SOCK_DIR
;
48 const char default_global_apps_pipe
[] = DEFAULT_GLOBAL_APPS_PIPE
;
50 /* Static functions */
51 static int set_signal_handler(void);
52 static int set_socket_perms(void);
53 static void sighandler(int sig
);
54 static void cleanup(void);
55 static void copy_common_data(struct lttcomm_lttng_msg
*llm
, struct lttcomm_session_msg
*lsm
);
56 static int check_existing_daemon(void);
57 static int notify_apps(const char* name
);
58 static int connect_app(pid_t pid
);
59 static int find_app_by_pid(pid_t pid
);
60 static int init_daemon_socket(void);
61 static int process_client_msg(int sock
, struct lttcomm_session_msg
*);
62 static int send_unix_sock(int sock
, void *buf
, size_t len
);
63 static int setup_data_buffer(char **buf
, size_t size
, struct lttcomm_lttng_msg
*llm
);
64 static void add_traceable_app(struct ltt_traceable_app
*lta
);
65 static void del_traceable_app(struct ltt_traceable_app
*lta
);
66 static void add_session_list(struct ltt_session
*ls
);
67 static void del_session_list(struct ltt_session
*ls
);
69 /* Command function */
70 static void get_list_apps(pid_t
*pids
);
71 static void get_list_sessions(struct lttng_session
*lt
);
73 static void *thread_manage_clients(void *data
);
74 static void *thread_manage_apps(void *data
);
76 static int create_session(char *name
, uuid_t
*session_id
);
77 static int destroy_session(uuid_t
*uuid
);
79 static struct ltt_session
*find_session_by_uuid(uuid_t session_id
);
80 static struct ltt_session
*find_session_by_name(char *name
);
84 const char *opt_tracing_group
;
85 static int opt_sig_parent
;
86 static int opt_daemon
;
89 static int is_root
; /* Set to 1 if the daemon is running as root */
92 static char apps_unix_sock_path
[PATH_MAX
]; /* Global application Unix socket path */
93 static char client_unix_sock_path
[PATH_MAX
]; /* Global client Unix socket path */
95 static int client_socket
;
96 static int apps_socket
;
98 static struct ltt_session
*current_session
;
100 /* Number of element for the list below. */
101 static unsigned int session_count
;
102 static unsigned int traceable_app_count
;
104 /* Init session's list */
105 static struct ltt_session_list ltt_session_list
= {
106 .head
= CDS_LIST_HEAD_INIT(ltt_session_list
.head
),
109 /* Init ust traceabl application's list */
110 static struct ltt_traceable_app_list ltt_traceable_app_list
= {
111 .head
= CDS_LIST_HEAD_INIT(ltt_traceable_app_list
.head
),
115 pthread_mutex_t ltt_traceable_app_list_mutex
;
120 * This thread manage the application socket communication
122 static void *thread_manage_apps(void *data
)
125 struct ltt_traceable_app
*lta
;
127 /* TODO: Something more elegant is needed but fine for now */
129 int reg
; /* 1:register, 0:unregister */
134 /* Notify all applications to register */
135 notify_apps(default_global_apps_pipe
);
137 ret
= lttcomm_listen_unix_sock(apps_socket
);
143 /* Blocking call, waiting for transmission */
144 sock
= lttcomm_accept_unix_sock(apps_socket
);
149 /* Basic recv here to handle the very simple data
150 * that the libust send to register (reg_msg).
152 ret
= recv(sock
, ®_msg
, sizeof(reg_msg
), 0);
158 /* Add application to the global traceable list */
159 if (reg_msg
.reg
== 1) {
161 lta
= malloc(sizeof(struct ltt_traceable_app
));
162 lta
->pid
= reg_msg
.pid
;
163 lta
->uid
= reg_msg
.uid
;
164 add_traceable_app(lta
);
167 cds_list_for_each_entry(lta
, <t_traceable_app_list
.head
, list
) {
168 if (lta
->pid
== reg_msg
.pid
&& lta
->uid
== reg_msg
.uid
) {
169 del_traceable_app(lta
);
183 * thread_manage_clients
185 * This thread manage all clients request using the unix
186 * client socket for communication.
188 static void *thread_manage_clients(void *data
)
191 struct lttcomm_session_msg lsm
;
193 ret
= lttcomm_listen_unix_sock(client_socket
);
198 /* Notify parent pid that we are ready
199 * to accept command for client side.
201 if (opt_sig_parent
) {
206 /* Blocking call, waiting for transmission */
207 sock
= lttcomm_accept_unix_sock(client_socket
);
213 * Data is received from the lttng client. The struct
214 * lttcomm_session_msg (lsm) contains the command and data
215 * request of the client.
217 ret
= lttcomm_recv_unix_sock(sock
, &lsm
, sizeof(lsm
));
222 /* This function dispatch the work to the LTTng or UST libs
223 * and then sends back the response to the client. This is needed
224 * because there might be more then one lttcomm_lttng_msg to
225 * send out so process_client_msg do both jobs.
227 ret
= process_client_msg(sock
, &lsm
);
229 /* Error detected but still accept command */
241 * Add a traceable application structure to the global
242 * list protected by a mutex.
244 static void add_traceable_app(struct ltt_traceable_app
*lta
)
246 pthread_mutex_lock(<t_traceable_app_list_mutex
);
247 cds_list_add(<a
->list
, <t_traceable_app_list
.head
);
248 traceable_app_count
++;
249 pthread_mutex_unlock(<t_traceable_app_list_mutex
);
255 * Delete a traceable application structure from the
256 * global list protected by a mutex.
258 static void del_traceable_app(struct ltt_traceable_app
*lta
)
260 pthread_mutex_lock(<t_traceable_app_list_mutex
);
261 cds_list_del(<a
->list
);
263 if (traceable_app_count
!= 0) {
264 traceable_app_count
--;
266 pthread_mutex_unlock(<t_traceable_app_list_mutex
);
272 * Add a ltt_session structure to the global list.
274 static void add_session_list(struct ltt_session
*ls
)
276 cds_list_add(&ls
->list
, <t_session_list
.head
);
283 * Delete a ltt_session structure to the global list.
285 static void del_session_list(struct ltt_session
*ls
)
287 cds_list_del(&ls
->list
);
289 if (session_count
!= 0) {
297 * Send data on a unix socket using the liblttsessiondcomm API.
299 * Return lttcomm error code.
301 static int send_unix_sock(int sock
, void *buf
, size_t len
)
303 /* Check valid length */
308 return lttcomm_send_unix_sock(sock
, buf
, len
);
314 * Return a socket connected to the libust communication socket
315 * of the application identified by the pid.
317 * If the pid is not found in the traceable list,
318 * return -1 to indicate error.
320 static int connect_app(pid_t pid
)
324 ret
= find_app_by_pid(pid
);
329 sock
= ustctl_connect_pid(pid
);
331 ERR("Fail connecting to the PID %d\n", pid
);
340 * Notify apps by writing 42 to a named pipe using name.
341 * Every applications waiting for a ltt-sessiond will be notified
342 * and re-register automatically to the session daemon.
344 * Return open or write error value.
346 static int notify_apps(const char *name
)
351 /* Try opening the global pipe */
352 fd
= open(name
, O_WRONLY
);
357 /* Notify by writing on the pipe */
358 ret
= write(fd
, "42", 2);
370 * Iterate over the traceable apps list.
371 * On success, return 1, else return 0
373 static int find_app_by_pid(pid_t pid
)
375 struct ltt_traceable_app
*iter
;
377 pthread_mutex_lock(<t_traceable_app_list_mutex
);
378 cds_list_for_each_entry(iter
, <t_traceable_app_list
.head
, list
) {
379 if (iter
->pid
== pid
) {
380 pthread_mutex_unlock(<t_traceable_app_list_mutex
);
385 pthread_mutex_unlock(<t_traceable_app_list_mutex
);
391 * find_session_by_uuid
393 * Return a ltt_session structure ptr that matches the uuid.
395 static struct ltt_session
*find_session_by_uuid(uuid_t session_id
)
398 struct ltt_session
*iter
;
400 /* Sanity check for NULL session_id */
401 if (uuid_is_null(session_id
)) {
405 cds_list_for_each_entry(iter
, <t_session_list
.head
, list
) {
406 if (uuid_compare(iter
->uuid
, session_id
) == 0) {
420 * find_session_by_name
422 * Return a ltt_session structure ptr that matches name.
423 * If no session found, NULL is returned.
425 static struct ltt_session
*find_session_by_name(char *name
)
428 struct ltt_session
*iter
;
430 cds_list_for_each_entry(iter
, <t_session_list
.head
, list
) {
431 if (strncmp(iter
->name
, name
, strlen(iter
->name
)) == 0) {
447 * Delete session from the global session list
448 * and free the memory.
450 * Return -1 if no session is found.
451 * On success, return 1;
453 static int destroy_session(uuid_t
*uuid
)
456 struct ltt_session
*iter
;
458 cds_list_for_each_entry(iter
, <t_session_list
.head
, list
) {
459 if (uuid_compare(iter
->uuid
, *uuid
) == 0) {
460 del_session_list(iter
);
473 * Create a brand new session and add it to the
474 * global session list.
476 static int create_session(char *name
, uuid_t
*session_id
)
478 struct ltt_session
*new_session
;
480 new_session
= find_session_by_name(name
);
481 if (new_session
!= NULL
) {
485 /* Allocate session data structure */
486 new_session
= malloc(sizeof(struct ltt_session
));
487 if (new_session
== NULL
) {
493 if (asprintf(&new_session
->name
, "%s", name
) < 0) {
497 /* Generate session name based on the session count */
498 if (asprintf(&new_session
->name
, "%s%d", "lttng-", session_count
) < 0) {
503 /* UUID generation */
504 uuid_generate(new_session
->uuid
);
505 uuid_copy(*session_id
, new_session
->uuid
);
507 /* Set consumer (identifier) to 0. This means that there is
508 * NO consumer attach to that session yet.
510 new_session
->ust_consumer
= 0;
511 new_session
->lttng_consumer
= 0;
514 CDS_INIT_LIST_HEAD(&new_session
->ust_traces
);
515 CDS_INIT_LIST_HEAD(&new_session
->lttng_traces
);
517 /* Add new session to the global session list */
518 add_session_list(new_session
);
532 * Create an userspace trace using pid.
533 * This trace is then appended to the current session
536 static int ust_create_trace(pid_t pid
)
539 struct ltt_ust_trace
*trace
;
541 trace
= malloc(sizeof(struct ltt_ust_trace
));
552 /* Connect to app using ustctl API */
553 sock
= connect_app(pid
);
555 ret
= LTTCOMM_NO_TRACEABLE
;
559 ret
= ustctl_create_trace(sock
, "auto");
561 ret
= LTTCOMM_CREATE_FAIL
;
565 /* Check if current session is valid */
566 if (current_session
) {
567 cds_list_add(&trace
->list
, ¤t_session
->ust_traces
);
577 * List traceable user-space application and fill an
580 static void get_list_apps(pid_t
*pids
)
583 struct ltt_traceable_app
*iter
;
585 /* Protected by a mutex here because the threads manage_client
586 * and manage_apps can access this list.
588 pthread_mutex_lock(<t_traceable_app_list_mutex
);
589 cds_list_for_each_entry(iter
, <t_traceable_app_list
.head
, list
) {
593 pthread_mutex_unlock(<t_traceable_app_list_mutex
);
599 * List sessions and fill the data buffer.
601 static void get_list_sessions(struct lttng_session
*lt
)
604 struct ltt_session
*iter
;
605 struct lttng_session lsess
;
607 /* Iterate over session list and append data after
608 * the control struct in the buffer.
610 cds_list_for_each_entry(iter
, <t_session_list
.head
, list
) {
611 /* Copy name and uuid */
612 uuid_unparse(iter
->uuid
, lsess
.uuid
);
613 strncpy(lsess
.name
, iter
->name
, sizeof(lsess
.name
));
614 lsess
.name
[sizeof(lsess
.name
) - 1] = '\0';
615 memcpy(<
[i
], &lsess
, sizeof(lsess
));
617 /* Reset struct for next pass */
618 memset(&lsess
, 0, sizeof(lsess
));
625 * Copy common data between lttcomm_lttng_msg and lttcomm_session_msg
627 static void copy_common_data(struct lttcomm_lttng_msg
*llm
, struct lttcomm_session_msg
*lsm
)
629 llm
->cmd_type
= lsm
->cmd_type
;
633 if (!uuid_is_null(lsm
->session_id
)) {
634 uuid_copy(llm
->session_id
, lsm
->session_id
);
637 strncpy(llm
->trace_name
, lsm
->trace_name
, strlen(llm
->trace_name
));
638 llm
->trace_name
[strlen(llm
->trace_name
) - 1] = '\0';
644 * Setup the outgoing data buffer for the response
645 * data allocating the right amount of memory.
647 * Return total size of the buffer pointed by buf.
649 static int setup_data_buffer(char **buf
, size_t s_data
, struct lttcomm_lttng_msg
*llm
)
654 buf_size
= sizeof(struct lttcomm_lttng_msg
) + s_data
;
655 *buf
= malloc(buf_size
);
662 /* Setup lttcomm_lttng_msg data and copy
663 * it to the newly allocated buffer.
665 llm
->size_payload
= s_data
;
666 memcpy(*buf
, llm
, sizeof(struct lttcomm_lttng_msg
));
677 * This takes the lttcomm_session_msg struct and process the command requested
678 * by the client. It then creates response(s) and send it back to the
679 * given socket (sock).
681 * Return any error encountered or 0 for success.
683 static int process_client_msg(int sock
, struct lttcomm_session_msg
*lsm
)
687 char *send_buf
= NULL
;
688 struct lttcomm_lttng_msg llm
;
690 /* Copy common data to identify the response
691 * on the lttng client side.
693 copy_common_data(&llm
, lsm
);
695 /* Check command that needs a session */
696 if (lsm
->cmd_type
!= LTTNG_CREATE_SESSION
&&
697 lsm
->cmd_type
!= LTTNG_LIST_SESSIONS
&&
698 lsm
->cmd_type
!= UST_LIST_APPS
)
700 current_session
= find_session_by_uuid(lsm
->session_id
);
701 if (current_session
== NULL
) {
702 ret
= LTTCOMM_SELECT_SESS
;
708 /* Default return code.
709 * In our world, everything is OK... right? ;)
711 llm
.ret_code
= LTTCOMM_OK
;
713 /* Process by command type */
714 switch (lsm
->cmd_type
) {
715 case LTTNG_CREATE_SESSION
:
717 ret
= create_session(lsm
->session_name
, &llm
.session_id
);
720 ret
= LTTCOMM_EXIST_SESS
;
727 buf_size
= setup_data_buffer(&send_buf
, 0, &llm
);
735 case LTTNG_DESTROY_SESSION
:
737 ret
= destroy_session(&lsm
->session_id
);
739 ret
= LTTCOMM_NO_SESS
;
744 /* No auxiliary data so only send the llm struct. */
747 case UST_CREATE_TRACE
:
749 ret
= ust_create_trace(lsm
->pid
);
751 ret
= LTTCOMM_CREATE_FAIL
;
755 /* No auxiliary data so only send the llm struct. */
760 /* Stop right now if no apps */
761 if (traceable_app_count
== 0) {
762 ret
= LTTCOMM_NO_APPS
;
766 /* Setup data buffer and details for transmission */
767 buf_size
= setup_data_buffer(&send_buf
,
768 sizeof(pid_t
) * traceable_app_count
, &llm
);
774 get_list_apps((pid_t
*)(send_buf
+ sizeof(struct lttcomm_lttng_msg
)));
778 case LTTNG_LIST_SESSIONS
:
780 /* Stop right now if no session */
781 if (session_count
== 0) {
782 ret
= LTTCOMM_NO_SESS
;
786 /* Setup data buffer and details for transmission */
787 buf_size
= setup_data_buffer(&send_buf
,
788 (sizeof(struct lttng_session
) * session_count
), &llm
);
794 get_list_sessions((struct lttng_session
*)(send_buf
+ sizeof(struct lttcomm_lttng_msg
)));
800 /* Undefined command */
806 ret
= send_unix_sock(sock
, send_buf
, buf_size
);
808 if (send_buf
!= NULL
) {
815 /* Notify client of error */
817 llm
.size_payload
= 0;
818 send_unix_sock(sock
, (void*) &llm
, sizeof(llm
));
824 * usage function on stderr
826 static void usage(void)
828 fprintf(stderr
, "Usage: %s OPTIONS\n\nOptions:\n", progname
);
829 fprintf(stderr
, " -h, --help Display this usage.\n");
830 fprintf(stderr
, " -c, --client-sock PATH Specify path for the client unix socket\n");
831 fprintf(stderr
, " -a, --apps-sock PATH Specify path for apps unix socket.\n");
832 fprintf(stderr
, " -d, --daemonize Start as a daemon.\n");
833 fprintf(stderr
, " -g, --group NAME Specify the tracing group name. (default: tracing)\n");
834 fprintf(stderr
, " -V, --version Show version number.\n");
835 fprintf(stderr
, " -S, --sig-parent Send SIGCHLD to parent pid to notify readiness.\n");
836 fprintf(stderr
, " -q, --quiet No output at all.\n");
840 * daemon argument parsing
842 static int parse_args(int argc
, char **argv
)
846 static struct option long_options
[] = {
847 { "client-sock", 1, 0, 'c' },
848 { "apps-sock", 1, 0, 'a' },
849 { "daemonize", 0, 0, 'd' },
850 { "sig-parent", 0, 0, 'S' },
851 { "help", 0, 0, 'h' },
852 { "group", 1, 0, 'g' },
853 { "version", 0, 0, 'V' },
854 { "quiet", 0, 0, 'q' },
859 int option_index
= 0;
860 c
= getopt_long(argc
, argv
, "dhqVS" "a:c:g:s:", long_options
, &option_index
);
867 fprintf(stderr
, "option %s", long_options
[option_index
].name
);
869 fprintf(stderr
, " with arg %s\n", optarg
);
873 snprintf(client_unix_sock_path
, PATH_MAX
, "%s", optarg
);
876 snprintf(apps_unix_sock_path
, PATH_MAX
, "%s", optarg
);
882 opt_tracing_group
= strdup(optarg
);
888 fprintf(stdout
, "%s\n", VERSION
);
897 /* Unknown option or other error.
898 * Error is printed by getopt, just return */
909 * Creates the two needed socket by the daemon.
910 * apps_socket - The communication socket for all UST apps.
911 * client_socket - The communication of the cli tool (lttng).
913 static int init_daemon_socket()
918 old_umask
= umask(0);
920 /* Create client tool unix socket */
921 client_socket
= lttcomm_create_unix_sock(client_unix_sock_path
);
922 if (client_socket
< 0) {
927 /* File permission MUST be 660 */
928 ret
= chmod(client_unix_sock_path
, S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
);
934 /* Create the application unix socket */
935 apps_socket
= lttcomm_create_unix_sock(apps_unix_sock_path
);
936 if (apps_socket
< 0) {
941 /* File permission MUST be 660 */
942 ret
= chmod(apps_unix_sock_path
, S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
| S_IROTH
| S_IWOTH
);
954 * check_existing_daemon
956 * Check if the global socket is available.
957 * If yes, error is returned.
959 static int check_existing_daemon()
963 ret
= access(client_unix_sock_path
, F_OK
);
965 ret
= access(apps_unix_sock_path
, F_OK
);
974 * Return pointer to home directory path using
975 * the env variable HOME.
979 static const char *get_home_dir(void)
981 const char *home_path
;
983 if ((home_path
= (const char *) getenv("HOME")) == NULL
) {
984 home_path
= default_home_dir
;
993 * Set the tracing group gid onto the client socket.
995 static int set_socket_perms(void)
1000 /* Decide which group name to use */
1001 (opt_tracing_group
!= NULL
) ?
1002 (grp
= getgrnam(opt_tracing_group
)) :
1003 (grp
= getgrnam(default_tracing_group
));
1006 ERR("Missing tracing group. Aborting execution.\n");
1011 ret
= chown(client_unix_sock_path
, 0, grp
->gr_gid
);
1021 * set_signal_handler
1023 * Setup signal handler for :
1024 * SIGINT, SIGTERM, SIGPIPE
1026 static int set_signal_handler(void)
1029 struct sigaction sa
;
1032 if ((ret
= sigemptyset(&sigset
)) < 0) {
1033 perror("sigemptyset");
1037 sa
.sa_handler
= sighandler
;
1038 sa
.sa_mask
= sigset
;
1040 if ((ret
= sigaction(SIGTERM
, &sa
, NULL
)) < 0) {
1041 perror("sigaction");
1045 if ((ret
= sigaction(SIGINT
, &sa
, NULL
)) < 0) {
1046 perror("sigaction");
1050 if ((ret
= sigaction(SIGPIPE
, &sa
, NULL
)) < 0) {
1051 perror("sigaction");
1061 * Signal handler for the daemon
1063 static void sighandler(int sig
)
1082 * Cleanup the daemon on exit
1084 static void cleanup()
1087 MSG("\n%c[%d;%dm*** assert failed *** ==> %c[%dm", 27,1,31,27,0);
1088 MSG("%c[%d;%dmMatthew, BEET driven development works!%c[%dm",27,1,33,27,0);
1091 unlink(client_unix_sock_path
);
1092 unlink(apps_unix_sock_path
);
1098 int main(int argc
, char **argv
)
1103 pthread_t threads
[2];
1105 /* Parse arguments */
1107 if ((ret
= parse_args(argc
, argv
) < 0)) {
1120 /* Check if daemon is UID = 0 */
1121 is_root
= !getuid();
1123 /* Set all sockets path */
1125 if (strlen(apps_unix_sock_path
) == 0) {
1126 (snprintf(apps_unix_sock_path
, PATH_MAX
,
1127 DEFAULT_GLOBAL_APPS_UNIX_SOCK
));
1130 if (strlen(client_unix_sock_path
) == 0) {
1131 (snprintf(client_unix_sock_path
, PATH_MAX
,
1132 DEFAULT_GLOBAL_CLIENT_UNIX_SOCK
));
1135 if (strlen(apps_unix_sock_path
) == 0) {
1136 (snprintf(apps_unix_sock_path
, PATH_MAX
,
1137 DEFAULT_HOME_APPS_UNIX_SOCK
, get_home_dir()));
1140 /* Set the cli tool unix socket path */
1141 if (strlen(client_unix_sock_path
) == 0) {
1142 (snprintf(client_unix_sock_path
, PATH_MAX
,
1143 DEFAULT_HOME_CLIENT_UNIX_SOCK
, get_home_dir()));
1147 /* See if daemon already exist. If any of the two
1148 * socket needed by the daemon are present, this test fails
1150 if ((ret
= check_existing_daemon()) == 0) {
1151 ERR("Already running daemon.\n");
1152 /* We do not goto error because we must not
1153 * cleanup() because a daemon is already working.
1155 return EXIT_FAILURE
;
1158 if (set_signal_handler() < 0) {
1162 /* Setup the two needed unix socket */
1163 if (init_daemon_socket() < 0) {
1167 /* Set credentials to socket */
1168 if (is_root
&& (set_socket_perms() < 0)) {
1172 /* Get parent pid if -S, --sig-parent is specified. */
1173 if (opt_sig_parent
) {
1178 /* Create thread to manage the client socket */
1179 ret
= pthread_create(&threads
[0], NULL
, thread_manage_clients
, (void *) NULL
);
1181 perror("pthread_create");
1185 /* Create thread to manage application socket */
1186 ret
= pthread_create(&threads
[1], NULL
, thread_manage_apps
, (void *) NULL
);
1188 perror("pthread_create");
1192 for (i
= 0; i
< 2; i
++) {
1193 ret
= pthread_join(threads
[i
], &status
);
1195 perror("pthread_join");
1207 return EXIT_FAILURE
;