systemtap script linux scsi timeout

January 19, 2012 at 9:44 AM (Uncategorized)

1 #!/usr/bin/stap
2
3 probe begin{
4         print(“Starting probe, watching for SG_IO with threshold greater than “);
5             print($1 / 1000);
6                 print(” seconds.\nType control-c to stop.\n”);
7 }
8
9 probe kernel.function(“sg_io”)
10 {
11         if ($hdr->timeout > $1) {
12                    printf(“%s(%d) called sg_io with timeout = %d, greater than threshold\n”,
13                                         execname(), pid(), $hdr->timeout);
14         }
15         if ($q->sg_timeout > $1){
16                     printf(“%s(%d) called sg_io with sg_timeout = %d, greater than threshold\n”,
17                     execname(), pid(), $q->sg_timeout);
18         }
19 }
20
21 probe end {
22         print(“End probe\n”);
23 }

 

 281static int sg_io(struct request_queue *q, struct gendisk *bd_disk,
 282                struct sg_io_hdr *hdr, fmode_t mode)
 283{
 284        unsigned long start_time;

 

 

Permalink Leave a Comment

memory map glibc pmap PROT_NONE

January 18, 2012 at 12:58 PM (Uncategorized) ()

02:18 PM) mdarade: cld u tell me use cases of PROT_NONE except buffer overflow?
(06:02:43 PM) mdarade: & what decides size of areas protected with PROT_NONE?
(06:03:05 PM) mdarade: I mean i see upto 64K area being marked as PROT_NONE
(06:06:02 PM) siddhesh: PROT_NONE is basically just no permissions
(06:06:06 PM) siddhesh: use it as you will
(06:06:29 PM) siddhesh: typically they’re used to mark guard pages to catch buffr overflows
(06:07:02 PM) siddhesh: but it’s generally a good idea to mark pages as PTOR_NONE if they’re not intended to be used
(06:07:11 PM) siddhesh: libc uses it for its arena allocations
(06:08:34 PM) mdarade: size of areas protected with PROT_NONE is fixed?
(06:08:56 PM) siddhesh: whatever size you want, rounded to page size of course
(06:09:09 PM) mdarade: what is use in having 64k area protected with it?
(06:09:24 PM) siddhesh: depends on where it is used
(06:09:27 PM) siddhesh: where is it used?
(06:10:05 PM) mdarade: i see 132k anon allocation
(06:10:09 PM) mdarade: now to guard it
(06:10:24 PM) mdarade: why prot_none area size have to be 64?
(06:10:48 PM) siddhesh: where? which code?
(06:10:50 PM) mdarade: 64400k?
(06:11:08 PM) mdarade: pmap of java
(06:11:24 PM) siddhesh: ok, is it multithreaded?
(06:11:43 PM) mdarade: yeap
(06:12:13 PM) siddhesh: then those must be arenas allocated by libc for each thread
(06:12:21 PM) siddhesh: arenas act as heaps for each thread
(06:12:26 PM) siddhesh: to reduce locking between them
(06:12:54 PM) siddhesh: a new arena is always allocated with PROT_NONE and then parts of it given access as and when needed
(06:13:03 PM) siddhesh: for malloc requests
(06:13:07 PM) mdarade: got it :D thanks

Permalink Leave a Comment

Fraud happened in Magarpatta City, Hadapsar, Pune

December 15, 2011 at 4:29 PM (Uncategorized) ()

This blog post is for those lucky ones who prefer to dig a little deeper before investing even a rupee. I want to share a story (which accidentally happened with me) while I was staying at A-35, Erica, Magarpatta city. When my employer provided accommodation was about to get over and I was looking out for some place I was contacted real estate agent/broker named Shahaji Somavanshi. He was a middleman whose job was to rent out someone else’s (actual owner) bungalow as he was working part time as a cab driver. Looking at him I realized I cannot trust this guy (thanks to my analytical skills) so I decided not to give deposit amount more than five thousand.

Finally I successfully negotiated the deal and stayed there for only two months. Even though serving one months notice he failed to return deposit back at the time of leaving. I contacted him after two weeks and again he promised some random date. This went happening until one day when I find out that he blocked my number. Finally I realized that it doesn’t make sense to contact this guy and its time to file a police complaint. Police managed to take money from that guy and I got my money back. Well not all of it :D but yes the process was all hectic, waste of energy and time.

Do remember name of those frauds.

Shahaji Somvanshi.

Santosh Kambale.

This post is my first contribution to society  :-) .

Permalink Leave a Comment

rsyslog patch

December 15, 2011 at 10:05 AM (Uncategorized) ()

--- a/tools/syslogd.c	2011-12-14 14:38:53.557984324 +0530
+++ b/tools/syslogd.c	2011-12-14 14:38:45.011984782 +0530
@@ -3177,6 +3177,7 @@
 	uchar *LocalHostName;
 	uchar *LocalDomain;
 	uchar *LocalFQDNName;
+	int i;

 	/* first, parse the command line options. We do not carry out any actual work, just
 	 * see what we should do. This relieves us from certain anomalies and we can process
@@ -3316,9 +3317,22 @@
 		 */
 		hent = gethostbyname((char*)LocalHostName);
 		if(hent) {
+			if(hent->h_aliases) {
+				for (i=0; hent->h_aliases[i]; i++) {
+					if(strstr((hent->h_aliases[i]), (char*)LocalHostName)) {
+						//found hostname matching in aliases. use currently found one and break loop
+						 break;
+					}
+				}
+			}
+
 			free(LocalHostName);
-			CHKmalloc(LocalHostName = (uchar*)strdup(hent->h_name));
-
+			if(hent->h_aliases[i]) {
+				CHKmalloc(LocalHostName = (uchar*)strdup(hent->h_aliases[i]));
+			} else {
+				CHKmalloc(LocalHostName = (uchar*)strdup(hent->h_name));
+			}
+
 			if((p = (uchar*)strchr((char*)LocalHostName, '.')))
 			{
 				*p++ = '';

Permalink Leave a Comment

systemtap script

December 15, 2011 at 10:02 AM (Uncategorized) ()

probe begin {
    printf(“probe started”);
}

probe end {
    printf(“probe finished”);
}

probe kernel.function(“radix_tree_insert”).return {
    if ($return) {
        printf(“%s: comm %s, pid %d, retval %d\n”, probefunc(), execname(), pid(), $return);
        print_backtrace();
    }
}

Permalink Leave a Comment

bit play with signed unsigned

December 8, 2011 at 9:47 AM (Uncategorized)

[root@dhcp209-92 /]# cat size_t_size.c
#include <stdio.h>
#include <stdlib.h>
int main() {
size_t len = -1;
/*    ssize_t chk = -1;
size_t toprint;
printf(“size of size_t is %d”, sizeof(size_t));
printf(“size of ssize_t is %d”, sizeof(ssize_t));
printf(“len is %d”, len);
toprint = (int) len;
printf(“toprint is %d”, toprint);
*/
if( len <= 0 || len == -1)
printf(” -1 if cond worked”);
//    if ( len == chk )
//        printf(” -1 cond worked”);
return 0;
}
[root@dhcp209-92 /]#

I don’t prefer to post output for different conditions as I want readers to try it out so that they understand it better :D .

Permalink Leave a Comment

C snippet showing conditional function prototype

November 4, 2011 at 11:40 AM (Uncategorized)

1441         send_file_entry(f, fbuf, file,
1442 #ifdef SUPPORT_LINKS
1443                 symlink_name, symlink_len,
1444 #endif
1445                 flist->used, flist->ndx_start);

389 static void send_file_entry(int f, const char *fname, struct file_struct *file,
390 #ifdef SUPPORT_LINKS
391                 const char *symlink_name, int symlink_len,
392 #endif
393                 int ndx, int first_ndx)

Permalink Leave a Comment

signals linux ipc

August 19, 2011 at 9:26 AM (Uncategorized)

0x00000fff922453cc in do_sigsuspend (set=0xfffc72dc668) at ../sysdeps/unix/sysv/linux/sigsuspend.c:63
63        return INLINE_SYSCALL (rt_sigsuspend, 2, CHECK_SIGSET (set), _NSIG / 8);

If pattern

<signal handler called>

is not present around above bt snippet then signal didn't occur and process which have
called sigsuspend has terminated abnormally.

Permalink Leave a Comment

How to use syslog for logging messages

August 8, 2011 at 12:18 PM (Uncategorized)

[root@mdarade sample_code]# cat syslog_md.c
#include <stdio.h>
#include <syslog.h>
#include <unistd.h>
int main() {
char hello[]=”mahaveer darade”;
openlog(“syslog_md”, LOG_PID, LOG_DAEMON );
syslog(LOG_INFO, “%s\n”, hello);
printf(“pid is %d\n”, getpid());
closelog();
return 0;
}
[root@mdarade sample_code]#
[root@mdarade sample_code]# tail -f /var/log/messages
Aug  8 17:43:14 mdarade syslog_md[4144]: mahaveer darade
Config files: /etc/syslog.conf, /etc/sysonfig/syslog

Permalink Leave a Comment

script to find files having ge number of lines

August 4, 2011 at 12:17 PM (Uncategorized)

[mdarade@mdarade net-snmp-5.3.2.2]$ cat ~/scripts/find_files_having_specific_number_of_lines.sh
#!/usr/bin/env bash
find . -type f | while read line
do
        no_of_lines=`wc -l $line| cut -d" " -f1`;
        if [ $no_of_lines -ge $1 ] ; then
            ls -l "$line";
        fi
done
[mdarade@mdarade net-snmp-5.3.2.2]$ 

Permalink Leave a Comment

Next page »

Follow

Get every new post delivered to your Inbox.