Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"Gotcha, you snot-necked weenies!" -- Post Bros. Comics


devel / comp.lang.c / Re: Debugging a very simple program to change directories

SubjectAuthor
* Debugging a very simple program to change directoriesBithov Vinu
+- Re: Debugging a very simple program to change directoriesMichael S
+- Re: Debugging a very simple program to change directoriesJohann Klammer
+* Re: Debugging a very simple program to change directoriesPeter van Hooft
|`- Re: Debugging a very simple program to change directoriesKenny McCormack
`- Re: Debugging a very simple program to change directoriesMark Bluemel

1
Debugging a very simple program to change directories

<285c4d88-376a-4012-a5ef-b56b9aa77fa0n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17960&group=comp.lang.c#17960

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a37:9e55:: with SMTP id h82mr9310037qke.42.1629013209737;
Sun, 15 Aug 2021 00:40:09 -0700 (PDT)
X-Received: by 2002:a37:5dc2:: with SMTP id r185mr10537695qkb.186.1629013209059;
Sun, 15 Aug 2021 00:40:09 -0700 (PDT)
Path: i2pn2.org!i2pn.org!paganini.bofh.team!usenet.pasdenom.info!usenet-fr.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sun, 15 Aug 2021 00:40:08 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=86.179.215.44; posting-account=jVhIEwoAAABR5i3grS7Vym8lJdjHRjAz
NNTP-Posting-Host: 86.179.215.44
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <285c4d88-376a-4012-a5ef-b56b9aa77fa0n@googlegroups.com>
Subject: Debugging a very simple program to change directories
From: bithov.v...@gmail.com (Bithov Vinu)
Injection-Date: Sun, 15 Aug 2021 07:40:09 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Bithov Vinu - Sun, 15 Aug 2021 07:40 UTC

I have what is probably the simplest possible useful program in C, under a POSIX system:

#include <unistd.h>
int main(int argc, char* argv[]) {
chdir(argv[1]);
return 0;
}

That's it - no checking for whether argv[1] exists, it just assumes that argv[1] is a real folder and moves you there. When compiled with GCC it doesn't work though - it'll simply exist and "ls" shows no signs that the directory has changed.

How do I fix this?

Re: Debugging a very simple program to change directories

<6a5c476a-1f03-41cd-b9b1-a996131714b3n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17961&group=comp.lang.c#17961

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ac8:b82:: with SMTP id h2mr8882136qti.214.1629013721269;
Sun, 15 Aug 2021 00:48:41 -0700 (PDT)
X-Received: by 2002:a05:620a:448c:: with SMTP id x12mr10326654qkp.39.1629013720984;
Sun, 15 Aug 2021 00:48:40 -0700 (PDT)
Path: i2pn2.org!i2pn.org!paganini.bofh.team!usenet.pasdenom.info!usenet-fr.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sun, 15 Aug 2021 00:48:40 -0700 (PDT)
In-Reply-To: <285c4d88-376a-4012-a5ef-b56b9aa77fa0n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=87.68.183.224; posting-account=ow8VOgoAAAAfiGNvoH__Y4ADRwQF1hZW
NNTP-Posting-Host: 87.68.183.224
References: <285c4d88-376a-4012-a5ef-b56b9aa77fa0n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <6a5c476a-1f03-41cd-b9b1-a996131714b3n@googlegroups.com>
Subject: Re: Debugging a very simple program to change directories
From: already5...@yahoo.com (Michael S)
Injection-Date: Sun, 15 Aug 2021 07:48:41 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Michael S - Sun, 15 Aug 2021 07:48 UTC

On Sunday, August 15, 2021 at 10:40:15 AM UTC+3, Bithov Vinu wrote:
> I have what is probably the simplest possible useful program in C, under a POSIX system:
>
> #include <unistd.h>
> int main(int argc, char* argv[]) {
> chdir(argv[1]);
> return 0;
> }
>
> That's it - no checking for whether argv[1] exists, it just assumes that argv[1] is a real folder and moves you there. When compiled with GCC it doesn't work though - it'll simply exist and "ls" shows no signs that the directory has changed.
>
> How do I fix this?

Impossible, under most, if not all, shells running on POSIX -compliant systems.
Child process has no [direct] way to change directory of parent process.

Of course, I have to say that in comp.lanc.c your question is off topic.

Re: Debugging a very simple program to change directories

<sfagtl$tse$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17962&group=comp.lang.c#17962

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!Y+ifqOXS44A4JUdqg9lb9A.user.46.165.242.91.POSTED!not-for-mail
From: klamm...@NOSPAM.a1.net (Johann Klammer)
Newsgroups: comp.lang.c
Subject: Re: Debugging a very simple program to change directories
Date: Sun, 15 Aug 2021 09:48:58 +0200
Organization: Aioe.org NNTP Server
Message-ID: <sfagtl$tse$1@gioia.aioe.org>
References: <285c4d88-376a-4012-a5ef-b56b9aa77fa0n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="30606"; posting-host="Y+ifqOXS44A4JUdqg9lb9A.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Icedove/24.5.0
X-Notice: Filtered by postfilter v. 0.9.2
 by: Johann Klammer - Sun, 15 Aug 2021 07:48 UTC

On 08/15/2021 09:40 AM, Bithov Vinu wrote:
> I have what is probably the simplest possible useful program in C, under a POSIX system:
>
> #include <unistd.h>
> int main(int argc, char* argv[]) {
> chdir(argv[1]);
> return 0;
> }
>
> That's it - no checking for whether argv[1] exists, it just assumes that argv[1] is a real folder and moves you there. When compiled with GCC it doesn't work though - it'll simply exist and "ls" shows no signs that the directory has changed.
>
> How do I fix this?
>
I believe this is local to the process(your program) and not the bash instance it runs from.

Re: Debugging a very simple program to change directories

<slrnshhhrm.20h.pjvh@xs9.xs4all.nl>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17963&group=comp.lang.c#17963

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!feeder1.feed.usenet.farm!feed.usenet.farm!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!nzpost2.xs4all.net!not-for-mail
Newsgroups: comp.lang.c
From: pjv...@xs9.xs4all.nl (Peter van Hooft)
Subject: Re: Debugging a very simple program to change directories
References: <285c4d88-376a-4012-a5ef-b56b9aa77fa0n@googlegroups.com>
User-Agent: slrn/1.0.3 (Linux)
Message-ID: <slrnshhhrm.20h.pjvh@xs9.xs4all.nl>
Date: 15 Aug 2021 07:51:18 GMT
Lines: 21
NNTP-Posting-Host: 6563676e.usenet.xs4all.nl
X-Trace: G=+w5ePNOg,C=U2FsdGVkX19KY9s2dQlgLNifYlQ1i5xy7ptOyUCHVVQj6vSHLHnkg82DFe1pxBatfCiosWKrIerXEyc3RKx0A1kXp8sLRvkMydx1WBDVpDDwiPl8r0s1djUC2zVhyVMn
X-Complaints-To: abuse@xs4all.nl
 by: Peter van Hooft - Sun, 15 Aug 2021 07:51 UTC

On 2021-08-15, Bithov Vinu <bithov.vinub@gmail.com> wrote:
> I have what is probably the simplest possible useful program in C,
> under a POSIX system:
>
> #include <unistd.h>
> int main(int argc, char* argv[]) {
> chdir(argv[1]);
> return 0;
> }
>
> That's it - no checking for whether argv[1] exists, it just assumes
> that argv[1] is a real folder and moves you there. When compiled with
> GCC it doesn't work though - it'll simply exist and "ls" shows no signs
> that the directory has changed. > > How do I fix this?

Your program does a chdir(), but that doesn't affect the calling program,
probably your shell, so your program doesn't have any effect. You could
exec a shell in your program which would be started in argv[1].

peter

Re: Debugging a very simple program to change directories

<sfak1h$r9cr$1@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17964&group=comp.lang.c#17964

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.lang.c
Subject: Re: Debugging a very simple program to change directories
Date: Sun, 15 Aug 2021 08:42:25 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <sfak1h$r9cr$1@news.xmission.com>
References: <285c4d88-376a-4012-a5ef-b56b9aa77fa0n@googlegroups.com> <slrnshhhrm.20h.pjvh@xs9.xs4all.nl>
Injection-Date: Sun, 15 Aug 2021 08:42:25 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="894363"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Sun, 15 Aug 2021 08:42 UTC

In article <slrnshhhrm.20h.pjvh@xs9.xs4all.nl>,
Peter van Hooft <pjvh@xs9.xs4all.nl> wrote:
>On 2021-08-15, Bithov Vinu <bithov.vinub@gmail.com> wrote:
>> I have what is probably the simplest possible useful program in C,
>> under a POSIX system:
>>
>> #include <unistd.h>
>> int main(int argc, char* argv[]) {
>> chdir(argv[1]);
>> return 0;
>> }
>>
>> That's it - no checking for whether argv[1] exists, it just assumes
>> that argv[1] is a real folder and moves you there. When compiled with
>> GCC it doesn't work though - it'll simply exist and "ls" shows no signs
>> that the directory has changed. > > How do I fix this?
>
>Your program does a chdir(), but that doesn't affect the calling program,
>probably your shell, so your program doesn't have any effect. You could
>exec a shell in your program which would be started in argv[1].

Actually, it does work, if you name your program "cd" and move it into
$HOME/bin (which is on your PATH). Then when you run it from the shell
like this, it will work:

$ cd /tmp
$ ls

The "ls" will list the contents of /tmp.

(Yes, folks, I am kidding)

--
Just for a change of pace, this sig is *not* an obscure reference to
comp.lang.c...

Re: Debugging a very simple program to change directories

<d8829d50-1f1a-40a3-b661-f0a86bf92656n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17968&group=comp.lang.c#17968

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:620a:890:: with SMTP id b16mr12886355qka.433.1629054046590;
Sun, 15 Aug 2021 12:00:46 -0700 (PDT)
X-Received: by 2002:ae9:edd2:: with SMTP id c201mr6398337qkg.495.1629054046403;
Sun, 15 Aug 2021 12:00:46 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sun, 15 Aug 2021 12:00:46 -0700 (PDT)
In-Reply-To: <285c4d88-376a-4012-a5ef-b56b9aa77fa0n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=109.153.60.56; posting-account=3LA7mQoAAAByiBtHIUvpFq0_QEKnHGc9
NNTP-Posting-Host: 109.153.60.56
References: <285c4d88-376a-4012-a5ef-b56b9aa77fa0n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d8829d50-1f1a-40a3-b661-f0a86bf92656n@googlegroups.com>
Subject: Re: Debugging a very simple program to change directories
From: mark.blu...@gmail.com (Mark Bluemel)
Injection-Date: Sun, 15 Aug 2021 19:00:46 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Mark Bluemel - Sun, 15 Aug 2021 19:00 UTC

On Sunday, 15 August 2021 at 08:40:15 UTC+1, Bithov Vinu wrote:
> I have what is probably the simplest possible useful program in C, under a POSIX system:

No. You have a totally useless program.

> #include <unistd.h>
> int main(int argc, char* argv[]) {
> chdir(argv[1]);
> return 0;
> }
>
> That's it - no checking for whether argv[1] exists, it just assumes that argv[1] is a real folder and moves you there. When compiled with GCC it doesn't work though - it'll simply exist and "ls" shows no signs that the directory has changed.

It works perfectly. The problem is your lack of understanding.

> How do I fix this?

Learn about unix-style operating systems. This isn't the right newsgroup for that.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor