Parcourir la source

Made sure /etc directories exists

Fredrik Haikarainen il y a 10 ans
Parent
révision
cbb147b4e7
1 fichiers modifiés avec 20 ajouts et 1 suppressions
  1. 20
    1
      src/light.c

+ 20
- 1
src/light.c Voir le fichier

@@ -5,6 +5,8 @@
5 5
 #include <string.h>
6 6
 #include <unistd.h>
7 7
 #include <getopt.h>
8
+#include <sys/stat.h>
9
+#include <errno.h>
8 10
 
9 11
 void light_defaultConfig()
10 12
 {
@@ -205,6 +207,8 @@ void light_printHelp(){
205 207
 
206 208
 LIGHT_BOOL light_initialize(int argc, char** argv)
207 209
 {
210
+  int mkdirVal;
211
+
208 212
   light_defaultConfig();
209 213
   if(!light_parseArguments(argc, argv))
210 214
   {
@@ -216,7 +220,22 @@ LIGHT_BOOL light_initialize(int argc, char** argv)
216 220
   {
217 221
       return TRUE;
218 222
   }
219
-  
223
+
224
+  /* Make sure we have a valid /etc/light directory, as well as /etc/light/mincap */
225
+  mkdirVal = mkdir("/etc/light", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
226
+  if(mkdirVal != 0 && errno != EEXIST)
227
+  {
228
+    LIGHT_ERR("/etc/light does not exist and could not be created");
229
+    return FALSE;
230
+  }
231
+
232
+  mkdirVal = mkdir("/etc/light/mincap", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
233
+  if(mkdirVal != 0 && errno != EEXIST)
234
+  {
235
+    LIGHT_ERR("/etc/light/mincap does not exist and could not be created");
236
+    return FALSE;
237
+  }
238
+
220 239
   /* Make sure we have a valid controller before we proceed */
221 240
   if(light_Configuration.controllerMode == LIGHT_AUTO)
222 241
   {