Browse code

core: create runtime dir if doesn't exist

- test and create runtime dir (default /var/run/kamailio)
- do chown of runtime dir if user/group parameters are set for kamailio

Daniel-Constantin Mierla authored on 28/09/2015 21:02:27
Showing 1 changed files
... ...
@@ -1799,6 +1799,7 @@ int main(int argc, char** argv)
1799 1799
 	int dont_fork_cnt;
1800 1800
 	struct name_lst* n_lst;
1801 1801
 	char *p;
1802
+	struct stat st = {0};
1802 1803
 
1803 1804
 	/*init*/
1804 1805
 	time(&up_since);
... ...
@@ -2343,6 +2344,19 @@ try_again:
2343 2343
 		}
2344 2344
 		sock_gid = gid;
2345 2345
 	}
2346
+	/* create runtime dir if doesn't exist */
2347
+	if (stat(runtime_dir, &st) == -1) {
2348
+		if(mkdir(runtime_dir, 0700) == -1) {
2349
+			fprintf(stderr,  "failed to create runtime dir\n");
2350
+			goto error;
2351
+		}
2352
+		if(sock_uid!=-1 || sock_gid!=-1) {
2353
+			if(chown(runtime_dir, sock_uid, sock_gid) == -1) {
2354
+				fprintf(stderr,  "failed to change owner of runtime dir\n");
2355
+				goto error;
2356
+			}
2357
+		}
2358
+	}
2346 2359
 	if (fix_all_socket_lists()!=0){
2347 2360
 		fprintf(stderr,  "failed to initialize list addresses\n");
2348 2361
 		goto error;