From d9c99a29a0d3384c9c3d2adce430f5cb1134ab6a Mon Sep 17 00:00:00 2001 From: Michael Biebl Date: Wed, 30 Mar 2016 00:56:30 +0200 Subject: Imported Upstream version 1.1.92 --- src/main-utils.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'src/main-utils.c') diff --git a/src/main-utils.c b/src/main-utils.c index e0f254b7..86242802 100644 --- a/src/main-utils.c +++ b/src/main-utils.c @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -111,6 +112,31 @@ nm_main_utils_write_pidfile (const char *pidfile) return success; } +void +nm_main_utils_ensure_statedir () +{ + gs_free char *parent = NULL; + int errsv; + + parent = g_path_get_dirname (NMSTATEDIR); + + /* Ensure parent state directories exists */ + if ( parent + && parent[0] == '/' + && parent[1] != '\0' + && g_mkdir_with_parents (parent, 0755) != 0) { + errsv = errno; + fprintf (stderr, "Cannot create parents for '%s': %s", NMSTATEDIR, g_strerror (errsv)); + exit (1); + } + /* Ensure state directory exists */ + if (g_mkdir_with_parents (NMSTATEDIR, 0700) != 0) { + errsv = errno; + fprintf (stderr, "Cannot create '%s': %s", NMSTATEDIR, g_strerror (errsv)); + exit (1); + } +} + void nm_main_utils_ensure_rundir () { @@ -178,7 +204,7 @@ void nm_main_utils_ensure_root () { if (getuid () != 0) { - fprintf (stderr, _("You must be root to run %s!\n"), str_if_set (g_get_prgname (), "")); + fprintf (stderr, _("You must be root to run %s!\n"), g_get_prgname () ?: ""); exit (1); } } -- cgit 1.3.0-6-gf8a5