Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Mon 28 Jul 2014, 22:43
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Get Linux kernel to read link as a PATH ?
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 2 [19 Posts]   Goto page: 1, 2 Next
Author Message
sunburnt


Joined: 08 Jun 2005
Posts: 5010
Location: Arizona, U.S.A.

PostPosted: Tue 06 Dec 2011, 12:03    Post subject:  Get Linux kernel to read link as a PATH ?  

I tried an experiment, I made a link with a PATH as a target.
The stat command shows this:
Code:
sh-4.1# stat et
  File: `et' -> `/etc:/usr/etc:/usr/local/etc'
  Size: 28           Blocks: 0          IO Block: 4096   symbolic link
Device: bh/11d   Inode: 8007        Links: 1
Access: (0777/lrwxrwxrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2011-12-04 15:41:40.000000000 -0700
Modify: 2011-12-04 15:41:40.000000000 -0700
Change: 2011-12-04 15:41:40.000000000 -0700

But to try to use it, the kernel doesn`t know what to do with it ( of course...).
Code:
sh-4.1# ls et
et

Can anyone think of a way to get it to work?
Kernel programming changes needed may not be all that bad.
Could reuse kernel code used for $PATH, or maybe easier to write new code.
Back to top
View user's profile Send private message 
amigo

Joined: 02 Apr 2007
Posts: 2221

PostPosted: Tue 06 Dec 2011, 15:03    Post subject:  

Use a variable:
et='/etc:/usr/etc:/usr/local/etc' ; IFS=: ; ls $et
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 5010
Location: Arizona, U.S.A.

PostPosted: Tue 06 Dec 2011, 19:20    Post subject:  

Hi amigo; I tried you`re suggestion and "ls $et" gives the dir. listing of /root (where et is).
I have the link: et
I ran rxvt and typed: IFS=:
Then I typed: ls $et

Is this correct?
I was suprised to see "ls" echo something other than "et"
How to make it echo the contense of the et path (all the dirs.).?
Back to top
View user's profile Send private message 
puppyluvr


Joined: 06 Jan 2008
Posts: 3186
Location: Chickasha Oklahoma

PostPosted: Tue 06 Dec 2011, 19:27    Post subject:  

Very Happy Hello,
Is "et" in the Path?
IE.. /root/my-applications/bin?
@Edit..
Maybe I misunderstood...
Im not sure of your intended result...
Would an alias do it...
A symlink is a link with a path in it isnt it?..

I`m over my head..huh???

_________________
Close the Windows, and open your eyes, to a whole new world
http://puppylinuxstuff.meownplanet.net/puppyluvr/
Puppy Linux Users Group on Facebook

Puppy since 2.15CE...
Back to top
View user's profile Send private message Visit poster's website 
seaside

Joined: 11 Apr 2007
Posts: 886

PostPosted: Tue 06 Dec 2011, 20:45    Post subject:  

sunburnt wrote:

I have the link: et et is NOT a variable
I ran rxvt and typed: IFS=:
Then I typed: ls $et

Is this correct?
I was suprised to see "ls" echo something other than "et"
How to make it echo the contense of the et path (all the dirs.).?


sunburnt,

That link (et) you made to three directories most likely is a broken one. So I think you have to put them in a variable as amigo suggested.

You got the current directory listing because it defaulted when $et was empty.

Regards,
s
(Has ET returned from space Very Happy )
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 5010
Location: Arizona, U.S.A.

PostPosted: Tue 06 Dec 2011, 22:16    Post subject:  

Hey seaside;
Yes, et shows red as the kernel doesn`t know what to do with a link with a path in it.

But how to get the kernel to access the paths like it does $PATH?
PATH and LD_LIBRARY_PATH are the only paths the kernel recognizes.
If the kernel`s PATH code could be used for "micro paths", a variable would work.

This has to be part of the normal file access methods, not just commands.
So any files can be in a path so to speak, not just exec. and libraries.

Like: cat /root/et/someFile.txt
( /etc, /usr/etc, and /usr/local/etc are searched for: someFile.txt )

So it acts just like a link does.
I think you can see what I`m trying to do...
Access the link and all the dirs. in it`s path are accessed just like a link.

# So how to make a variable to act like a link then?

A multi-target link would act like a simple union file system.
But no white-out files and no copy up/down.


puppyluvr; No, et isn`t in the path, doesn`t matter if it is...
It`s a link with multiple target dirs. I want to act sort of like a path does.
As said above, the kernel only does 2 paths and only does links with one target.
Back to top
View user's profile Send private message 
amigo

Joined: 02 Apr 2007
Posts: 2221

PostPosted: Wed 07 Dec 2011, 03:31    Post subject:  

A link cannot contain multiple targets -or, better said, it will not be considered a valid link. You can in fact create a link with any arbitrary text in it, but it will not be valid.

Here's the output from the command I suggested on my box:
Code:
 et='/usr/etc:/usr/local/etc' ; IFS=: ; ls $et     
/usr/etc:
MiniGUI.cfg        kismet_drone.conf  namazu          stuff
bonobo-activation  kismet_ui.conf     pacman-g2       wmconfig
dpidrc             makepkg.conf       pacman-g2.conf
getpixrc           monopd.conf-dist   partimaged
kismet.conf        mplayer            printcap

/usr/local/etc:
kazehakase  tuxprint


It would be better if you explain what you are trying to do so we can help you reach your goal, instead of hoping to arbitrarily impose your implementation on the kernel or other software. The idea that a link could point to more than one object is a no-go. Of course a link could point to a directory which contains the contents of a union mount.
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 5010
Location: Arizona, U.S.A.

PostPosted: Wed 07 Dec 2011, 14:00    Post subject:  

Thanks amigo; This is a Q I`ve asked from time to time over the years.

Any manner that the kernel can automatically search given paths.
It only does this for $PATH (exec.) and $LD_LIBRARY_PATH (libs.).
A link is the closest thing to this, but it can only have one target.

Your example works for "ls", but other commands ( cp ) don`t work.
To run: cp /(multi-link)/someFile
Should copy the first someFile found in the multi-link`s target paths to the current dir..

Code:
sh-4.1# P=0:1
sh-4.1# cp $P/*
cp: missing destination file operand after `0:1/*'
Try `cp --help' for more information.
sh-4.1#

You can see the path isn`t parsed properly with the wildcard file.
Same for this:
Code:
sh-4.1# ls 00/$P
00/0:
file.0

1:
bb_409.mp3_ORG   GSMB-0.5         rox-pinbd     SambaGtk.tar.gz
bb_409_sfx   makeself-2.1.4         rox-pinbd.gz  SambaGtk.tar.gz_ORG
bb_409.tar   makeself_script-part  SambaGtk_sfx  sfx.sh
sh-4.1# ^C
sh-4.1#

The first part of the $P path is 00/0 , but the second part is just 1 .

A hard link points to only files ( I think ).
A sym link points to dirs. and files.
A multi. link would point to only dirs.

As stated, a multi. target link ( or work alike ) would act as a simple union.
A command run on a multi-link effects all of it`s targets in path hierarchy.

To access a multi-link is just like a regular link for each of it`s paths in turn,
until the command can be satisfied or it fails due to no operational matches.
Just like $PATH and $LD_LIBRARY_PATH operate, but for all dirs. and files.

# I don`t know if this clears up my intentions any...
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4280

PostPosted: Thu 08 Dec 2011, 05:52    Post subject:  

does this help?
Code:
et='/etc:/usr/etc:/usr/local/etc:/root/etc'
for x in ${et//:/ }; do echo $x;done


I will elaborate once you've mulled it over a bit.
hint1: you can do it with a function containing [ -e ... ], break and echo/printf

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 5010
Location: Arizona, U.S.A.

PostPosted: Thu 08 Dec 2011, 20:46    Post subject:  

Hi again technosaurus; I was fiddling with a script like yours...
I used yours "partly" successfully:
Code:
sh-4.1# ml() { for x in ${1//:/ }; do echo $x ;done ; }
sh-4.1# e='etc:local/etc'
sh-4.1# find /usr/`ml $e` -name gconf     
/usr/etc/gconf
find: `local/etc': No such file or directory
sh-4.1#

The first path comes out correctly with /usr/ prepended.
But the second fails not having /usr/ prepended.

To work like a link it has to work with pre-paths to the link.
Being a multi-link, it doesn`t have any post-paths after it.

Using `ml (variable)` isn`t quite what I had hoped for, but... Cool
Again remember that this has to work for any command on all paths.
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4280

PostPosted: Fri 09 Dec 2011, 00:44    Post subject:  

by convention, I would call the various etc directories SYSCONF_PATH
(you kinda need the full path, that's where your previous attempt failed)
Code:
#!/bin/sh
FILE=$1
shift
SYSCONF_PATH=${SYSCONF_PATH:-/etc:/usr/etc:/usr/local/etc:$HOME/.etc}
for x in ${SYSCONF_PATH//://$FILE } ; do
[ -e "$x" ] && echo $x
done


the shift is there in case you want to modify it to run:
$@ $x
instead of just echo $x (where $@ is a command with args)

HTH
-Brad

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 5010
Location: Arizona, U.S.A.

PostPosted: Fri 09 Dec 2011, 23:04    Post subject:  

technosaurus; I`m a little lost on how to make this work like a link.
I had hoped for a real file system object...
Like a link with a set extension that the kernel recognizes: ( link name ).mpl
These links could point to a script that would read a file for the path.
But it still takes kernel code to get it to act like a normal link does.
# The cleanest method would be to make the kernel utilize the link-with-path.

# Is there some kernel mechanism I don`t know of that could be exploited?
The C language making system calls to the kernel could probably do it.

Using a variable is kinda like a file system virtual object.
But... It has to be triggered from the file system. ( Any access to the path...)
This access could come from any type of code from anywhere ( old code ).

Your code didn`t work quite right:
Code:
sh-4.1# SYSCONF_PATH=${SYSCONF_PATH:-/etc:/usr/etc:/usr/local/etc}
sh-4.1# echo "$SYSCONF_PATH"
/etc:/usr/etc:/usr/local/etc
sh-4.1# for x in ${SYSCONF_PATH//://gconf } ; do [ -e "$x" ] && echo $x ;done
/etc/gconf
/usr/etc/gconf
/usr/local/etc
sh-4.1#

The final path is echoed even though it has no dir. gconf in it. Easily fixed...

Find reports it correctly of course:
Code:
sh-4.1# for x in `echo $SYSCONF_PATH |sed 's#:# #g'` ;do find $x -name $TARGET ;done
/etc/gconf
/usr/etc/gconf
sh-4.1#

I`m sure my code is much slower due to the number of exec. used (4).
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4280

PostPosted: Fri 09 Dec 2011, 23:51    Post subject:  

Oops forgot there was no colon at the end ... Needs an extra $file there

It was just a template to get you going anyways ... For instance if you only want it to act on the first matching file as in PATH ... just add && break after the command.

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 5010
Location: Arizona, U.S.A.

PostPosted: Sat 10 Dec 2011, 03:33    Post subject:  

A good point, some commands the first match, and some all matches...

I`ll fiddle with it more and let you know... Thanks... Terry B.
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 5010
Location: Arizona, U.S.A.

PostPosted: Tue 13 Dec 2011, 20:57    Post subject:  

I tried making a link:
Code:
ln -s *.x link.x

In the dir. are the dirs.: 0.x, 1.x, 2.x

The link shows red of course, same as a link with a path.
I had hoped a link might at least allow wild cards.
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 2 [19 Posts]   Goto page: 1, 2 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0918s ][ Queries: 11 (0.0058s) ][ GZIP on ]