|
pianod2
multisource multiuser scriptable networked music player
|
Read/write documents and do filesystem interaction. More...
#include <config.h>#include <cstdio>#include <cstring>#include <cstdint>#include <cstdlib>#include <unistd.h>#include <sys/types.h>#include <sys/stat.h>#include <pwd.h>#include <grp.h>#include <iostream>#include <fstream>#include <stdexcept>#include <parsnip/parsnip.h>#include "logging.h"
Macros | |
| #define | SYSCONFDIR "/etc" |
Functions | |
| static bool | running_as_root (void) |
| static char * | select_nobody_user (const char *nobody_name, const char *group_names) |
| static void | drop_root_privs (void) |
| static void | precreateDirectory (const std::string &directory, bool own) |
| Ensure the pianod configuration directory is owned by the user we become when dropping root privileges. More... | |
| static std::string | getConfigDirectory (const char *location, const char *home, const char *package) |
| Determine the configuration directory in accordance with the Free Desktop Base Directory Specification. More... | |
| const std::string & | setupConfigDirectory (const char *location, const char *package, const char *nobody_name, const char *nobody_groups_list) |
| Choose and configure a directory for configuration files. More... | |
| bool | carefullyWriteFile (std::string filename, Parsnip::Data &document) |
| Write a document into a file. More... | |
| const Parsnip::Data | retrieveJsonFile (std::string filename, int minimum_version) |
| Restore from a file. More... | |
Variables | |
| static const char * | FileCreator = "author" |
| static const char * | FileCreatorVersion = "version" |
| static std::string | config_directory |
| static bool | have_nobody = false |
| static struct passwd | nobody |
| static gid_t * | nobody_groups |
| static int | nobody_groups_count |
Read/write documents and do filesystem interaction.
| #define SYSCONFDIR "/etc" |
| bool carefullyWriteFile | ( | std::string | filename, |
| Parsnip::Data & | document | ||
| ) |
Write a document into a file.
Write into a temporary file, and when complete, then rename files so as to keep as backup while moving the new file into place. If compression is supported, writes compressed file; otherwise, writes uncompressed JSON. This is set at compile time, with no run-time choice.
| filename | The filename, without path. |
| document | The document to write. Top level must be a document. |
document parameter is altered to contain authoring package identification. 

|
static |


|
static |
Determine the configuration directory in accordance with the Free Desktop Base Directory Specification.
| location | Put config files in this directory if specified. |
| home | Use this directory instead of $HOME if specified. |
| package | This package's name. |


|
static |
Ensure the pianod configuration directory is owned by the user we become when dropping root privileges.

| const Parsnip::Data retrieveJsonFile | ( | std::string | filename, |
| int | minimum_version | ||
| ) |
Restore from a file.
Tries .gz (if supported) first, then falls back to uncompressed version.
| filename | The filename, without path. |
| minimum_version | The lowest file format version number supported. If the input file has a version number lower than this, a DataFormatException is thrown. |
| bad_alloc,io_base::failure,or | a Parsnip serialization exception. |


|
static |

|
static |


| const std::string& setupConfigDirectory | ( | const char * | location, |
| const char * | package, | ||
| const char * | nobody_name, | ||
| const char * | nobody_groups_list | ||
| ) |
Choose and configure a directory for configuration files.
| location | Pathname to use, or nullptr to use default. |
| package | Name of this package. |
| nobody_name | Name of user to run as, if running as root. |
| nobody_groups_list | List of groups to adopt before giving up root privs. |


|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |