From 4ff9e938522d1f5980706cbbb09019493ea7425a Mon Sep 17 00:00:00 2001 From: Alex Nikiforov <a.nikifo...@samsung.com> Date: Fri, 8 Jul 2011 13:09:57 +0400
Move PID check code from the server to the client. We dont need any read()/write() if it's not valid. Signed-off-by: Alex Nikiforov <a.nikifo...@samsung.com> --- src/daemon/cgrulesengd.c | 7 ------- src/tools/cgclassify.c | 11 ++++++++--- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/daemon/cgrulesengd.c b/src/daemon/cgrulesengd.c index 2f42a57..eb6893a 100644 --- a/src/daemon/cgrulesengd.c +++ b/src/daemon/cgrulesengd.c @@ -550,8 +550,6 @@ static void cgre_receive_unix_domain_msg(int sk_unix) pid_t pid; struct sockaddr_un caddr; socklen_t caddr_len; - struct stat buff_stat; - char path[FILENAME_MAX]; caddr_len = sizeof(caddr); fd_client = accept(sk_unix, (struct sockaddr *)&caddr, &caddr_len); @@ -563,11 +561,6 @@ static void cgre_receive_unix_domain_msg(int sk_unix) cgroup_dbg("read error: %s\n", strerror(errno)); goto close; } - sprintf(path, "/proc/%d", pid); - if (stat(path, &buff_stat)) { - cgroup_dbg("There is not such process (PID: %d)", pid); - goto close; - } if (read(fd_client, &flags, sizeof(flags)) < 0) { cgroup_dbg("read error: %s\n", strerror(errno)); goto close; diff --git a/src/tools/cgclassify.c b/src/tools/cgclassify.c index 397b725..029d091 100644 --- a/src/tools/cgclassify.c +++ b/src/tools/cgclassify.c @@ -121,7 +121,8 @@ int main(int argc, char *argv[]) struct cgroup_group_spec *cgroup_list[CG_HIER_MAX]; int c; char *endptr; - + char path[FILENAME_MAX]; + struct stat buff_stat; if (argc < 2) { usage(1, argv[0]); @@ -167,8 +168,12 @@ int main(int argc, char *argv[]) } for (i = optind; i < argc; i++) { + pid = (uid_t) strtol(argv[i], &endptr, 10); - if (endptr[0] != '\0') { + snprintf(path, FILENAME_MAX, "/proc/%d", pid); + + /* check PID */ + if (endptr[0] != '\0' || stat(path, &buff_stat)) { /* the input argument was not a number */ fprintf(stderr, "Error: %s is not valid pid.\n", argv[i]); @@ -190,6 +195,6 @@ int main(int argc, char *argv[]) if (ret) exit_code = 1; } - return exit_code; + return exit_code; } -- 1.7.4.1 ------------------------------------------------------------------------------ All of the data generated in your IT infrastructure is seriously valuable. Why? It contains a definitive record of application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-d2d-c2 _______________________________________________ Libcg-devel mailing list Libcg-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libcg-devel