Jump to content
  • Advertisement
Sign in to follow this  

Where to store system wide settings?

This topic is 3121 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'd like my application to have two kinds of settings: settings per user, and system wide settings. The settings per user, I store in "~/.config/appname/settings.xml". For the system-wide settings, I need a folder where any user can read and write to, and that exists in all normal linux distributions. I thought it'd be /etc/, but it turns out that (at least on ubuntu), /etc/ isn't writable to by non-root users! I need a dir where ANYONE can write. I need something that has the same functionality as the folder "CSIDL_COMMON_APPDATA" has in Windows. Does there exist any such folder in typical linux distro's that is destined for that? Or is it impossible to share settings between multiple users in linux without ever having root access?

Share this post


Link to post
Share on other sites
Advertisement
Not impossible, but nontraditional.

I suppose you could make a sub-directory in your program's /etc, say /etc/myprogram/userconfig. Make that directory world readable/writable/executable and set the sticky bit so that it's like /tmp, to keep users from messing with each others files.

Personally (not knowing more about what you're trying to achieve), I'd probably just leave the per-user configuration in the users' home directories. Most users have world readable/executable home directories, so scanning these directories from your program executed by any user shouldn't be too hard.

Share this post


Link to post
Share on other sites
Hmm actually I just made a class called "Persist" which stores named settings in an xml file, with a Win32 and a Linux implementation, and I gave it a flag "global" for system-wide settings. I thought the difference between system-wide and user settings was so common that in unix systems too there'd be a dedicated directory for that. But there isn't so I can't really use the "global" flag and better remove it from the interface of my Persist class since it's not multiplatform.

Share this post


Link to post
Share on other sites
Quote:
Original post by Lode
I thought the difference between system-wide and user settings was so common that in unix systems too there'd be a dedicated directory for that.
There are few settings in Linux that are be *both* system-wide and user-local by default. Those that are both have often been artificially created - look at your .bash_profile: it only inherits system-wide definitions if it manually loads the system-wide .bashrc.

In addition, unix in general takes the position that no unpriviledged user should ever be able to change the system-wide settings. You are free to support system-wide settings, but they can only be set by the super-user/sudoers.

Share this post


Link to post
Share on other sites
Uhm, had a look at http://doc.trolltech.com/4.5/qsettings.html#setPath
And it says /etc/xdg. And yes, I have write access to this. Didn't know it before. Good to know.

Since it's Qt's saying it is probably true?!

regards

Share this post


Link to post
Share on other sites
Quote:
Original post by hydroo
Uhm, had a look at http://doc.trolltech.com/4.5/qsettings.html#setPath
And it says /etc/xdg. And yes, I have write access to this. Didn't know it before. Good to know.

Since it's Qt's saying it is probably true?!

regards

Keep in mind this is only defined by freedesktop.org's Base Directory Specification. Presumably you'd need a compliant X desktop installed first. For example, my headless Debian machine doesn't have a /etc/xdg.

Share this post


Link to post
Share on other sites
@mattd: That's because XDG is part of the free desktop specifications. Your headless machine is not a desktop machine :-) If you install Gnome, KDE or any other XDG compliant desktop environment (I think LXDE does it as well) then /etc/xdg should be created.

@Lode: The proper solution is that a normal user should not be able to change system-wide settings. Take for example the network settings or printer settings under Gnome or KDE. A normal user can see them but not change them. They first have to click "Unlock" which makes them root. And root can change the settings. That's what you should add to your application as well.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sander
@mattd: That's because XDG is part of the free desktop specifications. Your headless machine is not a desktop machine :-) If you install Gnome, KDE or any other XDG compliant desktop environment (I think LXDE does it as well) then /etc/xdg should be created.

Yeah, I'm aware :) I'm just saying that relying on that directory existing wouldn't be good for users in my situation.

Share this post


Link to post
Share on other sites
Normal practice for doing this is to have a master config file, generally under /etc, that's not updated by users, and local config files under the user's home directory that override it. For a commercial game that does this, look at UT2004. Really if it's a system wide setting only the admin should be touching it. For a game especially though, it should be possible to install entirely under the ~/ directory for that user and never touch the system itself.

If you still want to though, I guess if you really wanted to share a system wide setting, editable by users, I'd create a folder under /usr/local/share and either create a group for it or give permissions to it to the users group. Highly frowned upon and not a good idea, but still very do-able.

About xdg also, it's locked down on many distro's to not be writable by users due to security concerns

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!