Browse code

core: change the uid and gid for pid and pgid files

- use the user and group given to daemon to update ownership of pid and
pgid files
- reported by Ovidiu Sas, FS#472

Daniel-Constantin Mierla authored on 01/10/2014 15:27:49
Showing 1 changed files
... ...
@@ -272,6 +272,14 @@ int daemonize(char*  name,  int status_wait)
272 272
 	pid_t pid;
273 273
 	int r, p;
274 274
 	char pipe_status;
275
+	uid_t pid_uid;
276
+	gid_t pid_gid;
277
+
278
+	if(uid) pid_uid = uid;
279
+	else pid_uid = -1;
280
+
281
+	if(gid) pid_gid = gid;
282
+	else pid_gid = -1;
275 283
 
276 284
 	p=-1;
277 285
 	/* flush std file descriptors to avoid flushes after fork
... ...
@@ -360,6 +368,10 @@ int daemonize(char*  name,  int status_wait)
360 368
 		}else{
361 369
 			fprintf(pid_stream, "%i\n", (int)pid);
362 370
 			fclose(pid_stream);
371
+			if(chown(pid_file, pid_uid, pid_gid)<0) {
372
+				LM_ERR("failed to chwon PID file: %s\n", strerror(errno));
373
+				goto error;
374
+			}
363 375
 		}
364 376
 	}
365 377
 
... ...
@@ -384,6 +396,10 @@ int daemonize(char*  name,  int status_wait)
384 396
 			}else{
385 397
 				fprintf(pid_stream, "%i\n", (int)pid);
386 398
 				fclose(pid_stream);
399
+				if(chown(pid_file, pid_uid, pid_gid)<0) {
400
+					LM_ERR("failed to chwon PGID file: %s\n", strerror(errno));
401
+					goto error;
402
+				}
387 403
 			}
388 404
 		}else{
389 405
 			LOG(L_WARN, "we don't have our own process so we won't save"