Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^6: umask when calling xterm from perl

by Special_K (Monk)
on Apr 11, 2019 at 15:52 UTC ( [id://1232452]=note: print w/replies, xml ) Need Help??


in reply to Re^5: umask when calling xterm from perl
in thread umask when calling xterm from perl

I ran system("env > ~/env_before_xterm") in perl right before launching the xterm window, and then in the xterm window I ran "env > ~/env_within_xterm. When I diff the results, the only differences are the following variables:

MANPATH PWD REMOTEHOST SHLVL TMPDIR WINDOWID _

Additionally, the following variables are present in the env inside the xterm but not in the env within perl:

XTERM_LOCALE XTERM_SHELL XTERM_VERSION

None of these seem to have anything to do with umask values. Is there anything else I can check?

Replies are listed 'Best First'.
Re^7: umask when calling xterm from perl
by hippo (Bishop) on May 09, 2019 at 10:08 UTC
    None of these seem to have anything to do with umask values. Is there anything else I can check?

    They don't have anything explicitly to do with umask, but the fact that they are different shows that something is changing the enviroment and that something could just as easily change the umask. Your task is to determine what that something is. Look through all the shell initialisation files both for your user and at the system-wide level. You will hopefully find whatever it is that is changing the umask there. Good luck.

Re^7: umask when calling xterm from perl
by bliako (Monsignor) on May 09, 2019 at 11:13 UTC

    because of the latest answer to your post, i have just seen your post and answering now.

    In linux I can enquire umask using /usr/bin/umask. In my case, env does not report anything about umask. Umask is usually set when a shell like bash starts. For bash that happens probably via ~/.bashrc, /etc/bashrc, /etc/profile. But for other shells, like csh it could be in other files. So, each shell has its own configuration setup and somewhere in there should be a umask. Of course you could insert one yourself umask 022 at the end of your ~/.bashrc and that will overwrite any previous umask settings.

    When you run system("env ...") you will get the ENV of some shell that Perl spawns via system(). (In my system that's sh). When you run system("xterm") you will create an xterm which will then launch a shell. Now which shell will that be? Perhaps $XTERM_SHELL can give you a hint. The new shell will inherit environment from parent and also read configuration from rc files. Sometimes Perl's system() will not launch a new shell just to run your command but instead it will run the command directly if it's possible. So, if it launches a shell, that could be sh. (In my system, system("xterm") causes Perl to run a sh -c xterm which in turn spawns a bash shell.) It will then read some configuration files, and then run xterm which launches yet another shell which inherits env from parent shell and also reads some configuration from its own rc files. If your current shell is bash but xterm launches sh, then it's possible to have different umasks.

    Regarding ENV inheritance, the following says it all, it creates a shell within a shell which had its umask chamged. The new shell inherit's parent shell's umask:

    % umask 0002 % umask 0 % umask 0000 % bash %% umask 0000 %% exit

    Bottomline: there are a lot of shells being spawned, one inside the other in what you are doing. Shells inherit their environment (and also umask) from parent shells. They also configure using rc files (like ~/.bashrc). If you can find which shell your xterm runs then you can edit its configuration and alter its umask. Alternatively, force xterm to launch the shell you want which reads from the rc file you want:system("echo 'umask 03' > mybashrc; xterm -e '/bin/bash --rcfile mybashrc'"); . For me, this creates an xterm running bash with umask 0003.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1232452]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2024-03-29 12:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found