run command while remapping file names


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users run command while remapping file names
# 1  
Old 01-24-2012
run command while remapping file names

Is there a way to run an arbitrary command under a specified remapping of path names, i.e. so that when the command opens file named A it would instead open file named B?
Essentially, I'd like to intercept the open() system call and modify its argument.
I've seen references on the web for techniques for doing that, but is there a
simple standalone utility that will run a given command under a given file name remapping?

Thanks for help,

ilya
# 2  
Old 01-24-2012
There's not really a simple standalone utility for that, no. Besides -- you haven't even said what your system is.

There might be smarter ways to do whatever you're trying to accomplish than intercepting system calls to make your application open the wrong files.
# 3  
Old 01-24-2012
Thanks for looking at my question.

The system is x86_64 GNU/Linux, CentOS.

As for other ways, none of them would be as general. This would be a once-and-for-all solution.

Is there some technical reason such a utility doesn't exist, or is it just the lack of demand?

Thanks,

ilya
# 4  
Old 01-24-2012
It's unportable, and insecure -- arguably operating through a security hole that some think shouldn't be permitted. It introduces the possibility for new and interesting bugs inside the open() call itself. And if making system calls lie to the application seems like the best solution, it's either a really badly designed application, or an application restriction that wasn't intended to be circumvented, or just a solution that needs more thinking through. There's almost always a better way, even if it means fixing the broken app.

Also consider the sheer number of system calls that might need trapping. Is open() really the only system call your application needs? what about stat(), unlink(), and the dozens of other system calls that need a filename. It's not as "easy" as it looks on first blush. I tried writing something like this to overload gettimeofday() to make programs run "slower". It worked, sort of, but we found more and more time-related calls which needed to be trapped to work right. Eventually I realized I needed to trap and deal with the hardcoded asm timing-related things in pthreads itself, and gave up. Stuff that alters how kernel calls operate that drastically belongs in the kernel.

One after-the-fact fix I see done with it is libkeepalive, to set TCP keepalive intervals by default whenever a program calls socket(). Since nearly no programs have the ability to do so themselves, and you'd hardly want to set keepalives on every single socket in your system, it can be handy. It's also relatively easy, since it only needs to trap exactly one system call -- socket().

And you haven't explained what your actual goal is, either. Until you do I'm not convinced this would be the best way.

Last edited by Corona688; 01-24-2012 at 06:49 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Exclude certain file names while selectingData files coming in different names in a file name called

Data files coming in different names in a file name called process.txt. 1. shipments_yyyymmdd.gz 2 Order_yyyymmdd.gz 3. Invoice_yyyymmdd.gz 4. globalorder_yyyymmdd.gz The process needs to discard all the below files and only process two of the 4 file names available ... (1 Reply)
Discussion started by: dsravanam
1 Replies

2. Shell Programming and Scripting

Script for telnet and run one command kill it and run another command using while loop

( sleep 3 echo ${LOGIN} sleep 2 echo ${PSWD} sleep 2 while read line do echo "$line" PID=$? sleep 2 kill -9 $PID done < temp sleep 5 echo "exit" ) | telnet ${HOST} while is executing only command and exits. (5 Replies)
Discussion started by: sooda
5 Replies

3. Shell Programming and Scripting

find specific file names and execute a command depending on file's name

Hi, As a newbie, I'm desperate ro make my shell script work. I'd like a script which checks all the files in a directory, check the file name, if the file name ends with "extracted", store it in a variable, if it has a suffix of ".roi" stores in another variable. I'm going to use these two... (3 Replies)
Discussion started by: armando110
3 Replies

4. Shell Programming and Scripting

Getting file names in GREP command

Hi friends, It gives me 3 lines in output which contain word "automation". But along with it I want the script to return file name from which it got the word. How to do it? Plz guide me Anu (4 Replies)
Discussion started by: anushree.a
4 Replies

5. UNIX for Dummies Questions & Answers

command to extract sub-string out of file names

I have these files in a directory. It may have more class than the sample below: DEPT_CHEM101LEC_D_20110301.DAT DEPT_CHEM101LAB_D_20110301.DAT DEPT_BIO105LEC_D_20110325.DAT DEPT_BIO105LAB_D_20110325.DAT DEPT_CSC308LEC_D_20110327.DAT DEPT_CSC308LAB_D_20110327.DAT Is there way to extract out... (5 Replies)
Discussion started by: lv99
5 Replies

6. Shell Programming and Scripting

convert file names to upper case using tr command in Unix

Hi All, Need to convert file names to upper case using tr command in Unix. In a folder -> /apps/dd01/misc there are two files like: pi-abcd.pdf pi-efgh.pdf The output of should be like: pi-ABCD.pdf pi-EFGH.pdf I have used the command to work for a single file at a time... (3 Replies)
Discussion started by: a1_win
3 Replies

7. UNIX for Dummies Questions & Answers

How to list file names instead of lines when grep a gzcat command?

Hi, I want to list filenames instead of lines when i search in compresed files for a string. #gzcat *.gz | grep -l 12345 gives me: <stdin> Anyone got a solution on this problem? (2 Replies)
Discussion started by: HugoH
2 Replies

8. UNIX for Dummies Questions & Answers

How to list file names in a certain date range using ls command?

Hi experts, I Need to print file names in a certain date range using ls:confused:. Please help me with any sample script. Thanks a lot in advance. Regards, Satish (4 Replies)
Discussion started by: satish.vutti
4 Replies

9. UNIX for Dummies Questions & Answers

Copying file names returned from a grep command into another directory

When I do the following : grep -l "string" *, I get a list of file names returned. Is there a way to copy the files returned from the list into another directory ?. Thanks. (4 Replies)
Discussion started by: Kartheg
4 Replies

10. UNIX for Dummies Questions & Answers

find command not giving file names accord. to timestamps

Currently iam working on solaris environment, Iam using find command to get list of all files between any two given dates. But the find command is not listing files accord. to timestamp. I tried using -exec option as -exec ls -ltr {} \; Still the files are not listed according to timestamp..... (8 Replies)
Discussion started by: thanuman
8 Replies
Login or Register to Ask a Question