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/lttng.h>
40 #include "liblttsessiondcomm.h"
41 #include "ltt-sessiond.h"
45 #include "traceable-app.h"
49 * teardown: signal SIGTERM handler -> write into pipe. Threads waits
50 * with epoll on pipe and on other pipes/sockets for commands. Main
51 * simply waits on pthread join.
55 const char default_home_dir
[] = DEFAULT_HOME_DIR
;
56 const char default_tracing_group
[] = DEFAULT_TRACING_GROUP
;
57 const char default_ust_sock_dir
[] = DEFAULT_UST_SOCK_DIR
;
58 const char default_global_apps_pipe
[] = DEFAULT_GLOBAL_APPS_PIPE
;
60 /* Static functions */
61 static int check_existing_daemon(void);
62 static int ust_connect_app(pid_t pid
);
63 static int init_daemon_socket(void);
64 static int notify_apps(const char* name
);
65 static int process_client_msg(struct command_ctx
*cmd_ctx
);
66 static int send_unix_sock(int sock
, void *buf
, size_t len
);
67 static int set_signal_handler(void);
68 static int set_permissions(void);
69 static int setup_lttng_msg(struct command_ctx
*cmd_ctx
, size_t size
);
70 static int create_lttng_rundir(void);
71 static int set_kconsumerd_sockets(void);
72 static void cleanup(void);
73 static void sighandler(int sig
);
74 static void clean_command_ctx(struct command_ctx
*cmd_ctx
);
76 static void *thread_manage_clients(void *data
);
77 static void *thread_manage_apps(void *data
);
78 static void *thread_manage_kconsumerd(void *data
);
84 const char *opt_tracing_group
;
85 static int opt_sig_parent
;
86 static int opt_daemon
;
87 static int is_root
; /* Set to 1 if the daemon is running as root */
90 static char apps_unix_sock_path
[PATH_MAX
]; /* Global application Unix socket path */
91 static char client_unix_sock_path
[PATH_MAX
]; /* Global client Unix socket path */
92 static char kconsumerd_err_unix_sock_path
[PATH_MAX
]; /* kconsumerd error Unix socket path */
93 static char kconsumerd_cmd_unix_sock_path
[PATH_MAX
]; /* kconsumerd command Unix socket path */
95 static int client_sock
;
97 static int kconsumerd_err_sock
;
100 * thread_manage_kconsumerd
102 * This thread manage the kconsumerd error sent
103 * back to the session daemon.
105 static void *thread_manage_kconsumerd(void *data
)
109 DBG("[thread] Manage kconsumerd started");
111 ret
= lttcomm_listen_unix_sock(kconsumerd_err_sock
);
116 sock
= lttcomm_accept_unix_sock(kconsumerd_err_sock
);
122 //ret = lttcomm_recv_unix_sock(sock, &lsm, sizeof(lsm));
124 /* TODO: Consumerd died? */
136 * This thread manage the application socket communication
138 static void *thread_manage_apps(void *data
)
142 /* TODO: Something more elegant is needed but fine for now */
143 /* FIXME: change all types to either uint8_t, uint32_t, uint64_t
144 * for 32-bit vs 64-bit compat processes. */
145 /* replicate in ust with version number */
147 int reg
; /* 1:register, 0:unregister */
152 DBG("[thread] Manage apps started");
154 ret
= lttcomm_listen_unix_sock(apps_sock
);
159 /* Notify all applications to register */
160 notify_apps(default_global_apps_pipe
);
163 /* Blocking call, waiting for transmission */
164 sock
= lttcomm_accept_unix_sock(apps_sock
);
169 /* Basic recv here to handle the very simple data
170 * that the libust send to register (reg_msg).
172 ret
= recv(sock
, ®_msg
, sizeof(reg_msg
), 0);
178 /* Add application to the global traceable list */
179 if (reg_msg
.reg
== 1) {
181 ret
= register_traceable_app(reg_msg
.pid
, reg_msg
.uid
);
183 /* register_traceable_app only return an error with
184 * ENOMEM. At this point, we better stop everything.
190 unregister_traceable_app(reg_msg
.pid
);
200 * thread_manage_clients
202 * This thread manage all clients request using the unix
203 * client socket for communication.
205 static void *thread_manage_clients(void *data
)
208 struct command_ctx
*cmd_ctx
;
210 DBG("[thread] Manage client started");
212 ret
= lttcomm_listen_unix_sock(client_sock
);
217 /* Notify parent pid that we are ready
218 * to accept command for client side.
220 if (opt_sig_parent
) {
225 /* Blocking call, waiting for transmission */
226 DBG("Accepting client command ...");
227 sock
= lttcomm_accept_unix_sock(client_sock
);
232 /* Allocate context command to process the client request */
233 cmd_ctx
= malloc(sizeof(struct command_ctx
));
235 /* Allocate data buffer for reception */
236 cmd_ctx
->lsm
= malloc(sizeof(struct lttcomm_session_msg
));
238 cmd_ctx
->session
= NULL
;
241 * Data is received from the lttng client. The struct
242 * lttcomm_session_msg (lsm) contains the command and data request of
245 DBG("Receiving data from client ...");
246 ret
= lttcomm_recv_unix_sock(sock
, cmd_ctx
->lsm
, sizeof(struct lttcomm_session_msg
));
252 * This function dispatch the work to the kernel or userspace tracer
253 * libs and fill the lttcomm_lttng_msg data structure of all the needed
254 * informations for the client. The command context struct contains
255 * everything this function may needs.
257 ret
= process_client_msg(cmd_ctx
);
259 /* TODO: Inform client somehow of the fatal error. At this point,
260 * ret < 0 means that a malloc failed (ENOMEM). */
261 /* Error detected but still accept command */
262 clean_command_ctx(cmd_ctx
);
266 DBG("Sending response to client (size: %d)", cmd_ctx
->lttng_msg_size
);
267 ret
= send_unix_sock(sock
, cmd_ctx
->llm
, cmd_ctx
->lttng_msg_size
);
269 ERR("Failed to send data back to client");
272 clean_command_ctx(cmd_ctx
);
282 * Send data on a unix socket using the liblttsessiondcomm API.
284 * Return lttcomm error code.
286 static int send_unix_sock(int sock
, void *buf
, size_t len
)
288 /* Check valid length */
293 return lttcomm_send_unix_sock(sock
, buf
, len
);
299 * Free memory of a command context structure.
301 static void clean_command_ctx(struct command_ctx
*cmd_ctx
)
303 DBG("Clean command context structure %p", cmd_ctx
);
319 * Return a socket connected to the libust communication socket
320 * of the application identified by the pid.
322 * If the pid is not found in the traceable list,
323 * return -1 to indicate error.
325 static int ust_connect_app(pid_t pid
)
328 struct ltt_traceable_app
*lta
;
330 DBG("Connect to application pid %d", pid
);
332 lta
= find_app_by_pid(pid
);
335 DBG("Application pid %d not found", pid
);
339 sock
= ustctl_connect_pid(lta
->pid
);
341 ERR("Fail connecting to the PID %d\n", pid
);
350 * Notify apps by writing 42 to a named pipe using name.
351 * Every applications waiting for a ltt-sessiond will be notified
352 * and re-register automatically to the session daemon.
354 * Return open or write error value.
356 static int notify_apps(const char *name
)
361 DBG("Notify the global application pipe");
363 /* Try opening the global pipe */
364 fd
= open(name
, O_WRONLY
);
369 /* Notify by writing on the pipe */
370 ret
= write(fd
, "42", 2);
382 * Setup the outgoing data buffer for the response (llm) by allocating the
383 * right amount of memory and copying the original information from the lsm
386 * Return total size of the buffer pointed by buf.
388 static int setup_lttng_msg(struct command_ctx
*cmd_ctx
, size_t size
)
390 int ret
, buf_size
, trace_name_size
;
393 * Check for the trace_name. If defined, it's part of the payload data of
396 trace_name_size
= strlen(cmd_ctx
->lsm
->trace_name
);
397 buf_size
= trace_name_size
+ size
;
399 cmd_ctx
->llm
= malloc(sizeof(struct lttcomm_lttng_msg
) + buf_size
);
400 if (cmd_ctx
->llm
== NULL
) {
406 /* Copy common data */
407 cmd_ctx
->llm
->cmd_type
= cmd_ctx
->lsm
->cmd_type
;
408 cmd_ctx
->llm
->pid
= cmd_ctx
->lsm
->pid
;
409 if (!uuid_is_null(cmd_ctx
->lsm
->session_uuid
)) {
410 uuid_copy(cmd_ctx
->llm
->session_uuid
, cmd_ctx
->lsm
->session_uuid
);
413 cmd_ctx
->llm
->trace_name_offset
= trace_name_size
;
414 cmd_ctx
->llm
->data_size
= size
;
415 cmd_ctx
->lttng_msg_size
= sizeof(struct lttcomm_lttng_msg
) + buf_size
;
417 /* Copy trace name to the llm structure. Begining of the payload. */
418 memcpy(cmd_ctx
->llm
->payload
, cmd_ctx
->lsm
->trace_name
, trace_name_size
);
429 * Process the command requested by the lttng client within the command
430 * context structure. This function make sure that the return structure (llm)
431 * is set and ready for transmission before returning.
433 * Return any error encountered or 0 for success.
435 static int process_client_msg(struct command_ctx
*cmd_ctx
)
439 DBG("Processing client command %d", cmd_ctx
->lsm
->cmd_type
);
441 /* Check command that needs a session */
442 switch (cmd_ctx
->lsm
->cmd_type
) {
443 case LTTNG_CREATE_SESSION
:
444 case LTTNG_LIST_SESSIONS
:
448 cmd_ctx
->session
= find_session_by_uuid(cmd_ctx
->lsm
->session_uuid
);
449 if (cmd_ctx
->session
== NULL
) {
450 ret
= LTTCOMM_SELECT_SESS
;
456 /* Connect to ust apps if available pid */
457 if (cmd_ctx
->lsm
->pid
> 0) {
458 /* Connect to app using ustctl API */
459 cmd_ctx
->ust_sock
= ust_connect_app(cmd_ctx
->lsm
->pid
);
460 if (cmd_ctx
->ust_sock
< 0) {
461 ret
= LTTCOMM_NO_TRACEABLE
;
466 /* Process by command type */
467 switch (cmd_ctx
->lsm
->cmd_type
) {
468 case LTTNG_CREATE_SESSION
:
470 /* Setup lttng message with no payload */
471 ret
= setup_lttng_msg(cmd_ctx
, 0);
476 ret
= create_session(cmd_ctx
->lsm
->session_name
, &cmd_ctx
->llm
->session_uuid
);
479 ret
= LTTCOMM_EXIST_SESS
;
489 case LTTNG_DESTROY_SESSION
:
491 /* Setup lttng message with no payload */
492 ret
= setup_lttng_msg(cmd_ctx
, 0);
497 ret
= destroy_session(&cmd_ctx
->lsm
->session_uuid
);
499 ret
= LTTCOMM_NO_SESS
;
506 case LTTNG_LIST_TRACES
:
508 unsigned int trace_count
;
510 trace_count
= get_trace_count_per_session(cmd_ctx
->session
);
511 if (trace_count
== 0) {
512 ret
= LTTCOMM_NO_TRACE
;
516 ret
= setup_lttng_msg(cmd_ctx
, sizeof(struct lttng_trace
) * trace_count
);
521 get_traces_per_session(cmd_ctx
->session
,
522 (struct lttng_trace
*)(cmd_ctx
->llm
->payload
));
527 case UST_CREATE_TRACE
:
529 /* Setup lttng message with no payload */
530 ret
= setup_lttng_msg(cmd_ctx
, 0);
535 ret
= ust_create_trace(cmd_ctx
);
543 unsigned int app_count
;
545 app_count
= get_app_count();
546 DBG("Traceable application count : %d", app_count
);
547 if (app_count
== 0) {
548 ret
= LTTCOMM_NO_APPS
;
552 ret
= setup_lttng_msg(cmd_ctx
, sizeof(pid_t
) * app_count
);
557 get_app_list_pids((pid_t
*)(cmd_ctx
->llm
->payload
));
562 case UST_START_TRACE
:
564 /* Setup lttng message with no payload */
565 ret
= setup_lttng_msg(cmd_ctx
, 0);
570 ret
= ust_start_trace(cmd_ctx
);
578 /* Setup lttng message with no payload */
579 ret
= setup_lttng_msg(cmd_ctx
, 0);
584 ret
= ust_stop_trace(cmd_ctx
);
590 case LTTNG_LIST_SESSIONS
:
592 unsigned int session_count
;
594 session_count
= get_session_count();
595 if (session_count
== 0) {
596 ret
= LTTCOMM_NO_SESS
;
600 ret
= setup_lttng_msg(cmd_ctx
, sizeof(struct lttng_session
) * session_count
);
605 get_lttng_session((struct lttng_session
*)(cmd_ctx
->llm
->payload
));
611 /* Undefined command */
612 ret
= setup_lttng_msg(cmd_ctx
, 0);
621 /* Set return code */
622 cmd_ctx
->llm
->ret_code
= ret
;
627 DBG("Return code to client %d", ret
);
629 if (cmd_ctx
->llm
== NULL
) {
630 DBG("Missing llm structure. Allocating one.");
631 ret
= setup_lttng_msg(cmd_ctx
, 0);
636 /* Notify client of error */
637 cmd_ctx
->llm
->ret_code
= ret
;
644 * usage function on stderr
646 static void usage(void)
648 fprintf(stderr
, "Usage: %s OPTIONS\n\nOptions:\n", progname
);
649 fprintf(stderr
, " -h, --help Display this usage.\n");
650 fprintf(stderr
, " -c, --client-sock PATH Specify path for the client unix socket\n");
651 fprintf(stderr
, " -a, --apps-sock PATH Specify path for apps unix socket\n");
652 fprintf(stderr
, " --kconsumerd-err-sock PATH Specify path for the kernel consumer error socket\n");
653 fprintf(stderr
, " --kconsumerd-cmd-sock PATH Specify path for the kernel consumer command socket\n");
654 fprintf(stderr
, " -d, --daemonize Start as a daemon.\n");
655 fprintf(stderr
, " -g, --group NAME Specify the tracing group name. (default: tracing)\n");
656 fprintf(stderr
, " -V, --version Show version number.\n");
657 fprintf(stderr
, " -S, --sig-parent Send SIGCHLD to parent pid to notify readiness.\n");
658 fprintf(stderr
, " -q, --quiet No output at all.\n");
659 fprintf(stderr
, " -v, --verbose Verbose mode. Activate DBG() macro.\n");
663 * daemon argument parsing
665 static int parse_args(int argc
, char **argv
)
669 static struct option long_options
[] = {
670 { "client-sock", 1, 0, 'c' },
671 { "apps-sock", 1, 0, 'a' },
672 { "kconsumerd-cmd-sock", 1, 0, 0 },
673 { "kconsumerd-err-sock", 1, 0, 0 },
674 { "daemonize", 0, 0, 'd' },
675 { "sig-parent", 0, 0, 'S' },
676 { "help", 0, 0, 'h' },
677 { "group", 1, 0, 'g' },
678 { "version", 0, 0, 'V' },
679 { "quiet", 0, 0, 'q' },
680 { "verbose", 0, 0, 'v' },
685 int option_index
= 0;
686 c
= getopt_long(argc
, argv
, "dhqvVS" "a:c:g:s:E:C:", long_options
, &option_index
);
693 fprintf(stderr
, "option %s", long_options
[option_index
].name
);
695 fprintf(stderr
, " with arg %s\n", optarg
);
699 snprintf(client_unix_sock_path
, PATH_MAX
, "%s", optarg
);
702 snprintf(apps_unix_sock_path
, PATH_MAX
, "%s", optarg
);
708 opt_tracing_group
= strdup(optarg
);
714 fprintf(stdout
, "%s\n", VERSION
);
720 snprintf(kconsumerd_err_unix_sock_path
, PATH_MAX
, "%s", optarg
);
723 snprintf(kconsumerd_cmd_unix_sock_path
, PATH_MAX
, "%s", optarg
);
732 /* Unknown option or other error.
733 * Error is printed by getopt, just return */
744 * Creates the two needed socket by the daemon.
745 * apps_sock - The communication socket for all UST apps.
746 * client_sock - The communication of the cli tool (lttng).
748 static int init_daemon_socket()
753 old_umask
= umask(0);
755 /* Create client tool unix socket */
756 client_sock
= lttcomm_create_unix_sock(client_unix_sock_path
);
757 if (client_sock
< 0) {
758 ERR("Create unix sock failed: %s", client_unix_sock_path
);
763 /* File permission MUST be 660 */
764 ret
= chmod(client_unix_sock_path
, S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
);
766 ERR("Set file permissions failed: %s", client_unix_sock_path
);
771 /* Create the application unix socket */
772 apps_sock
= lttcomm_create_unix_sock(apps_unix_sock_path
);
774 ERR("Create unix sock failed: %s", apps_unix_sock_path
);
779 /* File permission MUST be 666 */
780 ret
= chmod(apps_unix_sock_path
, S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
| S_IROTH
| S_IWOTH
);
782 ERR("Set file permissions failed: %s", apps_unix_sock_path
);
793 * check_existing_daemon
795 * Check if the global socket is available.
796 * If yes, error is returned.
798 static int check_existing_daemon()
802 ret
= access(client_unix_sock_path
, F_OK
);
804 ret
= access(apps_unix_sock_path
, F_OK
);
813 * Return pointer to home directory path using
814 * the env variable HOME.
818 static const char *get_home_dir(void)
820 const char *home_path
;
822 if ((home_path
= (const char *) getenv("HOME")) == NULL
) {
823 home_path
= default_home_dir
;
832 * Set the tracing group gid onto the client socket.
834 * Race window between mkdir and chown is OK because we are going from
835 * less permissive (root.root) to more permissive (root.tracing).
837 static int set_permissions(void)
842 /* Decide which group name to use */
843 (opt_tracing_group
!= NULL
) ?
844 (grp
= getgrnam(opt_tracing_group
)) :
845 (grp
= getgrnam(default_tracing_group
));
848 ERR("Missing tracing group. Aborting execution.\n");
853 /* Set lttng run dir */
854 ret
= chown(LTTNG_RUNDIR
, 0, grp
->gr_gid
);
856 ERR("Unable to set group on " LTTNG_RUNDIR
);
860 /* lttng client socket path */
861 ret
= chown(client_unix_sock_path
, 0, grp
->gr_gid
);
863 ERR("Unable to set group on %s", client_unix_sock_path
);
867 /* kconsumerd error socket path */
868 ret
= chown(kconsumerd_err_unix_sock_path
, 0, grp
->gr_gid
);
870 ERR("Unable to set group on %s", kconsumerd_err_unix_sock_path
);
874 DBG("All permissions are set");
881 * create_lttng_rundir
883 * Create the lttng run directory needed for all
884 * global sockets and pipe.
886 static int create_lttng_rundir(void)
890 ret
= mkdir(LTTNG_RUNDIR
, S_IRWXU
| S_IRWXG
);
892 ERR("Unable to create " LTTNG_RUNDIR
);
901 * set_kconsumerd_sockets
903 * Setup sockets and directory needed by the kconsumerd
904 * communication with the session daemon.
906 static int set_kconsumerd_sockets(void)
910 if (strlen(kconsumerd_err_unix_sock_path
) == 0) {
911 snprintf(kconsumerd_err_unix_sock_path
, PATH_MAX
, KCONSUMERD_ERR_SOCK_PATH
);
914 if (strlen(kconsumerd_cmd_unix_sock_path
) == 0) {
915 snprintf(kconsumerd_cmd_unix_sock_path
, PATH_MAX
, KCONSUMERD_CMD_SOCK_PATH
);
918 ret
= mkdir(KCONSUMERD_PATH
, S_IRWXU
| S_IRWXG
);
920 ERR("Failed to create " KCONSUMERD_PATH
);
924 /* Create the kconsumerd error unix socket */
925 kconsumerd_err_sock
= lttcomm_create_unix_sock(kconsumerd_err_unix_sock_path
);
926 if (kconsumerd_err_sock
< 0) {
927 ERR("Create unix sock failed: %s", kconsumerd_err_unix_sock_path
);
932 /* File permission MUST be 660 */
933 ret
= chmod(kconsumerd_err_unix_sock_path
, S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
);
935 ERR("Set file permissions failed: %s", kconsumerd_err_unix_sock_path
);
947 * Setup signal handler for :
948 * SIGINT, SIGTERM, SIGPIPE
950 static int set_signal_handler(void)
956 if ((ret
= sigemptyset(&sigset
)) < 0) {
957 perror("sigemptyset");
961 sa
.sa_handler
= sighandler
;
964 if ((ret
= sigaction(SIGTERM
, &sa
, NULL
)) < 0) {
969 if ((ret
= sigaction(SIGINT
, &sa
, NULL
)) < 0) {
974 if ((ret
= sigaction(SIGPIPE
, &sa
, NULL
)) < 0) {
979 DBG("Signal handler set for SIGTERM, SIGPIPE and SIGINT");
987 * Signal handler for the daemon
989 static void sighandler(int sig
)
993 DBG("SIGPIPE catched");
996 DBG("SIGINT catched");
1000 DBG("SIGTERM catched");
1013 * Cleanup the daemon on exit
1015 static void cleanup()
1023 MSG("\n%c[%d;%dm*** assert failed *** ==> %c[%dm", 27,1,31,27,0);
1024 MSG("%c[%d;%dmMatthew, BEET driven development works!%c[%dm",27,1,33,27,0);
1027 unlink(client_unix_sock_path
);
1028 unlink(apps_unix_sock_path
);
1029 unlink(kconsumerd_err_unix_sock_path
);
1031 ret
= asprintf(&cmd
, "rm -rf " LTTNG_RUNDIR
);
1033 ERR("asprintf failed. Something is really wrong!");
1036 /* Remove lttng run directory */
1039 ERR("Unable to clean " LTTNG_RUNDIR
);
1046 int main(int argc
, char **argv
)
1051 pthread_t threads
[2];
1053 /* Parse arguments */
1055 if ((ret
= parse_args(argc
, argv
) < 0)) {
1068 /* Check if daemon is UID = 0 */
1069 is_root
= !getuid();
1071 /* Set all sockets path */
1073 ret
= create_lttng_rundir();
1078 if (strlen(apps_unix_sock_path
) == 0) {
1079 snprintf(apps_unix_sock_path
, PATH_MAX
,
1080 DEFAULT_GLOBAL_APPS_UNIX_SOCK
);
1083 if (strlen(client_unix_sock_path
) == 0) {
1084 snprintf(client_unix_sock_path
, PATH_MAX
,
1085 DEFAULT_GLOBAL_CLIENT_UNIX_SOCK
);
1088 ret
= set_kconsumerd_sockets();
1093 if (strlen(apps_unix_sock_path
) == 0) {
1094 snprintf(apps_unix_sock_path
, PATH_MAX
,
1095 DEFAULT_HOME_APPS_UNIX_SOCK
, get_home_dir());
1098 /* Set the cli tool unix socket path */
1099 if (strlen(client_unix_sock_path
) == 0) {
1100 snprintf(client_unix_sock_path
, PATH_MAX
,
1101 DEFAULT_HOME_CLIENT_UNIX_SOCK
, get_home_dir());
1105 DBG("Client socket path %s", client_unix_sock_path
);
1106 DBG("Application socket path %s", apps_unix_sock_path
);
1108 /* See if daemon already exist. If any of the two
1109 * socket needed by the daemon are present, this test fails
1111 if ((ret
= check_existing_daemon()) == 0) {
1112 ERR("Already running daemon.\n");
1113 /* We do not goto error because we must not
1114 * cleanup() because a daemon is already running.
1119 if (set_signal_handler() < 0) {
1123 /* Setup the needed unix socket */
1124 if (init_daemon_socket() < 0) {
1128 /* Set credentials to socket */
1129 if (is_root
&& (set_permissions() < 0)) {
1133 /* Get parent pid if -S, --sig-parent is specified. */
1134 if (opt_sig_parent
) {
1139 /* Create thread to manage the client socket */
1140 ret
= pthread_create(&threads
[0], NULL
, thread_manage_clients
, (void *) NULL
);
1142 perror("pthread_create");
1146 /* Create thread to manage application socket */
1147 ret
= pthread_create(&threads
[1], NULL
, thread_manage_apps
, (void *) NULL
);
1149 perror("pthread_create");
1153 for (i
= 0; i
< 2; i
++) {
1154 ret
= pthread_join(threads
[i
], &status
);
1156 perror("pthread_join");