From: Alexey Chernobaev Date: Tue, 28 Aug 2018 19:46:38 +0000 (+0300) Subject: Rename IO streams X-Git-Tag: submit/tizen/20180911.125435~30 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=18767cfaa783441b2bf2e282f349301034df41e4;p=sdk%2Ftools%2Fprofctl.git Rename IO streams --- diff --git a/profctl.c b/profctl.c index 874271b..0df6dd3 100644 --- a/profctl.c +++ b/profctl.c @@ -50,9 +50,9 @@ static int isPipeOwner = 0; static int controlPort = -1; static int statPort = -1; -static FILE *cfile; -static FILE *ofile; -static FILE *sfile; +static FILE *ctrl_file_in = NULL; +static FILE *data_file_out = NULL; +static FILE *stat_file_out = NULL; static struct option long_options[] = { {"appid", required_argument, 0, 'a'}, @@ -118,7 +118,7 @@ static void log_system_error_and_exit(const char *msg) } static void openFileProcess(); -static FILE *tf; +static FILE *pipef; static void *output_thread(void *arg) { @@ -128,8 +128,8 @@ static void *output_thread(void *arg) openFileProcess(); int linesRead = 0; - while (getline(&buffer, &lsize, tf) != -1) { - fputs(buffer, ofile); + while (getline(&buffer, &lsize, pipef) != -1) { + fputs(buffer, data_file_out); ++linesRead; } free(buffer); @@ -158,13 +158,13 @@ static void finish() tcsetattr(0,TCSANOW, &sterm); } #endif /* TIZEN */ - if (tf != NULL) { - fclose(tf); + if (pipef != NULL) { + fclose(pipef); if (isPipeOwner) { unlink(pname); } } - fflush(ofile); + fflush(data_file_out); log_error("=== finished ==="); kill(getpid(), SIGKILL); } @@ -172,7 +172,6 @@ static void finish() static void split(char *line, char **array, int n) { int i; - for (i = 0; i < n; i++) { while(line[0] == ' ') *line++ = 0; array[i] = line; @@ -213,7 +212,7 @@ static void *outstat(void *arg) ncpu = ncpu - tmp + 1; long psize = sysconf(_SC_PAGESIZE); - fprintf(sfile, "psize %ld ncpu %d\n", psize, ncpu); + fprintf(stat_file_out, "psize %ld ncpu %d\n", psize, ncpu); FILE *memf = fopen("/proc/meminfo", "r"); if (memf == NULL ) { @@ -355,13 +354,13 @@ static void *outstat(void *arg) ? (fstat.f_bsize / 1024) * fstat.f_bavail : fstat.f_bavail / (1024 / fstat.f_bsize); - fprintf(sfile, + fprintf(stat_file_out, "%ld.%03d" " %s %s %s" " %s %s" " %s %s %ld %ld\n", t, millisec, stats[1], stats[3], stats[4], /* user system idle */ pstats[14 - 1], pstats[15 - 1], /* puser psystem */ mt[1], mf[1], available, pages * psize); - fflush(sfile); + fflush(stat_file_out); usleep(timeoutMicrosec); } @@ -504,8 +503,8 @@ static int app_dead_handler(int npid, void *data) static void openFileProcess() { if (ename == NULL) { - tf = fopen(pname, "r"); - if (tf == NULL) { + pipef = fopen(pname, "r"); + if (pipef == NULL) { log_system_error_and_exit("fopen"); } return; @@ -570,8 +569,8 @@ static void openFileProcess() log_error("PARENT close(%d)", id); } - tf = fdopen(pipefd[0], "r"); - if (tf == NULL) { + pipef = fdopen(pipefd[0], "r"); + if (pipef == NULL) { log_system_error_and_exit("fopen"); } if (verbose) { @@ -633,9 +632,9 @@ int main(int argc, char **argv) char *line = NULL; ssize_t len = 0; - cfile = stdin; - ofile = stdout; - sfile = stdout; + ctrl_file_in = stdin; + data_file_out = stdout; + stat_file_out = stdout; while(!process_option(argc, argv)); @@ -694,16 +693,16 @@ int main(int argc, char **argv) if (controlPort > 0) { int s = openPort(controlPort); - cfile = fdopen(s, "r"); - if (cfile == NULL) { + ctrl_file_in = fdopen(s, "r"); + if (ctrl_file_in == NULL) { log_system_error_and_exit("fdopen(control,r)"); } } if (doinfo && (statPort > 0)) { int s = openPort(statPort); - sfile = fdopen(s, "w"); - if (sfile == NULL) { + stat_file_out = fdopen(s, "w"); + if (stat_file_out == NULL) { log_system_error_and_exit("fdopen(stat,w)"); } } @@ -720,7 +719,7 @@ int main(int argc, char **argv) #endif /* TIZEN */ /* Read command loop */ - while((len = getline(&line, &len, cfile)) != -1) { + while((len = getline(&line, &len, ctrl_file_in)) != -1) { if (verbose) { if ((len > 0) && (line[len - 1] == '\n')) { line[len - 1] = 0; @@ -752,7 +751,7 @@ int main(int argc, char **argv) SimpleThread(&outstat); } } - } + } // while return 0; }