30 #include <sys/types.h> 55 char *l_name_ptr =
NULL;
57 memset(l_exe_link, 0,
sizeof(l_exe_link));
58 snprintf(l_exe_link,
sizeof(l_exe_link) - 1,
"/proc/%d/exe", p_pid);
60 if (readlink(l_exe_link,
g_buffer, p_exec_name_maxsize) < 0)
66 memset(p_exec_name, 0, p_exec_name_maxsize);
67 strncpy(p_exec_name, l_name_ptr + 1, p_exec_name_maxsize - 1);
90 fprintf(p_fout,
"\n==== Dumping file <%s> ====\n", p_src_filename);
92 if ((l_fin = fopen(p_src_filename,
"rt")) ==
NULL)
94 syslog(LOG_ERR,
"ERR opening info file '%s' for dumping [%s]",
98 fprintf(p_fout,
"**error**\n");
109 for (i = 0; i < bytes_read; i++)
115 fwrite(
g_buffer, 1, bytes_read, p_fout);
118 syslog(LOG_ERR,
"Writing in context file failed [%s]", strerror(errno));
129 syslog(LOG_ERR,
"reading '%s' failed [%s]", p_src_filename, strerror(errno));
137 fprintf(p_fout,
"\n");
208 str[1] = mode & S_IRUSR ?
'r' :
'-';
209 str[2] = mode & S_IWUSR ?
'w' :
'-';
210 str[3] = (mode & S_ISUID
211 ? (mode & S_IXUSR ?
's' :
'S')
213 (mode & S_IXUSR ?
'x' :
'-'));
214 str[4] = mode & S_IRGRP ?
'r' :
'-';
215 str[5] = mode & S_IWGRP ?
'w' :
'-';
216 str[6] = (mode & S_ISGID
217 ? (mode & S_IXGRP ?
's' :
'S')
219 (mode & S_IXGRP ?
'x' :
'-'));
220 str[7] = mode & S_IROTH ?
'r' :
'-';
221 str[8] = mode & S_IWOTH ?
'w' :
'-';
222 str[9] = (mode & S_ISVTX
223 ? (mode & S_IXOTH ?
't' :
'T')
225 (mode & S_IXOTH ?
'x' :
'-'));
243 struct dirent* l_entity =
NULL;
245 if ((l_dd = opendir(p_dirname)) ==
NULL)
247 syslog(LOG_ERR,
"ERR reading info dir '%s' failed [%s]", p_dirname, strerror(errno));
251 fprintf(p_fout,
"==== Listing directory <%s> ====\n", p_dirname);
253 while ((l_entity = readdir(l_dd)) !=
NULL)
257 char l_modebuf[12] = { 0 };
262 if (!strcmp(l_entity->d_name,
".") || !strcmp(l_entity->d_name,
".."))
265 snprintf(l_fullpath,
sizeof(l_fullpath),
"%s/%s", p_dirname, l_entity->d_name);
267 if (lstat(l_fullpath, &l_stat) < 0)
269 syslog(LOG_ERR,
"ERR lstat on '%s' failed. [%s]", l_fullpath, strerror(errno));
273 strmode(l_stat.st_mode, l_modebuf);
275 fprintf(p_fout,
"%s %ld %d %d %ld %4s",
283 switch (l_stat.st_mode & S_IFMT)
286 fprintf(p_fout,
" [block device]\n");
290 fprintf(p_fout,
" [character device]\n");
294 fprintf(p_fout,
" [directory]\n");
298 fprintf(p_fout,
" [FIFO/pipe]\n");
302 l_size = readlink(l_fullpath, l_linkpath,
sizeof(l_linkpath));
303 l_linkpath[l_size] = 0;
304 fprintf(p_fout,
" -> %s\n", l_linkpath);
308 fprintf(p_fout,
" [regular file]\n");
312 fprintf(p_fout,
" [socket]\n");
316 fprintf(p_fout,
" [unknown?]\n");
322 fprintf(p_fout,
"===========================\n");
345 char l_procfile[256] = { 0 };
357 if ((l_fout = fopen(l_outfilename,
"w+t")) ==
NULL)
359 syslog(LOG_ERR,
"ERR Cannot open context file '%s' [%s]", l_outfilename, strerror(errno));
363 #define PROC_FILENAME(x) do{\ 364 snprintf(l_procfile, sizeof(l_procfile), "/proc/%d/"x,\ 368 fprintf(l_fout,
"ProcName:%s\n", p_proc->
name);
369 fprintf(l_fout,
"ThreadName:%s\n", p_proc->
threadname);
370 fprintf(l_fout,
"PID:%d\n", p_proc->
pid);
371 fprintf(l_fout,
"signal:%d\n", p_proc->
signal);
cdh_status_t get_exec_name(unsigned int p_pid, char *p_exec_name, int p_exec_name_maxsize)
char name[MAX_PROC_NAME_LENGTH]
static char ftypelet(mode_t bits)
#define CONTEXT_FILE_PATTERN
#define CORE_TMP_DIRECTORY
cdh_status_t list_dircontent_to(const char *p_dirname, FILE *p_fout)
cdh_status_t write_proc_context(const proc_info_t *p_proc)
cdh_status_t dump_file_to(const char *p_src_filename, FILE *p_fout)
char threadname[MAX_PROC_NAME_LENGTH]
static char str[DLT_DAEMON_TEXTBUFSIZE]
#define CORE_MAX_FILENAME_LENGTH
void strmode(mode_t mode, char *str)