[SSI] openssi/procps/proc readproc.c,1.1.15.2,1.1.15.2.2.1

Roger Tsang <[email protected]> Sun, 08 Aug 2010 03:41:08 +0000
Newsgroups gmane.linux.cluster.ssic.cvs
Message-ID <[email protected]>
Update of /cvsroot/ssic-linux/openssi/procps/proc
In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv10105/proc

Modified Files:
      Tag: OPENSSI-CENTOS
	readproc.c 
Log Message:
OpenSSI changes for procps-3.2.3-8.17.el4_8.2


Index: readproc.c
===================================================================
RCS file: /cvsroot/ssic-linux/openssi/procps/proc/Attic/readproc.c,v
retrieving revision 1.1.15.2
retrieving revision 1.1.15.2.2.1
diff -u -d -r1.1.15.2 -r1.1.15.2.2.1
--- readproc.c	8 Aug 2010 03:33:58 -0000	1.1.15.2
+++ readproc.c	8 Aug 2010 03:41:06 -0000	1.1.15.2.2.1
@@ -364,6 +364,18 @@
 /*    fprintf(stderr, "statm2proc converted %d fields.\n",num); */
 }
 
+/* OpenSSI : This routine fills the proc_t->enode field */
+static void where2proc (char* S, proc_t* P) {
+    /* Read the node num into the proc_t structure */
+    sscanf(S, "%d", &P->enode);
+}
+
+/* OpenSSI : This routine fills the proc_t->ttynode field */
+static void ttynode2proc (char* S, proc_t* P) {
+    /* Read the node num into the proc_t structure */
+    sscanf(S, "%u", &P->ttynode);
+}
+
 static int file2str(const char *directory, const char *what, char *ret, int cap) {
     static char filename[80];
     int fd, num_read;
@@ -529,6 +541,21 @@
       p->wchan = (KLONG)~0ull;
     }
 
+    /*** Start: OpenSSI ****/
+    /* Read the /proc/#/where file ***/
+    if ((file2str(path, "where", sbuf, sizeof sbuf)) != -1)
+        where2proc(sbuf, p);
+    else
+        p->enode = -1;
+
+    /* Read the /proc/#/ttynode file ***/
+    if ((file2str(path, "ttynode", sbuf, sizeof sbuf)) != -1)
+        ttynode2proc(sbuf, p);
+    else
+        p->ttynode = 0;
+    /*** End: OpenSSI  ***/
+
+
     /* some number->text resolving which is time consuming and kind of insane */
     if (flags & PROC_FILLUSR){
 	memcpy(p->euser,   user_from_uid(p->euid), sizeof p->euser);
@@ -863,6 +890,20 @@
         _exit(47);
     }
     stat2proc(sbuf, p);    // parse /proc/self/stat
+
+    /*** Start: OpenSSI ****/
+    /* Read the /proc/#/where file ***/
+    if ((file2str("/proc/self", "where", sbuf, sizeof sbuf)) != -1)
+        where2proc(sbuf, p);
+    else
+        p->enode = -1;
+
+    /* Read the /proc/#/ttynode file ***/
+    if ((file2str("/proc/self", "ttynode", sbuf, sizeof sbuf)) != -1)
+        ttynode2proc(sbuf, p);
+    else
+        p->ttynode = 0;
+    /*** End: OpenSSI  ***/
 }
 
 HIDDEN_ALIAS(readproc);
@@ -1005,3 +1046,36 @@
 
 	return p;
 }
+
+/*
+ * 	OpenSSI : added this routine to  check if ps has been called 
+ *	under localview, on a SSI kernel
+ */
+int
+check_if_localview(pid_t pid)
+{
+	char filename[32], sbuf[1024], view[32];
+	int ret ;
+	int fd;
+
+	sprintf(filename,"/proc/%d/localview",pid);
+
+	if ( ( fd = open(filename, O_RDONLY, 0)) != -1 ) {
+		if ( read(fd,sbuf,1023) <= 0 ) 
+			return -1;
+		close(fd);
+		ret = sscanf (sbuf,"%s",view);
+		if ( ret == 0 || ret == EOF )
+			return -1;
+
+		if( strcmp(view,"localview") == 0 )	
+			return 1;
+		else 
+			return 0;
+	}	
+	if (errno == ENOENT )
+		/* Not running in a OpenSSI cluster. detaul to localview */
+		return 1;
+	else 
+		return -1;
+}


------------------------------------------------------------------------------
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev