void TraceMgr::OpenFile() { // Get seq char seq_file_name[255]; snprintf(seq_file_name, 255, "/tmp/%d-seq-num", getpid()); FILE* fp_seq = NULL; char linebuf[255]; struct stat s; if (stat(seq_file_name, &s) == 0) { sp_debug("%s exists\n", seq_file_name); fp_seq = fopen(seq_file_name, "rw"); if (fp_seq == NULL) { sp_perror("fail to open %s\n", seq_file_name); } setbuf(fp_seq, NULL); if (fgets(linebuf, 255, fp_seq) == NULL) { sp_perror("fail to read %s\n", seq_file_name); } } else { sp_debug("%s not exists\n", seq_file_name); fp_seq = fopen(seq_file_name, "w"); if (fp_seq == NULL) { sp_perror("fail to open %s\n", seq_file_name); } setbuf(fp_seq, NULL); fprintf(fp_seq, "1"); fflush(fp_seq); strcpy(linebuf, "1"); } int seq = atoi(linebuf); // Construct trace file name char trace_file_name[255]; snprintf(trace_file_name, 255, "/tmp/%d-%d.xml", getpid(), seq); filename_ = trace_file_name; fp_ = fopen(trace_file_name, "w"); if (fp_ == NULL) { sp_perror("fail to open %s\n", trace_file_name); } setbuf(fp_, NULL); // Write back seq ++seq; rewind(fp_seq); fprintf(fp_seq, "%d", seq); fflush(fp_seq); fclose(fp_seq); // Write initial data string init = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"; init += "<process><head>"; init += "</head></process>"; WriteString(init); }
static char * __so_socket_path_sock2path(int domain, int type, int protocol) { struct sockpath *sp; char *result = NULL; if ((sp = getsockpathent(domain, type, protocol)) != NULL) { if ((result = strdup(sp->sp_path)) == NULL) sp_error = SP_NOMEM; freesockpathent(sp); } if (!result) { sp_perror("socklib"); } return (result); }
void TraceMgr::OpenFile() { // Get seq unsigned long seq = MistUtils::GetUsec(); // Construct trace file name char trace_file_name[255]; snprintf(trace_file_name, 255, "/tmp/%d-%.14lu.xml", getpid(), seq); filename_ = trace_file_name; fp_ = fopen(trace_file_name, "w"); if (fp_ == NULL) { sp_perror("fail to open %s\n", trace_file_name); } setbuf(fp_, NULL); // Write initial data string init = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"; init += "<process><head>"; init += "</head></process>"; WriteString(init); }