Current working directory

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Current working directory

Rajula Vineet
Hi all,

I am working on improving pharo command line as a part of my GSoC project. I have been looking at different current working directory implementations. I have written a blog post on it. It would be of great help, if you can take a look and give your feedback.

Rajula
Reply | Threaded
Open this post in threaded view
|

Re: Current working directory

Guillermo Polito
Thanks Rajula :)

This is cool!

On Wed, May 17, 2017 at 1:38 PM, Rajula Vineet <[hidden email]> wrote:
Hi all,

I am working on improving pharo command line as a part of my GSoC project. I
have been looking at different current working directory implementations. I
have written a  blog post
<https://vineetreddy.wordpress.com/2017/05/17/pwd-vs-getcwd/>   on it. It
would be of great help, if you can take a look and give your feedback.

Rajula



--
View this message in context: http://forum.world.st/Current-working-directory-tp4947453.html
Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.




--

   

Guille Polito


Research Engineer

French National Center for Scientific Research - http://www.cnrs.fr



Web: http://guillep.github.io

Phone: +33 06 52 70 66 13

Reply | Threaded
Open this post in threaded view
|

Re: Current working directory

philippeback
Definitely.

I read that you had a crash and you didn't know why.

It is a good idea to run pharo under gdb so you can do a bt (backtrace) and see where it bombed.
You can inspect parameters etc. Usually this is revealing of the problem when I do like that.

Check http://stackoverflow.com/questions/6121094/how-do-i-run-a-program-with-commandline-args-using-gdb-within-a-bash-script

Like 

gdb -ex=r --args pharo-vm/pharo Pharo.image

(not sure this is all right, but you'll figure it out).

I also like to use a debug or assert VM so that I get all debugging symbols information.

Alternatively, connect to a running Pharo with gdb -p PID

I usually do that from something like Code::Blocks with an assert VM + source code around for whatever library I am trying to use from UFFI. Works nicely. Especially when you put a breakpoint before a crashing site, allowing you to see the stackframes etc.

With gdb command line, it is worth knowing about frames: http://www.delorie.com/gnu/docs/gdb/gdb_44.html

Namaste,

Phil








On Wed, May 17, 2017 at 2:08 PM, Guillermo Polito <[hidden email]> wrote:
Thanks Rajula :)

This is cool!

On Wed, May 17, 2017 at 1:38 PM, Rajula Vineet <[hidden email]> wrote:
Hi all,

I am working on improving pharo command line as a part of my GSoC project. I
have been looking at different current working directory implementations. I
have written a  blog post
<https://vineetreddy.wordpress.com/2017/05/17/pwd-vs-getcwd/>   on it. It
would be of great help, if you can take a look and give your feedback.

Rajula



--
View this message in context: http://forum.world.st/Current-working-directory-tp4947453.html
Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.




--

   

Guille Polito


Research Engineer

French National Center for Scientific Research - http://www.cnrs.fr



Web: http://guillep.github.io

Phone: <a href="tel:+33%206%2052%2070%2066%2013" value="+33652706613" target="_blank">+33 06 52 70 66 13


Reply | Threaded
Open this post in threaded view
|

Re: Current working directory

K K Subbu
In reply to this post by Rajula Vineet
On Wednesday 17 May 2017 05:08 PM, Rajula Vineet wrote:
> Hi all,
>
> I am working on improving pharo command line as a part of my GSoC project. I
> have been looking at different current working directory implementations. I
> have written a  blog post
> <https://vineetreddy.wordpress.com/2017/05/17/pwd-vs-getcwd/>   on it. It
> would be of great help, if you can take a look and give your feedback.
Vineet,

Don't depend on getenv(). It is the parent (e.g. sh) which sets PWD to
the current working directory before exec-ing your program. When a child
process is spawned, the parent can decide not to pass this down to
child. e.g.

$ env -u PWD ./try

Or, if the child process changes its working directory using chdir(),
PWD will not change. e.g.

--- try.c ---
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <limits.h>

int main(int argc, char *argv[])
{
        char cwd[PATH_MAX];

        for(;;) {
                if (getcwd(cwd, sizeof(cwd)) != NULL)
                        printf("getcwd: %s\n", cwd);
                else
                        perror("getcwd() error");
                printf("PWD: %s\n", getenv("PWD"));
                if (argv[1]) {
                        printf("chdir %s\n", argv[1]);
                        chdir(argv[1]);
                        argc--; argv++;
                }
                else
                        break;
        }
        return 0;
}
-------

Regards .. Subbu


Reply | Threaded
Open this post in threaded view
|

Re: Current working directory

Ben Coman
In reply to this post by Rajula Vineet
On Wed, May 17, 2017 at 7:38 PM, Rajula Vineet <[hidden email]> wrote:
> Hi all,
>
> I am working on improving pharo command line as a part of my GSoC project. I
> have been looking at different current working directory implementations. I
> have written a  blog post
> <https://vineetreddy.wordpress.com/2017/05/17/pwd-vs-getcwd/>   on it. It
> would be of great help, if you can take a look and give your feedback.
>
> Rajula

I'm not sure what value you might gain from it, but it may be
interesting to review...
https://github.com/lattera/freebsd/blob/master/bin/pwd/pwd.c

(FreeBSD is better to review at since its license is more permissive than Linux)

-----
Back when I was using Pharo on Windows, I was involved in some
discussions regarding the semantics of working directories.  These
weren't brought to a conclusion and remain open questions...

FileSystem on Windows should maintain per drive current working directory
https://pharo.fogbugz.com/f/cases/13094

Windows FileSystem '\test\bar' not an absolute path
http://forum.world.st/Windows-FileSystem-test-bar-not-an-absolute-path-td4748378.html#a4748379

Strange Validation with issue 15820
http://forum.world.st/Strange-Validation-with-issue-15820-td4845673.html#a4845863

-----
Finally some grammar feedback...

where you say...
   Implementation:
   buffer:= String new:100.

better might be...
   Usage:
   buffer:= String new:100.

The implementation would be the method above it ??

cheers -ben

Reply | Threaded
Open this post in threaded view
|

Re: Current working directory

Eliot Miranda-2
In reply to this post by philippeback
Hi Phil, Hi Rajula,

On May 17, 2017, at 5:56 AM, "[hidden email]" <[hidden email]> wrote:

Definitely.

I read that you had a crash and you didn't know why.

It is a good idea to run pharo under gdb so you can do a bt (backtrace) and see where it bombed.
You can inspect parameters etc. Usually this is revealing of the problem when I do like that.

Check http://stackoverflow.com/questions/6121094/how-do-i-run-a-program-with-commandline-args-using-gdb-within-a-bash-script

Like 

gdb -ex=r --args pharo-vm/pharo Pharo.image

(not sure this is all right, but you'll figure it out).

Newer versions of the launch script take --gdb as an argument so you can simply say

    pharo-vm/pharo -gdb Pharo.image

I also like to use a debug or assert VM so that I get all debugging symbols information.

+1

Alternatively, connect to a running Pharo with gdb -p PID

I usually do that from something like Code::Blocks with an assert VM + source code around for whatever library I am trying to use from UFFI. Works nicely. Especially when you put a breakpoint before a crashing site, allowing you to see the stackframes etc.

With gdb command line, it is worth knowing about frames: http://www.delorie.com/gnu/docs/gdb/gdb_44.html

Namaste,

Phil








On Wed, May 17, 2017 at 2:08 PM, Guillermo Polito <[hidden email]> wrote:
Thanks Rajula :)

This is cool!

On Wed, May 17, 2017 at 1:38 PM, Rajula Vineet <[hidden email]> wrote:
Hi all,

I am working on improving pharo command line as a part of my GSoC project. I
have been looking at different current working directory implementations. I
have written a  blog post
<https://vineetreddy.wordpress.com/2017/05/17/pwd-vs-getcwd/>   on it. It
would be of great help, if you can take a look and give your feedback.

Rajula
--
View this message in context: http://forum.world.st/Current-working-directory-tp4947453.html
Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
--

   

Guille Polito


Research Engineer

French National Center for Scientific Research - http://www.cnrs.fr



Web: http://guillep.github.io

Phone: <a href="tel:+33%206%2052%2070%2066%2013" value="+33652706613" target="_blank">+33 06 52 70 66 13

Reply | Threaded
Open this post in threaded view
|

Re: Current working directory

Stephane Ducasse-3
In reply to this post by Rajula Vineet
This super important! We should be able to use Pharo to write script!!!


On Wed, May 17, 2017 at 1:38 PM, Rajula Vineet <[hidden email]> wrote:
Hi all,

I am working on improving pharo command line as a part of my GSoC project. I
have been looking at different current working directory implementations. I
have written a  blog post
<https://vineetreddy.wordpress.com/2017/05/17/pwd-vs-getcwd/>   on it. It
would be of great help, if you can take a look and give your feedback.

Rajula



--
View this message in context: http://forum.world.st/Current-working-directory-tp4947453.html
Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.