Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re^4: umask when calling xterm from perl

by Special_K (Scribe)
on Apr 10, 2019 at 15:42 UTC ( #1232407=note: print w/replies, xml ) Need Help??

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

Would the best way to do this be to just run "env" before calling the xterm and then within the new xterm, and then diff'ing the 2 results?
  • Comment on Re^4: umask when calling xterm from perl

Replies are listed 'Best First'.
Re^5: umask when calling xterm from perl
by hippo (Chancellor) on Apr 10, 2019 at 15:48 UTC

    Yes, that's what I would do. You'll probably have to sort before diff'ing as env itself rarely sorts the output.

      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:


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


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

        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.

        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?

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2020-07-12 10:08 GMT
Find Nodes?
    Voting Booth?

    No recent polls found