Browse code

- write the pgid file only if we have our own pgid

Andrei Pelinescu-Onciul authored on 03/05/2004 11:21:52
Showing 1 changed files
... ...
@@ -142,14 +142,21 @@ int daemonize(char*  name)
142 142
 				goto error;
143 143
 			}
144 144
 		}
145
-		pid=getpgid(0);
146
-		if ((pid_stream=fopen(pgid_file, "w"))==NULL){
147
-			LOG(L_WARN, "unable to create pgid file %s: %s\n",
148
-			    pgid_file, strerror(errno));
149
-			goto error;
145
+		if (own_pgid){
146
+			pid=getpgid(0);
147
+			if ((pid_stream=fopen(pgid_file, "w"))==NULL){
148
+				LOG(L_WARN, "unable to create pgid file %s: %s\n",
149
+					pgid_file, strerror(errno));
150
+				goto error;
151
+			}else{
152
+				fprintf(pid_stream, "%i\n", (int)pid);
153
+				fclose(pid_stream);
154
+			}
150 155
 		}else{
151
-			fprintf(pid_stream, "%i\n", (int)pid);
152
-			fclose(pid_stream);
156
+			LOG(L_WARN, "we don't have our own process so we won't save"
157
+					" our pgid\n");
158
+			unlink(pgid_file); /* just to be sure nobody will miss-use the old
159
+								  value*/
153 160
 		}
154 161
 	}
155 162