On Sun, Mar 22, 2009 at 22:05, Alexander Hjalmarsson <hja...@sgh.se> wrote: > -----Original Message----- > From: Sorin Manolache [mailto:sor...@gmail.com] > Sent: den 22 mars 2009 19:57 > To: modules-dev@httpd.apache.org > Subject: Re: path problem > > On Sun, Mar 22, 2009 at 11:24, Alexander Hjalmarsson <hja...@sgh.se> wrote: >> Hi! >> >> I want to get the path in a module I've created but I have some kind of >> problem with it. It just works like the ordinary "pwd", and in 30% of the >> cases it works like it should, but in the rest, it doesn't return anything >> at all. >> >> if ((buffad = (char *)malloc((size_t)sizead)) != NULL) >> ptrad = getcwd(buffad, (size_t)sizead); >> >> That is the call that is made, and buffed is a char *, as well as ptrad. >> sizead is a long. >> >> Can this be a problem with permissions or something? The only cases that > it >> do work for is when theres a more advanced script that is called, such as > a >> forum or a blog (phpbb or wordpress in example). For normal, static html >> pages, it just returns "/" instead of the real path. >> >> I've checked all the paths by writing each request to a file so I manually >> can check them. I can't see why it should have anything to do with >> permissions, but since it does work in some cases but not all, that's my >> first thought. >> >> I would love all kind of help here! Feel free to ask anything, I'll try to >> answer as good as I can! >> >> I've tried on all kind of forums, irc-networks and mailing lists with no >> luck, but I guess this is the "right" place :) > > Hello, > > getcwd returns the working directory of the apache process. It has > nothing to do with modules. > > A process may work in any directory. If, after it starts running, the > process performs a chdir(whatever_existing_dir) system call, all > subsequent calls to getcwd will return whatever_existing_dir. You can > see the working directory of a process with process ID x by running > > ls -l /proc/x/cwd > > Which path do you want to get? The path of the served file? > > S > > -- > A: Because it reverses the logical flow of conversation. > Q: Why is top-posting frowned upon? > A: Top-posting. > Q: What is the most annoying thing in e-mail? > -------- > > I'm sorry if I wasn't clear with my question! I want the path of the served > file and the problem is that it doesn't always returns the correct path, > sometimes it just returns "/". > > In example, if the served file is domain.com/index.html, the path should be > /www/domain/a/b/c/abc/htdocs/index.html, but then without the index.html, > since the directory path is just /www/domain/a/b/c/abc/htdocs/. That is the > structure I have now, but in most cases it doesn't work. As I said before, > it looks like it works more often with forum software and blog software then > static content or non-complex php-scripts. I would really love to solve > this, so thank you for answering so far:) > >
Please read again my previous answer why getcwd is not the solution. Also read the man page of getcwd. I think r->filename should be what you're looking for, where r is a pointer to the request_rec of the currently served request. Pass r->filename to dirname() (man 3 dirname) in order to extract the directory name from the path of the served file. Sorin -- A: Because it reverses the logical flow of conversation. Q: Why is top-posting frowned upon? A: Top-posting. Q: What is the most annoying thing in e-mail?