#include <sys/stat.h>
#include <sys/xattr.h>
#include <sys/statvfs.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
#include <fcntl.h>
struct app_info {
static char *appid = NULL;
static char *pname = NULL;
static char *ename = NULL;
-static const char *oname = NULL;
+static char *oname = NULL;
static int isPipeOwner = 0;
+static int controlPort = -1;
+static int statPort = -1;
+static FILE *cfile;
+static FILE *ofile;
+static FILE *sfile;
+
static struct option long_options[] = {
{"appid", required_argument, 0, 'a'},
{"pipe", required_argument, 0, 'p'},
{"list", no_argument, 0, 'l'},
{"info", no_argument, 0, 'i'},
{"pipe-owner", no_argument, 0, 'w'},
+ {"server", required_argument, 0, 's'},
+ {"stat", required_argument, 0, 'S'},
{0, 0, 0, 0}
};
static void finish()
{
#if TIZEN
- tcsetattr(0,TCSANOW, &sterm);
+ if (controlPort < 0) {
+ tcsetattr(0,TCSANOW, &sterm);
+ }
#endif /* TIZEN */
if (tf != NULL) {
fclose(tf);
unlink(pname);
}
}
+ fflush(ofile);
kill(getpid(), SIGKILL);
}
long psize = sysconf(_SC_PAGESIZE);
struct statvfs fstat;
- printf("psize %ld\n", psize);
+ fprintf(sfile, "psize %ld\n", psize);
if (sstat == NULL ) {
perror("open /proc/stat");
? (fstat.f_bsize / 1024) * fstat.f_bavail
: fstat.f_bavail / (1024 / fstat.f_bsize);
- printf("%ld.%d %d" " %s %s %s" " %s %s" " %s %s %ld %ld\n",
+ fprintf(sfile,
+ "%ld.%d %d" " %s %s %s" " %s %s" " %s %s %ld %ld\n",
t, millisec, ncpu,
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);
usleep(timeoutMicrosec);
}
{
int option_index;
- switch(getopt_long(argc, argv, "-a:p:vle:o:it:w",
+ switch(getopt_long(argc, argv, "-a:p:vle:o:it:ws:S:",
long_options, &option_index)) {
case 1:
if (appid == NULL) {
case 'i': doinfo = 1; break;
case 't': timeoutMicrosec = atoi(optarg) * 1000; break;
case 'w': isPipeOwner = 1; break;
+ case 's': controlPort = atoi(optarg); break;
+ case 'S': statPort = atoi(optarg); break;
default:
return -1;
}
}
}
+static int openPort(int port)
+{
+ int result;
+ int enable = 1;
+ struct sockaddr_in saddr = {0};
+ struct sockaddr_in caddr;
+ int csize = sizeof(caddr);
+ int sock = socket(AF_INET, SOCK_STREAM, 0);
+
+ if (sock < 0) {
+ perror("socket");
+ exit(1);
+ }
+
+ if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)) < 0)
+ {
+ perror("setsockopt");
+ exit(1);
+ }
+
+ saddr.sin_family = AF_INET;
+ saddr.sin_addr.s_addr = INADDR_ANY;
+ saddr.sin_port = htons(port);
+
+ if (bind(sock, (struct sockaddr *)&saddr, sizeof(saddr)) < 0)
+ {
+ perror("bind");
+ exit(1);
+ }
+
+ listen(sock, 5);
+
+ result = accept(sock, (struct sockaddr *) &caddr, &csize);
+ if (result < 0) {
+ perror("accept");
+ exit(1);
+ }
+ return result;
+}
+
int main(int argc, char **argv)
{
#if TIZEN
char *line = NULL;
size_t len = 0;
+ cfile = stdin;
+ ofile = stdout;
+ sfile = stdout;
+
while(!process_option(argc, argv));
#if TIZEN
freopen(oname, "w", stderr);
setbuf(stderr, NULL);
+ if (verbose) {
+ int i;
+ for (i = 0; i < argc; i++) {
+ fprintf(stderr, "argv[%d] = %s\n", i, argv[i]);
+ }
+ }
+
if (pname && isPipeOwner) {
unlink(pname);
if (mkfifo(pname, 0666)) {
}
#if TIZEN
- /* stty */
- tcgetattr(0, &term);
- sterm = term;
+ if (controlPort < 0 && statPort < 0) {
+ /* stty */
+ tcgetattr(0, &term);
+ sterm = term;
- term.c_lflag &= ~(ECHO|ECHONL); /* no echo and so on */
- term.c_oflag &= ~OPOST; /* no additional CR and so on */
+ term.c_lflag &= ~(ECHO|ECHONL); /* no echo and so on */
+ term.c_oflag &= ~OPOST; /* no additional CR and so on */
- tcsetattr(0,TCSANOW, &term);
+ tcsetattr(0,TCSANOW, &term);
+ }
#endif /* TIZEN */
+ if (controlPort > 0) {
+ int s = openPort(controlPort);
+ cfile = fdopen(s, "r");
+ ofile = fdopen(s, "w");
+ if (cfile == NULL || ofile == NULL) {
+ perror("fdopen");
+ exit(1);
+ }
+ }
+
+ if (doinfo && (statPort > 0)) {
+ int s = openPort(statPort);
+ sfile = fdopen(s, "w");
+ if (sfile == NULL) {
+ perror("fdopen");
+ exit(1);
+ }
+ }
+
atexit(finish);
if (pname) {
#endif /* TIZEN */
/* Read command loop */
- while((len = getline(&line, &len, stdin)) != -1) {
+ while((len = getline(&line, &len, cfile)) != -1) {
if (verbose) {
fprintf(stderr, "line :%s#\n", line);
}