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 360
 		}else{
361 361
 			fprintf(pid_stream, "%i\n", (int)pid);
362 362
 			fclose(pid_stream);
363
+			if(chown(pid_file, pid_uid, pid_gid)<0) {
364
+				LM_ERR("failed to chwon PID file: %s\n", strerror(errno));
365
+				goto error;
366
+			}
363 367
 		}
364 368
 	}
365 369
 
... ...
@@ -384,6 +396,10 @@ int daemonize(char*  name,  int status_wait)
384 384
 			}else{
385 385
 				fprintf(pid_stream, "%i\n", (int)pid);
386 386
 				fclose(pid_stream);
387
+				if(chown(pid_file, pid_uid, pid_gid)<0) {
388
+					LM_ERR("failed to chwon PGID file: %s\n", strerror(errno));
389
+					goto error;
390
+				}
387 391
 			}
388 392
 		}else{
389 393
 			LOG(L_WARN, "we don't have our own process so we won't save"