Get Linux kernel to read link as a PATH ?

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

Get Linux kernel to read link as a PATH ?

#1 Post by sunburnt »

I tried an experiment, I made a link with a PATH as a target.
The stat command shows this:

Code: Select all

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: Select all

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.

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#2 Post by amigo »

Use a variable:
et='/etc:/usr/etc:/usr/local/etc' ; IFS=: ; ls $et

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#3 Post by sunburnt »

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.).?

User avatar
puppyluvr
Posts: 3470
Joined: Sun 06 Jan 2008, 23:14
Location: Chickasha Oklahoma
Contact:

#4 Post by puppyluvr »

:D 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
I am Lead Dog of the
Puppy Linux Users Group on Facebook
Join us!

Puppy since 2.15CE...

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#5 Post by seaside »

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 :D )

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#6 Post by sunburnt »

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.

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#7 Post by amigo »

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: Select all

 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.

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#8 Post by sunburnt »

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: Select all

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: Select all

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...

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#9 Post by technosaurus »

does this help?

Code: Select all

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
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#10 Post by sunburnt »

Hi again technosaurus; I was fiddling with a script like yours...
I used yours "partly" successfully:

Code: Select all

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... 8)
Again remember that this has to work for any command on all paths.

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#11 Post by technosaurus »

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: Select all

#!/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
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#12 Post by sunburnt »

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: Select all

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: Select all

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).

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#13 Post by technosaurus »

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.
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#14 Post by sunburnt »

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.

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#15 Post by sunburnt »

I tried making a link:

Code: Select all

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.

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#16 Post by technosaurus »

cp does and it supports symlinks ... still think you'll need for... in ... do ... done at a minimum though (its faster than find or ls though - which looks like the direction you are going)
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#17 Post by sunburnt »

Yep... I know cp will create links instead of copying files.
I think this is how Tiny Core Linux makes the thousands of links to it`s app`s. squash files.

I think this definitely has to be a file system object ( a true link ).
As I envisioned... It has to work with all path accesses, not just in code.
A legacy system script utility should be able to access through this thing.
Any command should be able to access the paths to do it`s task.

Either that or I`m missing something about what you`re trying to tell me technosaurus.

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#18 Post by technosaurus »

As I envisioned... It has to work with all path accesses, not just in code.
A legacy system script utility should be able to access through this thing.
well then yeah, you'll need to look at coding some C and do an LD_PRELOAD attack on yourself to override things like fopen amongst many others... the whole idea of it wreaks of insecurity and bad idea, especially running as root ... unless that is the goal, in which case, you should probably be using IRC

I totally get what you are saying though - instead of PATH and LD_LIBRARY_PATH ...

let those be
PATH=$PREFIX_PATH/{bin,sbin}
LD_LIBRARY_PATH=$PREFIX_PATH/lib
SYSCONF_PATH=$PREFIX_PATH/etc
LOCALSTATE_PATH=$PREFIX_PATH/var
and so on...

it would certainly simplify applications with the default config files and such
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#19 Post by sunburnt »

Hadn`t thought about security, but a multi-link is no worse then the normal links.
If the link targets a secure dir., access is through permission protocols, right?

The kernel uses code to follow $PATH, so this code could be used to read the path in a link with the same criteria.
IE: Acting upon the first match it finds.
touch, cp, mv, and mkdir are the only commands I can think of at the moment that would create multiple files or dirs.
And what to do with the rm, and rmdir commands? The multi-link specs. say delete first matching item in the paths.
This brings up the possibility of "act on first item found" or "act on all items in all the paths".

The idea has some new conditions it imposes, but nothing very bad I don`t think. More investigating is warranted...

Post Reply