[GRASS5] temp file permissions: 0666?

Hi,

while working on r.los, I found numerous lines in
GRASS where temporary files are created with 0666 permissions:

creat (tempname, 0666)
                  ^^^^
(and similar)

A good thing?

Markus

Markus Neteler wrote:

while working on r.los, I found numerous lines in
GRASS where temporary files are created with 0666 permissions:

creat (tempname, 0666)
                  ^^^^
(and similar)

A good thing?

Yep.

The actual permissions of the resulting file are obtained by AND-ing
the specified permissions with ones-complement of the process' umask
setting.

E.g. if you pass 0666 to creat(), and the umask is 0022 (which is a
fairly typical setting), the file will have permissions of 0644.

The mode passed to creat() or open(..., O_CREAT) should almost always
be 0666 (except for executable files, where it should be 0777). That
way, the user has maximum control over the actual permissions, via
their umask setting.

[You can set or view the umask for a bash process via the "umask"
built-in command. New processes inherit the umask from their parent,
so putting a umask command into e.g. ~/.bashrc will determine the
umask for all of your processes.]

--
Glynn Clements <glynn@gclements.plus.com>

Glynn Clements wrote:

Markus Neteler wrote:

while working on r.los, I found numerous lines in
GRASS where temporary files are created with 0666 permissions:

creat (tempname, 0666)
                 ^^^^
(and similar)

A good thing?

Yep.

The actual permissions of the resulting file are obtained by AND-ing
the specified permissions with ones-complement of the process' umask
setting.

E.g. if you pass 0666 to creat(), and the umask is 0022 (which is a
fairly typical setting), the file will have permissions of 0644.

The mode passed to creat() or open(..., O_CREAT) should almost always
be 0666 (except for executable files, where it should be 0777). That
way, the user has maximum control over the actual permissions, via
their umask setting.

[You can set or view the umask for a bash process via the "umask"
built-in command. New processes inherit the umask from their parent,
so putting a umask command into e.g. ~/.bashrc will determine the
umask for all of your processes.]

What does happen with umask in this case?:

    execl ("/bin/sh", "sh", "-c", startup, 0);

The problem appeares in DB drivers which create 0666 files even if umask in shell is 0022. How to set umask correctly?

Radim

Radim Blazek wrote:

What does happen with umask in this case?:

    execl ("/bin/sh", "sh", "-c", startup, 0);

The child inherits its umask from the parent.

The problem appeares in DB drivers which create 0666 files even if umask
  in shell is 0022. How to set umask correctly?

lib/db/dbmi_driver/driver.c:

  db_driver(int argc,
      char *argv)
  {
      int stat;
      int procnum;
      int i;
      int rfd, wfd;
      FILE *send, *recv;
  
      umask(0);

Remove that umask() call.

--
Glynn Clements <glynn@gclements.plus.com>