Permalink
Browse files

Merge branch 'master' into findpids

  • Loading branch information...
2 parents 71e57a6 + cc81024 commit 4dbe7767ca1143765cc9d74a8e64f7dee8a42985 @dmaloney-r7 dmaloney-r7 committed Sep 19, 2012
Showing 1,664 changed files with 91,166 additions and 142,177 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -644,26 +644,62 @@ DWORD linux_parse_proc_net_file(char * filename, struct connection_table ** tabl
DWORD linux_proc_get_program_name(struct connection_entry * connection, unsigned char * pid)
{
FILE *fd;
- char buffer[30], buffer_file[50], name[30];
+ char buffer[30], buffer_file[256], name[256];
+ char * bname;
+ int do_status = 0;
- snprintf(buffer, sizeof(buffer), "/proc/%s/status", pid);
+ do {
+ // try /proc/PID/cmdline first
+ snprintf(buffer, sizeof(buffer)-1, "/proc/%s/cmdline", pid);
+ fd = fopen(buffer, "r");
- fd = fopen(buffer, "r");
- if (fd == NULL)
- return -1;
+ // will try /proc/PID/status
+ if (fd == NULL) {
+ do_status = 1;
+ break;
+ }
+ if (fgets(buffer_file, sizeof(buffer_file), fd) == NULL) {
+ do_status = 1;
+ break;
+ }
+ // each entry in cmdline is seperated by '\0' so buffer_file contains first the path of the executable launched
+ if ((bname = basename(buffer_file)) == NULL) {
+ do_status = 1;
+ break;
+ }
+ // copy basename into name to be consistent at the end
+ strncpy(name, bname, sizeof(name)-1);
+ name[sizeof(name)-1] = '\0';
- if (fgets(buffer_file, sizeof(buffer_file), fd) == NULL) {
- fclose(fd);
- return -1;
- }
+ } while (0);
- if (sscanf(buffer_file, "Name: %s\n", name) != 1) {
- fclose(fd);
- return -1;
- }
+ if (fd != NULL)
+ fclose(fd);
- snprintf(connection->program_name, sizeof(connection->program_name), "%s/%s",pid,name);
- fclose(fd);
+
+ // /proc/PID/cmdline failed, try /proc/PID/status
+ if (do_status == 1) {
+ snprintf(buffer, sizeof(buffer)-1, "/proc/%s/status", pid);
+ fd = fopen(buffer, "r");
+
+ // will try /proc/PID/status
+ if (fd == NULL)
+ return -1;
+
+ if (fgets(buffer_file, sizeof(buffer_file), fd) == NULL) {
+ fclose(fd);
+ return -1;
+ }
+
+ if (sscanf(buffer_file, "Name: %200s\n", name) != 1) {
+ fclose(fd);
+ return -1;
+ }
+ fclose(fd);
+
+ }
+
+ snprintf(connection->program_name, sizeof(connection->program_name), "%s/%s", pid, name);
return 0;
}
@@ -10,9 +10,13 @@ require 'rubygems'
version = ">= 0"
-if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
- version = $1
- ARGV.shift
+if ARGV.first
+ str = ARGV.first
+ str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
+ if str =~ /\A_(.*)_\z/
+ version = $1
+ ARGV.shift
+ end
end
gem 'railties', version
@@ -10,9 +10,13 @@ require 'rubygems'
version = ">= 0"
-if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
- version = $1
- ARGV.shift
+if ARGV.first
+ str = ARGV.first
+ str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
+ if str =~ /\A_(.*)_\z/
+ version = $1
+ ARGV.shift
+ end
end
gem 'thor', version
@@ -10,9 +10,13 @@ require 'rubygems'
version = ">= 0"
-if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
- version = $1
- ARGV.shift
+if ARGV.first
+ str = ARGV.first
+ str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
+ if str =~ /\A_(.*)_\z/
+ version = $1
+ ARGV.shift
+ end
end
gem 'thor', version
Oops, something went wrong. Retry.

0 comments on commit 4dbe776

Please sign in to comment.