OSDN Git Service

(LibGoblin)
[drdeamon64/drdeamon64.git] / deamon / drd64_marshald_boot_debugd.c
1 /*DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64
2
3                          D r . D e a m o n  6 4
4                         for INTEL64(R), AMD64(R)
5         
6    Copyright(C) 2007-2009 Koine Yuusuke(koinec). All rights reserved.
7
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10
11  1. Redistributions of source code must retain the above copyright notice,
12     this list of conditions and the following disclaimer.
13  2. Redistributions in binary form must reproduce the above copyright
14     notice, this list of conditions and the following disclaimer in the
15     documentation and/or other materials provided with the distribution.
16
17 THIS SOFTWARE IS PROVIDED BY Koine Yuusuke(koinec) ``AS IS'' AND ANY
18 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL Koine Yuusuke(koinec) OR CONTRIBUTORS BE
21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
27 OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64*/
30
31 /* File Info -----------------------------------------------------------
32 File: drd64_.c
33 Function: 
34 Comment: 
35 ----------------------------------------------------------------------*/
36
37 #define DRD64_SRCID_MARSHALD_BOOT_DEBUGD        0x0000
38 #include"drd64_marshald.h"
39
40 #define DRD64_FUNCID_Marshald_Boot_Debugd       0x01
41
42 /*----------------------------------------------------------------------
43 ----------------------------------------------------------------------*/
44 int
45         Drd64_Marshald_Boot_Debugd(
46                 char    *pstr_sockname_debugd,
47                 int             i_prog_pid,
48                 int             i_request_rid,
49                 int             i_attach_cid )
50 {
51         int             i_pid_debugd;
52         char    str_sockname[DRD64_MAX_PATH+1];
53         char    str_pid_debugd[10];
54         char    str_request_fd[10];
55         char    str_debugd_connect_id[10];
56         DWord   dw_errcode;
57         DWord   dw_location;
58
59         DRD64_LOG_DEBUG("  [DEBUG] Boot Debugd Start");
60
61         /* Phase 0 : Init ----------------------------*/
62         dw_errcode      = DRD64_ERROR_CODE_CLEAR;
63         dw_location     = DRD64_ERROR_SET_LOCATION(
64                                                 DRD64_ERROR_MODULE_MARSHALD,
65                                                 DRD64_ERROR_ARCH_NODEPEND,
66                                                 DRD64_SRCID_MARSHALD_BOOT_DEBUGD,
67                                                 DRD64_FUNCID_Marshald_Boot_Debugd );
68
69         /* Phase 1 : Generate Debugd Param -----------*/
70         /* n : socketname(PF_UNIX) for debugd<=>Client */
71         strcpy( str_sockname, "/tmp/tmpdrd64debugd_client_XXXXXXXXXX" );
72         if( NULL == mktemp( str_sockname ))     {
73                 dw_errcode  = DRD64_ERROR_SET_CODE(
74                                                         DRD64_ERROR_TYPE_ERROR,
75                                                         DRD64_ERROR_PTN_SYSCALL,
76                                                         0x00, 0x01 );
77                 //Drd64_LibBrownie_Error_SetErrorInfo( dw_errcode, dw_location, errno );
78
79                 return -0x02;
80         }
81
82         /* a : attach pid => p_attach->i_prog_pid */
83         snprintf( str_pid_debugd, 10, "%d", i_prog_pid );
84
85         /* r : request fd */
86         snprintf( str_request_fd, 10, "%d", i_request_rid );
87
88         /* m : to Debugd ConnectInfo ID */
89         snprintf( str_debugd_connect_id, 10, "%d", i_attach_cid );
90
91         /* XXX c : coredump file */
92
93
94         /* Phase 2 : Exec debugd ----------------------*/
95         i_pid_debugd    = fork();
96         /* fork error */
97         if( 0 > i_pid_debugd )  {
98                 dw_errcode  = DRD64_ERROR_SET_CODE(
99                                                         DRD64_ERROR_TYPE_ERROR,
100                                                         DRD64_ERROR_PTN_SYSCALL,
101                                                         0x00, 0x02 );
102                 //Drd64_LibBrownie_Error_SetErrorInfo( dw_errcode, dw_location, errno );
103
104                 return i_pid_debugd;
105         }
106         /* child Proc. */
107         else if( 0 == i_pid_debugd )    {
108                 /* XXX */
109                 execl( drd64_marshald_info.str_path_debugd,
110                                 DRD64_MODULENAME_DEBUGD,
111                                 "-n", str_sockname,
112                                 "-r", str_request_fd,
113                                 "-m", str_debugd_connect_id,
114                                 "-a", str_pid_debugd, NULL );
115                 exit( 0 );
116         }
117
118         /* Parent Proc. */
119         strncpy( pstr_sockname_debugd, str_sockname, DRD64_MAX_PATH );
120
121         DRD64_LOG_DEBUG("  [DEBUG] Boot Debugd Ended");
122
123         return i_pid_debugd;
124 }
125
126
127 /* EOF of drd64_.c ----------------------------------- */