Wrapper for unix program - urgent help needed


 
Thread Tools Search this Thread
Top Forums Programming Wrapper for unix program - urgent help needed
# 1  
Old 09-18-2012
Wrapper for unix program - urgent help needed

Hello all ,
i need some help asap
i have a program that keeps killing the machine
when i did google searches and 2 days later i ran strace
it seems the programm keeps making a system call to gettimeofday
to i guess increment a counter ?
Code:
gettimeofday({1347986584, 464904}, NULL) = 0
rt_sigprocmask(SIG_UNBLOCK, [], NULL, 8) = 0
poll([{fd=4, events=POLLIN}, {fd=0, events=POLLIN}], 2, 4) = 0 (Timeout)
rt_sigprocmask(SIG_BLOCK, [], NULL, 8)  = 0
gettimeofday({1347986584, 469698}, NULL) = 0

is there a way i can put a wrapper around it so any calls to gettimeofday are not handled ?


thanx all

Last edited by jim mcnamara; 09-18-2012 at 03:02 PM..
# 2  
Old 09-18-2012
Program wrapper for handle system call gettimeofday

hi all
i posted in another thread but this is what i found since
i am trying to handle a gettimeofday call by a program thats killing cpu on my machine

i searched and found this

can any of you gurus help me ? if we can use this as a base
i need to
a) handle gettimeofday with it
b) compile it under gcc in ubuntu ( tried compiling this as is , lots of error )

thank you all
Code:
#include linux/module.h //put the '<'
#include linux/kernel.h //put the '<'
#include linux/init.h//put the '<'
#include linux/moduleparam.h//put the '<'
#include linux/cdev.h//put the '<'

#define POS_SYSCALL_WRITE 4
#define POS_SYSCALL_OPEN 5
#define POS_SYSCALL_CLOSE 6
#define POS_SYSCALL_LSEEK 19
#define POS_SYSCALL_CLONE 120 
#define POS_SYSCALL_DUP 41 

extern void * sys_call_table[];
MODULE_AUTHOR("Lu -");
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Syscall wrapper driver");

void enable_syscall_table (void);
void disable_syscall_table (void);

long sys_open_local(const char __user * filename, int flags, int mode);
long (*sys_open_old)(const char __user * filename, int flags, int mode)=NULL;
long sys_close_local(unsigned int fd);
long (*sys_close_old)(unsigned int fd)=NULL;
ssize_t sys_write_local(unsigned int fd, const char __user * buf, size_t count);
ssize_t (*sys_write_old)(unsigned int fd, const char __user * buf, size_t count)=NULL;
off_t sys_lseek_local(unsigned int fd, off_t offset, unsigned int origin);
off_t (*sys_lseek_old)(unsigned int fd, off_t offset, unsigned int origin)=NULL;
int sys_clone_local(struct pt_regs regs);
int (*sys_clone_old)(struct pt_regs regs)=NULL;
long sys_dup_local(unsigned int fd);
long (*sys_dup_old)(unsigned int fd) = NULL;

static int __init Mymodule_init (void)
{
 printk(KERN_DEBUG "Mymodule carregat amb exit\n");
 enable_syscall_table();
 return 0;
}

static void __exit Mymodule_exit (void)
{
 printk(KERN_DEBUG "Mymodule desKrregat amb exit\n");
 disable_syscall_table();
}
module_init(Mymodule_init);
module_exit(Mymodule_exit);

void enable_syscall_table (void){
 sys_dup_old = sys_call_table[POS_SYSCALL_DUP];
 sys_call_table[POS_SYSCALL_DUP] = sys_dup_local;
 
 sys_open_old = sys_call_table[POS_SYSCALL_OPEN];
 sys_call_table[POS_SYSCALL_OPEN] = sys_open_local;

 sys_close_old = sys_call_table[POS_SYSCALL_CLOSE];
 sys_call_table[POS_SYSCALL_CLOSE] = sys_close_local;

 sys_write_old = sys_call_table[POS_SYSCALL_WRITE];
 sys_call_table[POS_SYSCALL_WRITE] = sys_write_local;

 sys_lseek_old = sys_call_table[POS_SYSCALL_LSEEK];
 sys_call_table[POS_SYSCALL_LSEEK] = sys_lseek_local;

 sys_clone_old = sys_call_table[POS_SYSCALL_CLONE];
 sys_call_table[POS_SYSCALL_CLONE] = sys_clone_local;

}
void disable_syscall_table (void){
 sys_call_table[POS_SYSCALL_DUP] = sys_dup_old;
 sys_call_table[POS_SYSCALL_OPEN] = sys_open_old;
 sys_call_table[POS_SYSCALL_CLOSE] = sys_close_old;
 sys_call_table[POS_SYSCALL_WRITE] = sys_write_old;
 sys_call_table[POS_SYSCALL_LSEEK] = sys_lseek_old;
 sys_call_table[POS_SYSCALL_CLONE] = sys_clone_old;
}
long sys_open_local(const char __user * filename, int flags, int mode) {
 long ret;
 ret = sys_open_old(filename, flags, mode);
 return ret;
}
long sys_close_local(unsigned int fd){
 long ret;
 ret = sys_close_old(fd);
 return ret;
}
ssize_t sys_write_local(unsigned int fd, const char __user * buf, size_t count){
 ssize_t ret;
 ret = sys_write_old(fd, buf, count);
 return ret;
}
off_t sys_lseek_local(unsigned int fd, off_t offset, unsigned int origin){
 off_t ret;
 ret = sys_lseek_old(fd, offset, origin);
 return ret;
}
int sys_clone_local(struct pt_regs regs){
 int ret;
 ret = sys_clone_old(regs);
 return ret;
}

Moderator's Comments:
Mod Comment Please use code tags

Last edited by jim mcnamara; 09-18-2012 at 03:04 PM..
# 3  
Old 09-18-2012
I think you should look at time spent in calls. gettimeofday is one of the least expensive system calls there is.

Steps to do what you asked
1. create your own shared library, call it mylib.so
You do this by writing a do-nthing call:
Code:
int gettimeofday(void *a, void *b)
{
    return 1;
}

compile it as a shared library.
2. change your environment variables:
add
Code:
    export LD_PRELOAD=/path/to/mylib.so

When you run the application it will load YOUR version of gettimeofday.
1. it may not work in secure environments like selinux because you are hijacking a syscall.
2. it will not work with setuid or setgid executables

google for LD_PRELOAD and see other examples.
# 4  
Old 09-18-2012
thanx jm
nevermind googled some lines of code trying it now
thanx

Last edited by NetworkLearning; 09-18-2012 at 03:25 PM..
# 5  
Old 09-18-2012
Use the settings to create a shared library with gcc:

Creating a shared and static library with the gnu compiler [gcc]

If you do not know anything about C and compiling, please ignore all my advice, you will keep running into frustration.
# 6  
Old 09-18-2012
What does the application, that you are trying to fix, do for you? If it is some opensource free download version 0.04 it is probably nothing but headaches for everyone. Especially you.

1. name of the app?

2. function(s) it performs?
# 7  
Old 09-19-2012
It worked a little bit
no more messages in log for gettime so i guess its using my gettime
but the program is hanging and log shows

---------- Post updated at 10:42 PM ---------- Previous update was at 02:06 PM ----------

Can anyone please help

now its stuck at

poll([{fd=4, events=POLLIN}, {fd=0, events=POLLIN}], 2, 4) = 0 (Timeout)
rt_sigprocmask(SIG_BLOCK, [], NULL, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [], NULL, 8) = 0
poll([{fd=4, events=POLLIN}, {fd=0, events=POLLIN}], 2, 4) = 0 (Timeout)
rt_sigprocmask(SIG_BLOCK, [], NULL, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [], NULL, 8) = 0

Last edited by NetworkLearning; 09-18-2012 at 04:40 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Urgent help needed.. C++ program to convert decimal to hexa decimal

Hi , seq can be 0...128 int windex = seq / 8; int bindex = seq % 8; unsigned char bitvalue = '\x01' << (7-bindex) ; bpv.bitmapvalue = bitvalue; This is the part of a program to convert decimal to bitmap value of hexadecimal. I want this to change to convert only to... (1 Reply)
Discussion started by: greenworld123
1 Replies

2. Shell Programming and Scripting

Help needed on wrapper script

Hi Gurus, I need to build a wrapper script which will be passing the loading date and the data file name (provides option to the user to load a single data file or load all the data files) to the actual loader data_load.ksh to load in the database. 1. I want to execute the loader script... (6 Replies)
Discussion started by: express14
6 Replies

3. Shell Programming and Scripting

How to make bash wrapper for java/groovy program with variable length arguments lists?

The following bash script does not work because the java/groovy code always thinks there are four arguments even if there are only 1 or 2. As you can see from my hideous backslashes, I am using cygwin bash on windows. export... (1 Reply)
Discussion started by: siegfried
1 Replies

4. Shell Programming and Scripting

Urgent Help needed please

Hi, I have a small grepping problem in my script.I am having a file from which i need to make sure "#^A17" is the last updation (Next # can be ignored) before ################.The idea behind this is, if this file contains "A17" as the last updation, i need to do a particular activity. please... (7 Replies)
Discussion started by: Renjesh
7 Replies

5. UNIX for Dummies Questions & Answers

Urgent Help Needed

Hello Friends, I am a Graduate in Computers. I completed BCA degree this year. I want to make my career in UNIX. But, unfortunately I don't know anybody who can guide me. I am totally confuse because I don't know where to start and what are the future prospect in UNIX. Please give your... (4 Replies)
Discussion started by: Luckyless
4 Replies

6. UNIX for Advanced & Expert Users

Urgent help needed!!!

-------------------------------------------------------------------------------- hy guys, i got few interview questions i need someone to answer urgently: 1)If you cant get to the root, you try to fsck it, but gets errors to read file systems. What steps do you take to recover the host... (1 Reply)
Discussion started by: charneet
1 Replies

7. UNIX for Dummies Questions & Answers

Urgent help needed to delete some text without opening the file in unix

Hi To delete some text in 2 files in line1 ( not complete line) in unix without opening the files. For example: source file is like this <?xml version="1.0"... (5 Replies)
Discussion started by: pyaranoid
5 Replies

8. Shell Programming and Scripting

urgent needed

hi i want solution regarding usage of array. i m having code which is written using if- elif and can i use or access using arrays. here i wana use array values along with if -elif condition. i dnt wana use command line argument parameter1=(scram no_scram) if ; then ... (0 Replies)
Discussion started by: manish1
0 Replies

9. UNIX for Dummies Questions & Answers

Unix book (urgent help needed)

hi guys i am new to UNIX and i am very much excited to learn how it works.. i was very confused with how to start and what book to follow so i went to my lecturer and asked him if he could suggest something. he advised me to get this book Your UNIX: The Ultimate Guide by "Sumitabha Das" ISBN:... (4 Replies)
Discussion started by: prabhashkashyap
4 Replies

10. Shell Programming and Scripting

urgent help needed !!

i have a script, which is continuously looping. i want to view the script name when i use ps command... it is only showing -sh ... UID PID PPID C STIME TTY TIME COMMAND informix 8533 20923 0 18:19:28 pts/ta 0:00 -sh but i dont have my scriptname displayed .... how can i do that my script is... (0 Replies)
Discussion started by: guhas
0 Replies
Login or Register to Ask a Question