summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-03-21 12:01:26 +0100
committerThomas Haller <thaller@redhat.com>2016-03-21 13:31:40 +0100
commitacf9496ccf4c8186fc3d393b3810eaa968abbce6 (patch)
treef31f328f2d24d0ba0fd5bea512283503c3c6f1ed
parent8297683605c56efc96defbbb622ff8af8e05bb91 (diff)
downloadNetworkManager-acf9496ccf4c8186fc3d393b3810eaa968abbce6.tar.gz
main: create parent directories of NMSTATEDIR with permissions 755
In case, "$PREFIX/var/lib" does not exist, we want to create those directories with permissions 755, not 700.
-rw-r--r--src/main-utils.c26
-rw-r--r--src/main-utils.h1
-rw-r--r--src/main.c7
3 files changed, 28 insertions, 6 deletions
diff --git a/src/main-utils.c b/src/main-utils.c
index 7385e9c2a4..8624280221 100644
--- a/src/main-utils.c
+++ b/src/main-utils.c
@@ -29,6 +29,7 @@
#include <sys/stat.h>
#include <locale.h>
+#include <glib/gstdio.h>
#include <glib-unix.h>
#include <gmodule.h>
@@ -112,6 +113,31 @@ nm_main_utils_write_pidfile (const char *pidfile)
}
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 ()
{
/* Setup runtime directory */
diff --git a/src/main-utils.h b/src/main-utils.h
index cae97b57a5..10ba3135f9 100644
--- a/src/main-utils.h
+++ b/src/main-utils.h
@@ -27,6 +27,7 @@ void nm_main_utils_ensure_root (void);
void nm_main_utils_setup_signals (GMainLoop *main_loop);
+void nm_main_utils_ensure_statedir (void);
void nm_main_utils_ensure_rundir (void);
gboolean nm_main_utils_write_pidfile (const char *pidfile);
diff --git a/src/main.c b/src/main.c
index bf1224dfd6..4616155d9a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -309,12 +309,7 @@ main (int argc, char *argv[])
nm_main_utils_ensure_not_running_pidfile (global_opt.pidfile);
- /* Ensure state directory exists */
- if (g_mkdir_with_parents (NMSTATEDIR, 0700) != 0) {
- fprintf (stderr, "Cannot create '%s': %s", NMSTATEDIR, strerror (errno));
- exit (1);
- }
-
+ nm_main_utils_ensure_statedir ();
nm_main_utils_ensure_rundir ();
/* When running from the build directory, determine our build directory